| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Chemistry::Pattern::Atom; |
|
2
|
|
|
|
|
|
|
$VERSION = '0.27'; |
|
3
|
|
|
|
|
|
|
# $Id: Atom.pm,v 1.12 2009/05/10 20:56:06 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
|
1
|
|
|
1
|
|
16
|
use 5.006; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
38
|
|
|
29
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
30
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
53
|
|
|
31
|
1
|
|
|
1
|
|
5
|
use base qw(Chemistry::Atom); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
198
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=over 4 |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub test { |
|
49
|
183
|
|
|
183
|
1
|
711
|
my ($what, $where) = @_; |
|
50
|
|
|
|
|
|
|
#print "\t\ttesting $where against $what\n"; |
|
51
|
|
|
|
|
|
|
#print $where->print, $what->print; |
|
52
|
183
|
50
|
|
|
|
403
|
if ($what->test_sub) { |
|
53
|
|
|
|
|
|
|
#print "\t\thave a test sub\n"; |
|
54
|
0
|
|
|
|
|
0
|
return $what->test_sub->($what, $where); |
|
55
|
|
|
|
|
|
|
} else { |
|
56
|
|
|
|
|
|
|
#print "\t\tdon't have a test sub\n"; |
|
57
|
183
|
|
|
|
|
1149
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
Chemistry::Obj::accessor('map_to'); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 VERSION |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
0.27 |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
L |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The PerlMol website L |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 AUTHOR |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Ivan Tubert-Brohman Eitub@cpan.orgE |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright (c) 2009 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
|
|
|
|
|
|
|
|