How to extract x,y,z coordinates of atoms from PDB file?

Tariq Abdullah
1 Min Read

The x, y, and z coordinates of atoms are provided in the PDB file. One way to extract them is by using the Biopython package [1]. In this article, we will extract coordinates of C-alpha atoms for each residue from the PDB file using Biopython.

Let’s say we have a PDB file named ‘input.pdb‘.



#!/usr/bin/env python3

from Bio.PDB import *
import numpy as np

p=PDBParser()

structure=p.get_structure('input', "input.pdb")

for model in structure:
      for chain in model:
            CA_coord = []
            for residue in chain:
                CA_coord.append((residue['CA'].get_vector()))
                print(CA_coord)

Save this file as Python script, for example, as ‘ca_coord.py‘, keep your input file in the same directory or provide the full path in the script, and run it as:

python3 ca_coord.py

References

  1. https://biopython.org/
Share This Article
Tariq is founder of Bioinformatics Review and Lead Developer at IQL Technologies. His areas of expertise include algorithm design, phylogenetics, MicroArray, Plant Systematics, and genome data analysis. If you have questions, reach out to him via his homepage.
Leave a Comment

Leave a Reply