I have implemented this code on a drug dataset of moleculenet.org on google colab but can't find embedding using this code.the code is : from google.colab import files

df = files.upload()

import pandas as pd

df=pd.read_csv("BBBP.csv")

smiles=df['smiles']

from rdkit.Chem import AllChem

from torch_geometric.data import Data, DataLoader

def get_mol_graph(smiles):

# Use RDKit to parse the SMILES string and get the molecular graph

mol = Chem.MolFromSmiles(smiles)

if mol is None: return None

adjacency_matrix = Chem.rdmolops.GetAdjacencyMatrix(mol)

atoms = [atom.GetAtomicNum() for atom in mol.GetAtoms()]

return adjacency_matrix, atoms

def get_data_from_smiles(smiles_list):

data_list = []

for smiles in smiles_list:

graph = get_mol_graph(smiles)

if graph is not None:

data_list.append(Data(x=torch.tensor(graph[1]).unsqueeze(0), edge_index=torch.tensor(graph[0]).unsqueeze(0)))

return data_list

import rdkit

from rdkit import Chem

from rdkit.Chem import AllChem

from torch_geometric.data import Data, DataLoader

def get_mol_graph(smiles):

# Use RDKit to parse the SMILES string and get the molecular graph

mol = Chem.MolFromSmiles(smiles)

if mol is None: return None

adjacency_matrix = Chem.rdmolops.GetAdjacencyMatrix(mol)

atoms = [atom.GetAtomicNum() for atom in mol.GetAtoms()]

return adjacency_matrix, atoms

def get_data_from_smiles(smiles_list):

data = []

for smiles in smiles_list:

graph = get_mol_graph(smiles)

if graph is not None:

data.append(Data(x=torch.tensor(graph[1]).unsqueeze(0), edge_index=torch.tensor(graph[0]).unsqueeze(0)))

return data

import torch

import torch.nn as nn

import torch.nn.functional as F

from torch_geometric.nn import GCNConv

class GraphAutoEncoder(nn.Module):

def __init__(self, input_dim, hidden_dim):

super(GraphAutoEncoder, self).__init__()

self.conv1 = GCNConv(input_dim, hidden_dim)

self.conv2 = GCNConv(hidden_dim, input_dim)

def forward(self, data):

x, edge_index = data.x, data.edge_index

x = self.conv1(x, edge_index)

x = F.relu(x)

x = self.conv2(x, edge_index)

return x

import random

# Set the device

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

# Set the random seed

random.seed

# Load the model and move it to the appropriate device

input_dim = 50

hidden_dim = 32

model = GraphAutoEncoder(input_dim, hidden_dim).to(device)

smiles_list =smiles

# Load the input data

data = get_data_from_smiles(smiles_list)

# Extract the embeddings

embeddings = []

for datum in data:

datum = datum.to(device)

if all(datum.edge_index[0, 0] != datum.edge_index[0, 0]):

embedding = model((datum).detach().cpu().numpy())

embeddings.append(embedding)

for embedding in embeddings:

print(embedding)

This code successfully runs but printed no embedding.Please help me to solve this issue

More Souvik Panda's questions See All
Similar questions and discussions