コード例 #1
0
 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])
コード例 #2
0
ファイル: tests.py プロジェクト: caiyingchun/OASA
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
コード例 #3
0
ファイル: tests.py プロジェクト: Robot-Will/OASA
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
コード例 #4
0
    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)
コード例 #5
0
ファイル: tests.py プロジェクト: Robot-Will/OASA
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()]
コード例 #6
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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]) 
コード例 #7
0
ファイル: tests.py プロジェクト: caiyingchun/OASA
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()]
コード例 #8
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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)
コード例 #9
0
ファイル: tests.py プロジェクト: Robot-Will/OASA
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]
コード例 #10
0
 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)
コード例 #11
0
 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)
コード例 #12
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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)
コード例 #13
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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)
コード例 #14
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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)
コード例 #15
0
ファイル: tests.py プロジェクト: caiyingchun/OASA
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)
コード例 #16
0
ファイル: tests.py プロジェクト: caiyingchun/OASA
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()
コード例 #17
0
ファイル: tests.py プロジェクト: Robot-Will/OASA
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()
コード例 #18
0
 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)
コード例 #19
0
 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)
コード例 #20
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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)
コード例 #21
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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")
コード例 #22
0
 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")
コード例 #23
0
ファイル: tests.py プロジェクト: Robot-Will/OASA
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)
コード例 #24
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 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)
コード例 #25
0
ファイル: tests.py プロジェクト: caiyingchun/OASA
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)
コード例 #26
0
    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)
コード例 #27
0
ファイル: tests.py プロジェクト: caiyingchun/OASA
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])
コード例 #28
0
 def test_empty_smiles(self):
     conv = smiles.converter()
     for text in ("", "  "):
         mols = conv.read_text("")
         self.assertEqual(mols, [])
コード例 #29
0
ファイル: unittests.py プロジェクト: Robot-Will/OASA
 def test_empty_smiles( self):
   conv = smiles.converter()
   for text in ("", "  "):
     mols = conv.read_text( "")
     self.assertEqual( mols, [])
コード例 #30
0
ファイル: pybel_bridge.py プロジェクト: adelq/oasa
    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()
コード例 #31
0
ファイル: pybel_bridge.py プロジェクト: sctincman/oasa
  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()
コード例 #32
0
ファイル: tests.py プロジェクト: Robot-Will/OASA
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])