| 1 | package Chemistry::Pattern::Atom; | ||||||||||
| 2 | 10 | $VERSION = '0.26'; | |||||||||
| 3 | # $Id: Atom.pm,v 1.11 2005/05/16 22:08:15 itubert Exp $ | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Chemistry::Pattern::Atom - An atom that knows how to match | ||||||||||
| 8 | |||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||
| 10 | |||||||||||
| 11 | my $patt_atom = Chemistry::Pattern::Atom->new(symbol => C); | ||||||||||
| 12 | $patt_atom->test_sub( sub { | ||||||||||
| 13 | my ($what, $where) = @_; | ||||||||||
| 14 | $where->bonds == 3 ? 1 : 0; # only match atoms with three bonds | ||||||||||
| 15 | }); | ||||||||||
| 16 | |||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||
| 18 | |||||||||||
| 19 | Objects of this class represent atoms in a pattern. This is a subclass of | ||||||||||
| 20 | Chemistry::Atom. In addition to the properties of regular atoms, | ||||||||||
| 21 | pattern atoms have a method for testing if they match an atom in a molecule. | ||||||||||
| 22 | By default, a pattern atom matches an atom if they have the same symbol. | ||||||||||
| 23 | It is possible to substitute this by an arbitrary criterion by providing | ||||||||||
| 24 | a custom test subroutine. | ||||||||||
| 25 | |||||||||||
| 26 | =cut | ||||||||||
| 27 | |||||||||||
| 28 | 10 | ▶ | use 5.006; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 10 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 10 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 31 | 10 | ▶ | use base qw(Chemistry::Atom); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 32 | |||||||||||
| 33 | =head1 METHODS | ||||||||||
| 34 | |||||||||||
| 35 | =over 4 | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | 10 | our $Debug = 0; | |||||||||
| 40 | |||||||||||
| 41 | =item $patt_atom->test($atom) | ||||||||||
| 42 | |||||||||||
| 43 | Tests if the pattern atom matches the atom given by $atom. Returns true or | ||||||||||
| 44 | false. | ||||||||||
| 45 | |||||||||||
| 46 | =cut | ||||||||||
| 47 | |||||||||||
| 48 | 5337 | ▶ | sub test { | ||||||||
|
Subroutine
test: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||
| 49 | 5337 | my ($what, $where) = @_; | |||||||||
| 50 | #print "\t\ttesting $where against $what\n"; | ||||||||||
| 51 | #print $where->print, $what->print; | ||||||||||
| 52 | 5337 | ▶ | if ($what->test_sub) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | #print "\t\thave a test sub\n"; | ||||||||||
| 54 | 5337 | return $what->test_sub->($what, $where); | |||||||||
| 55 | } else { | ||||||||||
| 56 | #print "\t\tdon't have a test sub\n"; | ||||||||||
| 57 | 0 | return $what->symbol eq $where->symbol; | |||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | =item $patt_atom->test_sub(\&my_test_sub) | ||||||||||
| 62 | |||||||||||
| 63 | Specify an arbitrary test subroutine to be used instead of the default one. | ||||||||||
| 64 | &my_test_sub must take two parameters; the first one is the pattern atom | ||||||||||
| 65 | and the second is the atom to match. It must return true if there is a match. | ||||||||||
| 66 | |||||||||||
| 67 | =cut | ||||||||||
| 68 | |||||||||||
| 69 | 10 | Chemistry::Obj::accessor('test_sub'); | |||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | =item $patt_atom->map_to([$atom]) | ||||||||||
| 73 | |||||||||||
| 74 | Returns or sets the atom that is considered to be matched by $patt_atom. | ||||||||||
| 75 | |||||||||||
| 76 | =cut | ||||||||||
| 77 | |||||||||||
| 78 | 10 | Chemistry::Obj::accessor('map_to'); | |||||||||
| 79 | |||||||||||
| 80 | 10 | 1; | |||||||||
| 81 | |||||||||||
| 82 | =back | ||||||||||
| 83 | |||||||||||
| 84 | =head1 VERSION | ||||||||||
| 85 | |||||||||||
| 86 | 0.26 | ||||||||||
| 87 | |||||||||||
| 88 | =head1 SEE ALSO | ||||||||||
| 89 | |||||||||||
| 90 | L<Chemistry::Pattern> | ||||||||||
| 91 | |||||||||||
| 92 | The PerlMol website L<http://www.perlmol.org/> | ||||||||||
| 93 | |||||||||||
| 94 | =head1 AUTHOR | ||||||||||
| 95 | |||||||||||
| 96 | Ivan Tubert-Brohman E<lt>itub@cpan.orgE<gt> | ||||||||||
| 97 | |||||||||||
| 98 | =head1 COPYRIGHT | ||||||||||
| 99 | |||||||||||
| 100 | Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is | ||||||||||
| 101 | free software; you can redistribute it and/or modify it under the same terms as | ||||||||||
| 102 | Perl itself. | ||||||||||
| 103 | |||||||||||
| 104 | =cut | ||||||||||
| 105 | |||||||||||