[BioPython] Reassigning parent ids in Bio.PDB-structures?

Christian Meesters meesters at uni-mainz.de
Mon Oct 8 15:07:54 UTC 2007


Hi,

I'm trying to 'split' a structure in several pieces, e.g. a former chain
'A' should be splitted in 'A' and 'B', 'B' in 'C' and 'D' and so on.
Now, whatever I do I only get chains 'C', 'F', 'H', 'I', 'K', 'L' ...

Perhaps some code explains better what I'm trying to achieve:

breakpoints = [1254, 5444,
                6690, 10888,
                10889, 16332,
                16333, 21776,
                21776, 27220,
                27221, 32665]

def split_chain(structure, breakpoints, outname = 'split.pdb'):
    chains = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                    'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
                    'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
                    'X', 'Y', 'Z']

    chain = chains.pop(0)
    for atom in structure.get_atoms():
        number = atom.get_serial_number()
        if breaks and number == breaks[0]:
            breaks.pop(0)
            chain = chains.pop(0)
        atom.parent.parent.id = chain # assign new chain

    iostream = PDBIO()
    try:
        outfile = open(outname, 'w')
        iostream.set_structure(structure.structure)
        iostream.save(outfile)
    except IOError, msg:
        raise IOError(msg)

So, chain 'A' should stay 'A' from atom 1 to 1254 and 'B' from 1254 to
5444. Instead the written pdb-file contains all atoms, but with the
wrong chain ids (see above). (Please don't tell my how unpythonic the
code reads, point is that I've tried so many different things that I
first need to understand my logic mistake.)

Any ideas, where my mistake is?

Thanks,
Christian




More information about the Biopython mailing list