def CheckCTAB(ctab, isSmiles=True): if not __initCalled: initStruchk() mol_str = ctab if not mol_str: raise BadMoleculeException('Unexpected blank or NULL molecule') else: mol_str = _fix_line_ends(mol_str) mol_str = _fix_chemdraw_header(mol_str) if isSmiles: # branch for NULL_MOL checks if mol_str and NULL_SMILES_RE.match(mol_str): rval = T_NULL_MOL else: rval = pyAvalonTools.CheckMoleculeString(mol_str, isSmiles) else: # decompose the ctab into lines # the line terminator may be \n or \r\n, or even r'\n' ctab_lines = mol_str.split('\n') if len(ctab_lines) <= 3: raise BadMoleculeException('Not enough lines in CTAB') _ctab_remove_chiral_flag(ctab_lines) if not _ctab_has_atoms(ctab_lines): rval = T_NULL_MOL else: # reassemble the ctab lines into one string. mol_str = '\n'.join(ctab_lines) rval = pyAvalonTools.CheckMoleculeString(mol_str, isSmiles) return rval
def testStruChkInMemoryLog(self): r = pyAvalonTools.InitializeCheckMol(STRUCHK_INIT_IN_MEMORY_LOGGING) try: (err, fixed_mol) = pyAvalonTools.CheckMoleculeString(atom_clash, False) log = pyAvalonTools.GetCheckMolLog() self.assertTrue("of average bond length from bond" in log) # make sure that the log is cleared for the next molecule (err, fixed_mol) = pyAvalonTools.CheckMoleculeString("c1ccccc1", True) log = pyAvalonTools.GetCheckMolLog() self.assertFalse(log) finally: pyAvalonTools.CloseCheckMolFiles()
def testStruChk(self): smi_good = 'c1ccccc1C1(CC-C(C)C1)C' smi_bad = 'c1c(R)cccc1C1(CC-C(C)C1)C' r = pyAvalonTools.InitializeCheckMol(STRUCHK_INIT) self.assertEqual(r, 0) (err, fixed_mol) = pyAvalonTools.CheckMolecule(smi_good, True) self.assertEqual(err, 0) mol = Chem.MolFromSmiles(smi_good) (err, fixed_mol) = pyAvalonTools.CheckMolecule(mol) self.assertEqual(err, 0) (err, fixed_mol) = pyAvalonTools.CheckMoleculeString(smi_good, True) self.assertEqual(err, 0) self.assertNotEqual(fixed_mol, "") self.assertTrue(fixed_mol.find('M END') > 0) (err, fixed_mol) = pyAvalonTools.CheckMolecule(smi_bad, False) self.assertNotEqual(err, 0) self.assertFalse(fixed_mol) (err, fixed_mol) = pyAvalonTools.CheckMoleculeString(smi_bad, False) self.assertNotEqual(err, 0) self.assertFalse(fixed_mol) pyAvalonTools.CloseCheckMolFiles()