This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting residue name and residue ID from PDB.

I want to get residue name, residue ID pairs from a PDB file. Also, just to make sure, If I sort residues by ID and print residue name, I always get the sequence, correct?

Edit: I solved the residue name, but how to get a list of all residue numbers? I also wonder if there's a better solution and if I sort residues by ID and print residue name, would I always get the sequence?

from Bio.PDB.PDBParser import PDBParser
from Bio.PDB.Polypeptide import PPBuilder
structure = PDBParser().get_structure('5bmy', '5bmy.pdb')    
model = structure[0]
chain = model['A']
stored.residues = [1,2,3,4,5]
for i in stored.residues:
    print (chain[i].resname)
biopython pdb

Posting code you have tried ensures swift results for these type of questions.

1 answer

Have you tried get_sequece() method from Bio.PDB.Polypeptide http://biopython.org/DIST/docs/api/Bio.PDB.Polypeptide-pysrc.html ?

I'm not interested in the sequence per se, I want to get the residue number (ID).

Log in to answer this question.