Question

I am trying to align a short segment within structure A to a short structure B. I tried following "Protein Superposition using Biopython"

But because I only want to a short segment from A and save this one, I am getting problems saving the results.

Calling alignment works fine:

super_imposer.set_atoms(residuesBCA,residuesACA)

and the consecutive transformation to the alignment position runs through

for residue in residuesACA:
    residue.transform(super_imposer.rotran[0],super_imposer.rotran[1])

but I cannot check the result because I cannot save the residues with

io = PDBIO()  
io.set_structure(residuesACA)
io.save('./' + pdbFile)

io here expects a full structure, but in the previous loop I only transformed the segment residues. How can I save them to disk?

Was it helpful?

Solution

PDBIO indeed expects a full structure. The trick to saving only a subset of that structure is using a Select class. If you override any of the default methods (accept_chain, accept_residue, etc.) you can override which aspects of the SMCRA hierarchy are saved.

from Bio import PDB

class OnlyACAResideus(PDB.Select):
    def accept_residue(self, res):
        return res in residuesACA

io = PDBIO()

# Presumably, you still have the structure, but you can unfold it like so:
struct = PDB.Selection.unfold_entities(residuesACA, 'S')[0]
io.set_structure(struct)
io.save("struct.pdb", select=OnlyACAResidues())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top