| 1 | package Chemistry::Domain; | ||
| 2 | |||
| 3 | $VERSION = '0.06'; | ||
| 4 | # $Id: Domain.pm,v 1.6 2004/07/03 19:19:44 itubert Exp $ | ||
| 5 | |||
| 6 | |||
| 7 | use 5.006; | ||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | use base qw(Chemistry::Mol); | ||
| 11 | use Carp; | ||
| 12 | use Scalar::Util 'weaken'; | ||
| 13 | |||
| 14 | =head1 NAME | ||
| 15 | |||
| 16 | Chemistry::Domain - Class for domains in macromolecules | ||
| 17 | |||
| 18 | =head1 SYNOPSIS | ||
| 19 | |||
| 20 | use Chemistry::Domain; | ||
| 21 | my $domain = Chemistry::Domain->new(parent => $bigmol); | ||
| 22 | |||
| 23 | =head1 DESCRIPTION | ||
| 24 | |||
| 25 | A domain is a substructure of a larger molecule. It is typically used to | ||
| 26 | represent aminoacid residues within a protein, or bases within a nucleic acid, | ||
| 27 | but you could use it for any arbitrary substructure such as functional groups | ||
| 28 | and rings. A domain has all the properties of a molecule, plus a "parent". The | ||
| 29 | parent is the larger molecule that contains the domain. In other words, the | ||
| 30 | Chemistry::Domain class inherits from Chemistry::Mol. | ||
| 31 | |||
| 32 | =head1 METHODS | ||
| 33 | |||
| 34 | Note: the methods that are inherited from Chemistry::Mol are not repeated here. | ||
| 35 | |||
| 36 | =over 4 | ||
| 37 | |||
| 38 | =item Chemistry::Domain->new(parent => $mol, name => value, ...) | ||
| 39 | |||
| 40 | Create a new Domain object with the specified attributes. You can use the same | ||
| 41 | attributes as for Chemistry::Mol->new, plus the parent attribute, which is | ||
| 42 | required. | ||
| 43 | |||
| 44 | =cut | ||
| 45 | |||
| 46 | sub new { | ||
| 47 | my $class = shift; | ||
| 48 | my %args = @_; | ||
| 49 | my $self = bless $class->SUPER::new(), $class; | ||
| 50 | $self->$_($args{$_}) for (keys %args); | ||
| 51 | croak "Must specify parent to Chemistry::Domain->new" unless $self->parent; | ||
| 52 | return $self; | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | =item $domain->parent | ||
| 57 | |||
| 58 | Returns the parent of the domain. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | sub parent { | ||
| 63 | my $self = shift; | ||
| 64 | if (@_) { | ||
| 65 | $self->{parent} = shift; | ||
| 66 | weaken($self->{parent}); | ||
| 67 | return $self; | ||
| 68 | } else { | ||
| 69 | return $self->{parent}; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | =item $domain->add_atom($atom, ...) | ||
| 74 | |||
| 75 | Add one or more Atom objects to the domain. Returns the last atom added. It | ||
| 76 | also automatically adds the atoms to the atom table of the parent molecule. | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | sub add_atom { | ||
| 81 | my $self = shift; | ||
| 82 | $self->add_atom_np(@_); # add atom to self (domain) | ||
| 83 | $self->parent->add_atom(@_); # add atom to parent (macromol) | ||
| 84 | } | ||
| 85 | |||
| 86 | |||
| 87 | =item $domain->add_bond($bond, ...) | ||
| 88 | |||
| 89 | Add one or more Bond objects to the domain. Returns the last bond added. It | ||
| 90 | also automatically adds the bond to the bond table of the parent molecule. | ||
| 91 | |||
| 92 | =cut | ||
| 93 | |||
| 94 | sub add_bond { | ||
| 95 | my $self = shift; | ||
| 96 | $self->add_bond_np(@_); # add bond to self (domain) | ||
| 97 | $self->parent->add_bond(@_); # add bond to parent (macromol) | ||
| 98 | } | ||
| 99 | |||
| 100 | |||
| 101 | 1; | ||
| 102 | |||
| 103 | =back | ||
| 104 | |||
| 105 | =head1 VERSION | ||
| 106 | |||
| 107 | 0.06 | ||
| 108 | |||
| 109 | =head1 SEE ALSO | ||
| 110 | |||
| 111 | L<Chemistry::MacroMol>, L<Chemistry::Mol>, L<Chemistry::Atom>, | ||
| 112 | L<Chemistry::Bond> | ||
| 113 | |||
| 114 | =head1 AUTHOR | ||
| 115 | |||
| 116 | Ivan Tubert, E<lt>itub@cpan.orgE<gt> | ||
| 117 | |||
| 118 | =head1 COPYRIGHT AND LICENSE | ||
| 119 | |||
| 120 | Copyright 2004 by Ivan Tubert | ||
| 121 | |||
| 122 | This library is free software; you can redistribute it and/or modify | ||
| 123 | it under the same terms as Perl itself. | ||
| 124 | |||
| 125 | =cut | ||
| 126 |