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.assert_(i < len(sum_forms)) self.assertEqual(str(mol.get_formula_dict()), sum_forms[i])
def stereo2(): sms = ["C\C=C\C", "C\C=C/C"] c = smiles.converter() c.configuration['R_GENERATE_COORDS'] = True for i, sm in enumerate(sms): m = c.read_text(sm)[0] print m.stereochemistry
def stereo2(): sms = ["C\C=C\C","C\C=C/C"] c = smiles.converter() c.configuration['R_GENERATE_COORDS'] = True for i,sm in enumerate( sms): m = c.read_text( sm)[0] print m.stereochemistry
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 test_rings_in_disconnected_mol(): import smiles sc = smiles.converter() mol = smiles.text_to_mol( "c1ccccc1.c1ccccc1.c1ccccc1CC=C") mol.remove_zero_order_bonds() print mol, mol.is_connected() print [len( c) for c in mol.get_smallest_independent_cycles_e()]
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.assert_( i < len( sum_forms)) self.assertEqual( str( mol.get_formula_dict()), sum_forms[i])
def test_rings_in_disconnected_mol(): import smiles sc = smiles.converter() mol = smiles.text_to_mol("c1ccccc1.c1ccccc1.c1ccccc1CC=C") mol.remove_zero_order_bonds() print mol, mol.is_connected() print[len(c) for c in mol.get_smallest_independent_cycles_e()]
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 stereo(): sms = ["C\C=C\C","C\C=C/C"] c = smiles.converter() c.configuration['R_GENERATE_COORDS'] = True for i,sm in enumerate( sms): fname = "pokus%d.mol" % i m = c.read_text( sm)[0] print [(a.x,a.y) for a in m.vertices]
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, 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, 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 _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 stereo(): sms = ["C\C=C\C", "C\C=C/C"] c = smiles.converter() c.configuration['R_GENERATE_COORDS'] = True for i, sm in enumerate(sms): fname = "pokus%d.mol" % i m = c.read_text(sm)[0] print[(a.x, a.y) for a in m.vertices] f = file(fname, "w") molfile.mol_to_file(m, f)
def test_sdf_processing(): import gzip import molfile, smiles m = molfile.converter() m2 = smiles.converter() f = gzip.open("00000001_00025000.sdf.gz", "r") for mol in m.read_file(f): mol.remove_unimportant_hydrogens() mols = mol.get_disconnected_subgraphs() print m2.mols_to_text(mols) f.close()
def test_sdf_processing(): import gzip import molfile, smiles m = molfile.converter() m2 = smiles.converter() f = gzip.open("00000001_00025000.sdf.gz","r") for mol in m.read_file( f): mol.remove_unimportant_hydrogens() mols = mol.get_disconnected_subgraphs() print m2.mols_to_text( mols) f.close()
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 _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 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 smiles_from_db(): import structure_database import time, sys c = smiles.converter() c.configuration['R_GENERATE_COORDS'] = True i = 0 errors, ok = 0, 0 t = time.time() for hit in structure_database.get_compounds_from_database(): i += 1 try: mol = c.read_text( hit[3]) except: print >> sys.stderr, "CRASH:", hit[3] errors += 1 else: ok += 1 if i % 100 == 0: tm = time.time() - t print "%d, %d ok, %d crashes; %.1f per second" % (i, ok, errors, i/tm)
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 smiles_from_db(): import structure_database import time, sys c = smiles.converter() c.configuration['R_GENERATE_COORDS'] = True i = 0 errors, ok = 0, 0 t = time.time() for hit in structure_database.get_compounds_from_database(): i += 1 try: mol = c.read_text(hit[3]) except: print >> sys.stderr, "CRASH:", hit[3] errors += 1 else: ok += 1 if i % 100 == 0: tm = time.time() - t print "%d, %d ok, %d crashes; %.1f per second" % (i, ok, errors, i / tm)
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 stereo_from_coords2(): f = file("cis_trans_cycles.mol", "r") mol = molfile.file_to_mol(f) f.close() c = smiles.converter() print c.mols_to_text([mol])
def test_empty_smiles(self): conv = smiles.converter() for text in ("", " "): mols = conv.read_text("") self.assertEqual(mols, [])
def test_empty_smiles( self): conv = smiles.converter() for text in ("", " "): mols = conv.read_text( "") self.assertEqual( mols, [])
def update_coords(self): self.ff.UpdateCoordinates(self._amol.OBMol) for patom in self._amol: oatom = self._patom_idx2oatom[patom.idx] oatom.coords = patom.coords if __name__ == "__main__": import time pmol = pybel.readstring("smi", "CC(=O)O") omol = PybelConverter.pybel_to_oasa_molecule(pmol) print(omol) import smiles c = smiles.converter() print(c.mols_to_text([omol])) #print(get_supported_input_formats()) #print(get_supported_output_formats()) if False: import molfile with open("tbu-benzen.mol", 'r') as f: mol = molfile.file_to_mol(f) print(PybelConverter.oasa_to_pybel_molecule(mol)) t = time.time() ff = ForceFieldOptimizer(mol) gen = ff.conjugate_gradients()
def update_coords( self): self.ff.UpdateCoordinates( self._amol.OBMol) for patom in self._amol: oatom = self._patom_idx2oatom[ patom.idx] oatom.coords = patom.coords if __name__ == "__main__": import time pmol = pybel.readstring("smi", "CC(=O)O") omol = PybelConverter.pybel_to_oasa_molecule( pmol) print(omol) import smiles c = smiles.converter() print(c.mols_to_text([omol])) #print(get_supported_input_formats()) #print(get_supported_output_formats()) if False: import molfile with open("tbu-benzen.mol", 'r') as f: mol = molfile.file_to_mol(f) print(PybelConverter.oasa_to_pybel_molecule(mol)) t = time.time() ff = ForceFieldOptimizer( mol) gen = ff.conjugate_gradients()
def stereo_from_coords2(): f = file( "cis_trans_cycles.mol", "r") mol = molfile.file_to_mol( f) f.close() c = smiles.converter() print c.mols_to_text( [mol])