| Filename | /Users/dde/HackaMol_devel/HackaMol/lib/roles/PhysVecRole.pm |
| Statements | Executed 200018 statements in 387ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 200000 | 1 | 1 | 142ms | 142ms | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:20] |
| 1 | 1 | 1 | 22µs | 1.85ms | PhysVecRole::BEGIN@3 |
| 1 | 1 | 1 | 7µs | 35µs | PhysVecRole::BEGIN@4 |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:114] |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:128] |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:157] |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:192] |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:39] |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:46] |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_charge |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_coord |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_delta_charges_coderef |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_delta_coords_coderef |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_delta_forces_coderef |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_distance_coderef |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::_build_forces |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::delta_charges |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::delta_coords |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::delta_forces |
| 0 | 0 | 0 | 0s | 0s | PhysVecRole::distance |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package PhysVecRole; | ||||
| 2 | # ABSTRACT: Provides the core of HackaMol Atom and Molecule classes. | ||||
| 3 | 2 | 29µs | 2 | 3.68ms | # spent 1.85ms (22µs+1.83) within PhysVecRole::BEGIN@3 which was called:
# once (22µs+1.83ms) by Module::Runtime::require_module at line 3 # spent 1.85ms making 1 call to PhysVecRole::BEGIN@3
# spent 1.83ms making 1 call to Moose::Exporter::__ANON__[Moose/Exporter.pm:519] |
| 4 | 2 | 838µs | 2 | 63µs | # spent 35µs (7+28) within PhysVecRole::BEGIN@4 which was called:
# once (7µs+28µs) by Module::Runtime::require_module at line 4 # spent 35µs making 1 call to PhysVecRole::BEGIN@4
# spent 28µs making 1 call to Exporter::import |
| 5 | |||||
| 6 | 1 | 2µs | 1 | 3.77ms | has 'name' , is => 'rw', isa => 'Str' ; # spent 3.77ms making 1 call to Moose::Role::has |
| 7 | |||||
| 8 | 1 | 1µs | 1 | 78µs | has 'mass' , is => 'rw', isa => 'Num' , lazy => 1, default => 0; # spent 78µs making 1 call to Moose::Role::has |
| 9 | |||||
| 10 | 1 | 900ns | 1 | 76µs | has 't' , is => 'rw', isa => 'Int|ScalarRef' , default => 0; # spent 76µs making 1 call to Moose::Role::has |
| 11 | |||||
| 12 | 1 | 900ns | 1 | 70µs | has 'is_fixed' , is => 'rw', isa => 'Bool', lazy => 1, default => 0; # spent 70µs making 1 call to Moose::Role::has |
| 13 | |||||
| 14 | |||||
| 15 | 1 | 800ns | my @t_dep = qw(coords forces charges); | ||
| 16 | |||||
| 17 | has "_t$_" => ( | ||||
| 18 | traits => [ 'Array' ], | ||||
| 19 | isa => 'ArrayRef', | ||||
| 20 | 200000 | 386ms | # spent 142ms within PhysVecRole::__ANON__[lib/roles/PhysVecRole.pm:20] which was called 200000 times, avg 711ns/call:
# 200000 times (142ms+0s) by Atom::push_coords at line 10 of (eval 74)[Eval/Closure.pm:135], avg 711ns/call | ||
| 21 | handles => | ||||
| 22 | { | ||||
| 23 | "push_$_" => 'push' , | ||||
| 24 | "get_$_" => 'get' , | ||||
| 25 | "set_$_" => 'set' , | ||||
| 26 | "all_$_" => 'elements', | ||||
| 27 | "clear_$_" => 'clear' , | ||||
| 28 | "count_$_" => 'count' , | ||||
| 29 | }, | ||||
| 30 | lazy => 1, | ||||
| 31 | 1 | 17µs | 3 | 221µs | ) for @t_dep; # spent 221µs making 3 calls to Moose::Role::has, avg 74µs/call |
| 32 | |||||
| 33 | |||||
| 34 | 1 | 700ns | 1 | 68µs | has 'units' , is => 'rw', isa => 'Str' ; #flag for future use [SI] # spent 68µs making 1 call to Moose::Role::has |
| 35 | |||||
| 36 | has 'origin' => ( | ||||
| 37 | is => 'rw', | ||||
| 38 | isa => 'ArrayRef', | ||||
| 39 | default => sub{[0,0,0]}, | ||||
| 40 | 1 | 2µs | 1 | 67µs | lazy => 1, # spent 67µs making 1 call to Moose::Role::has |
| 41 | ); | ||||
| 42 | |||||
| 43 | has 'xyzfree' => ( | ||||
| 44 | is => 'rw', | ||||
| 45 | isa => 'ArrayRef[Int]', | ||||
| 46 | default => sub{[1,1,1]}, | ||||
| 47 | 1 | 2µs | 1 | 70µs | lazy => 1, # spent 70µs making 1 call to Moose::Role::has |
| 48 | ); | ||||
| 49 | |||||
| 50 | has $_ => ( | ||||
| 51 | is => 'rw', | ||||
| 52 | isa => 'Num', | ||||
| 53 | builder => "_build_$_", | ||||
| 54 | lazy => 1, | ||||
| 55 | predicate => "has_$_", | ||||
| 56 | 1 | 2µs | 1 | 77µs | ) foreach qw(charge); # spent 77µs making 1 call to Moose::Role::has |
| 57 | |||||
| 58 | has $_ => ( | ||||
| 59 | is => 'rw', | ||||
| 60 | isa => 'ArrayRef', | ||||
| 61 | builder => "_build_$_", | ||||
| 62 | lazy => 1, | ||||
| 63 | predicate => "has_$_", | ||||
| 64 | 1 | 4µs | 2 | 146µs | ) foreach qw(coord force); # spent 146µs making 2 calls to Moose::Role::has, avg 73µs/call |
| 65 | |||||
| 66 | sub _build_charge { | ||||
| 67 | my $self = shift; | ||||
| 68 | if ($self->count_charges){ | ||||
| 69 | return ( $self->get_charges($self->t) ); | ||||
| 70 | } | ||||
| 71 | else { | ||||
| 72 | return (0); | ||||
| 73 | } | ||||
| 74 | } | ||||
| 75 | |||||
| 76 | sub _build_coord { | ||||
| 77 | my $self = shift; | ||||
| 78 | if ($self->count_coords){ | ||||
| 79 | return ( $self->get_coords($self->t) ); | ||||
| 80 | } | ||||
| 81 | else { | ||||
| 82 | return ([0,0,0]); | ||||
| 83 | } | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | sub _build_forces { | ||||
| 87 | my $self = shift; | ||||
| 88 | if ($self->count_forces){ | ||||
| 89 | return ( $self->get_forces($self->t) ); | ||||
| 90 | } | ||||
| 91 | else { | ||||
| 92 | return ([0,0,0]); | ||||
| 93 | } | ||||
| 94 | } | ||||
| 95 | |||||
| 96 | |||||
| 97 | has "$_\_coderef" => ( | ||||
| 98 | is => 'rw', | ||||
| 99 | isa => 'CodeRef', | ||||
| 100 | builder => "_build_$_\_coderef", | ||||
| 101 | lazy => 1, | ||||
| 102 | 1 | 5µs | 3 | 212µs | ) foreach qw (delta_charges delta_coords delta_forces); # spent 212µs making 3 calls to Moose::Role::has, avg 71µs/call |
| 103 | |||||
| - - | |||||
| 106 | sub _build_delta_charges_coderef { | ||||
| 107 | my $self = shift; | ||||
| 108 | my $sub = sub{ | ||||
| 109 | my $self = shift; | ||||
| 110 | my $ti = shift; | ||||
| 111 | my $tf = shift; | ||||
| 112 | my $dq = $self->get_charges($tf) - $self->get_charges($ti); | ||||
| 113 | return ($dq); | ||||
| 114 | }; | ||||
| 115 | return ($sub); | ||||
| 116 | } | ||||
| 117 | |||||
| 118 | |||||
| 119 | sub _build_delta_coords_coderef { | ||||
| 120 | my $self = shift; | ||||
| 121 | my $sub = sub{ | ||||
| 122 | my $self = shift; | ||||
| 123 | my $ti = shift; | ||||
| 124 | my $tf = shift; | ||||
| 125 | my $vi = $self->get_coords($ti); | ||||
| 126 | my $vf = $self->get_coords($tf); | ||||
| 127 | return ([map{$vf->[$_]- $vi->[$_]} 0 .. 2]); | ||||
| 128 | }; | ||||
| 129 | return ($sub); | ||||
| 130 | } | ||||
| 131 | |||||
| 132 | sub delta_charges { | ||||
| 133 | my $self = shift; | ||||
| 134 | croak "delta_charges> pass initial and final time" unless (@_ == 2); | ||||
| 135 | my $ti = shift; | ||||
| 136 | my $tf = shift; | ||||
| 137 | &{$self->delta_charges_coderef}($self,$ti,$tf); | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | sub delta_coords { | ||||
| 141 | my $self = shift; | ||||
| 142 | croak "delta_coords> pass initial and final time" unless (@_ == 2); | ||||
| 143 | my $ti = shift; | ||||
| 144 | my $tf = shift; | ||||
| 145 | &{$self->delta_coords_coderef}($self,$ti,$tf); | ||||
| 146 | } | ||||
| 147 | |||||
| 148 | sub _build_delta_forces_coderef { | ||||
| 149 | my $self = shift; | ||||
| 150 | my $sub = sub{ | ||||
| 151 | my $self = shift; | ||||
| 152 | my $ti = shift; | ||||
| 153 | my $tf = shift; | ||||
| 154 | my $vi = $self->get_forces($ti); | ||||
| 155 | my $vf = $self->get_forces($tf); | ||||
| 156 | return ([map{$vf->[$_]- $vi->[$_]} 0 .. 2]); | ||||
| 157 | }; | ||||
| 158 | return ($sub); | ||||
| 159 | } | ||||
| 160 | |||||
| 161 | sub delta_forces { | ||||
| 162 | my $self = shift; | ||||
| 163 | croak "delta_forces> pass initial and final time" unless (@_ == 2); | ||||
| 164 | my $ti = shift; | ||||
| 165 | my $tf = shift; | ||||
| 166 | &{$self->delta_forces_coderef}($self,$ti,$tf); | ||||
| 167 | } | ||||
| 168 | |||||
| 169 | |||||
| 170 | 1 | 800ns | 1 | 68µs | has 'distance_coderef' => ( # spent 68µs making 1 call to Moose::Role::has |
| 171 | is => 'rw', | ||||
| 172 | isa => 'CodeRef', | ||||
| 173 | builder => '_build_distance_coderef', | ||||
| 174 | lazy => 1, | ||||
| 175 | ); | ||||
| 176 | |||||
| 177 | sub _build_distance_coderef { | ||||
| 178 | my $self = shift; | ||||
| 179 | my $sub = sub{ | ||||
| 180 | my $obj1 = shift; | ||||
| 181 | my $obj2 = shift; | ||||
| 182 | my $tobj1 = $obj1->t; | ||||
| 183 | my $tobj2 = $obj2->t; | ||||
| 184 | if ($tobj1 != $tobj2){ | ||||
| 185 | carp "you are comparing the distance between objects with different times"; | ||||
| 186 | } | ||||
| 187 | my $vec1 = $obj1->get_coords($tobj1); | ||||
| 188 | my $vec2 = $obj2->get_coords($tobj2); | ||||
| 189 | my $dist = 0; | ||||
| 190 | $dist += ($vec1->[$_]-$vec2->[$_])**2 foreach 0 .. 2; | ||||
| 191 | return (sqrt($dist)); | ||||
| 192 | }; | ||||
| 193 | return ($sub); | ||||
| 194 | } | ||||
| 195 | |||||
| 196 | sub distance { | ||||
| 197 | my $self = shift; | ||||
| 198 | my $obj2 = shift or croak "need to pass another obj that does PhysVecRole" ; | ||||
| 199 | my $dist = &{$self->distance_coderef}($self,$obj2); | ||||
| 200 | return ($dist); | ||||
| 201 | } | ||||
| 202 | |||||
| 203 | 1 | 30µs | 1; | ||
| 204 | |||||
| 205 | __END__ |