line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HackaMol::Bond; |
2
|
|
|
|
|
|
|
$HackaMol::Bond::VERSION = '0.051'; |
3
|
|
|
|
|
|
|
#ABSTRACT: HackaMol Bond class |
4
|
12
|
|
|
12
|
|
1139
|
use 5.008; |
|
12
|
|
|
|
|
54
|
|
5
|
12
|
|
|
12
|
|
93
|
use Moose; |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
108
|
|
6
|
12
|
|
|
12
|
|
88470
|
use namespace::autoclean; |
|
12
|
|
|
|
|
33
|
|
|
12
|
|
|
|
|
149
|
|
7
|
12
|
|
|
12
|
|
1203
|
use Carp; |
|
12
|
|
|
|
|
39
|
|
|
12
|
|
|
|
|
966
|
|
8
|
12
|
|
|
12
|
|
101
|
use MooseX::StrictConstructor; |
|
12
|
|
|
|
|
35
|
|
|
12
|
|
|
|
|
116
|
|
9
|
|
|
|
|
|
|
#use MooseX::Storage; |
10
|
|
|
|
|
|
|
#with Storage( 'io' => 'StorableFile' ), |
11
|
|
|
|
|
|
|
with 'HackaMol::Roles::NameRole', 'HackaMol::Roles::AtomGroupRole'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has $_ => ( |
14
|
|
|
|
|
|
|
is => 'rw', |
15
|
|
|
|
|
|
|
isa => 'Num', |
16
|
|
|
|
|
|
|
default => 1, |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
clearer => 'clear_bond_order', |
19
|
|
|
|
|
|
|
) foreach qw(bond_order); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has $_ => ( |
22
|
|
|
|
|
|
|
is => 'rw', |
23
|
|
|
|
|
|
|
isa => 'Num', |
24
|
|
|
|
|
|
|
default => 0, |
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
clearer => "clear_$_", |
27
|
|
|
|
|
|
|
) foreach qw(bond_fc bond_length_eq); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'bond_efunc' => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
isa => 'CodeRef', |
32
|
|
|
|
|
|
|
builder => "_build_bond_efunc", |
33
|
|
|
|
|
|
|
lazy => 1, |
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _build_bond_efunc { |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#my $self = shift; #self is passed by moose, but we don't use it here |
39
|
|
|
|
|
|
|
my $subref = sub { |
40
|
2
|
|
|
2
|
|
13
|
my $bond = shift; |
41
|
2
|
|
|
|
|
17
|
my $val = ( $bond->bond_length - $bond->bond_length_eq )**2; |
42
|
2
|
|
|
|
|
49
|
return ( $bond->bond_fc * $val ); |
43
|
1
|
|
|
1
|
|
18
|
}; |
44
|
1
|
|
|
|
|
33
|
return ($subref); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub bond_vector { |
48
|
22
|
|
|
22
|
1
|
46
|
my $self = shift; |
49
|
22
|
|
|
|
|
881
|
my @atoms = $self->all_atoms; |
50
|
22
|
|
|
|
|
82
|
return ( $atoms[0]->inter_dcoords( $atoms[1] ) ); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub bond_length { |
54
|
458
|
|
|
458
|
1
|
2311
|
my $self = shift; |
55
|
458
|
|
|
|
|
15340
|
my @atoms = $self->all_atoms; |
56
|
458
|
|
|
|
|
1201
|
return ( $atoms[0]->distance( $atoms[1] ) ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub bond_energy { |
60
|
3
|
|
|
3
|
1
|
8
|
my $self = shift; |
61
|
3
|
|
|
|
|
4
|
my $energy = &{ $self->bond_efunc }( $self, @_ ); |
|
3
|
|
|
|
|
79
|
|
62
|
3
|
|
|
|
|
41
|
return ($energy); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
HackaMol::Bond - HackaMol Bond class |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 VERSION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
version 0.051 |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SYNOPSIS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
use HackaMol::Atom; |
84
|
|
|
|
|
|
|
use HackaMol::Bond; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $atom1 = HackaMol::Atom->new( |
87
|
|
|
|
|
|
|
name => 'O1', |
88
|
|
|
|
|
|
|
coords => [ V( 2.05274, 0.01959, -0.07701 ) ], |
89
|
|
|
|
|
|
|
Z => 8, |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
my $atom2 = HackaMol::Atom->new( |
93
|
|
|
|
|
|
|
name => 'H1', |
94
|
|
|
|
|
|
|
coords => [ V( 1.08388, 0.02164, -0.12303 ) ], |
95
|
|
|
|
|
|
|
Z => 1, |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $atom3 = HackaMol::Atom->new( |
99
|
|
|
|
|
|
|
name => 'H2', |
100
|
|
|
|
|
|
|
coords => [ V( 2.33092, 0.06098, -1.00332 ) ], |
101
|
|
|
|
|
|
|
Z => 1, |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $bond1 = HackaMol::Bond->new(name=>'O1H1', atoms=>[$atom1,$atom2]); |
105
|
|
|
|
|
|
|
my $bond2 = HackaMol::Bond->new(name=>'O1H2', atoms=>[$atom1,$atom3]); |
106
|
|
|
|
|
|
|
my $bond3 = HackaMol::Bond->new(name=>'H1H2', atoms=>[$atom2,$atom3]); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my @bonds = ($bond1, $bond2, $bond3); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
foreach my $bond ( @bonds ){ |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my $pbond = sprintf( |
113
|
|
|
|
|
|
|
"Bond: %s, Length: %.2f, Vector: %.5 %.5 %.5 \n", |
114
|
|
|
|
|
|
|
$bond->name, |
115
|
|
|
|
|
|
|
$bond->bond_length, |
116
|
|
|
|
|
|
|
@{$bond->bond_vector}, |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
print $pbond; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my @COM_ats = map {HackaMol::Atom->new( |
125
|
|
|
|
|
|
|
name => "X".$_->name."X", |
126
|
|
|
|
|
|
|
coords => [ $_->COM ], |
127
|
|
|
|
|
|
|
Z => 1, |
128
|
|
|
|
|
|
|
) |
129
|
|
|
|
|
|
|
} @bonds; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
my @HH_bonds = grep { $_->get_atoms(0)->Z == 1 and |
132
|
|
|
|
|
|
|
$_->get_atoms(1)->Z == 1} @bonds; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 DESCRIPTION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The HackaMol Bond class provides a set of methods and attributes for working |
137
|
|
|
|
|
|
|
with connections between two atoms. The Bond class consumes the |
138
|
|
|
|
|
|
|
AtomGroupRole providing Bond objects with methods to determine the center of |
139
|
|
|
|
|
|
|
mass, total charge, etc (see L<HackaMol::AtomGroupRole>). |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The Bond class also provides attributes and methods to set force_constants and |
142
|
|
|
|
|
|
|
measure energy. The bond_energy method calls on a CodeRef attribute that the |
143
|
|
|
|
|
|
|
user may define. See descriptions below. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head1 METHODS |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 bond_vector |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
no arguments. returns Math::Vector::Real object from |
150
|
|
|
|
|
|
|
$atoms[0]->inter_dcoords($atoms[1]) for the two atoms in the bond. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 bond_length |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
no arguments. returns $atoms[0]->distance($atoms[1]) for the two atoms in |
155
|
|
|
|
|
|
|
the bond. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head2 bond_energy |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
arguments, as many as you want. Calculates energy using the bond_efunc |
160
|
|
|
|
|
|
|
described below, if the attribute, bond_fc > 0. The bond_energy method calls |
161
|
|
|
|
|
|
|
the bond_efunc as follows: |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
my $energy = &{$self->bond_efunc}($self,@_); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
which will pass $self and that in @_ array to bond_efunc, which can be |
166
|
|
|
|
|
|
|
redefined. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 atoms |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
isa ArrayRef[Atom] that is lazy with public ARRAY traits provided by the AtomGroupRole (see documentation for more details). |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Pushing (atom1, atom2) on to the Bond object will produce bond_length and bond_vector from atom1 to atom2 (the atom12 interatomic vector). |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 name |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
isa Str that is lazy and rw. useful for labeling, bookkeeping... |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 bond_order |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
isa Num that is lazy and rw. default = 1, single bond. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head2 bond_fc |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
isa Num that is lazy and rw. default = 0. force constant for harmonic bond |
187
|
|
|
|
|
|
|
potentials. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head2 bond_length_eq |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
isa Num that is lazy and rw. default = 0. Equilibrium bond length. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 bond_efunc |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
isa CodeRef that is lazy and rw. default uses builder to generate harmonic |
196
|
|
|
|
|
|
|
potential from the bond_fc, bond_length_eq, and bond_length. See the |
197
|
|
|
|
|
|
|
_build_bond_efunc, if interested in changing the function form. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 SEE ALSO |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=over 4 |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item * |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L<HackaMol::AtomGroupRole> |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L<HackaMol::Angle> |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
L<HackaMol::Dihedral> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item * |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L<Chemistry::Bond> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=back |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 EXTENDS |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=over 4 |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item * L<Moose::Object> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=back |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 CONSUMES |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=over 4 |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=item * L<HackaMol::Roles::AtomGroupRole> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=item * L<HackaMol::Roles::NameRole> |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item * L<HackaMol::Roles::NameRole|HackaMol::Roles::AtomGroupRole> |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 AUTHOR |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Demian Riccardi <demianriccardi@gmail.com> |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Demian Riccardi. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
250
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=cut |