1

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')
Cave
  • 201
  • 1
  • 4
  • 14

1 Answers1

1
  • In your last loop for atom in residue you are defining the function rotmat every time you loop over an atom but you never call the function.
  • Try removing the line def rotmat():
  • Currently both your rotation and your translation wouldn't change the atom coordinates.

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')
Maximilian Peters
  • 30,348
  • 12
  • 86
  • 99
  • Thank you so much! Also, how can I get only x coordinates for example. I set the transformed coordinates to a variable 'coord' (i.e coord = atom.transform(rotation_matrix, -atom_C1). Then I set x = coord[30:38] but I got an error message. – Cave Dec 15 '17 at 03:04
  • Not sure if I understood the question but you `atom.coord` is a numpy array. `atom.coord[0]` would give you the x-value, 1 --> y, 2 --> z. – Maximilian Peters Dec 15 '17 at 08:41
  • Thank you so much for your reply. I tried your method `atom.coord[0]` but the coordinates are printed vertically, three times and line by line. For example: 0.807000213623 0.807000213623 0.807000213623 2.84700017548 2.84700017548 2.84700017548 1.16100030518 1.16100030518 1.16100030518 3.08599954224 3.08599954224 3.08599954224 1.40100007629 1.40100007629 1.40100007629 – Cave Dec 15 '17 at 15:27
  • Hm, that's strange: `for model in struct: for chain in model: for residue in chain: for atom in residue: print(atom.coord[0])` gives me a new line separated list of single x-coordinates – Maximilian Peters Dec 15 '17 at 16:11