pythonbiopythonprotein-database

How to move protein coordinates with respect to a reference frame


I have a PDB file '1abz' (https://files.rcsb.org/view/1ABZ.pdb), which is containing the coordinates of a protein structure. Please ignore the lines of the header remarks, the interesting information starts at line 276 which says 'MODEL 1'.

I would like to shift the coordinates with respect to a reference frame at the origin (i.e x=0, y=0, z=0) and generate a new coordinate file.

I read through biopython tutorial (http://biopython.org/wiki/The_Biopython_Structural_Bioinformatics_FAQ), used the transform method of the Atom object (http://biopython.org/DIST/docs/api/Bio.PDB.Atom.Atom-class.html#transform), and came up with this script but no success.

How can I go about this? Many thanks in advance!

from Bio import PDB
import numpy as np

parser = PDB.PDBParser()
io = PDB.PDBIO()
struct = parser.get_structure('1abz','1abz.pdb')

for model in struct:
    for chain in model:
        for residue in chain:
            for atom in residue:
                def rotmat():
                    rotation = rotmat(np.pi, Vector(0.0, 0.0, 0.0))
                    translation = np.array((0.0, 0.0, 0.0), 'f')
                    atom.transform(rotation, translation)

io.set_structure(struct)
io.save('1abz_coord.pdb')

Solution

  • If you want for example to define C1 as your reference point you could use the following code.

    rotation_matrix is just a matrix which does not rotate your protein. np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) would do the same.

    from Bio import PDB
    import numpy as np
    
    parser = PDB.PDBParser()
    io = PDB.PDBIO()
    struct = parser.get_structure('1abz','1abz.pdb')
    
    rotation_matrix = PDB.rotmat(PDB.Vector([0, 0, 0]), PDB.Vector([0, 0, 0]))
    
    for atom in struct.get_atoms():
        atom_C1 = atom.coord.copy()
        break
    
    for model in struct:
        for chain in model:
            for residue in chain:
                for atom in residue:
                    atom.transform(rotation_matrix, -atom_C1)
    
    io.set_structure(struct)
    io.save('1abz_coord.pdb')