I have a pdb file having 30 frames. I want to calculate the average structure. Two add the coordinates, I wrote the following python code:
#!/usr/bin/python
from Bio.PDB.PDBParser import PDBParser
import numpy as np
parser=PDBParser(PERMISSIVE=1)
structure_id="mode_7"
filename="mode_7.pdb"
structure=parser.get_structure(structure_id, filename)
model1=structure[0]
newc=[]
coord=[]
for chain1 in model1.get_list():
for residue1 in chain1.get_list():
ca1=residue1["CA"]
coord1=ca1.get_coord()
newc.append(coord1)
for i in range(1,29):
model=structure[i]
for chain in model.get_list():
for residue in chain.get_list():
ca=residue["CA"]
coord.append(ca.get_coord())
newc=np.add(newc,coord)
print newc
print "END"
It gives out the following error:
Traceback (most recent call last):
File "./average.py", line 26, in <module>
newc=np.add(newc,coord)
ValueError: operands could not be broadcast together with shapes (124,3) (248,3)
I can not figure out how it takes 248 atoms. Because, each of the models has only 124 atoms.
Can you help???