Chemistry::File::PDB - Protein Data Bank file format reader/writer


    use Chemistry::File::PDB;

    # read a PDB file
    my $macro_mol = Chemistry::MacroMol->read("myfile.pdb");

    # write a PDB file

    # read all models in a multi-model file
    my @mols = Chemistry::MacroMol->read("models.pdb");

    # read one model at a time
    my $file = Chemistry::MacroMol->file("models.pdb");
    while (my $mol = $file->read_mol($file->fh)) {
        # do something with $mol


This module reads and writes PDB files. The PDB file format is commonly used to describe proteins, particularly those stored in the Protein Data Bank ( The current version of this module only reads the following record types, ignoring everything else:


This module automatically registers the 'pdb' format with Chemistry::Mol, so that PDB files may be identified and read by Chemistry::Mol->read(). For autodetection purpuses, it assumes that files ending in .pdb or having a line matching /^(ATOM |HETATM)/ are PDB files.

The PDB reader and writer is designed for dealing with Chemistry::MacroMol objects, but it can also create and use Chemistry::Mol objects by throwing some information away.


When reading and writing files, this module stores or gets some of the information in the following places:


The residue type, such as "ARG".


The type and sequence number, such as "ARG114".


The residue sequence number as given in the PDB file.


The chain to which this residue belongs (one character).


The residue insertion code (see the PDB specification for details).


The PDB atom name, such as "CA".


The name of the residue, as discussed above.


The serial number for the atom, as given in the PDB file.

If some of this information is not available when writing a PDB file, this module tries to make it up (by counting the atoms or residues, for example). The default residue name for writing is UNK (unknown). Atom names are just the atomic symbols.

Multi-model files

If a PDB file has multiple models (separated by END or ENDMDL records), each call to read_mol will return one model.

Output features

On writing Chemistry::Mol objects, which don't have macromolecule information and usually don't have atom names, the atom names are made up by concatenating the atomic symbol with a unique ID (up to 1296 atoms are possible). The ID can be disabled by setting the option 'noid':

    $mol->write("out.pdb", noid => 1);

The molecule's name is written as a HEADER record; A REMARK record is added listing the version of Chemistry::File::PDB that was used.




Chemistry::MacroMol, Chemistry::Mol, Chemistry::File,

The PDB format description at

There is another PDB reader in Perl, as part of the BioPerl project: Bio::Structure::IO::pdb.


Ivan Tubert-Brohman <>


Copyright (c) 2009 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.