| 1 | package HackaMol::Atom; | ||||||||||||||||||||||||||||
| 2 | 19 | $HackaMol::Atom::VERSION = '0.053'; | |||||||||||||||||||||||||||
| 3 | #ABSTRACT: HackaMol Atom Class | ||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 19 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 19 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | #use MooseX::Storage; | ||||||||||||||||||||||||||||
| 11 | #with Storage('format' => 'JSON', 'io' => 'File'); | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 19 | with 'HackaMol::Roles::NameRole', | |||||||||||||||||||||||||||
| 14 | 'HackaMol::Roles::PhysVecMVRRole', | ||||||||||||||||||||||||||||
| 15 | 'HackaMol::Roles::PdbRole', | ||||||||||||||||||||||||||||
| 16 | 'HackaMol::Roles::QmAtomRole'; | ||||||||||||||||||||||||||||
| 17 | use HackaMol::PeriodicTable | ||||||||||||||||||||||||||||
| 18 | 19 | ▶ | qw(@ELEMENTS %ELEMENTS %ATOMIC_MASSES @COVALENT_RADII @VDW_RADII %ATOM_MULTIPLICITY); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 19 | my @delta_attrs = qw(Z symbol mass vdw_radius covalent_radius); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 19 | has 'is_dirty' => ( | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # when attributes change, the Atom gets dirty. change_symbol, change_Z | ||||||||||||||||||||||||||||
| 25 | # generally, classes that have Atom should decide whether to clean Atom | ||||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||
| 27 | isa => 'Bool', | ||||||||||||||||||||||||||||
| 28 | lazy => 1, | ||||||||||||||||||||||||||||
| 29 | default => 0, # anytime called, the atom becomes dirty forever! | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 19 | has 'bond_count' => ( | |||||||||||||||||||||||||||
| 33 | traits => ['Counter'], | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | isa => 'Num', | ||||||||||||||||||||||||||||
| 36 | default => 0, | ||||||||||||||||||||||||||||
| 37 | handles => { | ||||||||||||||||||||||||||||
| 38 | inc_bond_count => 'inc', | ||||||||||||||||||||||||||||
| 39 | dec_bond_count => 'dec', | ||||||||||||||||||||||||||||
| 40 | reset_bond_count => 'reset', | ||||||||||||||||||||||||||||
| 41 | }, | ||||||||||||||||||||||||||||
| 42 | ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 19 | has 'symbol' => ( | |||||||||||||||||||||||||||
| 45 | is => 'rw', | ||||||||||||||||||||||||||||
| 46 | isa => 'Str', | ||||||||||||||||||||||||||||
| 47 | predicate => 'has_symbol', | ||||||||||||||||||||||||||||
| 48 | clearer => 'clear_symbol', | ||||||||||||||||||||||||||||
| 49 | lazy => 1, | ||||||||||||||||||||||||||||
| 50 | builder => '_build_symbol', | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 1173 | ▶ | sub _build_symbol { | ||||||||||||||||||||||||||
|
Subroutine
_build_symbol: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 1173 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 1173 | return ( _Z_to_symbol( $self->Z ) ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 19 | has 'Z' => ( | |||||||||||||||||||||||||||
| 59 | is => 'rw', | ||||||||||||||||||||||||||||
| 60 | isa => 'Int', | ||||||||||||||||||||||||||||
| 61 | predicate => 'has_Z', | ||||||||||||||||||||||||||||
| 62 | clearer => 'clear_Z', | ||||||||||||||||||||||||||||
| 63 | lazy => 1, | ||||||||||||||||||||||||||||
| 64 | builder => '_build_Z', | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 3853 | ▶ | sub _build_Z { | ||||||||||||||||||||||||||
|
Subroutine
_build_Z: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 3853 | my $self = shift; | |||||||||||||||||||||||||||
| 69 | 3853 | return ( _symbol_to_Z( $self->symbol ) ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | has $_ => ( | ||||||||||||||||||||||||||||
| 73 | is => 'rw', | ||||||||||||||||||||||||||||
| 74 | isa => 'Num', | ||||||||||||||||||||||||||||
| 75 | predicate => "has_$_", | ||||||||||||||||||||||||||||
| 76 | clearer => "clear_$_", | ||||||||||||||||||||||||||||
| 77 | lazy => 1, | ||||||||||||||||||||||||||||
| 78 | builder => "_build_$_", | ||||||||||||||||||||||||||||
| 79 | 19 | ) foreach (qw(covalent_radius vdw_radius)); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 83 | ▶ | sub _build_covalent_radius { | ||||||||||||||||||||||||||
|
Subroutine
_build_covalent_radius: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | 83 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 83 | return ( _Z_to_covalent_radius( $self->Z ) ); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | sub _build_vdw_radius { | ||||||||||||||||||||||||||
|
Subroutine
_build_vdw_radius: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 88 | 1 | return ( _Z_to_vdw_radius( $self->Z ) ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 2 | ▶ | sub change_Z { | ||||||||||||||||||||||||||
|
Subroutine
change_Z: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | 2 | ▶ | my $Z = shift or croak "pass argument Z to change_Z method"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 1 | $self->_clean_atom; | |||||||||||||||||||||||||||
| 95 | 1 | $self->Z($Z); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 2 | ▶ | sub change_symbol { | ||||||||||||||||||||||||||
|
Subroutine
change_symbol: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 2 | ▶ | my $symbol = shift or croak "pass argument symbol to change_Z method"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 1 | $self->_clean_atom; | |||||||||||||||||||||||||||
| 102 | 1 | $self->symbol( _fix_symbol($symbol) ); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 12 | ▶ | sub charge { | ||||||||||||||||||||||||||
|
Subroutine
charge: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | 12 | ▶ | carp "charge> takes no arguments. returns get_charges(t)" if (@_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 12 | ▶ | if ( $self->has_charges ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 11 | return ( $self->get_charges( $self->t ) ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||
| 112 | 1 | return 0; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 2 | ▶ | sub _clean_atom { | ||||||||||||||||||||||||||
|
Subroutine
_clean_atom: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 117 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 118 | 2 | foreach my $clearthis ( map { "clear_$_" } @delta_attrs ) { | |||||||||||||||||||||||||||
| 119 | 10 | $self->$clearthis; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | 2 | carp "cleaning atom attributes for in place change. setting atom->is_dirty"; | |||||||||||||||||||||||||||
| 122 | 2 | $self->is_dirty(1); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 6794 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 6794 | my $self = shift; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 6794 | ▶ | unless ( $self->has_Z or $self->has_symbol ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_Z or $self->has_symbol
MC/DC100%2/2
$self->has_Z or $self->has_symbol
$self->has_Z
$self->has_symbol
Truth table100%3/3
A or B
A= $self->has_ZB= $self->has_symbol
| |||||||||||||||||||||||||||||
| 129 | 1 | croak "Either Z or Symbol must be set when calling Atom->new()"; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 6793 | ▶ | if ( $self->has_Z ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | #clear out the symbol if Z is passed. Z is faster and takes precedence | ||||||||||||||||||||||||||||
| 135 | 1219 | $self->clear_symbol; | |||||||||||||||||||||||||||
| 136 | 1219 | return; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 5574 | $self->symbol( _fix_symbol( $self->symbol ) ); | |||||||||||||||||||||||||||
| 140 | 5574 | return; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1459 | ▶ | sub _build_mass { | ||||||||||||||||||||||||||
|
Subroutine
_build_mass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 144 | 1459 | my $self = shift; | |||||||||||||||||||||||||||
| 145 | 1459 | return ( _symbol_to_mass( $self->symbol ) ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 3853 | ▶ | sub _symbol_to_Z { | ||||||||||||||||||||||||||
|
Subroutine
_symbol_to_Z: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 149 | 3853 | my $symbol = shift; | |||||||||||||||||||||||||||
| 150 | 3853 | $symbol = ucfirst( lc($symbol) ); | |||||||||||||||||||||||||||
| 151 | 3853 | return $ELEMENTS{$symbol}; | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 1173 | ▶ | sub _Z_to_symbol { | ||||||||||||||||||||||||||
|
Subroutine
_Z_to_symbol: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 155 | 1173 | my $Z = shift; | |||||||||||||||||||||||||||
| 156 | 1173 | return $ELEMENTS[$Z]; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 1459 | ▶ | sub _symbol_to_mass { | ||||||||||||||||||||||||||
|
Subroutine
_symbol_to_mass: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 160 | 1459 | my $symbol = shift; | |||||||||||||||||||||||||||
| 161 | 1459 | return $ATOMIC_MASSES{$symbol}; | |||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 5575 | ▶ | sub _fix_symbol { | ||||||||||||||||||||||||||
|
Subroutine
_fix_symbol: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | 5575 | return ucfirst( lc(shift) ); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 83 | ▶ | sub _Z_to_covalent_radius { | ||||||||||||||||||||||||||
|
Subroutine
_Z_to_covalent_radius: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 169 | 83 | my $Z = shift; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # index 1 for single bond length.. | ||||||||||||||||||||||||||||
| 172 | 83 | return $COVALENT_RADII[$Z][1] / 100; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 1 | ▶ | sub _Z_to_vdw_radius { | ||||||||||||||||||||||||||
|
Subroutine
_Z_to_vdw_radius: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 176 | 1 | my $Z = shift; | |||||||||||||||||||||||||||
| 177 | 1 | return $VDW_RADII[$Z][1] / 100; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 19 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 19 | 1; | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | __END__ | ||||||||||||||||||||||||||||