line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HackaMol::X::Calculator; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Abstract calculator class for HackaMol |
4
|
2
|
|
|
2
|
|
262752
|
use 5.008; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
51
|
|
5
|
2
|
|
|
2
|
|
856
|
use Moose; |
|
2
|
|
|
|
|
405336
|
|
|
2
|
|
|
|
|
12
|
|
6
|
2
|
|
|
2
|
|
10348
|
use MooseX::StrictConstructor; |
|
2
|
|
|
|
|
28911
|
|
|
2
|
|
|
|
|
8
|
|
7
|
2
|
|
|
2
|
|
10995
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
8
|
2
|
|
|
2
|
|
2476
|
use namespace::autoclean; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
9
|
2
|
|
|
2
|
|
105
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
519
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with qw(HackaMol::X::ExtensionRole); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _build_map_in{ |
14
|
1
|
|
|
1
|
|
10
|
my $sub_cr = sub { return (@_) }; |
|
1
|
|
|
1
|
|
37
|
|
15
|
1
|
|
|
|
|
20
|
return $sub_cr; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_map_out{ |
19
|
1
|
|
|
1
|
|
10
|
my $sub_cr = sub { return (@_) }; |
|
1
|
|
|
1
|
|
40
|
|
20
|
1
|
|
|
|
|
22
|
return $sub_cr; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub build_command { |
24
|
|
|
|
|
|
|
# exe -options file.inp -moreoptions > file.out |
25
|
5
|
|
|
5
|
0
|
1341
|
my $self = shift; |
26
|
5
|
100
|
|
|
|
123
|
return 0 unless $self->exe; |
27
|
4
|
|
|
|
|
19
|
my $cmd; |
28
|
4
|
|
|
|
|
74
|
$cmd = $self->exe; |
29
|
4
|
100
|
|
|
|
99
|
$cmd .= " " . $self->in_fn->stringify if $self->has_in_fn; |
30
|
4
|
100
|
|
|
|
182
|
$cmd .= " " . $self->exe_endops if $self->has_exe_endops; |
31
|
4
|
100
|
|
|
|
161
|
$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
|
4
|
|
|
|
|
79
|
return $cmd; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub BUILD { |
38
|
12
|
|
|
12
|
0
|
13
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
12
|
100
|
|
|
|
327
|
if ( $self->has_scratch ) { |
41
|
7
|
100
|
|
|
|
189
|
$self->scratch->mkpath unless ( $self->scratch->exists ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
12
|
100
|
|
|
|
1146
|
unless ( $self->has_command ) { |
45
|
9
|
100
|
|
|
|
266
|
return unless ( $self->has_exe ); |
46
|
2
|
|
|
|
|
10
|
my $cmd = $self->build_command; |
47
|
2
|
|
|
|
|
42
|
$self->command($cmd); |
48
|
|
|
|
|
|
|
} |
49
|
5
|
|
|
|
|
133
|
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.01 |
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::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::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::ExeRole> |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * L<HackaMol::ExeRole|HackaMol::PathRole> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * L<HackaMol::PathRole> |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item * L<HackaMol::X::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 |