def array_rep_from_smiles(smiles): """Precompute everything we need from MolGraph so that we can free the memory asap.""" molgraph = graph_from_smiles_tuple(smiles) arrayrep = { 'atom_features': molgraph.feature_array('atom'), 'bond_features': molgraph.feature_array('bond'), 'atom_list': molgraph.neighbor_list('molecule', 'atom'), # List of lists. 'rdkit_ix': molgraph.rdkit_ix_array() } # For plotting only. #print "atom_features", len(arrayrep['atom_features']),len(arrayrep['atom_features'][0]) #print arrayrep['atom_features'] #print "bond_features", len(arrayrep['bond_features']), len(arrayrep['bond_features'][0]) #print arrayrep['bond_features'] #print "atom_list", len(arrayrep['bond_features']), len(arrayrep['bond_features'][0]) #print arrayrep['atom_list'] #print "rdkit_ix", len(arrayrep['bond_features']), len(arrayrep['bond_features'][0]) #print arrayrep['rdkit_ix'] #import pdb;pdb.set_trace() for degree in degrees: arrayrep[('atom_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'atom'), dtype=int) arrayrep[('bond_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'bond'), dtype=int) return arrayrep
def main(): print "This is the file" mol_smile = [('OCC3OC(OCC2OC(OC(C#N)c1ccccc1)C(O)C(O)C2O)C(O)C(O)C3O'),('c1ccsc1')] # mol_smile = mol_smile[1] # m = Chem.MolFromSmiles(mol_smile) # alist = m.GetAtoms() # a = alist[0] print mol_smile molgraph = graph_from_smiles_tuple(mol_smile) arrayrep = {'atom_features' : molgraph.feature_array('atom'), 'bond_features' : molgraph.feature_array('bond'), 'atom_list' : molgraph.neighbor_list('molecule', 'atom'), # List of lists. 'rdkit_ix' : molgraph.rdkit_ix_array()} # For plotting only. for degree in degrees: # import pdb; pdb.set_trace() arrayrep[('atom_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'atom'), dtype=int) #V: The degree of an atom is defined to be its number of directly-bonded neighbors. arrayrep[('bond_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'bond'), dtype=int) # pdb.set_trace() filename = 'varun_visualize_atoms' molecule_idx = 1 highlight_atom_nodes = arrayrep['atom_list'][molecule_idx] highlight_list_rdkit = [arrayrep['rdkit_ix'][our_ix] for our_ix in highlight_atom_nodes] pdb.set_trace() draw_molecule_with_highlights(filename, mol_smile[molecule_idx],highlight_list_rdkit[0:3])
def array_rep_from_smiles(smiles): """extract features from molgraph""" molgraph = graph_from_smiles_tuple(smiles) arrayrep = {'atom_features' : molgraph.feature_array('atom'), 'bond_features' : molgraph.feature_array('bond'), 'atom_list' : molgraph.neighbor_list('molecule', 'atom'), # List of lists. 'rdkit_ix' : molgraph.rdkit_ix_array()} # For plotting only. for degree in degrees: arrayrep[('atom_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'atom'), dtype=int) arrayrep[('bond_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'bond'), dtype=int) return arrayrep
def array_rep_from_smiles(smiles): """Precompute everything we need from MolGraph so that we can free the memory asap.""" molgraph = graph_from_smiles_tuple(smiles) arrayrep = {'atom_features' : molgraph.feature_array('atom'), 'bond_features' : molgraph.feature_array('bond'), 'atom_list' : molgraph.neighbor_list('molecule', 'atom'), # List of lists. 'rdkit_ix' : molgraph.rdkit_ix_array()} # For plotting only. for degree in degrees: # import pdb; pdb.set_trace() arrayrep[('atom_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'atom'), dtype=int) #V: The degree of an atom is defined to be its number of directly-bonded neighbors. arrayrep[('bond_neighbors', degree)] = \ np.array(molgraph.neighbor_list(('atom', degree), 'bond'), dtype=int) # import pdb; pdb.set_trace() return arrayrep