Pybel
Pybel 提供了方便的函数和类,让用户使用Open Babel libraries更方便!尤其是 file input/output,以及获取分子的属性。Pybel的函数和类可以与openbabel的OBAtom/OBMol模组进行自由转换。
python项目中,为使用Pybel,需要先 import pybel 或 from pybel import *
原始文献:http://openbabel.org/docs/2.3.1/UseTheLibrary/Python_Pybel.html#id1
Draw函数、原子2D坐标
The draw() method of a Molecule generates 2D coordinates and a 2D depiction ofa molecule.
The defaultoptions are to show the image on the screen (show=True), not towrite to a file (filename=None), to calculate 2D coordinates(usecoords=False) but not to store them (update=False).
原子3D坐标(Atom(OBAtom)类的参数:coords)
If a molecule does not have 3D coordinates, they can be generatedusing the make3D() method. By default, this includes 50 steps of a geometryoptimisation using the MMFF94 forcefield.
读取分子
readfile(format, filename, opt=None)函数 返回的是iterable的迭代器。
readstring(format,string,opt=None)函数 返回一个分子
#使用next函数读取下一个分子:mol=next(readfile("smi","myfile.smi"))
#使用list函数将所有分子排成列表:mols = list(readfile("smi", "myfile.smi"))
#计算总共有多少个原子:
atomtotal = 0 for mol in readfile("sdf", "head.sdf"): atomtotal += len(mol.atoms)
网友评论