def detect_mixtures(mol, *args, **kwargs): """Detects mixtures. Generates a SMILES out of the entered mol for validation, performs fragment removal, turns the changed mol into another SMILES and validates it with the first SMILES created. Parameters ---------- mol: rdkit.Chem.Mol The molecule which has to be searched for non-organic substructures. Returns ------- boolean: bool Returns if the stucture contains a mixture (True), or not (False). """ smiles_before = _validation_smiles(mol) mol_without_fragment = rdMolStandardize.FragmentRemover().remove(mol) smiles_after = _validation_smiles(mol_without_fragment) if smiles_before == smiles_after: return False else: return True
def test7Fragment(self): fragremover = rdMolStandardize.FragmentRemover() mol = Chem.MolFromSmiles("CN(C)C.Cl.Cl.Br") nm = fragremover.remove(mol) self.assertEqual(Chem.MolToSmiles(nm), "CN(C)C") lfragchooser = rdMolStandardize.LargestFragmentChooser() mol2 = Chem.MolFromSmiles("[N+](=O)([O-])[O-].[CH3+]") nm2 = lfragchooser.choose(mol2) self.assertEqual(Chem.MolToSmiles(nm2), "O=[N+]([O-])[O-]") lfragchooser2 = rdMolStandardize.LargestFragmentChooser( preferOrganic=True) nm3 = lfragchooser2.choose(mol2) self.assertEqual(Chem.MolToSmiles(nm3), "[CH3+]") fragremover = rdMolStandardize.FragmentRemover(skip_if_all_match=True) mol = Chem.MolFromSmiles("[Na+].Cl.Cl.Br") nm = fragremover.remove(mol) self.assertEqual(nm.GetNumAtoms(), mol.GetNumAtoms())
def remove_fragments(mol): """Filters out fragments. A predefined list contains numerous known fragments which can be filtered out. Parameters ---------- mol: rdkit.Chem.Mol A molecule with various fragments. Returns ------- mol: rdkit.Chem.Mol Returns a molecule filtered from known fragments. Notes ----- The predefined list containing fragments is a list REMOVE_FRAGMENTS saved in rdkit/Chem/MolStandardize/fragments.py """ return rdMolStandardize.FragmentRemover().remove(mol)
def test7Fragment(self): fragremover = rdMolStandardize.FragmentRemover() mol = Chem.MolFromSmiles("CN(C)C.Cl.Cl.Br") nm = fragremover.remove(mol) self.assertEqual(Chem.MolToSmiles(nm), "CN(C)C") lfragchooser = rdMolStandardize.LargestFragmentChooser() mol2 = Chem.MolFromSmiles("[N+](=O)([O-])[O-].[CH3+]") nm2 = lfragchooser.choose(mol2) self.assertEqual(Chem.MolToSmiles(nm2), "O=[N+]([O-])[O-]") lfragchooser2 = rdMolStandardize.LargestFragmentChooser( preferOrganic=True) nm3 = lfragchooser2.choose(mol2) self.assertEqual(Chem.MolToSmiles(nm3), "[CH3+]") fragremover = rdMolStandardize.FragmentRemover(skip_if_all_match=True) mol = Chem.MolFromSmiles("[Na+].Cl.Cl.Br") nm = fragremover.remove(mol) self.assertEqual(nm.GetNumAtoms(), mol.GetNumAtoms()) smi3 = "CNC[C@@H]([C@H]([C@@H]([C@@H](CO)O)O)O)O.c1cc2c(cc1C(=O)O)oc(n2)c3cc(cc(c3)Cl)Cl" lfParams = rdMolStandardize.CleanupParameters() lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol3 = Chem.MolFromSmiles(smi3) lfrag3 = lfrag_params.choose(mol3) self.assertEqual(Chem.MolToSmiles(lfrag3), "CNC[C@H](O)[C@@H](O)[C@H](O)[C@H](O)CO") lfParams = rdMolStandardize.CleanupParameters() lfParams.largestFragmentChooserCountHeavyAtomsOnly = True lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol3 = Chem.MolFromSmiles(smi3) lfrag3 = lfrag_params.choose(mol3) self.assertEqual(Chem.MolToSmiles(lfrag3), "O=C(O)c1ccc2nc(-c3cc(Cl)cc(Cl)c3)oc2c1") lfParams = rdMolStandardize.CleanupParameters() lfParams.largestFragmentChooserUseAtomCount = False lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol3 = Chem.MolFromSmiles(smi3) lfrag3 = lfrag_params.choose(mol3) self.assertEqual(Chem.MolToSmiles(lfrag3), "O=C(O)c1ccc2nc(-c3cc(Cl)cc(Cl)c3)oc2c1") smi4 = "CC.O=[Pb]=O" lfParams = rdMolStandardize.CleanupParameters() lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol4 = Chem.MolFromSmiles(smi4) lfrag4 = lfrag_params.choose(mol4) self.assertEqual(Chem.MolToSmiles(lfrag4), "CC") lfParams = rdMolStandardize.CleanupParameters() lfParams.largestFragmentChooserCountHeavyAtomsOnly = True lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol4 = Chem.MolFromSmiles(smi4) lfrag4 = lfrag_params.choose(mol4) self.assertEqual(Chem.MolToSmiles(lfrag4), "O=[Pb]=O") lfParams = rdMolStandardize.CleanupParameters() lfParams.largestFragmentChooserUseAtomCount = False lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol4 = Chem.MolFromSmiles(smi4) lfrag4 = lfrag_params.choose(mol4) self.assertEqual(Chem.MolToSmiles(lfrag4), "O=[Pb]=O") lfParams = rdMolStandardize.CleanupParameters() lfParams.largestFragmentChooserCountHeavyAtomsOnly = True lfParams.preferOrganic = True lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol4 = Chem.MolFromSmiles(smi4) lfrag4 = lfrag_params.choose(mol4) self.assertEqual(Chem.MolToSmiles(lfrag4), "CC") lfParams = rdMolStandardize.CleanupParameters() lfParams.largestFragmentChooserUseAtomCount = False lfParams.preferOrganic = True lfrag_params = rdMolStandardize.LargestFragmentChooser(lfParams) mol4 = Chem.MolFromSmiles(smi4) lfrag4 = lfrag_params.choose(mol4) self.assertEqual(Chem.MolToSmiles(lfrag4), "CC")