Demian Riccardi > HackaMol-0.017 > HackaMol



Annotate this POD


View/Report Bugs
Module Version: 0.017   Source  


HackaMol - HackaMol: Object-Oriented Library for Molecular Hacking


version 0.017


       use HackaMol;
       use Math::Vector::Real;

       my $hack = HackaMol->new( name => "hackitup" );

       # all coordinates from NMR ensemble are loaded into atoms
       my $mol  = $hack->read_file_mol("1L2Y.pdb");

       #recenter all coordinates to center of mass
       foreach my $t ( 0 .. $mol->tmax) {
           $mol->translate( -$mol->COM );

       #create array of CA atoms with full occupancy

       my @CAs = grep {
                        $_->name    eq 'CA'  and
                        $_->occ == 1
                      } $mol->all_atoms;

       #print out the pdb with CA for several models from the NMR
                              )-> print_pdb_ts([8,2,4,6,8,0], 'some.pdb');

       # print coordinates to and return filehandle for future
       # writing
       my $fh = $mol->print_xyz( $mol->name . ".xyz" );
       foreach ( 1 .. 10 ) {
               V( 0, 0, 1 ),    # rotation vector
               36,              # rotate by 36 degrees
               V( 5, 0, 0 )     # origin of rotation

       # translate/rotate method is provided by AtomGroupRole
       # populate groups byatom resid attr
       my @groups = $hack->group_by_atom_attr( 'resid', $mol->all_atoms );

       foreach my $ang ( 1 .. 10 ) {
           $_->rotate( V( 1, 1, 1 ), 36, $_->COM ) foreach $mol->all_groups;


The HackaMol library simplifies powerful scripting of multiscale molecular modeling and analysis. HackaMol seeks to provide intuitive attributes and methods that may be harnessed to coerce molecular computation through a common core. The library is inspired by PerlMol, BioPerl, MMTSB, and our own experiences as researchers.

The library is organized into two regions: HackaMol, the core (contained here) that has classes for atoms and molecules, and HackaMol::X, the extensions, such as HackaMol::X::Vina (an interface to Autodock Vina) or HackaMol::X::Calculator, a more general abstract calculator for interfacing external programs. The three major goals of the core are for it to be well-tested, well-documented, and easy to install. The goal of the extensions is to provide a more flexible space for researchers to develop and share new methods that use the core.

HackaMol uses Math::Vector::Real (MVR) for all the vector operations. The methods of MVR overlap very well with those needed for working with atoms and coarse grained molecules. MVR is a lightweight solution with an XS drop-in that makes vector analyses very fast. Extensions that treat much larger systems will definitely benefit from the capabilities of PDL.

The HackaMol class (loaded in Synopsis) uses the core classes to provide some object building utilities described below. This class consumes HackaMol::MolReadRole to provide structure readers for xyz and pdb coordinates. See Open Babel if other formats needed (All suggestions, contributions welcome!).



takes a list of atoms and returns a list of bonds. The bonds are generated for "list neighbors" by simply stepping through the atom list one at a time. e.g.

  my @bonds = $hack->build_bonds(@atoms[1,3,5]);

will return two bonds: B13 and B35


takes a list of atoms and returns a list of angles. The angles are generated analagously to build_bonds, e.g.

  my @angles = $hack->build_angles(@atoms[1,3,5]);

will return one angle: A135


takes a list of atoms and returns a list of dihedrals. The dihedrals are generated analagously to build_bonds, e.g.

  my @dihedral = $hack->build_dihedrals(@atoms[1,3,5]);

will croak! you need atleast four atoms.

  my @dihedral = $hack->build_dihedrals(@atoms[1,3,5,6,9]);

will return two dihedrals: D1356 and D3569


takes atom attribute and a list of atoms as arguments and builds AtomGroup objects by attribute. Grouping by graphical searches are needed!


takes hash argument list and returns bonds. Find bonds between bond_atoms and the candidates.

  my @oxy_bonds = $hack->find_bonds_brute(
                                    bond_atoms => [$hg],
                                    candidates => [$mol->all_atoms],
                                    fudge      => 0.45,
                                    max_bonds  => 6,

fudge is optional with Default is 0.45 (open babel uses same default); max_bonds is optional with default of 99. max_bonds is compared against the atom bond count, which are incremented during the search. Before returning the bonds, the bond_count are returned the values before the search. For now, molecules are responsible for setting the number of bonds in atoms. find_bonds_brute uses a bruteforce algorithm that tests the interatomic separation against the sum of the covalent radii + fudge. It will not test for bond between atoms if either atom has >= max_bonds. It does not return a self bond for an atom ( next if refaddr($ati) == refaddr($atj) ).


takes a list of atoms and returns the disulfide bonds as bond objects.



name is a rw str provided by HackaMol::NameRole.





Demian Riccardi <>


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.

syntax highlighting: