[Biopython-dev] Parsing "element" out of PDB file

João Rodrigues anaryin at gmail.com
Tue Jun 22 19:25:17 UTC 2010


Hello all,

I've been using some non-standard pdb files outputted by some programs and
they miss the chemical element column in each ATOM line. I was looking at
the PDBParser code and element is dealt with like this:

        if element is None:
            import warnings
            from PDBExceptions import PDBConstructionWarning
            warnings.warn("Atom object (name=%s) without element" % name,
                          PDBConstructionWarning)
            element = "?"
            print name, "--> ?"
        elif len(element)>2 or element != element.upper() or element !=
element.strip():
            raise ValueError(element)
        self.element=element


In my case, the element line is not "None" but just an empty string - ' ' -
which fails these tests and is then passed on. This would be no problem at
all, but I've added a "mass" attribute to the Atom object defined like this:

        self.mass = IUPACData.atom_weigths[element]

I've added the ? to the atom_weights list as I thought it would deal with
the empty element cases.

I'd suggest adding to the first if statement a test to check if the element
string is empty and if so, treat it as None.

        if element is None or element is '':
            import warnings
            from PDBExceptions import PDBConstructionWarning
            warnings.warn("Atom object (name=%s) without element" % name,
                          PDBConstructionWarning)
            element = "?"
            print name, "--> ?"
        elif len(element)>2 or element != element.upper() or element !=
element.strip():
            raise ValueError(element)
        self.element=element


What do you think?

Best!

João [...] Rodrigues
@ http://doeidoei.wordpress.org




More information about the Biopython-dev mailing list