[Biopython] PDB parser: suppress warnings
Peter Cock
p.j.a.cock at googlemail.com
Tue Jul 22 20:15:00 UTC 2014
Hi Frederico,
The Python standard library lets you ignore warnings
(and do other things like upgrade them into exceptions).
So the general approach to ignore a particular class of
warnings would be:
import warnings
from Bio import PDBConstructionWarning
warnings.simplefilter('ignore', PDBConstructionWarning)
#all your code here
Better yet, to localise the ignoring of warnings use a
context manager:
import warnings
from Bio import PDBConstructionWarning
#your code
with warnings.catch_warnings():
warnings.simplefilter('ignore', PDBConstructionWarning)
#your code which might trigger the warning
#rest of your code here
However, because this is so common, you can just use the
QUIET=True option on the PDBParser object:
from Bio.PDB.PDBParser import PDBParser
struct = PDBParser(QUIET=True).get_structure('tmp', pdbf)
Try help(PDBParser) for more, or see:
http://biopython.org/DIST/docs/api/Bio.PDB.PDBParser%27.PDBParser-class.html#__init__
Regards,
Peter
On Tue, Jul 22, 2014 at 7:14 PM, Frederico Moraes Ferreira
<ferreirafm at usp.br> wrote:
> Hi Biopythonees,
> Has anybody happen to know how to suppress warnings when reading PDBs with
> hydrogenated waters?
>
> from Bio.PDB.PDBParser import PDBParser
> struct = PDBParser().get_structure('tmp', pdbf)
>
> My PDBs came from MD so as all water molecules have hydrogens causing
> thousands of warnings like:
> ...
> /usr/lib64/python2.7/site-packages/Bio/PDB/PDBParser.py:284:
> PDBConstructionWarning: PDBConstructionException: Atom 2H defined twice in
> residue <Residue HOH het=W resseq=2640 icode= > at line 71037.
> Exception ignored.
> Some atoms or residues may be missing in the data structure.
> % message, PDBConstructionWarning)
> ...
>
> Thanks in advance.
> Fred
>
>
> --
> Dr. Frederico Moraes Ferreira
> University of Sao Paulo
> Heart Institute, School of Medicine
> Laboratoy of Immunology
> Av. Dr. Enéas de Carvalho Aguiar, 44
> 05403-900 Sao Paulo - SP
> Brasil
>
> _______________________________________________
> Biopython mailing list - Biopython at mailman.open-bio.org
> http://mailman.open-bio.org/mailman/listinfo/biopython
More information about the Biopython
mailing list