def uncharge_smiles(smiles): """Utility function that returns the uncharged SMILES for a given SMILES string.""" mol = Chem.MolFromSmiles(smiles) u = Uncharger() mol = u.uncharge(mol) if mol: return Chem.MolToSmiles(mol, isomericSmiles=True)
def normalize(smiles): #print(smiles) # Generate Mol mol = Chem.MolFromSmiles(smiles) # Uncharge uncharger = Uncharger() mol = uncharger.uncharge(mol) # LargestFragmentChooser flagmentChooser = LargestFragmentChooser() mol = flagmentChooser(mol) # Sanitaize Chem.SanitizeMol(mol) # Normalize normalizer = Normalizer() mol = normalizer.normalize(mol) tautomerCanonicalizer = TautomerCanonicalizer() mol = tautomerCanonicalizer.canonicalize(mol) return Chem.MolToSmiles(mol)
def normalize(smiles): #print(smiles) # Generate Mol mol1 = Chem.MolFromSmiles(smiles) # Uncharge uncharger = Uncharger() mol2 = uncharger.uncharge(mol1) # LargestFragmentChooser flagmentChooser = LargestFragmentChooser() try: mol3 = flagmentChooser(mol2) except: try: mol3 = flagmentChooser(mol1) except: mol3 = mol1 # Sanitaize Chem.SanitizeMol(mol3) # Normalize normalizer = Normalizer() mol4 = normalizer.normalize(mol3) #tautomerCanonicalizer = TautomerCanonicalizer() #mol = tautomerCanonicalizer.canonicalize(mol) return Chem.MolToSmiles(mol4)
def FullStandardization(smi): try: mol = Chem.MolFromSmiles(smi) if mol == None: # If rdkit could not parse the smiles, returns Error 1 return "Error 1" else: STD = Standardizer() LFC = LargestFragmentChooser() UC = Uncharger() RI = Reionizer() TC = TautomerCanonicalizer() mol = STD(mol) mol = LFC(mol) allowed_elements = { "H", "B", "C", "N", "O", "F", "Si", "P", "S", "Cl", "Se", "Br", "I" } actual_elements = set( [atom.GetSymbol() for atom in mol.GetAtoms()]) if len(actual_elements - allowed_elements) == 0: mol = UC(mol) mol = RI(mol) RemoveStereochemistry(mol) mol = TC(mol) return Chem.MolToSmiles(mol) else: # If molecule contains other than the allowed elements, returns "Error 2" return "Error 2" except: return "Check manually"
def normalize(smiles): from copy import deepcopy #print(smiles) # Generate Mol mol = Chem.MolFromSmiles(smiles) # Uncharge uncharger = Uncharger() try: mol2 = uncharger.uncharge(mol) except: mol2 = mol mol2 = mol # LargestFragmentChooser flagmentChooser = LargestFragmentChooser() try: mol3 = flagmentChooser(mol2) except: mol3 = mol2 # Sanitaize mol3_tmp = deepcopy(mol3) try: ret = Chem.SanitizeMol(mol3, catchErrors=False) except: mol3 = mol3_tmp # Normalize normalizer = Normalizer() try: mol4 = normalizer.normalize(mol3) except: mol4 = mol3 #print(mol4) tautomerCanonicalizer = TautomerCanonicalizer() mol4 = tautomerCanonicalizer.canonicalize(mol4) new_smiles = Chem.MolToSmiles(mol4) #print(new_smiles) return new_smiles
class Neutralize(CurationStep): """ Class to neutralize compounds """ def __init__(self, **kwargs): self.neutralizer = Uncharger(**kwargs) def filterFunction(self, cmp): return self.neutralizer.uncharge(cmp) def runStep(self, df, cmp_index): df.iloc[:, cmp_index] = [self.filterFunction(mol) for mol in df[cmp_index]] return df
def getNeutralMolecule(mol): uncharger = Uncharger() return uncharger.uncharge(mol)
def __init__(self, **kwargs): self.neutralizer = Uncharger(**kwargs)