[Biopython-dev] Parsing "element" out of PDB file
João Rodrigues
anaryin at gmail.com
Thu Jun 24 20:25:23 UTC 2010
Ok, I was looking at the element attribution and there's a slight problem. I
thought I could easily fetch if the atom is from an ATOM or HETATM, but
since the "parenting" of the Atom is only done *after* the Atom is created,
there is no way (as is) of knowing where it comes from. Therefore, I thought
of the following work around. *hetero_flag* is already defined when the Atom
is created. It could be passed to the Atom as another of its arguments.
It would then be a conditional like this inside the Atom class:
if not element or element not in IUPACData:
if hetatm:
if atom.name in IUPACData:
element = atom.name
else:
element = ?
else: # Not HETATM
t_element = atom.name[0] if not atom.name[0].isdigit() else atom.name[1]
if t_element in IUPACData:
element = t_element
else:
element = ?
else: # Has element and it is in IUPACData
element = element
The advantage is that either if you don't give an element or if it fails the
IUPACData check, it will try to recover it from the atom name.
It also makes it possible to thrown an exception when the element is not
found. Or a warning since for now, only the CoM function uses it and it has
a failsafe against it (defaults to geometrical).
Opinions?
João
More information about the Biopython-dev
mailing list