def test_smiles_from_adjacent_matrix(smiles): charged_fragments = True quick = True # Cut apart the smiles mol = get_mol(smiles) atoms = get_atoms(mol) charge = Chem.GetFormalCharge(mol) adjacent_matrix = Chem.GetAdjacencyMatrix(mol) # mol = Chem.RemoveHs(mol) canonical_smiles = Chem.MolToSmiles(mol) # Define new molecule template from atoms new_mol = x2m.get_proto_mol(atoms) # reconstruct the molecule from adjacent matrix, atoms and total charge new_mols = x2m.AC2mol(new_mol, adjacent_matrix, atoms, charge, charged_fragments, quick) new_mol_smiles_list = [] for new_mol in new_mols: new_mol = Chem.RemoveHs(new_mol) new_mol_smiles = Chem.MolToSmiles(new_mol) new_mol_smiles_list.append(new_mol_smiles) assert canonical_smiles in new_mol_smiles_list return
def take_elementary_step(mol, charge, E_cutoff, heterolytic, quick): chiral_parent = Chem.FindMolChiralCenters(mol, includeUnassigned=True) parent_is_chiral = len(chiral_parent) > 0 if parent_is_chiral: atom2chirality = {key: value for (key, value) in chiral_parent} atomicNumList = [a.GetAtomicNum() for a in mol.GetAtoms()] proto_mol = xyz2mol.get_proto_mol(atomicNumList) AC = Chem.GetAdjacencyMatrix(mol) num_atoms = len(atomicNumList) I_elementary = get_I_elementary(AC, num_atoms, atomicNumList) smiles_list = [] molecules = [] raw_smiles_list = [] raw_molecules = [] for I in I_elementary: newmol = xyz2mol.AC2mol(proto_mol, I, atomicNumList, charge, heterolytic, quick) if parent_is_chiral: newmol = set_chirality(mol, newmol, atom2chirality) raw_smiles = Chem.MolToSmiles(newmol, isomericSmiles=True) if raw_smiles not in raw_smiles_list: raw_smiles_list.append(raw_smiles) raw_molecules.append(newmol) energy_of_reactant = get_BO_energy(mol) for smiles, raw_mol in zip(raw_smiles_list, raw_molecules): try: test_mol = Chem.MolFromSmiles(smiles) except: continue if test_mol != None: energy = get_BO_energy(raw_mol) if smiles not in smiles_list and energy_of_reactant - energy < E_cutoff: smiles_list.append(smiles) molecules.append(raw_mol) smiles_list.insert(0, Chem.MolToSmiles(mol, isomericSmiles=True)) molecules.insert(0, mol) return smiles_list, molecules
def take_elementary_step(mol, charge, E_cutoff, heterolytic): atomicNumList = [a.GetAtomicNum() for a in mol.GetAtoms()] proto_mol = xyz2mol.get_proto_mol(atomicNumList) AC = Chem.GetAdjacencyMatrix(mol) num_atoms = len(atomicNumList) I_elementary = get_I_elementary(AC, num_atoms, atomicNumList) smiles_list = [] molecules = [] raw_smiles_list = [] raw_molecules = [] for I in I_elementary: newmol = xyz2mol.AC2mol(proto_mol, I, atomicNumList, charge, heterolytic) raw_smiles = Chem.MolToSmiles(newmol) if raw_smiles not in raw_smiles_list: raw_smiles_list.append(raw_smiles) raw_molecules.append(newmol) energy_of_reactant = get_BO_energy(mol) for smiles, raw_mol in zip(raw_smiles_list, raw_molecules): try: test_mol = Chem.MolFromSmiles(smiles) except: continue if test_mol != None: energy = get_BO_energy(raw_mol) if smiles not in smiles_list and energy_of_reactant - energy < E_cutoff: smiles_list.append(smiles) molecules.append(raw_mol) smiles_list.insert(0, Chem.MolToSmiles(mol)) molecules.insert(0, mol) return smiles_list, molecules
#smiles_list = ['[O-]c1ccccc1[O-]'] #smiles_list = ['C[N+](=O)[O-]'] #smiles_list = ['N#CC(C#N)=CC=C1C=CC=CC(=C1)c1ccc(cc1)[N+](=O)[O-]'] #smiles_list = ['CNC([O-])=C([NH+]=C/CC(O)=O)C'] #smiles_list = ['Cc1cn(C2CC(O)C(COP(=O)([O-])OP(=O)([O-])OC3OC(C)C([NH3+])C(O)C3O)O2)c(=O)[nH]c1=O'] for smiles in smiles_list: #print(smiles) mol = Chem.MolFromSmiles(smiles) Chem.Kekulize(mol, clearAromaticFlags = True) charge = Chem.GetFormalCharge(mol) mol = Chem.AddHs(mol) atomicNumList = [a.GetAtomicNum() for a in mol.GetAtoms()] proto_mol = x2m.get_proto_mol(atomicNumList) AC = Chem.GetAdjacencyMatrix(mol) newmol = x2m.AC2mol(proto_mol,AC,atomicNumList,charge,charged_fragments,quick) #print Chem.MolToSmiles(newmol) newmol = Chem.RemoveHs(newmol) newmol_smiles = Chem.MolToSmiles(newmol) #print (newmol_smiles) mol = Chem.RemoveHs(mol) canonical_smiles = Chem.MolToSmiles(mol) if newmol_smiles != canonical_smiles: print("uh,oh", smiles, newmol_smiles)