当前位置: 首页>>代码示例>>Python>>正文


Python pybel.readstring函数代码示例

本文整理汇总了Python中pybel.readstring函数的典型用法代码示例。如果您正苦于以下问题:Python readstring函数的具体用法?Python readstring怎么用?Python readstring使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了readstring函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testSquarePlanar

 def testSquarePlanar(self):
     """Tighten up the parsing of SP stereochemistry in SMILES"""
     good = [
             "C[[email protected]](Cl)(Br)I",
             "C[[email protected]](Cl)(Br)I",
             "C[[email protected]](Cl)(Br)I",
             ]
     bad = [ # raises error
             "C[[email protected]](Cl)(Br)I",
             "C[[email protected]](Cl)(Br)I",
             "C[[email protected]@SP1](Cl)(Br)I",
             "C[[email protected]](Cl)(Br)I",
             "C[[email protected]](Cl)(Br)I",
           ]
     alsobad = [ # just a warning
             "C[[email protected]](Cl)(Br)(F)I",
             "C[[email protected]](Cl)(Br)(F)1CCCC1",
             ]
     for smi in good:
         mol = pybel.readstring("smi", smi)
         self.assertTrue(mol.OBMol.GetData(ob.StereoData))
     for smi in bad:
         self.assertRaises(IOError, pybel.readstring, "smi", smi)
     for smi in alsobad:
         mol = pybel.readstring("smi", smi)
         self.assertTrue(mol.OBMol.GetData(ob.StereoData))
开发者ID:jeffjanes,项目名称:openbabel,代码行数:26,代码来源:testbindings.py

示例2: _generate_conformers

    def _generate_conformers(self, input_sdf, n_conf=10, method="rmsd"):
        """Conformer generation.

        Given an input sdf string, call obabel to construct a specified
        number of conformers.
        """
        import subprocess
        import pybel as pb
        import re

        if n_conf == 0:
            return [pb.readstring("sdf", input_sdf)]

        command_string = 'echo "%s" | obabel -i sdf -o sdf --conformer --nconf %d\
        --score rmsd --writeconformers 2>&-' % (input_sdf, n_conf)
        sdf = subprocess.check_output(command_string, shell=True)
        # Clean the resulting output
        first_match = re.search('OpenBabel', sdf)
        clean_sdf = sdf[first_match.start():]
        # Accumulate molecules in a list
        mols = []
        # Each molecule in the sdf output begins with the 'OpenBabel' string
        matches = list(re.finditer('OpenBabel', clean_sdf))
        for i in range(len(matches) - 1):
            # The newline at the beginning is needed for obabel to
            # recognize the sdf format
            mols.append(
                pb.readstring("sdf", '\n' +
                              clean_sdf[matches[i].start():
                                        matches[i + 1].start()]))
        mols.append(pb.readstring("sdf", '\n' +
                                  clean_sdf[matches[-1].start():]))
        return mols
开发者ID:gianlucacorrado,项目名称:EDeN,代码行数:33,代码来源:molecular_graph.py

示例3: testCan

 def testCan(self):
     can = self.mol.write("can").split()[0]
     smi = self.mol.write("smi").split()[0]
     can_fromsmi = pybel.readstring("smi", smi).write("can").split()[0]
     self.assertEqual(can, can_fromsmi)
     can_fromcan = pybel.readstring("smi", can).write("can").split()[0]
     self.assertEqual(can, can_fromcan)
开发者ID:baoilleach,项目名称:obunittest,代码行数:7,代码来源:PR2498047.py

示例4: prediction

def prediction(request):
    """
    Form for submitting user calculations
    """
    allreceptors = Receptor.objects.all()
    
    
    if 'submitdocking' in request.POST:
        form = SubmitDocking(request.POST)
        form.is_valid()
        smiles = str(form.cleaned_data['smiles'])
        name = form.cleaned_data['name']
        
        error = []
        try:
            pybel.readstring("smi", str(smiles))
        except:
            error.append("Error in SMILES or compound molecular weight too big")
        if not error:
            uniquestring = ''.join(random.choice(string.ascii_lowercase) for x in range(10))
            dockid = adddocking(uniquestring,smiles,name)
            return HttpResponseRedirect('/docking/%s/' % uniquestring)
        else:
            form = SubmitDocking()
            return render(request, 'prediction.html', {'form':form, 'error':error, 'allreceptors':allreceptors})
    else:
        form = SubmitDocking()
        return render(request, 'prediction.html', {'form':form, 'allreceptors':allreceptors})
开发者ID:katrakolsek,项目名称:DoTS,代码行数:28,代码来源:views.py

