I am trying to obtain the sequence from PDB file, but no output is given when I run the following code :

from Bio import SeqIO

with open("1a9l.pdb", "r") as handle:
    for record in SeqIO.parse(handle, "pdb-atom"):
  • $\begingroup$ If you only want protein sequences for an PDB code, NCBI has already a dataset (in genbank format) for that. Therein the accession IDs are the code underscore chain letter... $\endgroup$ – Matteo Ferla Feb 10 '20 at 14:07
  • $\begingroup$ I was trying to do it through the script,as it is part of pipeline.. $\endgroup$ – shome Feb 10 '20 at 19:00

If you are using a conda version of python you can use Pymol module for this, which is actually more robust in some aspects than bio.PDB, although errors may cause segmentation faults. The following:

import pymol2
## paralellisable version.
with pymol2.PyMOL() as pymol:

Gives me:


Alternatively, you can use PDBe's API.

import requests

response = requests.get('https://www.ebi.ac.uk/pdbe/api/pdb/entry/molecules/1a9l').json()['1a9l']

for entity in response:
    if entity['molecule_type'] == 'polyribonucleotide':

Do note that missing 'residues' (residues, small molecules and nucleotides) will cause issues. PDB files do not have missing 'residues', while mmCIF files have a dictionary that does. The API will give you the latter.

  • $\begingroup$ Hi, I tried conda install -c schrodinger pymol to install pymol module. On import, it shows me an error : ModuleNotFoundError: No module named 'pymol2' Is this the way to download it for use with conda? $\endgroup$ – shome Feb 11 '20 at 15:21
  • $\begingroup$ conda install -c schrodinger pymol will install both. Does import pymol work? That is, is the version of python you are running the conda one? If so, single threaded pymol in the example runs as import pymol without the context manager line. Doing conda search -c schrodinger pymol for me (Ubuntu) gives me choices including pymol 2.1.1 for py27_2 and py36_2. Do you get the same versions? $\endgroup$ – Matteo Ferla Feb 11 '20 at 15:53
  • $\begingroup$ yes,I get same.No import pymol is also not working,yes I am running on same version of python as conda. $\endgroup$ – shome Feb 11 '20 at 16:02
  • $\begingroup$ Okay, just to clarify: (a) there is no sudo'ing/nohup/systemctl service going on, (b) your which python (or whichever you are calling) and your which conda point to the same folder and (c) when you type conda list pymol it gives it as installed, correct? $\endgroup$ – Matteo Ferla Feb 11 '20 at 16:11
  • $\begingroup$ I should have phrased it not as which python, but within your run sys.executable gives that one. $\endgroup$ – Matteo Ferla Feb 11 '20 at 16:12

That PDB entry is an RNA molecule, so there is no protein sequence to extract.

If it extracted the RNA sequence by default here you can see there could be an ambiguity as to whether it was an RNA sequence or a protein sequence, as the alphabets share characters.

  • $\begingroup$ Got it..So,I can't extract RNA sequence through this option. $\endgroup$ – shome Feb 10 '20 at 19:01
  • 1
    $\begingroup$ Not using SeqIO from Biopython, no. The "pdb-seqres" option won't work here either. You could download the flat file of PDB sequences and read them into a Python dictionary: rcsb.org/pages/download_features#FASTA. Be aware though that sometimes atoms are missing in the ATOM records, which may have been why you wanted to read directly from the atoms in the first place. $\endgroup$ – jgreener Feb 11 '20 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.