| 1 | package Chemistry::Pattern::Bond; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | $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 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use base qw(Chemistry::Bond); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub test { | ||||||||||||||||||||||||||||||||
|
Subroutine
test: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 46 | 0 | my ($what, $where) = @_; | |||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($what->test_sub) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 48 | 0 | return $what->test_sub->($what, $where); | |||||||||||||||||||||||||||||||||
| 49 | } else { | ||||||||||||||||||||||||||||||||||
| 50 | #return $what->order eq $where->order; | ||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | return ($what->order eq $where->order) || ($where->aromatic && $what->aromatic); | ||||||||||||||||||||||||||||||||
|
Condition0%0/6
$what->order eq $where->order || $where->aromatic && $what->aromatic
$where->aromatic and $what->aromatic
MC/DC0%0/3
$what->order eq $where->order || $where->aromatic && $what->aromatic
$what->order eq $where->order
$where->aromatic
$what->aromatic
Truth table0%0/4
A || B and C
A= $what->order eq $where->orderB= $where->aromaticC= $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 | 1 | 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 | 0 | ▶ | sub map_to { | ||||||||||||||||||||||||||||||||
|
Subroutine
map_to: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | #print "\t\tmapping $self to '@_'\n"; | ||||||||||||||||||||||||||||||||||
| 78 | 0 | ($self->{map_to}) = @_; | |||||||||||||||||||||||||||||||||
| 79 | 0 | $self; | |||||||||||||||||||||||||||||||||
| 80 | } else { | ||||||||||||||||||||||||||||||||||
| 81 | #print "\t\t$self is mapped to '$self->{map_to}'\n"; | ||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->{map_to}; | |||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 1 | 1; | |||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | =back | ||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||
| 90 | =head1 VERSION | ||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 0.27 | ||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||
| 94 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | L<Chemistry::Pattern> | ||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||
| 98 | The PerlMol website L<http://www.perlmol.org/> | ||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||
| 100 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||
| 102 | Ivan Tubert-Brohman E<lt>itub@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||