def test9Validate(self): vm = rdMolStandardize.RDKitValidation() mol = Chem.MolFromSmiles("CO(C)C", sanitize=False) msg = vm.validate(mol) self.assertEqual(len(msg), 1) self.assertEqual ("""INFO: [ValenceValidation] Explicit valence for atom # 1 O, 3, is greater than permitted""", msg[0]) vm2 = rdMolStandardize.MolVSValidation( [rdMolStandardize.FragmentValidation()]) # with no argument it also works # vm2 = rdMolStandardize.MolVSValidation() mol2 = Chem.MolFromSmiles( "COc1cccc(C=N[N-]C(N)=O)c1[O-].O.O.O.O=[U+2]=O") msg2 = vm2.validate(mol2) self.assertEqual(len(msg2), 1) self.assertEqual ("""INFO: [FragmentValidation] water/hydroxide is present""", msg2[0]) vm3 = rdMolStandardize.MolVSValidation() mol3 = Chem.MolFromSmiles("C1COCCO1.O=C(NO)NO") msg3 = vm3.validate(mol3) self.assertEqual(len(msg3), 2) self.assertEqual ("""INFO: [FragmentValidation] 1,2-dimethoxyethane is present""", msg3[0]) self.assertEqual ("""INFO: [FragmentValidation] 1,4-dioxane is present""", msg3[1]) atomic_no = [6, 7, 8] allowed_atoms = [Atom(i) for i in atomic_no] vm4 = rdMolStandardize.AllowedAtomsValidation(allowed_atoms) mol4 = Chem.MolFromSmiles("CC(=O)CF") msg4 = vm4.validate(mol4) self.assertEqual(len(msg4), 1) self.assertEqual ("""INFO: [AllowedAtomsValidation] Atom F is not in allowedAtoms list""", msg4[0]) atomic_no = [9, 17, 35] disallowed_atoms = [Atom(i) for i in atomic_no] vm5 = rdMolStandardize.DisallowedAtomsValidation(disallowed_atoms) mol5 = Chem.MolFromSmiles("CC(=O)CF") msg5 = vm4.validate(mol5) self.assertEqual(len(msg5), 1) self.assertEqual ("""INFO: [DisallowedAtomsValidation] Atom F is in disallowedAtoms list""", msg5[0]) msg6 = rdMolStandardize.ValidateSmiles("ClCCCl.c1ccccc1O") self.assertEqual(len(msg6), 1) self.assertEqual ("""INFO: [FragmentValidation] 1,2-dichloroethane is present""", msg6[0])
def check_mol_rdkit(self, clean=False): """ Checks validity of rdmol molecule against internal rules Valence electrons Bond order Charge Fragments Args: self: aemol object rdmol: rdkit molecule object Returns: if clean = True: returns cleaned molecule else: returns null """ if self.rdmol == None: self.to_rdkit() rdkit_vm = mol_std.RDKitValidation() molvs_vm = mol_std.MolVSValidation() rdkit_vm.validate(self.rdmol) molvs_vm.validate(self.rdmol) if clean: lfc = mol_stf.LargestFragmentChooser() idx = self.rdmol.GetProp('_Name') self.rdmol = lfc.choose(rself.rdmol) mol_std.Cleanup(self.rdmol) self.rdmol.SetProp('_Name', idx)
def validate_isotopes(mol): """Logs if molecule contains isotopes. Parameters ---------- mol: rdkit.Chem.Mol A molecule. Returns ------- message: str """ validation = [rdMolStandardize.IsotopeValidation()] message = rdMolStandardize.MolVSValidation(validation).validate(mol) return message or None
def validate_neutrality(mol): """Logs if not an overall neutral system. Parameters ---------- mol: rdkit.Chem.Mol A molecule. Returns ------- message: str """ validation = [rdMolStandardize.NeutralValidation()] message = rdMolStandardize.MolVSValidation(validation).validate(mol) return message or None
def validate_fragment(mol): """Logs if certain fragments are present. Parameters ---------- mol: rdkit.Chem.Mol A molecule. Returns ------- message: str """ validation = [rdMolStandardize.FragmentValidation()] message = rdMolStandardize.MolVSValidation(validation).validate(mol) return message or None
def validate_if_no_atom(mol): """Logs an error if the molecule has zero atoms. If the molecule has no atoms, no subsequent validations will run. Parameters ---------- mol: rdkit.Chem.Mol A molecule. Returns ------- message: str """ validation = [rdMolStandardize.NoAtomValidation()] message = rdMolStandardize.MolVSValidation(validation).validate(mol) return message or None
def validate_default(mol): """Performs the default validation which occurs in MolVS. Parameters ---------- mol: rdkit.Chem.Mol A molecule. Returns ------- message: str Notes ----- Default is to do all following validations: validate_if_no_atom, validate_fragment, validate_neutrality, validate_isotopes """ message = rdMolStandardize.MolVSValidation().validate(mol) return message or None