def draw_molecule(mol: Molecule) -> PIL.Image.Image: """ Draw a single molecule `mol` (make it `PIL.Image.Image`) :param mol: molecule to draw :return: corresponding image to `mol` """ img = Draw.MolToImage(mol.to_rdkit()) return img
def get_graph_data_for_distance_computation(mol): """ Returns graph representation for a molecule. """ if isinstance(mol, str): from mols.molecule import Molecule mol = Molecule(mol) rdk_mol = mol.to_rdkit() rdk_mol = Chem.AddHs(rdk_mol) adj_matrix = Chem.rdmolops.GetAdjacencyMatrix(rdk_mol) bonds = [(b.GetBeginAtomIdx(), b.GetEndAtomIdx()) for b in rdk_mol.GetBonds()] bond_types = [ rdk_mol.GetBondBetweenAtoms(b[0], b[1]).GetBondType() for b in bonds ] atom_idxs = list(range(len(rdk_mol.GetAtoms()))) atomic_numbers = [ rdk_mol.GetAtomWithIdx(idx).GetAtomicNum() for idx in atom_idxs ] atomic_symbols = [ rdk_mol.GetAtomWithIdx(idx).GetSymbol() for idx in atom_idxs ] atomic_masses = [ rdk_mol.GetAtomWithIdx(idx).GetMass() for idx in atom_idxs ] num_atoms = len(atom_idxs) bonds_of_each_atom = [ get_neighbors_and_bond_types(idx, bonds, atomic_symbols, bond_types) for idx in range(num_atoms) ] bond_type_counts_of_each_atom = [ get_bond_type_counts(bt) for bt in bonds_of_each_atom ] # Return graph_data = Namespace( rdk_mol=rdk_mol, adj_matrix=adj_matrix, bonds=bonds, bond_types=bond_types, atom_idxs=atom_idxs, atomic_numbers=atomic_numbers, atomic_symbols=atomic_symbols, atomic_masses=atomic_masses, num_atoms=num_atoms, bonds_of_each_atom=bonds_of_each_atom, bond_type_counts_of_each_atom=bond_type_counts_of_each_atom, ) return graph_data