def _testformula(self, num): smile1, sum_forms = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) for i, mol in enumerate(mols): self.assertTrue(i < len(sum_forms)) self.assertEqual(str(mol.get_formula_dict()), sum_forms[i])
def _testformula(self, num): def create_st_sum(st): symbols = [a.symbol for a in (st.references[0], st.references[-1])] symbols.sort() return tuple(symbols + [st.value == st.SAME_SIDE and 1 or -1]) # round 1 smile1 = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) self.assertEqual(len(mols), 1) mol = mols[0] sts1 = [create_st_sum(st) for st in mol.stereochemistry] # round 2 mol.stereochemistry = [] mol.detect_stereochemistry_from_coords() sts2 = [create_st_sum(st) for st in mol.stereochemistry] for stsum in sts2: if not stsum in sts1: # not necessarily an error, we must count changes changes = 0 for (v1, v2) in zip(stsum, sts1[0]): if v1 != v2: changes += 1 self.assertEqual(changes % 2, 0) else: self.assertEqual((stsum in sts1), True)
def _testformula(self, num): smile1, charges = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) comp_charges = [mol.charge for mol in mols] comp_charges.sort() charges = list(charges) charges.sort() self.assertEqual(comp_charges, charges)
def test2(self): """test reactions with some empty parts""" c = smiles.converter() reacts = c.read_text("C=C.[H][H]>>CC") self.assertEqual(len(reacts), 1) react = reacts[0] self.assertEqual(len(react.reagents), 0) self.assertEqual(len(react.reactants), 2) self.assertEqual(len(react.products), 1)
def _testformula(self, num): smile1, match_pair_num, exposed_vs_num = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) self.assertEqual(len(mols), 1) mol = mols[0] mate, nrex = mol.get_maximum_matching() self.assertEqual(nrex, exposed_vs_num) self.assertEqual(len([v for v, m in mate.items() if m != 0]), 2 * match_pair_num)
def _testformula(self, num): smile1, directions = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) self.assertEqual(len(mols), 1) mol = mols[0] sts = [ st.value == st.SAME_SIDE and 1 or -1 for st in mol.stereochemistry ] sts.sort() sts = tuple(sts) self.assertEqual(sts, directions)
def _testformula(self, num): smile1, (explicit_hs, occupied_v, free_v) = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) self.assertEqual(len(mols), 1) mol = mols[0] ns = [v for v in mol.vertices if v.symbol == 'N'] self.assertEqual(len(ns), 1) n = ns[0] self.assertEqual(n.explicit_hydrogens, explicit_hs) self.assertEqual(n.free_valency, free_v) self.assertEqual(n.occupied_valency, occupied_v)
def test1(self): """tests handling of reactions by the SMILES reader on a preparation of methyl-formate""" c = smiles.converter() reacts = c.read_text("O=CO.CO>[H+]>O=COC.O") self.assertEqual(reacts, c.result) self.assertEqual(c.last_status, c.STATUS_OK) self.assertEqual(len(reacts), 1) react = reacts[0] self.assertEqual(len(react.reactants), 2) self.assertEqual(len(react.reactants[0].molecule.atoms), 3) self.assertEqual(len(react.reactants[1].molecule.atoms), 2) self.assertEqual(len(react.reagents[0].molecule.atoms), 1) self.assertEqual(len(react.products[0].molecule.atoms), 4) self.assertEqual(len(react.products[1].molecule.atoms), 1) self.assertEqual(str(react.products[0].molecule.get_formula_dict()), "C2H4O2")
def _testformula(self, num): def create_st_sum(st): symbols = [a.symbol for a in (st.references[0], st.references[-1])] symbols.sort() return tuple(symbols + [st.value == st.SAME_SIDE and 1 or -1]) # round 1 smile1 = self.formulas[num] conv = smiles.converter() mols = conv.read_text(smile1) self.assertEqual(len(mols), 1) mol = mols[0] sts1 = [create_st_sum(st) for st in mol.stereochemistry] # round 2 smile2 = conv.mols_to_text([mol]) mols = conv.read_text(smile1) self.assertEqual(len(mols), 1) mol = mols[0] sts2 = [create_st_sum(st) for st in mol.stereochemistry] for stsum in sts2: self.assertEqual((stsum in sts1), True)
def test_empty_smiles(self): conv = smiles.converter() for text in ("", " "): mols = conv.read_text("") self.assertEqual(mols, [])