sam
sam

Reputation: 19194

How to get the atoms in the residue using Biopython

I am working with Biopython. I want to find out the atoms in a residue.

from Bio import PDB

pdb = "1dly.pdb"
name = pdb[:3]

p = PDB.PDBParser()
s = p.get_structure(name, pdb)

y = s.get_residues()
for x in y:
    print x, x.resname

I got the residue name but I need to get the atoms inside the residue. How can I do that?

Upvotes: 3

Views: 2327

Answers (1)

David Cain
David Cain

Reputation: 17353

Iterating over a Residue object will yield the atoms within:

for res in s.get_residues():
    for atom in res:
        print atom

If you're looking to obtain the atoms from some arbitrary Entity or list of Entity objects, you might want to try unfold_entities:

for atom in PDB.Selection.unfold_entities([res_1, res_2], target_level='A'):
    print atom

Additionally, Structure objects have a method get_atoms() that will yield all atoms within the structure.

Upvotes: 3

Related Questions