File Coverage

blib/lib/HackaMol/Roles/NERFRole.pm
Criterion Covered Total %
statement 14 38 36.8
branch 0 4 0.0
condition n/a
subroutine 5 9 55.5
pod 4 4 100.0
total 23 55 41.8


line stmt bran cond sub pod time code
1             package HackaMol::Roles::NERFRole;
2             # ABSTRACT: Role providing Natural extension reference frame implementation for molecular building
3             $HackaMol::Roles::NERFRole::VERSION = '0.051';
4 11     11   6590 use 5.008;
  11         56  
5 11     11   82 use Moose::Role;
  11         29  
  11         89  
6 11     11   59745 use Math::Vector::Real;
  11         34  
  11         607  
7 11     11   78 use Math::Trig;
  11         31  
  11         4948  
8              
9             my $orig = V(0,0,0);
10              
11             sub init {
12             # adding the first vector
13 0     0 1   my $self = shift;
14 0 0         if (@_ == 3){
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     0 1   my ($self, $a, $R, $optvec) = @_;
25 0 0         $optvec = V(1,0,0) unless defined($optvec);
26 0           return ($a + $R*$optvec->versor);
27             }
28              
29             sub extend_ab {
30 0     0 1   my ($self,$a,$b,$R,$ang) = @_;
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     0 1   my ($self,$a,$b,$c,$R,$ang,$tors) = @_;
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     11   96 no Moose::Role;
  11         36  
  11         65  
55              
56             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