NAME

HackaMol::X::Calculator - Abstract calculator class for HackaMol

VERSION

version 0.00_1

SYNOPSIS

  use Modern::Perl;
  use HackaMol;
  use HackaMol::X::Calculator;

  my $hack = HackaMol->new( 
                            name => "hackitup" , 
                            data => "local_pdbs",
                          );
   
  my $i = 0;

  foreach my $pdb ($hack->data->children(qr/\.pdb$/)){

     my $mol = $hack->read_file_mol($pdb);

     my $Calc = HackaMol::X::Calculator->new (
                   molecule => $mol,
                   scratch  => 'realtmp/tmp',
                   in_fn    => 'calc.inp'
                   out_fn   => "calc-$i.out"
                   map_in   => \&input_map,
                   map_out  => \&output_map,
                   exe      => '~/bin/xyzenergy < ', 
     );     

     $Calc->map_input;
     $Calc->capture_sys_command;
     my $energy = $Calc->map_output(627.51);

     printf ("Energy from xyz file: %10.6f\n", $energy);

     $i++;

  }

  #  our functions to map molec info to input and from output
  sub input_map {
    my $calc = shift;
    $calc->mol->print_xyz($calc->in_fn);
  }

  sub output_map {
    my $calc   = shift;
    my $conv   = shift;
    my @eners  = map { /ENERGY= (-\d+.\d+)/; $1*$conv } $calc->out_fn->lines; 
    return pop @eners;
  }

DESCRIPTION

Abstract calculator class for HackaMol. The HackaMol::X::Calculator extension generalizes molecular calculations using external programs. The Calculator class consumes roles provided by the HackaMol core that manages the running of executables... perhaps on files; perhaps in directories. This extension is intended to provide a simple example of interfaces with external programs. It is probably too flexible. New extensions can evolve from this starting point, in scripts, to more rigid encapsulated classes.

METHODS

map_input

changes to scratch directory, if set, and passes all arguments (including self) to map_in CodeRef. Thus, any input writing must

$calc->map_input(@args);

will invoke,

&{$calc->map_in}(@_);  #where @_ = ($self,@args)

and return anything returned by the map_in function.

map_output

completely analogous to map_input. Thus, the output must be opened and processed in the map_out function.

build_command

builds the command from the attributes: exe, inputfn, exe_endops, if they exist, and returns the command.

capture_sys_command

uses Capture::Tiny capture method to run a command using a system call. STDOUT, STDERR, are captured and returned.

my ($stdout, $stderr,@other) = capture { system($command) }

the $command is taken from $calc->command unless the $command is passed,

$calc->capture_sys_command($some_command);

capture_sys_command returns ($stdout, $stderr,@other) or 0 if there is no command set.

ATTRIBUTES

scratch

Coerced to be 'Path::Tiny' via AbsPath. If scratch is set, all work is carried out in that directory. See HackaMol::PathRole for more information about the scracth attribute.

mol

isa HackaMol::Molecule that is ro and required

map_in

isa CodeRef that is ro

intended for mapping input files from molecular information, but it is completely flexible. Used in map_input method. Can also be directly ivoked,

&{$calc->map_in}(@args); 

as any other subroutine would be.

map_out

intended for mapping molecular information from output files, but it is completely flexible and analogous to map_in.

EXTENDS

CONSUMES

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.