3

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 separately get the X, Y or Z coordinates from a pdb file.

This link explains the column numbers of a pdb file: http://cupnet.net/pdb-format/

This is the code that I have but I got an error message.

from Bio import PDB

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:
                XYZ = atom.get_coord()
                for line in XYZ:
                    x_coord = float(line[30:38].strip())
                    y_coord = float(line[38:46].strip())
                    z_coord = float(line[46:54].strip())
                    print x_coord
                    print y_coord
                    print z_coord
Cave
  • 201
  • 1
  • 4
  • 14
  • Please post the error message - format it as code – wwii Dec 15 '17 at 04:03
  • 1
    the advantage of BioPythons PDB parser is that you get a Python object. You don't need to parse the information yourself, i.e. `line[30:38]` will be done by BioPython and written in the x-coordinate. – Maximilian Peters Dec 15 '17 at 13:36

2 Answers2

2
>>> Bio.__version__
'1.69'

from Bio import PDB

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:
                x,y,z = atom.get_coord()
                print(x,y,z)

Result:

15.254 -0.607 3.211
16.429 -0.874 3.019
14.337 -1.034 2.53
14.908 0.287 4.404
13.772 1.237 4.018
12.591 1.037 4.971
11.729 0.213 4.737
15.778 0.862 4.685
14.596 -0.326 5.237
13.458 1.028 3.007
14.118 2.259 4.084
...
Kinght 金
  • 17,681
  • 4
  • 60
  • 74
2

Should do the same thing as above.

    import mdtraj as md 
    pdbfile='1ABZ.pdb'
    traj=md.load_pdb(pdbfile)
    print traj.xyz[0]
sridharn
  • 111
  • 7