HackaMol/Roles/NERFRole.pm

filter: Statementstmt 41.4% 17 / 41 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 44.8% 26 / 58 SCAR 16.4
CC
3
Cov
38%
init
6.0
extend_a
6.0
extend_ab
2.0
CRAP 5.2
« HackaMol/Roles/SelectionRole.pm ↑ Summary HackaMol/Roles/PdbRole.pm »
1 package HackaMol::Roles::NERFRole;
2 # ABSTRACT: Role providing Natural extension reference frame implementation for molecular building
3 11 $HackaMol::Roles::NERFRole::VERSION = '0.051';
4 11 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Math::Vector::Real;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Math::Trig;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 my $orig = V(0,0,0);
10  
11 sub init {
12 # adding the first vector
13 0 ▶ my $self = shift;
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
14 0 ▶ if (@_ == 3){
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 3) { } 0 0 0
15 0 return V(@_);
16 }
17 else {
18 0 return $orig;
19 }
20 }
21  
22 sub extend_a {
23 #allow the use of optvec to give control over the addition
24 0 ▶ my ($self, $a, $R, $optvec) = @_;
Subroutine extend_a: not called CC=2 SCAR=17.9
Pod documented
25 0 ▶ $optvec = V(1,0,0) unless defined($optvec);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $optvec 0 0 0
26 0 return ($a + $R*$optvec->versor);
27 }
28  
29 sub extend_ab {
30 0 ▶ my ($self,$a,$b,$R,$ang) = @_;
Subroutine extend_ab: not called CC=1 SCAR=6.9
Pod documented
31 0 $ang = deg2rad(180-$ang);
32 0 my ($ba, $j, $k) = ($b-$a)->rotation_base_3d;
33 0 my $c = $b+$ba*$R;
34 0 $c = $j->rotate_3d($ang, $c-$b) + $b;
35 0 return ($c);
36 }
37  
38 sub extend_abc {
39 0 ▶ my ($self,$a,$b,$c,$R,$ang,$tors) = @_;
Subroutine extend_abc: not called CC=1 SCAR=6.9
Pod documented
40 0 $ang = deg2rad(180-$ang);
41 0 $tors = deg2rad($tors);
42 0 my $cang = cos($ang);
43 0 my $sang = sin($ang);
44 0 my $ctor = cos($tors);
45 0 my $stor = sin($tors);
46  
47 0 my $bc = ($c-$b)->versor;
48 0 my $n = (($b-$a) x $bc)->versor;
49  
50 0 my $D = $R*($bc*$cang + ($n x $bc)*$sang*$ctor + $n*$sang*$stor) + $c;
51 0 return $D;
52 }
53  
54 11 ▶no Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 11 1;
57  
58 __END__
59  
60 =pod
61  
62 =head1 NAME
63  
64 HackaMol::Roles::NERFRole - Role providing Natural extension reference frame implementation for molecular building
65  
66 =head1 VERSION
67  
68 version 0.051
69  
70 =head1 SYNOPSIS
71  
72 # Adds the NERF capabilities to consuming classes
73 # Let's say that the $bld object below consumes this Role
74 #Let's build a six member ring
75  
76 push @vecs, $bld->init() ;
77 push @vecs, $bld->extend_a( $vecs[0] , 1.47 );
78 push @vecs, $bld->extend_ab( @vecs[0,1], 1.47, 109.5 );
79 push @vecs, $bld->extend_abc(@vecs[0,1,2], 1.47, 109.5, 60 );
80 push @vecs, $bld->extend_abc(@vecs[1,2,3], 1.47, 109.5, -60 );
81 push @vecs, $bld->extend_abc(@vecs[2,3,4], 1.47, 109.5, 60 );
82  
83 printf ("C %10.6f %10.6f %10.6f\n", @$_ ) foreach @vecs;
84  
85 =head1 DESCRIPTION
86  
87 The HackaMol::X::NERF library is a quick implementation of the Natural
88 Extension Reference Frame method for building cartesian coordinates from
89 internal coordinates. It is experimental. In fact, there are
90 no substantial tests yet! They will be added soon.
91 The API will change and expand. Currently, the class provides four methods four initializing and extending a vector space. Lend me a hand if you are interested!
92  
93 Study Z-matrices and the synopsis should be easy to understand. All angles are in degrees.
94  
95 =head1 METHODS
96  
97 =head2 init
98  
99 optional argument is list of three numbers: x, y, and z.
100  
101 Returns an MVR object constructed from V(0,0,0) or V(x,y,z).
102  
103 =head2 extend_a(MVR1, R)
104  
105 two arguments MVR1 and R, along with optional argument MVR2.
106  
107 Returns an MVR object that is a distance R from MVR1. This new vector will be
108 displaced along the x axis unless the optional MVR2 is passed. If MVR2 the
109 MVR returned is displace by R times the unit vector parallel to MVR1.
110  
111 =head2 extend_ab(MVR1, MVR2, R, ANGLE)
112  
113 four arguments MVR1, MVR2, R, and ANGLE.
114  
115 Returns an MVR object that is a distance R from MVR2 and at ANGLE from MVR1.
116  
117 =head2 extend_abc(MVR1, MVR2, MVR3, R, ANGLE, TORSION)
118  
119 six arguments MVR1, MVR2, MVR3, R, ANGLE, and TORSION.
120  
121 Returns an MVR object that is a distance R from MVR3, at ANGLE from MVR2,
122 and at TORSION from MVR1 via the vector between MVR2 and MVR3.
123  
124 =head1 AUTHOR
125  
126 Demian Riccardi <demianriccardi@gmail.com>
127  
128 =head1 COPYRIGHT AND LICENSE
129  
130 This software is copyright (c) 2017 by Demian Riccardi.
131  
132 This is free software; you can redistribute it and/or modify it under
133 the same terms as the Perl 5 programming language system itself.
134  
135 =cut
« HackaMol/Roles/SelectionRole.pm ↑ Summary HackaMol/Roles/PdbRole.pm »