NAME

HackaMol::AtomGroupRole - Role for a group of atoms

VERSION

version 0.00_21

SYNOPSIS

  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

DESCRIPTION

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.

METHODS

do_for_all

pass method and arguments down to atoms in group

$group->do_for_all('t',1); #sets t to 1 for all atoms

gt

integer argument. wraps do_for_all for setting time within group

$group->gt(1);

dipole

no arguments. return dipole calculated from charges and coordinates as Math::Vector::Real object

COM

no arguments. return center of mass calculated from masses and coordinates as Math::Vector::Real object

COZ

no arguments. return center of nuclear charge calculated from Zs and coordinates as Math::Vector::Real object

total_charge

no arguments. return sum of atom charges.

total_mass

no arguments. return sum of atom masses.

total_Z

no arguments. return sum of Zs.

dipole_moment

no arguments. returns the norm of the dipole in debye (assuming charges in electrons, AKMA)

bin_atoms

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.

count_unique_atoms

no arguments. returns the number of keys in each hash returned by bin_atoms

bin_atoms_name

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.

tmax

return (count_coords-1) if > 0; return 0 otherwise; croaks if not all atoms share the same tmax.

translate

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.

rotate

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

bin_this

argument: Str , return hash_ref of binned $self->Str.

$hash_ref{$_}++ foreach ( map {$_->$Str} $self->all_atoms );

what_time

returns the current setting of t by checking against all members of group.

fix_serial

argument, optional: Int, offset for resetting the serial number of atoms. Returns the offset.

$group->fix_serial(0); # serial starts from zero

ARRAY METHODS

push_atoms, get_atoms, set_atoms, all_atoms, count_atoms, clear_atoms

ARRAY traits for the atoms attribute, respectively: push, get, set, elements, count, clear

push_atoms

push atom on to atoms array

$group->push_atoms($atom1, $atom2, @otheratoms);

all_atoms

returns array of all elements in atoms array

print $_->symbol, "\n" foreach $group->all_atoms; 

get_atoms

return element by index from atoms array

print $group->get_atoms(1); # returns $atom2 from above

set_atoms

set atoms array by index

$group->set_atoms(1, $atom1);

count_atoms

return number of atoms in group

print $group->count_atoms; 

clear_atoms

clears atoms array

ATTRIBUTES

atoms

isa ArrayRef[Atom] that is lazy with public ARRAY traits described in ARRAY_METHODS

SEE ALSO

AUTHOR

Demian Riccardi <demianriccardi@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2014 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.