HackaMol::AtomGroupRole - Role for a group of atoms
version 0.00_02
my $atom1 = HackaMol::Atom->new( name => 'O1', coords => [ V( 2.05274, 0.01959, -0.07701 ) ], Z => 8, );
my $atom2 = HackaMol::Atom->new( name => 'H1', coords => [ V( 1.08388, 0.02164, -0.12303 ) ], Z => 1, );
my $atom3 = HackaMol::Atom->new( name => 'H2', coords => [ V( 2.33092, 0.06098, -1.00332 ) ], Z => 1, );
$atom1->push_charges(-0.834); $_->push_charges(0.417) foreach ($atom1, $atom2);
# instance of class that consumes the AtomGroupRole
my $group = Class_with_AtomGroupRole->new(atoms=> [$atom1,$atom2,$atom3]);
print $group->count_atoms . "\n"; #3
print $group->total_charge . "\n"; # 0
print $group->total_mass . "\n";
my @atoms = $group->all_atoms;
print $group->dipole_moment . "\n";
$group->do_forall('push_charges',0);
$group->do_forall('push_coords',$group->COM);
$group->gt(1); # same as $group->do_forall('t',1);
print $group->bin_atoms_name . "\n";
print $group->unique_atoms . "\n";
$group->translate(V(10,0,0));
$group->rotate( V(1,0,0), 180, V(0,0,0));
The HackaMol AtomGroupRole class provides core methods and attributes for consuming classes that use groups of atoms. The original implementation of this role relied heavily on attributes, builders, and clearers. Such an approach naturally gives fast lookup tables, but the ability to change atoms and coordinates made the role to difficult. Such an approach may be pursued again (without changing the API) in the future after the API has matured. The AtomGroupRole calculates all values for atoms using their own t attributes.
pass method and arguments down to atoms in group
$group->do_for_all('t',1); #sets t to 1 for all atoms
integer argument. wraps do_for_all for setting time within group
$group->gt(1);
no arguments. return dipole calculated from charges and coordinates as Math::Vector::Real object
no arguments. return center of mass calculated from masses and coordinates as Math::Vector::Real object
no arguments. return center of nuclear charge calculated from Zs and coordinates as Math::Vector::Real object
no arguments. return sum of atom charges.
no arguments. return sum of atom masses.
no arguments. return sum of Zs.
no arguments. returns the norm of the dipole in debye (assuming charges in electrons, AKMA)
no arguments. returns two hash references. The histogram of atom symbols, and a map from symbol-> Z for the same keys. The second hash reference was added, to be able to sort by Z in the absence of Atom objects.
no arguments. returns the number of keys in each hash returned by bin_atoms
no arguments. returns a string summary of the atoms in the group. Take the bin_atoms hashes, sorts by Z and generates something like OH2 for water or O2H2 for peroxide.
requires Math::Vector::Real vector argument. Optional argument: integer tf.
Translates all atoms in group by the MVR vector. Pass tf to the translate method to store new coordinates in tf rather than atom->t.
requires Math::Vector::Real vector, an angle (in degrees), and a MVR vector origin as arguments. Optional argument: integer tf.
Rotates all atoms in the group around the MVR vector. Pass tf to the translate method to store new coordinates in tf rather than atom->t.
ARRAY traits for the atoms attribute, respectively: push, get, set, elements, count, clear
push atom on to atoms array
$group->push_atoms($atom1, $atom2, @otheratoms);
returns array of all elements in atoms array
print $_->symbol, "\n" foreach $group->all_atoms;
return element by index from atoms array
print $group->get_atoms(1); # returns $atom2 from above
set atoms array by index
$group->set_atoms(1, $atom1);
return number of atoms in group
print $group->count_atoms;
clears atoms array
isa ArrayRef[Atom] that is lazy with public ARRAY traits described in ARRAY_METHODS
HackaMol::AtomGroup
HackaMol::Bond
HackaMol::Angle
HackaMol::Dihedral
Demian Riccardi <demianriccardi@gmail.com>
This software is copyright (c) 2013 by Demian Riccardi.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install HackaMol, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HackaMol
CPAN shell
perl -MCPAN -e shell install HackaMol
For more information on module installation, please visit the detailed CPAN module installation guide.