示例5: print_results

def print_results(results):
    t = PrettyTable(['smiles', 'predicted quality', 'logP', 'molwt'])
    [t.add_row([''.join(mol), predict,
                pybel.readstring('smi', ''.join(mol)).calcdesc(['logP'])['logP'],
                pybel.readstring("smi", ''.join(mol)).molwt])
            for mol, predict in results[:5]]
    print t
开发者ID:IU9-BMSTU,项目名称:Synthesio,代码行数:7,代码来源:logP.py

示例6: testReadSmi

 def testReadSmi(self):
     can = self.mol.write("can")
     smi = self.mol.write("smi")
     fromsmi = pybel.readstring("smi", smi)
     fromcan = pybel.readstring("smi", can)
     self.assertEqual(can, fromsmi.write("can"))
     self.assertEqual(can, fromcan.write("can"))
开发者ID:baoilleach,项目名称:obunittest,代码行数:7,代码来源:PR2694300.py

示例7: testOBMolSeparatePreservesAtomOrder

    def testOBMolSeparatePreservesAtomOrder(self):
        """Originally Separate() preserved DFS order rather
        than atom order"""
        # First test
        smi = "C123.F3.Cl2.Br1"
        mol = pybel.readstring("smi", smi)
        atomicnums = [atom.OBAtom.GetAtomicNum() for atom in mol]
        mols = mol.OBMol.Separate()
        new_atomicnums = [atom.OBAtom.GetAtomicNum() for atom in pybel.Molecule(mols[0])]
        for x, y in zip(atomicnums, new_atomicnums):
            self.assertEqual(x, y) # check that the atoms have not been permuted
        # Second test
        xyz = """6
examples/water_dimer.xyz
O          0.12908       -0.26336        0.64798
H          0.89795        0.28805        0.85518
H          0.10833       -0.20468       -0.33302
O          0.31020        0.07569       -2.07524
H          0.64083       -0.57862       -2.71449
H         -0.26065        0.64232       -2.62218
"""
        mol = pybel.readstring("xyz", xyz)
        mols = mol.OBMol.Separate()
        allatoms = pybel.Molecule(mols[0]).atoms + pybel.Molecule(mols[1]).atoms
        for idx, atom in enumerate(allatoms):
            xcoord = atom.OBAtom.GetX()
            orig_xcoord = mol.OBMol.GetAtom(idx+1).GetX()
            self.assertEqual(xcoord, orig_xcoord)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:28,代码来源:testbindings.py

示例8: testSameCanSpiro

 def testSameCanSpiro(self):
     """Test several representations of the same spiro molecule."""
     can = pybel.readstring("smi", "C1CN[[email protected]]12CCCN2").write("can").split()[0]
     for smile in ['C1CN[[email protected]]12CCCN2', 'C1CN[[email protected]@]21CCCN2',
                    'C1CN[[email protected]@]2(C1)CCN2']:
         mycan = pybel.readstring("smi", smile).write("can").split()[0]
         self.assertEqual(can, mycan, smile)
开发者ID:baoilleach,项目名称:obunittest,代码行数:7,代码来源:PR1805910.py

示例9: testReadingMassDifferenceInMolfiles

    def testReadingMassDifferenceInMolfiles(self):
        """Previously we were rounding incorrectly when reading the mass diff"""
        template = """
 OpenBabel02181811152D

  1  0  0  0  0  0  0  0  0  0999 V2000
    0.0000    0.0000    0.0000 %2s %2d  0  0  0  0  0  0  0  0  0  0  0
M  END
"""
        # Positive test cases:
        # These are the BIOVIA Draw answers for the first 50 elements for
        # a mass diff of 1
        answers = [2,5,8,10,12,13,15,17,20,21,24,25,28,29,32,33,36,41,40,41,46,49,52,53,56,57,60,60,65,66,71,74,76,80,81,85,86,89,90,92,94,97,99,102,104,107,109,113,116,120,123]
        for idx, answer in enumerate(answers):
            elem = idx + 1
            molfile = template % (ob.GetSymbol(elem), 1)
            mol = pybel.readstring("mol", molfile).OBMol
            iso = mol.GetAtom(1).GetIsotope()
            self.assertEqual(answer, iso)

        # Also test D and T - BIOVIA Draw ignores the mass diff
        for elem, answer in zip("DT", [2, 3]):
            molfile = template % (elem, 1)
            mol = pybel.readstring("mol", molfile).OBMol
            iso = mol.GetAtom(1).GetIsotope()
            self.assertEqual(answer, iso)

        # Negative test cases:
        # Test error message for out-of-range values
        for value in [5, -4]:
            molfile = template % ("C", value)
            mol = pybel.readstring("mol", molfile).OBMol
            iso = mol.GetAtom(1).GetIsotope()
            self.assertEqual(0, iso)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:34,代码来源:testbindings.py

