[BioPython] PDBConstructionException message
Peter (BioPython List)
biopython at maubp.freeserve.co.uk
Mon Jul 10 11:25:06 UTC 2006
Hi Gad,
I assume you've read Michael's post, but to recap:
If using PERMISSIVE=True (or 1 if you really like integers) then the
parser will catch "warning" exceptions internally, print them to screen,
and continue.
e.g.
from Bio.PDB.PDBParser import PDBParser
pdb = "1LUC"
filename = "1LUC.pdb"
s = parser.get_structure(pdb, filename)
results in:
PDBConstructionException: Atom O defined twice in residue <Residue GLN
het= resseq=355 icode= > at line 2930.
Exception ignored.
Some atoms or residues will be missing in the data structure.
If you use the PERMISSIVE=False (or 0 if you like integers) then the
parser will stop at the exception and you can catch it:
from Bio.PDB.PDBParser import PDBParser
from Bio.PDB.PDBExceptions import PDBConstructionException
pdb = "1LUC"
filename = "1LUC.pdb"
parser = PDBParser(PERMISSIVE=False)
try :
s = parser.get_structure(pdb, filename)
except PDBConstructionException, message:
print "Exception:"
print message
Giving:
Exception:
Atom O defined twice in residue <Residue GLN het= resseq=355 icode= >
at line 2930.
However, this doesn't actually load the whole PDB file - which I think
you wanted, based on your original question.
Gad Abraham wrote:
> I'm using Bio.PDB to parse the PDB file 1LUC, and write output to
> stdout (running python inside a script, not shown here).
I think you want to use the permissive parser (i.e. accept this invalid
but understandable file) WITHOUT printing the warning to screen.
This isn't currently possible - you will have to edit the module to do
this yourself. Open /Bio/PDB/PDBParser.py and find the section
_handle_PDB_exception and change this bit (edited for line widths):
if self.PERMISSIVE:
# just print a warning - some residues/atoms will be missing
print "PDBConstructionException: %s" % message
print "Exception ignored.\nSome atoms or residues will be ..."
else:
# exceptions are fatal - raise again with new message (...)
raise PDBConstructionException, message
To something like this:
if self.PERMISSIVE:
#QUICK HACK, don't print a warning - just carry on.
#Note some residues/atoms will be missing
pass
else:
# exceptions are fatal - raise again with new message (...)
raise PDBConstructionException, message
Thinking long term, maybe we should add an option not to print these
warnings... or send to stderr instead of stdout perhaps?
Peter
More information about the Biopython
mailing list