我有一个PDB文件'1abz‘(https://files.rcsb.org/view/1ABZ.pdb),包含有23个不同模型(编号为模型1-23)的蛋白质结构的坐标。请忽略标题注释,有趣的信息从第276行开始,上面写着“型号1”。
我想计算一种蛋白质的平均结构。蛋白质的PDB文件包含多个构象/模型,我想计算每个剩余原子的平均坐标,这样我就得到了一个构象/模型。
我不知道如何使用Biopython,所以我试着用Pandas计算出平均坐标。我想我已经计算出了平均值,但是现在的问题是我有一个不再是PDB格式的csv文件,所以我不能将这个文件加载到PyMol中。
我的问题是,如何将我的csv文件转换成PDB格式。更好的是,如何在不损害原始pdb文件格式的情况下,获得Biopython或Python中的平均坐标?
这是我用来计算熊猫平均坐标的代码。
#I first converted my pdb file to a csv file
import pandas as pd
import re
pdbfile = '1abz.pdb'
df = pd.DataFrame(columns=['Model','Residue','Seq','Atom','x','y','z']) #make dataframe object
i = 0 #counter
b = re.compile("MODEL\s+(\d+)")
regex1 = "([A-Z]+)\s+(\d+)\s+([^\s]+)\s+([A-Z]+)[+-]?\s+([A-Z]|)"
regex2 = "\s+(\d+)\s+([+-]?\d+\.\d+\s+[+-]?\d+\.\d+\s+[+-]?\d+\.\d+)"
reg = re.compile(regex1+regex2)
with open(pdbfile) as f:
columns = ('label', 'ident', 'atomName', 'residue', 'chain', 'sequence', 'x', 'y', 'z', 'occ', 'temp', 'element')
data = []
for line in f:
n = b.match(line)
if n:
modelNum = n.group(1)
m = reg.match(line)
if m:
d = dict(zip(columns, line.split()))
d['model'] = int(modelNum)
data.append(d)
df = pd.DataFrame(data)
df.to_csv(pdbfile[:-3]+'csv', header=True, sep='\t', mode='w')
#Then I calculated the average coordinates
df = pd.read_csv('1abz.csv', delim_whitespace = True, usecols = [0,5,7,8,10,11,12])
df1 = df.groupby(['atomName','residue','sequence'],as_index=False)['x','y','z'].mean()
df1.to_csv('avg_coord.csv', header=True, sep='\t', mode='w')发布于 2018-03-19 13:09:22
这在生物工程中当然是可行的。让我举个例子,忽略pdb文件中的HETRES:
首先,使用所有模型解析pdb文件:
import Bio.PDB
import numpy as np
parser = Bio.PDB.PDBParser(QUIET=True) # Don't show me warnings
structure = parser.get_structure('1abz', '1abz.pdb') # id of pdb file and location好了,既然我们有了文件的内容,并且假设您的所有模型中都有相同的原子,那么获得一个具有每个原子的唯一标识符的列表(例如: chain +残留物pos + atom名称):
atoms = [a.parent.parent.id + '-' + str(a.parent.id[1]) + '-' + a.name for a in structure[0].get_atoms() if a.parent.id[0] == ' '] # obtained from model '0'请注意,我忽略了a.parent.id[0] == ' '的异种残余物。现在让我们得到每个原子的平均值:
atom_avgs = {}
for atom in atoms:
atom_avgs[atom] = []
for model in structure:
atom_ = atom.split('-')
coor = model[atom_[0]][int(atom_[1])][atom_[2]].coord
atom_avgs[atom].append(coor)
atom_avgs[atom] = sum(atom_avgs[atom]) / len(atom_avgs[atom]) # average现在,让我们使用结构的一个模型创建新的pdb:
ns = Bio.PDB.StructureBuilder.Structure('id=1baz') # new structure
ns.add(structure[0]) # add model 0
for atom in ns[0].get_atoms():
chain = atom.parent.parent
res = atom.parent
if res.id[0] != ' ':
chain.detach_child(res) # detach hetres
else:
coor = atom_avgs[chain.id + '-' + str(res.id[1]) + '-' + atom.name]
atom.coord = coor现在让我们来写pdb
io = Bio.PDB.PDBIO()
io.set_structure(ns)
io.save('new_1abz.pdb')https://stackoverflow.com/questions/49356018
复制相似问题