HackaMol.pm

filter: Statementstmt 76.0% 305 / 401 Branchbran 58.1% 57 / 98 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 90.6% 29 / 32 Podpod 81.2% 13 / 16 totaltotal 72.5% 406 / 560 CC 68 SCAR 35.2
CC
68
Cov
72%
__diagonalize
109.9
rmsd
56.0
_qrotatable
42.0
CRAP 33.6
« HackaMol/Roles/RcsbRole.pm ↑ Summary HackaMol/Roles/ReadPdbRole.pm »
1 package HackaMol;
2 11 $HackaMol::VERSION = '0.053';
3 #ABSTRACT: HackaMol: Object-Oriented Library for Molecular Hacking
4 11 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use HackaMol::AtomGroup;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use HackaMol::Molecule;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use HackaMol::Atom;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use HackaMol::Bond;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use HackaMol::Angle;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use HackaMol::Dihedral;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Math::Vector::Real;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Scalar::Util qw(refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 11 has 'readline_func' => (
19 is => 'rw',
20 isa => 'CodeRef',
21 predicate => 'has_readline_func',
22 clearer => 'clear_readline_func',
23 );
24  
25 11 with
26 'HackaMol::Roles::NameRole',
27 'HackaMol::Roles::MolReadRole',
28 'HackaMol::Roles::PathRole',
29 'HackaMol::Roles::ExeRole',
30 'HackaMol::Roles::FileFetchRole',
31 'HackaMol::Roles::NERFRole',
32 'HackaMol::Roles::RcsbRole';
33  
34 1 ▶sub pdbid_mol {
Subroutine pdbid_mol: called CC=2 SCAR=9.2
Pod documented
35 1 my $self = shift;
36 1 ▶ my $pdbid = shift || croak "Croak on passing pdbid, e.g. 2cba";
Condition50%1/2
shift() || croak('Croak on passing pdbid, e.g. 2cba')
l!l
01
MC/DC0%0/1
shift() || croak('Croak on passing pdbid, e.g. 2cba')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
37 0 my ($file) = $self->getstore_pdbid($pdbid);
38 0 return $self->read_file_mol($file);
39 }
40  
41 5 ▶sub read_file_push_coords_mol {
Subroutine read_file_push_coords_mol: called CC=6 SCAR=17.9
Pod documented
42 5 my $self = shift;
43 5 my $file = shift;
44 5 ▶ my $mol = shift or croak "must pass molecule to add coords to";
Branch: 1 branch
BranchTrueFalseTotal
my $mol = shift() or croak("must pass molecule to add coords to") 4 1 5
45  
46 4 my @atoms = $self->read_file_atoms($file);
47 4 my @matoms = $mol->all_atoms;
48  
49 4 ▶ if ( scalar(@matoms) != scalar(@atoms) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @matoms != scalar @atoms) 1 3 4
50 1 croak "file_push_coords_mol> number of atoms not same";
51 }
52 3 foreach my $i ( 0 .. $#atoms ) {
53 117 ▶ if ( $matoms[$i]->Z != $atoms[$i]->Z ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matoms[$i]->Z != $atoms[$i]->Z) 1 116 117
54 1 croak "file_push_coords_mol> atom mismatch";
55 }
56 116 $matoms[$i]->push_coords($_) foreach ( $atoms[$i]->all_coords );
57 }
58 }
59  
60 1 ▶sub read_pdbfile_mol {
Subroutine read_pdbfile_mol: called CC=1 SCAR=0.0
Pod undocumented
61  
62 # keeps the header, and a map of model_ids
63 1 my $self = shift;
64 1 my $file = shift;
65 1 my ( $header, $atoms, $model_ids ) = $self->read_file_pdb_parts($file);
66 return (
67 1 HackaMol::Molecule->new(
68 name => $file,
69 atoms => $atoms,
70 info => $header,
71 model_ids => $model_ids
72 )
73 );
74 }
75  
76 6 ▶sub read_file_mol {
Subroutine read_file_mol: called CC=1 SCAR=0.0
Pod documented
77 6 my $self = shift;
78 6 my $file = shift;
79  
80 6 my @atoms = $self->read_file_atoms($file);
81 6 my $name = $file;
82 6 return ( HackaMol::Molecule->new( name => $name, atoms => [@atoms] ) );
83 }
84  
85 6 ▶sub read_string_mol {
Subroutine read_string_mol: called CC=2 SCAR=7.0
Pod undocumented
86 6 my $self = shift;
87 6 my $string = shift;
88 6 ▶ my $format = shift or croak "must pass format: xyz, pdb, pdbqt, zmat, yaml";
Branch: 1 branch
BranchTrueFalseTotal
my $format = shift() or croak("must pass format: xyz, pdb, pdbqt, zmat, yaml") 6 0 6
89  
90 6 my @atoms = $self->read_string_atoms( $string, $format );
91 6 my $name = $format . ".mol";
92 6 return ( HackaMol::Molecule->new( name => $name, atoms => [@atoms] ) );
93 }
94  
95 4 ▶sub build_bonds {
Subroutine build_bonds: called CC=3 SCAR=11.0
Pod documented
96  
97 #take a list of n, atoms; walk down list and generate bonds
98 4 my $self = shift;
99 4 my @atoms = @_;
100 4 ▶ croak "<2 atoms passed to build_bonds" unless ( @atoms > 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @atoms > 1 1 3 4
101 3 my @bonds;
102  
103 # build the bonds
104 3 my $k = 0;
105 3 ▶ while ( $k + 1 <= $#atoms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k + 1 <= $#atoms) 177 3 180
106 my $name =
107 177 join( "_", map { _name_resid( $_, 'B' ) } @atoms[ $k .. $k + 1 ] );
108 177 push @bonds,
109 HackaMol::Bond->new(
110 name => $name,
111 atoms => [ @atoms[ $k, $k + 1 ] ]
112 );
113 177 $k++;
114 }
115 3 return (@bonds);
116 }
117  
118 4 ▶sub build_angles {
Subroutine build_angles: called CC=3 SCAR=11.0
Pod documented
119  
120 #take a list of n, atoms; walk down list and generate angles
121 4 my $self = shift;
122 4 my @atoms = @_;
123 4 ▶ croak "<3 atoms passed to build_angles" unless ( @atoms > 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @atoms > 2 1 3 4
124 3 my @angles;
125  
126 # build the angles
127 3 my $k = 0;
128  
129 3 ▶ while ( $k + 2 <= $#atoms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k + 2 <= $#atoms) 174 3 177
130 my $name =
131 174 join( "_", map { _name_resid( $_, 'A' ) } @atoms[ $k .. $k + 2 ] );
132 174 push @angles,
133 HackaMol::Angle->new(
134 name => $name,
135 atoms => [ @atoms[ $k .. $k + 2 ] ]
136 );
137 174 $k++;
138 }
139 3 return (@angles);
140 }
141  
142 1560 ▶sub _name_resid {
Subroutine _name_resid: called CC=2 SCAR=6.9
143 1560 my $atom = shift;
144 1560 my $default = shift;
145 1560 ▶ return ( $default . $atom->resid )
Branch: 1 branch
BranchTrueFalseTotal
unless $atom->has_name 520 1040 1560
146 unless $atom->has_name; # this comes up when undefined atoms are passed
147 1040 return ( $atom->name . $atom->resid );
148 }
149  
150 4 ▶sub build_dihedrals {
Subroutine build_dihedrals: called CC=3 SCAR=11.0
Pod documented
151  
152 #take a list of n, atoms; walk down list and generate dihedrals
153 4 my $self = shift;
154 4 my @atoms = @_;
155 4 ▶ croak "<4 atoms passed to build_dihedrals" unless ( @atoms > 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @atoms > 3 1 3 4
156 3 my @dihedrals;
157  
158 # build the dihedrals
159 3 my $k = 0;
160 3 ▶ while ( $k + 3 <= $#atoms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k + 3 <= $#atoms) 171 3 174
161 my $name =
162 171 join( "_", map { _name_resid( $_, 'D' ) } @atoms[ $k .. $k + 3 ] );
163 171 push @dihedrals,
164 HackaMol::Dihedral->new(
165 name => $name,
166 atoms => [ @atoms[ $k .. $k + 3 ] ]
167 );
168 171 $k++;
169 }
170 3 return (@dihedrals);
171 }
172  
173 16 ▶sub group_by_atom_attr {
Subroutine group_by_atom_attr: called CC=2 SCAR=6.9
Pod documented
174  
175 # group atoms by attribute
176 # Z, name, bond_count, etc.
177 16 my $self = shift;
178 16 my $attr = shift;
179 16 my @atoms = @_;
180  
181 16 my %group;
182 16 foreach my $atom (@atoms) {
183 1520 push @{ $group{ $atom->$attr } }, $atom;
184 }
185  
186 my @atomgroups =
187 16 map { HackaMol::AtomGroup->new( atoms => $group{$_} ) } sort
188 keys(%group);
189  
190 16 return (@atomgroups);
191  
192 }
193  
194 1 ▶sub group_by_atom_attrs {
Subroutine group_by_atom_attrs: called CC=4 SCAR=13.9
Pod documented
195  
196 # group atoms by attributes
197 # Z, name, bond_count, etc.
198 # keep splitting the groups until there are no more attributes
199 1 my $self = shift;
200 1 my @attrs = @{ +shift };
201 1 my @atoms = @_;
202  
203 1 ▶ return () unless @attrs;
Branch: 1 branch
BranchTrueFalseTotal
unless @attrs 0 1 1
204  
205 1 my @groups = ( HackaMol::AtomGroup->new( atoms => [@atoms] ) );
206  
207 1 foreach my $attr (@attrs) {
208 2 my @local_groups;
209 2 foreach my $group (@groups) {
210 13 push @local_groups,
211 $self->group_by_atom_attr( $attr, $group->all_atoms );
212 }
213 2 @groups = @local_groups;
214 }
215  
216 1 return (@groups);
217  
218 }
219  
220 1 ▶sub mol_disulfide_bonds {
Subroutine mol_disulfide_bonds: called CC=6 SCAR=18.0
Pod documented
221  
222 # take atom group
223 1 my $self = shift;
224 1 my $mol = shift;
225 1 my $fudge = shift;
226 1 ▶ $fudge = 0.15 unless defined($fudge);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fudge 0 1 1
227  
228 1 my @sulfs = $mol->select_group("Z 16")->all_atoms;
229 1 ▶ return unless @sulfs;
Branch: 1 branch
BranchTrueFalseTotal
unless @sulfs 0 1 1
230 1 my $dcut = 2 * $sulfs[0]->covalent_radius + $fudge;
231 1 my $nm = "S-S";
232 1 my $count = 1;
233 1 my @bonds = ();
234 1 foreach my $is ( 0 .. $#sulfs ) {
235 27 my $at_i = $sulfs[$is];
236 27 foreach my $js ( $is + 1 .. $#sulfs ) {
237 351 my $at_j = $sulfs[$js];
238 351 my $dist = $at_j->distance($at_i);
239 351 ▶ if ( $dist <= $dcut ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist <= $dcut) 9 342 351
240 9 push @bonds,
241 HackaMol::Bond->new(
242 name => $nm . "_" . $count++,
243 atoms => [ $at_i, $at_j ],
244 );
245 }
246 }
247 }
248 1 return @bonds;
249 }
250  
251 1 ▶sub find_disulfide_bonds {
Subroutine find_disulfide_bonds: called CC=1 SCAR=0.0
Pod documented
252  
253 # to be deprecated
254 # works fine for single disulfide bonds
255 # but does not
256 1 my $self = shift;
257  
258 1 my @sulf = grep { $_->Z == 16 } @_;
259 1 my @ss = $self->find_bonds_brute(
260 bond_atoms => [@sulf],
261 candidates => [@sulf],
262 fudge => 0.15, # 0.45 is too large
263 max_bonds => 1,
264 );
265 1 return @ss;
266 }
267  
268 6 ▶sub find_bonds_brute {
Subroutine find_bonds_brute: called CC=10 SCAR=23.0
Pod documented
269 6 my $self = shift;
270 6 my %args = @_;
271 6 my @bond_atoms = @{ $args{bond_atoms} };
272 6 my @atoms = @{ $args{candidates} };
273  
274 6 my $fudge = 0.45;
275 6 my $max_bonds = 99;
276  
277 6 ▶ $fudge = $args{fudge} if ( exists( $args{fudge} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"fudge"} 5 1 6
278 6 ▶ $max_bonds = $args{max_bonds} if ( exists( $args{max_bonds} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"max_bonds"} 1 5 6
279  
280 6 my @init_bond_counts = map { $_->bond_count } ( @bond_atoms, @atoms );
281  
282 6 my @bonds;
283 my %name;
284  
285 6 foreach my $at_i (@bond_atoms) {
286 37 ▶ next if ( $at_i->bond_count >= $max_bonds );
Branch: 1 branch
BranchTrueFalseTotal
if $at_i->bond_count >= $max_bonds 9 28 37
287 28 my $cov_i = $at_i->covalent_radius;
288  
289 28 foreach my $at_j (@atoms) {
290 1030 ▶ next if ( refaddr($at_i) == refaddr($at_j) );
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($at_i) == builtin::refaddr($at_j) 28 1002 1030
291 1002 ▶ next if ( $at_j->bond_count >= $max_bonds );
Branch: 1 branch
BranchTrueFalseTotal
if $at_j->bond_count >= $max_bonds 158 844 1002
292 844 my $cov_j = $at_j->covalent_radius;
293 844 my $dist = $at_j->distance($at_i);
294  
295 844 ▶ if ( $dist <= $cov_i + $cov_j + $fudge ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dist <= $cov_i + $cov_j + $fudge) 33 811 844
296 33 my $nm = $at_i->symbol . "-" . $at_j->symbol;
297 33 $name{$nm}++;
298 push @bonds,
299 HackaMol::Bond->new(
300 33 name => "$nm\_" . $name{$nm},
301 atoms => [ $at_i, $at_j ],
302 );
303 33 $at_i->inc_bond_count;
304 33 $at_j->inc_bond_count;
305 }
306  
307 }
308 }
309  
310 6 my $i = 0;
311 6 foreach my $at ( @bond_atoms, @atoms ) {
312 338 $at->reset_bond_count;
313 338 $at->inc_bond_count( $init_bond_counts[$i] );
314 338 $i++;
315 }
316 6 return (@bonds);
317  
318 }
319  
320 0 ▶sub group_rot {
Subroutine group_rot: not called CC=1 SCAR=6.9
Pod undocumented
321  
322 # no pod yet
323 # this method walks out from the two atoms in a bond and returns a group
324 0 my $self = shift;
325 0 my $mol = shift;
326 0 my $bond = shift;
327 0 my $iba = $bond->get_atoms(0)->iatom;
328 0 my $ibb = $bond->get_atoms(1)->iatom;
329  
330 0 my $init = {
331 $iba => 1,
332 $ibb => 1,
333 };
334 0 my $root = $ibb;
335 0 my $rotation_indices = _qrotatable( $mol->atoms, $ibb, $init );
336 0 delete( $rotation_indices->{$iba} );
337 0 delete( $rotation_indices->{$ibb} );
338  
339 return (
340 HackaMol::AtomGroup->new(
341 atoms => [
342 0 map { $mol->get_atoms($_) }
343 0 keys %{$rotation_indices}
344 ]
345 )
346 );
347  
348 }
349  
350 1 ▶sub superpose_rt {
Subroutine superpose_rt: called CC=4 SCAR=13.9
Pod documented
351  
352 # args: two HackaMol::AtomGroup or HackaMol::Molecule with the same number of atoms
353 # the atoms are assumed to be in the same order, that's it!
354 #
355 # uses all vectors (mvr) in group to calculate the rotation matrix, and translation vector
356 # needed to superpose the second group on to the first group.
357 #
358 # a typical workflow will run this to get the rotation and translation and then the AtomGroupRole
359 # rotate_translate method to actually do the coordinate transformation.
360 #
361 # the algorithm is lifted from Bio::PDB::Structure, which in turn implements
362 # method from S. Kearsley, Acta Cryst. A45, 208-210 1989
363 # may not be very fast. better suited to PDL
364 #
365 # returns:
366 # 1. rotation matrix [3 rows, each is a MVR , e.g. x' = row_1 * xyz]
367 # 2. translation vector (MVR)
368 # 3. rmsd
369 #
370 1 my $self = shift;
371 1 my $g2 = shift; # switch order, function here vs method in Bio::PDB
372 1 my $g1 = shift;
373  
374 1 my $nrd1 = $g1->count_atoms;
375 1 my $nrd2 = $g2->count_atoms;
376 1 ▶ die "superpose error: groups must have same number of atoms\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $nrd1 == $nrd2 and $nrd1 > 0 0 1 1
Condition33%1/3
$nrd1 == $nrd2 and $nrd1 > 0
!ll&&!rl&&r
001
MC/DC0%0/2
$nrd1 == $nrd2 and $nrd1 > 0
$nrd1 == $nrd2 $nrd1 > 0
Truth table33%1/3
A and B
A= $nrd1 == $nrd2B= $nrd1 > 0
ABresult
0X0
100
111
377 unless ( $nrd1 == $nrd2 && $nrd1 > 0 );
378  
379 1 my ( $x1, $y1, $z1 );
380 1 my ( $x2, $y2, $z2 );
381 1 my ( $xm, $ym, $zm );
382 1 my ( $xp, $yp, $zp );
383 1 my ( $Sxmxm, $Sxpxp, $Symym, $Sypyp, $Szmzm, $Szpzp );
384 1 my ( $Sxmym, $Sxmyp, $Sxpym, $Sxpyp );
385 1 my ( $Sxmzm, $Sxmzp, $Sxpzm, $Sxpzp );
386 1 my ( $Symzm, $Symzp, $Sypzm, $Sypzp );
387  
388 1 my $gc1 = $g1->center;
389 1 my $gc2 = $g2->center; # these are MVRs
390  
391 1 my @mvr1 = map { $_->xyz - $gc1 } $g1->all_atoms;
392 1 my @mvr2 = map { $_->xyz - $gc2 } $g2->all_atoms;
393  
394 1 foreach my $i ( 0 .. $nrd1 - 1 ) {
395 7 ( $x1, $y1, $z1 ) = @{ $mvr1[$i] };
396 7 ( $x2, $y2, $z2 ) = @{ $mvr2[$i] };
397 7 $xm = ( $x1 - $x2 );
398 7 $xp = ( $x1 + $x2 );
399 7 $ym = ( $y1 - $y2 );
400 7 $yp = ( $y1 + $y2 );
401 7 $zm = ( $z1 - $z2 );
402 7 $zp = ( $z1 + $z2 );
403  
404 7 $Sxmxm += $xm * $xm;
405 7 $Sxpxp += $xp * $xp;
406 7 $Symym += $ym * $ym;
407 7 $Sypyp += $yp * $yp;
408 7 $Szmzm += $zm * $zm;
409 7 $Szpzp += $zp * $zp;
410  
411 7 $Sxmym += $xm * $ym;
412 7 $Sxmyp += $xm * $yp;
413 7 $Sxpym += $xp * $ym;
414 7 $Sxpyp += $xp * $yp;
415  
416 7 $Sxmzm += $xm * $zm;
417 7 $Sxmzp += $xm * $zp;
418 7 $Sxpzm += $xp * $zm;
419 7 $Sxpzp += $xp * $zp;
420  
421 7 $Symzm += $ym * $zm;
422 7 $Symzp += $ym * $zp;
423 7 $Sypzm += $yp * $zm;
424 7 $Sypzp += $yp * $zp;
425 }
426  
427 1 my @m;
428 1 $m[0] = $Sxmxm + $Symym + $Szmzm;
429 1 $m[1] = $Sypzm - $Symzp;
430 1 $m[2] = $Sxmzp - $Sxpzm;
431 1 $m[3] = $Sxpym - $Sxmyp;
432 1 $m[4] = $m[1];
433 1 $m[5] = $Sypyp + $Szpzp + $Sxmxm;
434 1 $m[6] = $Sxmym - $Sxpyp;
435 1 $m[7] = $Sxmzm - $Sxpzp;
436 1 $m[8] = $m[2];
437 1 $m[9] = $m[6];
438 1 $m[10] = $Sxpxp + $Szpzp + $Symym;
439 1 $m[11] = $Symzm - $Sypzp;
440 1 $m[12] = $m[3];
441 1 $m[13] = $m[7];
442 1 $m[14] = $m[11];
443 1 $m[15] = $Sxpxp + $Sypyp + $Szmzm;
444  
445 #compute the egienvectors and eigenvalues of the matrix
446 1 my ( $revec, $reval ) = &__diagonalize(@m);
447  
448 #the smallest eigenvalue is the rmsd for the optimal alignment
449 1 my $rmsd = sqrt( abs( $reval->[0] ) / $nrd1 );
450  
451 #fetch the optimal quaternion
452 1 my @q;
453 1 $q[0] = $revec->[0][0];
454 1 $q[1] = $revec->[1][0];
455 1 $q[2] = $revec->[2][0];
456 1 $q[3] = $revec->[3][0];
457  
458 #construct the rotation matrix given by the quaternion
459 1 my @mt;
460 1 $mt[0] = $q[0] * $q[0] + $q[1] * $q[1] - $q[2] * $q[2] - $q[3] * $q[3];
461 1 $mt[1] = 2.0 * ( $q[1] * $q[2] - $q[0] * $q[3] );
462 1 $mt[2] = 2.0 * ( $q[1] * $q[3] + $q[0] * $q[2] );
463  
464 1 $mt[3] = 2.0 * ( $q[2] * $q[1] + $q[0] * $q[3] );
465 1 $mt[4] = $q[0] * $q[0] - $q[1] * $q[1] + $q[2] * $q[2] - $q[3] * $q[3];
466 1 $mt[5] = 2.0 * ( $q[2] * $q[3] - $q[0] * $q[1] );
467  
468 1 $mt[6] = 2.0 * ( $q[3] * $q[1] - $q[0] * $q[2] );
469 1 $mt[7] = 2.0 * ( $q[3] * $q[2] + $q[0] * $q[1] );
470 1 $mt[8] = $q[0] * $q[0] - $q[1] * $q[1] - $q[2] * $q[2] + $q[3] * $q[3];
471  
472 #compute the displacement vector
473 1 my @vt;
474 1 $vt[0] =
475 $gc2->[0] - $mt[0] * $gc1->[0] - $mt[1] * $gc1->[1] - $mt[2] * $gc1->[2];
476 1 $vt[1] =
477 $gc2->[1] - $mt[3] * $gc1->[0] - $mt[4] * $gc1->[1] - $mt[5] * $gc1->[2];
478 1 $vt[2] =
479 $gc2->[2] - $mt[6] * $gc1->[0] - $mt[7] * $gc1->[1] - $mt[8] * $gc1->[2];
480  
481 1 return ( [ V( @mt[ 0, 1, 2 ] ), V( @mt[ 3, 4, 5 ] ), V( @mt[ 6, 7, 8 ] ) ],
482 V(@vt), $rmsd );
483 }
484  
485 0 ▶sub rmsd {
Subroutine rmsd: not called CC=7 SCAR=40.3
Pod documented
486 0 my $self = shift;
487 0 my $g1 = shift; # switch order, function here vs method in Bio::PDB
488 0 my $g2 = shift;
489 0 my $w = shift;
490  
491 0 my $nrd1 = $g1->count_atoms;
492 0 my $nrd2 = $g2->count_atoms;
493 0 ▶ die "rmsd error: groups must have same number of atoms\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $nrd1 == $nrd2 and $nrd1 > 0 0 0 0
Condition0%0/3
$nrd1 == $nrd2 and $nrd1 > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$nrd1 == $nrd2 and $nrd1 > 0
$nrd1 == $nrd2 $nrd1 > 0
Truth table0%0/3
A and B
A= $nrd1 == $nrd2B= $nrd1 > 0
ABresult
0X0
100
111
494 unless ( $nrd1 == $nrd2 && $nrd1 > 0 );
495  
496 0 my @w;
497 0 ▶ if ( defined($w) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $w) { } 0 0 0
498 0 @w = @{$w};
499 }
500 else {
501 0 @w = map { 1 } 0 .. $nrd1 - 1;
502 }
503  
504 0 ▶ die "rmsd error: atom array weight must have same dimension as groups\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $nrd1 == scalar @w 0 0 0
505 unless ( $nrd1 == scalar(@w) );
506 0 my $sum_weights =
507 0; # will be same as number of atoms if no weights are defined
508  
509 0 $sum_weights += $_ foreach @w;
510  
511 0 my @xyz_1 = map { $_->xyz } $g1->all_atoms;
512 0 my @xyz_2 = map { $_->xyz } $g2->all_atoms;
513  
514 0 my $sqr_dev = 0;
515 0 $sqr_dev += $w[$_] * $xyz_1[$_]->dist2( $xyz_2[$_] ) foreach 0 .. $#xyz_1;
516 0 return sqrt( $sqr_dev / $sum_weights );
517 }
518  
519 0 ▶sub _qrotatable {
Subroutine _qrotatable: not called CC=6 SCAR=37.4
520 0 my $atoms = shift;
521 0 my $iroot = shift;
522 0 my $visited = shift;
523  
524 0 $visited->{$iroot}++;
525  
526 0 ▶ if ( scalar( keys %$visited ) > 80 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$visited > 80) 0 0 0
527 0 carp "search too deep. exiting recursion";
528 0 return;
529 }
530  
531 0 my @cands;
532 0 foreach my $at (@$atoms) {
533 0 ▶ push @cands, $at unless ( grep { $at->iatom == $_ } keys %{$visited} );
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$at->iatom == $_;} keys %{$visited;} 0 0 0
534 }
535  
536 #not calling in object context, hence the dummy 'self'
537 0 my @bonds = find_bonds_brute(
538 'self',
539 bond_atoms => [ $atoms->[$iroot] ],
540 candidates => [@cands],
541 fudge => 0.45,
542 );
543  
544 0 foreach my $cand ( map { $_->get_atoms(1) } @bonds ) {
545 0 ▶ next if $visited->{ $cand->iatom };
Branch: 1 branch
BranchTrueFalseTotal
if $$visited{$cand->iatom} 0 0 0
546 0 my $visited = _qrotatable( $atoms, $cand->iatom, $visited );
547 }
548 0 return ($visited);
549 }
550  
551 #Jacobi diagonalizer
552 1 ▶sub __diagonalize {
Subroutine __diagonalize: called CC=22 SCAR=47.0
553 1 my ( $onorm, $dnorm );
554 1 my ( $b, $dma, $q, $t, $c, $s );
555 1 my ( $atemp, $vtemp, $dtemp );
556 1 my ( $i, $j, $k, $l );
557 1 my @a;
558 1 my @v;
559 1 my @d;
560 1 my $nrot = 30; #number of sweeps
561  
562 1 ▶ for ( $i = 0 ; $i < 4 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 4) 4 1 5
563 4 ▶ for ( $j = 0 ; $j < 4 ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 4) 16 4 20
564 16 $a[$i][$j] = $_[ 4 * $i + $j ];
565 16 $v[$i][$j] = 0.0;
566 }
567 }
568  
569 1 ▶ for ( $j = 0 ; $j <= 3 ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= 3) 4 1 5
570 4 $v[$j][$j] = 1.0;
571 4 $d[$j] = $a[$j][$j];
572 }
573  
574 1 ▶ for ( $l = 1 ; $l <= $nrot ; $l++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l <= $nrot) 1 0 1
575 1 $dnorm = 0.0;
576 1 $onorm = 0.0;
577 1 ▶ for ( $j = 0 ; $j <= 3 ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= 3) 4 1 5
578 4 $dnorm += abs( $d[$j] );
579 4 ▶ for ( $i = 0 ; $i <= $j - 1 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $j - 1) 6 4 10
580 6 $onorm += abs( $a[$i][$j] );
581 }
582 }
583 1 ▶ last if ( ( $onorm / $dnorm ) <= 1.0e-12 );
Branch: 1 branch
BranchTrueFalseTotal
if $onorm / $dnorm <= "1e-12" 1 0 1
584 0 ▶ for ( $j = 1 ; $j <= 3 ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= 3) 0 0 0
585 0 ▶ for ( $i = 0 ; $i <= $j - 1 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $j - 1) 0 0 0
586 0 $b = $a[$i][$j];
587 0 ▶ if ( abs($b) > 0.0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $b > 0) 0 0 0
588 0 $dma = $d[$j] - $d[$i];
589 0 ▶ if ( ( abs($dma) + abs($b) ) <= abs($dma) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs($dma) + abs($b) <= abs $dma) { } 0 0 0
590 0 $t = $b / $dma;
591 }
592 else {
593 0 $q = 0.5 * $dma / $b;
594 0 $t = 1.0 / ( abs($q) + sqrt( 1.0 + $q * $q ) );
595 0 ▶ $t *= -1.0 if ( $q < 0.0 );
Branch: 1 branch
BranchTrueFalseTotal
if $q < 0 0 0 0
596 }
597 0 $c = 1.0 / sqrt( $t * $t + 1.0 );
598 0 $s = $t * $c;
599 0 $a[$i][$j] = 0.0;
600 0 ▶ for ( $k = 0 ; $k <= $i - 1 ; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $i - 1) 0 0 0
601 0 $atemp = $c * $a[$k][$i] - $s * $a[$k][$j];
602 0 $a[$k][$j] = $s * $a[$k][$i] + $c * $a[$k][$j];
603 0 $a[$k][$i] = $atemp;
604 }
605 0 ▶ for ( $k = $i + 1 ; $k <= $j - 1 ; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= $j - 1) 0 0 0
606 0 $atemp = $c * $a[$i][$k] - $s * $a[$k][$j];
607 0 $a[$k][$j] = $s * $a[$i][$k] + $c * $a[$k][$j];
608 0 $a[$i][$k] = $atemp;
609 }
610 0 ▶ for ( $k = $j + 1 ; $k <= 3 ; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= 3) 0 0 0
611 0 $atemp = $c * $a[$i][$k] - $s * $a[$j][$k];
612 0 $a[$j][$k] = $s * $a[$i][$k] + $c * $a[$j][$k];
613 0 $a[$i][$k] = $atemp;
614 }
615 0 ▶ for ( $k = 0 ; $k <= 3 ; $k++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k <= 3) 0 0 0
616 0 $vtemp = $c * $v[$k][$i] - $s * $v[$k][$j];
617 0 $v[$k][$j] = $s * $v[$k][$i] + $c * $v[$k][$j];
618 0 $v[$k][$i] = $vtemp;
619 }
620 0 $dtemp =
621 $c * $c * $d[$i] + $s * $s * $d[$j] - 2.0 * $c * $s * $b;
622 0 $d[$j] =
623 $s * $s * $d[$i] + $c * $c * $d[$j] + 2.0 * $c * $s * $b;
624 0 $d[$i] = $dtemp;
625 }
626 }
627 }
628 }
629 1 $nrot = $l;
630 1 ▶ for ( $j = 0 ; $j <= 2 ; $j++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= 2) 3 1 4
631 3 $k = $j;
632 3 $dtemp = $d[$k];
633 3 ▶ for ( $i = $j + 1 ; $i <= 3 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 3) 6 3 9
634 6 ▶ if ( $d[$i] < $dtemp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d[$i] < $dtemp) 0 6 6
635 0 $k = $i;
636 0 $dtemp = $d[$k];
637 }
638 }
639  
640 3 ▶ if ( $k > $j ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k > $j) 0 3 3
641 0 $d[$k] = $d[$j];
642 0 $d[$j] = $dtemp;
643 0 ▶ for ( $i = 0 ; $i <= 3 ; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 3) 0 0 0
644 0 $dtemp = $v[$i][$k];
645 0 $v[$i][$k] = $v[$i][$j];
646 0 $v[$i][$j] = $dtemp;
647 }
648 }
649 }
650  
651 1 return ( \@v, \@d );
652 }
653  
654 11 __PACKAGE__->meta->make_immutable;
655  
656 11 1;
657  
658 __END__
« HackaMol/Roles/RcsbRole.pm ↑ Summary HackaMol/Roles/ReadPdbRole.pm »