Chemistry-File-PDB

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

# http://module-build.sourceforge.net/META-spec.html
#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
name:         Chemistry-File-PDB
version:      0.23
version_from: PDB.pm
installdirs:  site
requires:
    Chemistry::MacroMol:           0.05
    Chemistry::Mol:                0.30

distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.30

Makefile.PL  view on Meta::CPAN

use 5.006;
use ExtUtils::MakeMaker;

WriteMakefile(
    'NAME'		=> 'Chemistry::File::PDB',
    'VERSION_FROM'	=> 'PDB.pm', 
    'PREREQ_PM'		=> {
        'Chemistry::MacroMol'   => 0.05,
        'Chemistry::Mol'        => '0.30',
    },
);

PDB.pm  view on Meta::CPAN

package Chemistry::File::PDB;

our $VERSION = '0.23';
# $Id: PDB.pm,v 1.13 2009/05/10 21:57:32 itubert Exp $

use base qw(Chemistry::File);
use Chemistry::MacroMol;
use Chemistry::Domain;
use Scalar::Util qw(weaken);
use Carp;
use strict;
use warnings;

=head1 NAME

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

=head1 SYNOPSIS

    use Chemistry::File::PDB;

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

    # write a PDB file
    $macro_mol->write("out.pdb");

    # 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");
    $file->open;
    while (my $mol = $file->read_mol($file->fh)) {
        # do something with $mol
    }

=cut

=head1 DESCRIPTION

This module reads and writes PDB files. The PDB file format is commonly used to

PDB.pm  view on Meta::CPAN

    ATOM
    HETATM
    ENDMDL 
    END

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.

=head2 Properties

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

=over

PDB.pm  view on Meta::CPAN


=cut

Chemistry::Mol->register_format(pdb => __PACKAGE__);

sub read_mol {
    my ($self, $fh, %options) = @_;
    return if $fh->eof;

    my $domain;
    my $mol_class = $options{mol_class} || "Chemistry::MacroMol";
    my $mol = $mol_class->new;
    my $is_macro = $mol->isa('Chemistry::MacroMol');
    $domain = $mol unless $is_macro;

    local $_;
    my $curr_residue = 0;
    while (<$fh>) {
	if (/^TER/) {
            # TODO read separated molecules?
	} elsif (/^(?:HETATM|ATOM)/) {
	    my ($atom_n, $symbol, $suff, $res_name, $chain_id,
                $seq_n, $ins_code, $x, $y, $z

PDB.pm  view on Meta::CPAN

    }

    return 0;
}

sub write_string {
    my ($class, $mol, %opts) = @_;
    my $ret = '';
    $ret .= 'TITLE     ' . $mol->name . "\n" if defined $mol->name;
    $ret .= 'REMARK    Generated by ' . __PACKAGE__ . " version $VERSION\n";
    if ($mol->isa("Chemistry::MacroMol")) {
        my $i = 1;
        my $j = 1;
        for my $res ($mol->domains) {
            my $seq_n = $res->attr("pdb/sequence_number");
            $seq_n = $j++ unless defined $seq_n;
            my $res_name = substr($res->name, 0, 3) || "UNK";

            for my $atom ($res->atoms) {
                my $serial_n  = $res->attr("pdb/serial_number");
                my $ins_code  = $res->attr("pdb/insertion_code");

PDB.pm  view on Meta::CPAN

}

1;

=head1 VERSION

0.23

=head1 SEE ALSO

L<Chemistry::MacroMol>, L<Chemistry::Mol>, L<Chemistry::File>,
L<http://www.perlmol.org/>.

The PDB format description at 
L<http://www.rcsb.org/pdb/docs/format/pdbguide2.2/guide2.2_frame.html>

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

=head1 AUTHOR

README  view on Meta::CPAN

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
(L<http://www.rcsb.org/pdb/>). The current version of this module only uses the
ATOM and HETATM records, 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.

CHANGES SINCE VERSION 0.21
        - Add unique ID to atom names when generating from a $mol object.
        - Also treat END as a molecule separator in multi-molecule files.
        - Fixed insertion code bug (thanks to kparkes).
        - Fixed memory leak.
        - Fixed a couple of atom symbol bugs.
        - Add a title on output.

README  view on Meta::CPAN


   perl Makefile.PL
   make
   make test
   make install

DEPENDENCIES

This module requires these other modules and libraries:

  Chemistry::MacroMol   0.05
  Chemistry::Mol        0.24

COPYRIGHT AND LICENSE

Copyright (C) 2009 Ivan Tubert-Brohman

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. 

t/pdb.t  view on Meta::CPAN

use Test::More;

use Chemistry::File::PDB;

my $mol = Chemistry::Mol->read("test.pdb");
my $macromol = Chemistry::MacroMol->read("test.pdb");

plan tests => 9;

is(scalar($mol->atoms),             139,        '$mol->atoms');
is(scalar($macromol->atoms),        139,        '$macromol->atoms');
is(scalar($macromol->domains),      10,         '$macromol->domains');
is($macromol->domains(4)->type,     'VAL',      '$macromol->domains(4)->name');
is($macromol->domains(4)->name,     'VAL4',     '$macromol->domains(4)->name');
is($mol->atoms(48)->name,           'CG1',      '$mol->atoms(44)->name');
is($mol->atoms(48)->symbol,         'C',        '$mol->atoms(44)->name');

t/write.t  view on Meta::CPAN

#!/home/ivan/bin/perl

use strict;
use warnings;
use Test::More tests => 1;

use Chemistry::File::PDB;

my $mol = Chemistry::MacroMol->read("test.pdb");
$mol->write("out.pdb");

my ($got, $expected);
{
    local $/;
    open F, "<test.pdb" or die "couldn't open test.pdb: $!\n";
    $expected = <F>;
    open F, "<out.pdb" or die "couldn't open test.pdb: $!\n";
    $got = <F>;
}



( run in 0.677 second using v1.01-cache-2.11-cpan-49f99fa48dc )