HackaMol - HackaMol: Object-Oriented Library for Molecular Hacking


version 0.035


The HackaMol publication has a more complete description of the library (pdf available from researchgate).

Citation: J. Chem. Inf. Model., 2015, 55, 721

Loading the HackaMol library in a script with

       use HackaMol;

provides attributes and methods of a builder class. It also loads all the classes provided by the core so including them is not necessary, e.g.:

       use HackaMol::Atom;
       use HackaMol::Bond;
       use HackaMol::Angle;
       use HackaMol::Dihedral;
       use HackaMol::AtomGroup;
       use HackaMol::Molecule;

The methods, described below, facilitate the creation of objects from files and other objects.



one argument: pdbid

This method will download the pdb, unless it exists, and load it into a HackaMol::Molecule object. For example,

      my $mol = HackaMol->new->pdbid_mol('2cba');


one argument: filename.

This method parses the file (e.g., file.pdb) and returns an array of HackaMol::Atom objects.


one argument: filename.

This method parses the file (e.g., file.pdb) and returns a HackaMol::Molecule object.


two arguments: filename and a HackaMol::Molecule object.

This method reads the coordinates from a file and pushes them into the atoms contained in the molecule. Thus, the atoms in the molecule and the atoms in the file must be the same.


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


arguments are an atom attribute and then a list of atoms.

This method builds AtomGroup objects that are grouped by attribute.


The arguments are key_value pairs of bonding criteria (see example below).

This method returns bonds between bond_atoms and the candidates using the criteria (many of wich have defaults).

  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) ).


the argument is a list of atoms, e.g. '($mol->all_atoms)'.

this method returns disulfide bonds as bond objects.



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


       # simple example: load pdb file and extract the disulfide bonds

       use HackaMol;

       my $bldr = HackaMol->new( name => 'builder');
       my $mol  = $bldr->pdbid_mol('1kni');

       my @disulfide_bonds = $bldr->find_disulfide_bonds( $mol->all_atoms );

       print $_->dump foreach @disulfide_bonds;

See the above executed in this linked notebook





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.