使用sql查询的pdb解析器
pdb2sql的Python项目详细描述
PDB2SQL
pdb2sql允许使用sql查询来处理pdb文件。 该项目源于deeprank的开发,目前仍处于开发阶段。
目前有两种策略,一种是使用sqlite3,另一种是sqlalchemy。 sqlalchemy允许使用面向对象的方法,但速度似乎有点慢。
安装
pip install pdb2sql
PDB2SQL
以下脚本在大约0.02秒内将pdb文件“1ak4.pdb”(必须与脚本位于同一文件夹中)加载到sqlite3数据库中。您可以使用pdb2sql.get(attribute,**kwargs)
方法查询数据库。
frompdb2sql.pdb2sqlcoreimportpdb2sql#create the databasedb=pdb2sql('1AK4.pdb')print('SQL %f'%(time()-t0))# get the xyz of all the atomsxyz=db.get('x,y,z',model=0)# get the xyz of all the CA, C, O, N atoms of all VAL and LEU residues of chain Axyz=db.get('x,y,z',chainID='A',resName=['VAL','LEU'],name=['CA','C','O','N'])# move the resiude 1 of chain Axyz=db.get('x,y,z',chainID='A',resSeq=1)xyz=np.array(xyz)xyz-=np.mean(xyz)db.update('x,y,z',xyz,chainID='A',resSeq=1)
SQL查询
sql查询是非常通用的,可以用来返回原子的任何属性和相当复杂的选择。例如:
xyz=db.get('x,y,z',chainID='A',resName=['VAL','LEU'],name=['CA','C','O','N'])
返回链A的所有残基'val'和'leu'的c a、c、n和o原子的位置。可以返回任何其他属性(链id、resname、name…)在第一次辩论中使用它。例如
data=db.get('name,resSeq,resName',chainID='A')
返回链A中所有原子的名称、残数和残数名称。
负条件
负条件也可用于从选择中排除某些特定原子。例如:
data=db.get('name,resSeq,resName',chainID='A',no_name=['H','N'])
返回链a中除氢和氮之外的所有原子的名称、残基数和残基名。以no_
开头的所有条件都被视为否定。因此:
data=db.get('name,resSeq,resName',chainID='A',no_resName=['VAL','LEU'])
将从选择中排除leu和val残基。
修改数据库
数据库的值也可以用pdb2sql.update(attribute,values,kwargs)方法更新。例如
xyz=db.get('x,y,z',chainID='A',resSeq=1)xyz=np.array(xyz)xyz-=np.mean(xyz)db.update('x,y,z',xyz,chainID='A',resSeq=1)
将链a的reseq 1的余数平移到坐标的中心。请注意,名为transform.py的专用模块可以处理xyz坐标的平移、旋转等操作
PDB2SqlAlchemy
sqlalchemy结合了sql查询和面向对象编程。因此pdb2sqlalchemy的工作方式与pdb2sqlcore相同,但返回对象数组而不是嵌套列表。不过,速度有点慢。
frompdb2sql.pdb2sqlAlchemyimportpdb2sql_alchemy#create the databasedb=pdb2sql_alchemy('1AK4.pdb')# extract the xyz position of all VAL and LEU resiues of chain A but not the H atomsxyz=db.get('x,y,z',model=0)#chainID='A',resName=['VAL','LEU'],no_name=['H'])# put the data backdb.update('x,y,z',xyz)# extract atomsatoms=db.get(chainID='A',resName=['VAL','LEU'],no_name=['H'])foratinatoms:print(at.name,at.x,at.y,at.z)
在这里,您还可以从数据库中获取值,并使用.get()和.update()方法将值更新到数据库。语法与pdbsqlcore的语法相同:
# extract the xyz position of all VAL and LEU resiues of chain A but not the H atomsxyz=db.get('x,y,z',chainID='A',resName=['VAL','LEU'],no_name=['H'])# put the data backdb.update('x,y,z',xyz,chainID='A',resName=['VAL','LEU'],no_name=['H'])
返回原子对象
主要的区别是返回原子对象的可能性。如果在.get()调用中未指定任何属性,则可以实现此功能
atoms=db.get(chainID='A',resName=['VAL','LEU'],no_name=['H'])
这将返回Atom对象的列表。atom类也在pdb2sqlalchemy.py中定义。我们可以通过调用这些原子的属性来提取它们的信息
foratinatoms:print(at.name,at.x,at.y,at.z)
接口
py模块包含一个类,该类是pdb2sqlcore的子类(测试pdb2sqlalchemy而不是doneyet)。它允许分析pdb文件中包含的两个链之间接口的属性。该类允许轻松提取构象的接触原子和接触残基。
frompdb2sql.interfaceimportinterfacedb=interface('1AK4.pdb')contact_atoms=db.get_contact_atoms()contact_residues=db.get_contact_residues()
方法get_contact_atoms()在此返回接触原子的rowid。有几个选项可用于定义接口。
结构相似性
结构相似性模块允许计算给定构象相对于其原生构象的irmsd, lrmsd, Fnat
和dockQ
分数。只要序列排列整齐,原生构象可以是任何其他构象。
frompdb2sql.StructureSimilarityimportStructureSimilarity# create the class instancesim=StructureSimilarity('1AK4_300w.pdb','1AK4.pdb')# compute the irmsd with the two different methodsirmsd_fast=sim.compute_irmsd_fast(method='svd',izone='1AK4.izone')irmsd=sim.compute_irmsd_pdb2sql(method='svd',izone='1AK4.izone')# compute the lrmsd with the two different methodslrmsd_fast=sim.compute_lrmsd_fast(method='svd',lzone='1AK4.lzone',check=True)lrmsd=sim.compute_lrmsd_pdb2sql(exportpath=None,method='svd')# compute the Fnat with the two different methodsFnat_fast=sim.compute_Fnat_fast(ref_pairs='1AK4.ref_pairs')Fnat=sim.compute_Fnat_pdb2sql()# compute the DOCKQdockQ=sim.compute_DockQScore(Fnat_fast,lrmsd_fast,irmsd_fast)
如您所见,计算每个数量有两种方法。我们建议使用fast更快、测试更好。