• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pybel.readstring函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testInChIIsotopes

 def testInChIIsotopes(self):
     """Ensure that we correctly set and read isotopes in InChIs"""
     with open(os.path.join(here, "inchi", "inchi_isotopes.txt")) as inp:
         for line in inp:
             if line.startswith("#"): continue
             smi, inchi = line.rstrip().split("\t")
             minchi = pybel.readstring("smi", smi).write("inchi").rstrip()
             self.assertEqual(minchi, inchi)
             msmi = pybel.readstring("inchi", minchi).write("smi").rstrip()
             self.assertEqual(msmi, smi)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:10,代码来源:testbindings.py


示例17: testCML

 def testCML(self):
     """OB stores atom classes using _NN at the end of atom ids"""
     smis = ["[CH3:6]C", "[CH3:6][OH:6]",
             "O"+"[CH2:2]"*27+"O"
             ]
     for smi in smis:
         mol = pybel.readstring("smi", smi)
         cml = mol.write("cml")
         molb = pybel.readstring("mol", cml)
         out = mol.write("smi", opt={"a":True, "n":True, "nonewline":True})
         self.assertEqual(smi, out)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:11,代码来源:testbindings.py


示例18: main

def main():
	if len(sys.argv) < 2:
		print "No input file provided: Murcko.py filetosprocess.ext"
		print "The script will determine which file type to read from by the extension."
		print "It is recommended you run your structures through,\nfor example, ChemAxon's Standardizer first."
		sys.exit(1)
	molnum = 0
	Fragments = dict()
	for mol in pybel.readfile(sys.argv[1].split('.')[1], sys.argv[1]):
		molnum += 1
		if not (molnum % 10):
			print "Molecules processed:", molnum
		#if molnum == 210:
		#	break
		#print mol
		mol.OBMol.DeleteHydrogens()
		smiles = mol.write("smi").split("\t")[0]
		#print smiles
		#out.write(mol)
		#print "Number of rings:", len(mol.sssr)
		canmol = pybel.readstring("smi", smiles)
		FusedRingsMatrix = GetFusedRingsMatrix(canmol)
		FusedRings = GetFusedRings(FusedRingsMatrix, len(canmol.sssr))
		#print FusedRings
		RingSystems = GetAtomsInRingSystems(canmol, FusedRings, inclexo=True)
		# Delete all non-ring atoms: this is now done in GetCanonicalFragments()
		#for ringnum in range(len(mol.sssr)):
		#	mol = pybel.readstring("smi", smiles)
		#	ratoms = list(mol.sssr[ringnum]._path)
		#	#print "Atoms in ring:", sorted(ratoms, reverse=True)
		#	#Delete complementary atoms
		#	remove = list(set(range(1,len(mol.atoms)+1)).difference(set(ratoms)))
		#	for a in sorted(remove, reverse=True):
		#		mol.OBMol.DeleteAtom(mol.atoms[a-1].OBAtom)
		#	#print mol
		#	#out.write(mol)
		# Get all rings/ring systems
		frags = GetCanonicalFragments(smiles, RingSystems)
		for frag in frags:
			if frag in Fragments:
				Fragments[frag] += 1
			else:
				Fragments[frag] = 1

	# Write results to file
	print "Writing results to file."
	out = pybel.Outputfile("sdf", "fragments.sdf", overwrite=True)
	d = Fragments
	for k, v in sorted(d.items(), key=itemgetter(1), reverse=True):
		mol = pybel.readstring("smi", k)
		mol.data["COUNT"] = v
		mol.OBMol.DeleteHydrogens()
		out.write(mol)
	out.close()
开发者ID:dtomer,项目名称:electro-scripts,代码行数:54,代码来源:murko.py


示例19: testAtomMapsAfterDeletion

 def testAtomMapsAfterDeletion(self):
     """Removing atoms/hydrogens should not mess up the atom maps"""
     smis = ["C[NH2:2]", "[CH3:1][NH2:2]"]
     for smi in smis:
         mol = pybel.readstring("smi", smi)
         mol.OBMol.DeleteAtom(mol.OBMol.GetAtom(1))
         self.assertEqual(mol.write("smi", opt={"a":True}).rstrip(), "[NH2:2]")
     smi = "[H]C[NH:2]"
     mol = pybel.readstring("smi", smi)
     mol.removeh()
     self.assertEqual(mol.write("smi", opt={"a":True}).rstrip(), "C[NH:2]")
开发者ID:jeffjanes,项目名称:openbabel,代码行数:11,代码来源:testbindings.py


示例20: testFuzzingTestCases

    def testFuzzingTestCases(self):
        """Ensure that fuzzing testcases do not cause crashes"""

        # rejected as invalid smiles
        smis = [r"\0", "&0", "=&",
                "[H][S][S][[email protected]]0[S][[email protected]](0[[email protected]][S])0n"]
        for smi in smis:
            self.assertRaises(IOError, pybel.readstring, "smi", smi)

        smis = ["c0C[[email protected]](B)00O0"] # warning and stereo ignored
        for smi in smis:
            pybel.readstring("smi", smi)
开发者ID:jeffjanes,项目名称:openbabel,代码行数:12,代码来源:testbindings.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pybind11_tests.ConstructorStats类代码示例发布时间:2022-05-25
下一篇:
Python pybel.readfile函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap