HackaMol::Roles::AtomGroupRole - Role for a group of atoms
version 0.021
use HackaMol::AtomGroup; use HackaMol::Atom; 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 = HackaMol::AtomGroup->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->dipole_moment . "\n"; 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)); $group->print_xyz ; #STDOUT my $fh = $group->print_xyz("hackagroup.xyz"); #returns filehandle $group->print_xyz($fh) foreach (1 .. 9); # boring VMD movie with 10 frames
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)
Called with no arguments. Returns a hash with a count for each unique atom symbol.
no arguments. returns the number of unique atoms
no arguments. returns a string summary of the atoms in the group sorted by decreasing atomic number. For example; OH2 for water or O2H2 for peroxide.
return (count_coords-1) if > 0; return 0 otherwise; croaks if not all atoms share the same tmax.
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.
optional argument: filename or filehandle. with no argument, prints xyz formatted output to STDOUT. pass a filename and an xyz file with that name will be written or overwritten (with warning). pass filehandle for continuous writing to an open filehandle.
argument: array_ref containing the values of t to be used for printing. optional argument: filename or filehandle for writing out to file. For example,
$mol->print_xyz_ts([0 .. 3, 8, 4], 'fun.xyz');
will write the coordinates for all group atoms at t=0,1,2,3,8,4 to a file, in that order.
same as print_xyz, but for pdb formatted output
same as print_xyz_ts, but for pdb formatted output
argument: Str , return hash_ref of binned $self->Str.
$hash_ref{$_}++ foreach ( map {$_->$Str} $self->all_atoms );
returns the current setting of t by checking against all members of group.
argument, optional: Int, offset for resetting the serial number of atoms. Returns the offset.
$group->fix_serial(0); # serial starts from zero
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) 2015 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.