line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HackaMol::X::Calculator; |
2
|
|
|
|
|
|
|
$HackaMol::X::Calculator::VERSION = '0.011'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Abstract calculator class for HackaMol |
4
|
2
|
|
|
2
|
|
276542
|
use 5.008; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
64
|
|
5
|
2
|
|
|
2
|
|
1130
|
use Moose; |
|
2
|
|
|
|
|
544590
|
|
|
2
|
|
|
|
|
14
|
|
6
|
2
|
|
|
2
|
|
12694
|
use MooseX::StrictConstructor; |
|
2
|
|
|
|
|
37703
|
|
|
2
|
|
|
|
|
10
|
|
7
|
2
|
|
|
2
|
|
13606
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
8
|
2
|
|
|
2
|
|
3071
|
use namespace::autoclean; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
9
|
2
|
|
|
2
|
|
152
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
598
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with qw(HackaMol::X::Roles::ExtensionRole); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _build_map_in{ |
14
|
0
|
|
|
0
|
|
|
my $sub_cr = sub { return (@_) }; |
|
0
|
|
|
0
|
|
|
|
15
|
0
|
|
|
|
|
|
return $sub_cr; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_map_out{ |
19
|
0
|
|
|
0
|
|
|
my $sub_cr = sub { return (@_) }; |
|
0
|
|
|
0
|
|
|
|
20
|
0
|
|
|
|
|
|
return $sub_cr; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub build_command { |
24
|
|
|
|
|
|
|
# exe -options file.inp -moreoptions > file.out |
25
|
0
|
|
|
0
|
|
|
my $self = shift; |
26
|
0
|
0
|
|
|
|
|
return 0 unless $self->exe; |
27
|
0
|
|
|
|
|
|
my $cmd; |
28
|
0
|
|
|
|
|
|
$cmd = $self->exe; |
29
|
0
|
0
|
|
|
|
|
$cmd .= " " . $self->in_fn->stringify if $self->has_in_fn; |
30
|
0
|
0
|
|
|
|
|
$cmd .= " " . $self->exe_endops if $self->has_exe_endops; |
31
|
0
|
0
|
|
|
|
|
$cmd .= " > " . $self->out_fn->stringify if $self->has_out_fn; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# no cat of out_fn because of options to run without writing, etc |
34
|
0
|
|
|
|
|
|
return $cmd; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub BUILD { |
38
|
0
|
|
|
0
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
if ( $self->has_scratch ) { |
41
|
0
|
0
|
|
|
|
|
$self->scratch->mkpath unless ( $self->scratch->exists ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
unless ( $self->has_command ) { |
45
|
0
|
0
|
|
|
|
|
return unless ( $self->has_exe ); |
46
|
0
|
|
|
|
|
|
my $cmd = $self->build_command; |
47
|
0
|
|
|
|
|
|
$self->command($cmd); |
48
|
|
|
|
|
|
|
} |
49
|
0
|
|
|
|
|
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=pod |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
HackaMol::X::Calculator - Abstract calculator class for HackaMol |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 VERSION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
version 0.011 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
use Modern::Perl; |
71
|
|
|
|
|
|
|
use HackaMol; |
72
|
|
|
|
|
|
|
use HackaMol::X::Calculator; |
73
|
|
|
|
|
|
|
use Path::Tiny; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $path = shift || die "pass path to gaussian outputs"; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $hack = HackaMol->new( data => $path, ); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
foreach my $out ( $hack->data->children(qr/\.out$/) ) { |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my $Calc = HackaMol::X::Calculator->new( |
82
|
|
|
|
|
|
|
out_fn => $out, |
83
|
|
|
|
|
|
|
map_out => \&output_map, |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $energy = $Calc->map_output(627.51); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
printf( "%-40s: %10.6f\n", $Calc->out_fn->basename, $energy ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# our function to map molec info from output |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub output_map { |
95
|
|
|
|
|
|
|
my $calc = shift; |
96
|
|
|
|
|
|
|
my $conv = shift; |
97
|
|
|
|
|
|
|
my $re = qr/-\d+.\d+/; |
98
|
|
|
|
|
|
|
my @energys = $calc->out_fn->slurp =~ m/SCF Done:.*(${re})/g; |
99
|
|
|
|
|
|
|
return ( $energys[-1] * $conv ); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The HackaMol::X::Calculator extension generalizes molecular calculations using external programs. |
105
|
|
|
|
|
|
|
The Calculator class consumes the HackaMol::X::Roles::ExtensionRole role, which manage the running of executables... |
106
|
|
|
|
|
|
|
perhaps on files; perhaps in directories. This extension is intended to provide a |
107
|
|
|
|
|
|
|
simple example of interfaces with external programs. This is a barebones use of the ExtensionRole that is |
108
|
|
|
|
|
|
|
intended to be flexible. See the examples and testing directory for use of the map_in and map_out functions |
109
|
|
|
|
|
|
|
inside and outside of the map_input and map_output functions. Extensions with more rigid and encapsulated |
110
|
|
|
|
|
|
|
APIs can evolve from this starting point. In the synopsis, a Gaussian output is processed for the SCF Done |
111
|
|
|
|
|
|
|
value (a classic scripting of problem computational chemists). See the examples and tests to learn how the |
112
|
|
|
|
|
|
|
calculator can be used to: |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1. generate inputs |
115
|
|
|
|
|
|
|
2. run programs |
116
|
|
|
|
|
|
|
3. process outputs |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
via interactions with HackaMol objects. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 scratch |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
If scratch is set, the object will build that directory if needed. See HackaMol::PathRole for more information about |
125
|
|
|
|
|
|
|
the scratch attribute. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SEE ALSO |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=over 4 |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item * |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
L<HackaMol> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item * |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L<HackaMol::X::Roles::Extension> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L<HackaMol::PathRole> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=item * |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<Path::Tiny> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=back |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 EXTENDS |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=over 4 |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * L<Moose::Object> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 CONSUMES |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over 4 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * L<HackaMol::Roles::ExeRole> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * L<HackaMol::Roles::ExeRole|HackaMol::Roles::PathRole> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * L<HackaMol::Roles::PathRole> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item * L<HackaMol::X::Roles::ExtensionRole> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 AUTHOR |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Demian Riccardi <demianriccardi@gmail.com> |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Demian Riccardi. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
180
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |