| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Chemistry::Pattern::Bond; |
|
2
|
|
|
|
|
|
|
$VERSION = '0.27'; |
|
3
|
|
|
|
|
|
|
# $Id: Bond.pm,v 1.12 2009/05/10 20:59:02 itubert Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Chemistry::Pattern::Bond - A bond that knows how to match |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $patt_bond = Chemistry::Pattern::Bond->new(order => 2); |
|
12
|
|
|
|
|
|
|
$patt_bond->test_sub( sub { |
|
13
|
|
|
|
|
|
|
my ($what, $where) = @_; |
|
14
|
|
|
|
|
|
|
$where->type eq 'purple' ? 1 : 0; # only match purple bonds |
|
15
|
|
|
|
|
|
|
}); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Objects of this class represent bonds in a pattern. This is a subclass of |
|
20
|
|
|
|
|
|
|
Chemistry::Bond. In addition to the properties of regular bonds, pattern bonds |
|
21
|
|
|
|
|
|
|
have a method for testing if they match an bond in a molecule. By default, a |
|
22
|
|
|
|
|
|
|
pattern bond matches an bond if they have the same bond order or both are |
|
23
|
|
|
|
|
|
|
aromatic. It is possible to substitute this by an arbitrary criterion by |
|
24
|
|
|
|
|
|
|
providing a custom test subroutine. |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
16
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
41
|
|
|
29
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1016
|
|
|
30
|
1
|
|
|
1
|
|
16
|
use base qw(Chemistry::Bond); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
373
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=over 4 |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item $patt_bond->test($bond) |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Tests if the pattern bond matches the bond given by $bond. Returns true or |
|
41
|
|
|
|
|
|
|
false. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub test { |
|
46
|
136
|
|
|
136
|
1
|
202
|
my ($what, $where) = @_; |
|
47
|
136
|
50
|
|
|
|
338
|
if ($what->test_sub) { |
|
48
|
0
|
|
|
|
|
0
|
return $what->test_sub->($what, $where); |
|
49
|
|
|
|
|
|
|
} else { |
|
50
|
|
|
|
|
|
|
#return $what->order eq $where->order; |
|
51
|
136
|
|
66
|
|
|
908
|
return ($what->order eq $where->order) || ($where->aromatic && $what->aromatic); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=item $patt_bond->test_sub(\&my_test_sub) |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Specify an arbitrary test subroutine to be used instead of the default one. |
|
60
|
|
|
|
|
|
|
&my_test_sub must take two parameters; the first one is the pattern bond |
|
61
|
|
|
|
|
|
|
and the second is the bond to match. It must return true if there is a match. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Chemistry::Obj::accessor('test_sub'); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item $patt_bond->map_to([$bond]) |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Returns or sets the bond that is considered to be matched by $patt_bond. |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#Chemistry::Obj::accessor('map_to'); |
|
74
|
|
|
|
|
|
|
sub map_to { |
|
75
|
496
|
|
|
496
|
1
|
1969
|
my $self = shift; |
|
76
|
496
|
100
|
|
|
|
910
|
if (@_) { |
|
77
|
|
|
|
|
|
|
#print "\t\tmapping $self to '@_'\n"; |
|
78
|
333
|
|
|
|
|
547
|
($self->{map_to}) = @_; |
|
79
|
333
|
|
|
|
|
856
|
$self; |
|
80
|
|
|
|
|
|
|
} else { |
|
81
|
|
|
|
|
|
|
#print "\t\t$self is mapped to '$self->{map_to}'\n"; |
|
82
|
163
|
|
|
|
|
528
|
$self->{map_to}; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=back |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 VERSION |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
0.27 |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
L |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The PerlMol website L |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Ivan Tubert-Brohman Eitub@cpan.orgE |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Copyright (c) 2009 Ivan Tubert-Brohman. All rights reserved. This program is |
|
107
|
|
|
|
|
|
|
free software; you can redistribute it and/or modify it under the same terms as |
|
108
|
|
|
|
|
|
|
Perl itself. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|