This is certainly feasible in biopitone. Let me help you with an example that ignores HETRES in the pdb file:
First, analyze the pdb file with all your models:
import Bio.PDB import numpy as np parser = Bio.PDB.PDBParser(QUIET=True)
So, now that we have the contents of the file, and suppose you have the same atoms in all your models, get a list with a unique identifier for each atom (for example: chain + residue pos + atom name):
atoms = [a.parent.parent.id + '-' + str(a.parent.id[1]) + '-' + a.name for a in structure[0].get_atoms() if a.parent.id[0] == ' ']
Note that I ignore hetero-residual values ββwith a.parent.id[0] == ' ' . Now let's get the average value for each atom:
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
Now create a new pdb using one structure model:
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
Now write pdb
io = Bio.PDB.PDBIO() io.set_structure(ns) io.save('new_1abz.pdb')
source share