示例10: canonicalize

def canonicalize(lig, preserve_bond_order=False):
    """Get the canonical atom order for the ligand."""
    atomorder = None
    # Get canonical atom order

    lig = pybel.ob.OBMol(lig.OBMol)
    if not preserve_bond_order:
        for bond in pybel.ob.OBMolBondIter(lig):
            if bond.GetBondOrder() != 1:
                bond.SetBondOrder(1)
    lig.DeleteData(pybel.ob.StereoData)
    lig = pybel.Molecule(lig)
    testcan = lig.write(format='can')
    try:
        pybel.readstring('can', testcan)
        reference = pybel.readstring('can', testcan)
    except IOError:
        testcan, reference = '', ''
    if testcan != '':
        reference.removeh()
        isomorphs = get_isomorphisms(reference, lig)  # isomorphs now holds all isomorphisms within the molecule
        if not len(isomorphs) == 0:
            smi_dict = {}
            smi_to_can = isomorphs[0]
            for x in smi_to_can:
                smi_dict[int(x[1]) + 1] = int(x[0]) + 1
            atomorder = [smi_dict[x + 1] for x in range(len(lig.atoms))]
        else:
            atomorder = None
    return atomorder
开发者ID:ssalentin,项目名称:plip,代码行数:30,代码来源:supplemental.py

示例11: testAtom4Refs

 def testAtom4Refs(self):
     for mol in self.mols:
         can = mol.write("can")
         smi = mol.write("smi")
         can_fromsmi = pybel.readstring("smi", smi).write("can")
         self.assertEqual(can, can_fromsmi)
         can_fromcan = pybel.readstring("smi", can).write("can")
         self.assertEqual(can, can_fromcan)
开发者ID:baoilleach,项目名称:obunittest,代码行数:8,代码来源:SMILESparser.py

示例12: testMOL

 def testMOL(self):
     """Roundtrip thru MOL file"""
     smi = "C[CH3:6]"
     mol = pybel.readstring("smi", smi)
     molfile = mol.write("mol", opt={"a":True})
     molb = pybel.readstring("mol", molfile)
     out = mol.write("smi", opt={"a":True, "n":True, "nonewline":True})
     self.assertEqual(smi, out)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:8,代码来源:testbindings.py

示例13: testSmilesParsingAndWritingOfLargeIsotopes

 def testSmilesParsingAndWritingOfLargeIsotopes(self):
     smis = ["[1C]", "[11C]", "[111C]", "[1111C]"]
     for smi in smis:
         mol = pybel.readstring("smi", smi)
         self.assertEqual(mol.write("smi").rstrip(), smi)
     self.assertRaises(IOError, pybel.readstring, "smi", "[11111C]")
     mol = pybel.readstring("smi", "[C]")
     mol.atoms[0].OBAtom.SetIsotope(65535)
     self.assertEqual(mol.write("smi").rstrip(), "[C]")
开发者ID:jeffjanes,项目名称:openbabel,代码行数:9,代码来源:testbindings.py

示例14: testSettingSpinMult

 def testSettingSpinMult(self):
     """Set spin and read/write it"""
     mol = pybel.readstring("smi", "C")
     mol.atoms[0].OBAtom.SetSpinMultiplicity(2)
     molfile = mol.write("mol")
     self.assertEqual("M  RAD  1   1   2", molfile.split("\n")[5])
     molb = pybel.readstring("mol", molfile)
     self.assertEqual(2, molb.atoms[0].OBAtom.GetSpinMultiplicity())
     self.assertEqual(4, molb.atoms[0].OBAtom.GetImplicitHCount())
开发者ID:jeffjanes,项目名称:openbabel,代码行数:9,代码来源:testbindings.py

示例15: testRGroup

 def testRGroup(self):
     """[*:1] is converted to R1 in MOL file handling"""
     smi = "[*:6]C"
     mol = pybel.readstring("smi", smi)
     molfile = mol.write("mol")
     self.assertTrue("M  RGP  1   1   6" in molfile)
     molb = pybel.readstring("mol", molfile)
     out = mol.write("smi", opt={"a":True, "n":True, "nonewline":True})
     self.assertEqual(smi, out)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:9,代码来源:testbindings.py


注:本文中的pybel.readstring函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。