本文整理汇总了Python中MolKit.Read.write方法的典型用法代码示例。如果您正苦于以下问题:Python Read.write方法的具体用法?Python Read.write怎么用?Python Read.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MolKit.Read
的用法示例。
在下文中一共展示了Read.write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PDBWriterTests
# 需要导入模块: from MolKit import Read [as 别名]
# 或者: from MolKit.Read import write [as 别名]
class PDBWriterTests(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
if hasattr(self, 'mol'): del self.mol
def test_Write_1(self):
"""
Test the default option of the write method of a PdbWriter.
Just write the ATOM, HETATM and CONECT records and bondOrigin
is File.
"""
# read a molecule
from MolKit import Read
self.mol = Read("Data/1crn.pdb")[0]
# instanciate a PdbWriter and call the write method with the
# default arguments
from MolKit.pdbWriter import PdbWriter
writer = PdbWriter()
writer.write('Data/1crn_writer.pdb', self.mol)
# This should write only the ATOM and CONECT records
# The TER records are automatically created with the ATOM records
# 1- Make sure that the file has been created
import os
self.failUnless(os.path.exists('Data/1crn_writer.pdb'))
# 2- Make sure that the file created the proper records
# Get the default records from the new pdb files
from MolKit.pdbParser import PdbParser
nmol = Read("Data/1crn_writer.pdb")[0]
# COMPARE
ncoords = nmol.allAtoms.coords
ocoords = self.mol.allAtoms.coords
self.assertEqual(ncoords, ocoords)
nname = nmol.allAtoms.name
oname = nmol.allAtoms.name
self.assertEqual(nname, oname)
nbonds = nmol.allAtoms.bonds[0]
obonds = self.mol.allAtoms.bonds[0]
self.assertEqual(len(nbonds), len(obonds))
nbatms = nbonds.atom1+nbonds.atom2
nbatms = nbatms.uniq()
nbatms.sort()
nbatms = nbonds.atom1+nbonds.atom2
nbatms = nbatms.uniq()
nbatms.sort()
os.system("rm Data/1crn_writer.pdb")
def test_Write_2(self):
"""
Test writing out CONECT records for the bonds described in
the pdb file and built by distance.
"""
from MolKit import Read
self.mol = Read("Data/1crn.pdb")[0]
self.mol.buildBondsByDistance()
# instanciate a PdbWriter and call the write method with the
# default arguments
from MolKit.pdbWriter import PdbWriter
writer = PdbWriter()
writer.write('Data/1crn_writer.pdb', self.mol)
from MolKit.pdbParser import PdbParser
nmol = Read("Data/1crn_writer.pdb")[0]
os.system("rm Data/1crn_writer.pdb")
def test_Write_3(self):
"""
Test writing out CONECT records for the bonds described in
the pdb file eventhough the bonds built by distance exist.
"""
from MolKit import Read
self.mol = Read("Data/1crn.pdb")[0]
self.mol.buildBondsByDistance()
# instanciate a PdbWriter and call the write method with the
# default arguments
from MolKit.pdbWriter import PdbWriter
writer = PdbWriter()
writer.write('Data/1crn_writer.pdb', self.mol)
from MolKit.pdbParser import PdbParser
nmol = Read("Data/1crn_writer.pdb")[0]
os.system("rm Data/1crn_writer.pdb")
def test_Write_4(self):
"""
Test writing out the ATOM records and the CONECT records
without the HETATM
"""
from MolKit import Read
self.mol = Read("Data/1bsr.pdb")[0]
# instanciate a PdbWriter and call the write method with the
# default arguments
from MolKit.pdbWriter import PdbWriter
#.........这里部分代码省略.........