-
Notifications
You must be signed in to change notification settings - Fork 11
/
AaronInit.pm
336 lines (267 loc) · 10.7 KB
/
AaronInit.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
package Aaron::AaronInit;
use strict; use warnings;
use lib $ENV{'QCHASM'};
my $HOME = $ENV{'HOME'};
my $QCHASM = $ENV{'QCHASM'};
$QCHASM =~ s|/\z||; #Strip trailing / from $QCHASM if it exists
use Aaron::Constants qw(INFO OTHERS);
use AaronTools::Constants qw(NAMES);
use AaronTools::JobControl qw(get_job_template);
#use Aaron::AaronOutput qw(print_message print_message_to_log);
use Pod::Usage;
my @authors = @{ INFO->{AUTHORS} };
my $version = INFO->{VERSION};
my $lastupdate = INFO->{LASTUPDATE};
my $module = {};
#Check necessary modules are installed
my $helpMsg = "\nAARON: An Automated Reaction Optimizer for new catalyst\n".
"- Computational toolkit to aid in optimizing transition states with the Gaussian09 quantum chemistry software.\n\n".
"Authors: @authors.\n\nLast Update: $lastupdate\n\n".
"Based on a library of TS structures previously computed using model catalysts, \n".
"AARON replaces the model catalyst with a user-supplied catalyst and then performs a prescribed series of \n".
"constrained and uncontrained optimizations to arrive at final predicted structures and energies for all transition states.\n";
#arguments for AARON taking from command line
our %arg_parser = ( sleeptime => OTHERS->{SLEEP_TIME} );
use Cwd qw(getcwd);
use Getopt::Long;
use Exporter qw(import);
use AaronTools::Atoms qw(:BASIC :LJ);
use Aaron::G_Key;
use Data::Dumper;
#default values for some argument
our @EXPORT = qw($G_Key $W_Key %arg_parser $ligs_subs $parent $jobname
$template_job init_main write_status);
my $LIG_OLD = NAMES->{LIG_OLD};
my $LIG_NONE = NAMES->{LIG_NONE};
our $jobname;
our $parent = getcwd();
our $G_Key = new Aaron::G_Key();
our $W_Key = new Aaron::Workflow_Key();
my $input_file;
#content of template job file
our $template_job = get_job_template();
#ligand and substituent information
our $ligs_subs = {};
#read command line arguments
sub check_modules {
print "Checking for required Perl modules...\n";
#print_message_to_log("Checking for required Perl modules...\n");
eval {
require Data::Dumper;
$module->{Dumper}->{install} = 1;
1;
} or do {$module->{Dumper}->{install} = 0;};
$module->{Dumper}->{mod} = 'Data::Dumper';
my $msg = '';
my $quit = 0;
for my $mod (sort keys %$module) {
if (! $module->{$mod}->{install}) {
$msg .= "No $module->{$mod}->{mod} found in the perl library. " .
"This is fatal to Aaron, Aaron will quit at this time. " .
"Please install that module.\n";
$quit = 1;
}
}
print $msg;
#print_message_to_log($msg);
exit (1) if $quit;
print "Necessary Perl modules found. Starting AARON...\n";
#print_message_to_log("Necessary Perl modules found. Starting AARON...\n");
}
sub read_args{
GetOptions(
'debug' => \$W_Key->{debug},
'nosub' => \$W_Key->{nosub},
'skip1' => \$W_Key->{skip_step1},
'help|h' => \$arg_parser{help},
'restart' => \$arg_parser{restart},
'record' => \$W_Key->{record},
'short' => \$W_Key->{short},
'absthermo' => \$arg_parser{absthermo},
'sleep=s' => \$arg_parser{sleeptime},
'no_quota' => \$W_Key->{no_quota},
) or pod2usage (
-input => "$QCHASM/Aaron/pod_ref",
-exitval => 1,
-verbose => 1 );
pod2usage(
-msg => $helpMsg,
-input => "$QCHASM/Aaron/pod_ref",
-exitval => 1,
-verbose => 1) if $arg_parser{help};
($input_file) = grep { $_ =~ /\.in$/ } @ARGV;
$input_file or pod2usage (
-msg => "An input file must be provided\n",
-input => "$QCHASM/Aaron/pod_ref",
-exitval => 1,
-verbose => 0 );
($jobname) = $input_file =~ /(\S+)\.in/;
}
#read arguments from input file
sub read_params {
open my $in_h, "< $input_file" or die "Can't open $input_file:$!\n";
($jobname) = $input_file =~ /(\S+)\.in/;
my $lig = {};
my $sub = {};
my $custom;
while(<$in_h>) {
#new ligand information
/^\&[Ll]igands/ && do {
while(<$in_h>) {
/^\&$/ && do {last;};
/^\s*(\S+)\:\s*(.*)/ && do {
my $lig_ali = $1;
my $lig_info = $2;
my $lig_new;
my $lig_sub;
if ($lig_info =~ /^none$/i) {
$lig_new = $LIG_NONE;
}elsif ($lig_info =~ /^[Ll]igand=(\S+)(\s+(.*))?/) {
$lig_new = $1;
$lig_sub = $3;
}else{
$lig_new = $LIG_OLD;
$lig_sub = $lig_info;
}
$lig_sub //= '';
$lig->{$lig_ali} = {};
$lig->{$lig_ali}->{ligand} = $lig_new;
#Check if ligand exists!
if($lig_new ne 'ORIGIN' && ($lig_new ne 'NONE')) {
if (! -f "$QCHASM/AaronTools/Ligands/$lig_new.xyz" and ! -f "$HOME/Aaron_libs/Ligands/$lig_new.xyz") {
die "Requested ligand $lig_new that does not exist! Please add this ligand to $HOME/Aaron_libs/Ligands.\n";
}
}
my %substituents = split(/[=\s]/, $lig_sub);
$lig->{$lig_ali}->{substituents} = { map { $_ - 1 => $substituents{$_} }
keys %substituents };
}
}
};
#new Substrate information
/^\&[Ss]ubstrates/ && do {
while(<$in_h>) {
/^\&$/ && do {last;};
/^\s*(\S+)\:\s+(.*)/ && do { #Changing to handle any substrate name
my $sub_ali = $1;
my $sub_sub = $2;
my %substituents = split(/[=\s]/, $sub_sub);
$sub->{$sub_ali} = { map { $_ - 1 => $substituents{$_} }
keys %substituents };
}
}
};
}
close $in_h;
$G_Key->read_key_from_input($input_file);
$W_Key->read_input($input_file);
# pull job template file from custom default files
if ( $G_Key->{submission_template} ){
$W_Key->{submission_template} = $G_Key->{submission_template};
}
if( $W_Key->{submission_template} ){
#if a specific submission file template is requested, go get it
print "loading $W_Key->{submission_template}\n";
#print_message_to_log("loading $W_Key->{submission_template}\n");
$W_Key->{submission_template_o} = get_job_template($W_Key->{submission_template});
}
# use d_cutoff that the user specified
if ( $G_Key->{d_cutoff} ){
$W_Key->{d_cutoff} = $G_Key->{d_cutoff};
}
# use rmsd_cutoff that the user specified
if ( $G_Key->{rmsd_cutoff} ){
$W_Key->{rmsd_cutoff} = $G_Key->{rmsd_cutoff};
}
#combine ligand and sub information;
for my $ligand (keys %{ $lig }) {
$ligs_subs->{$ligand} = {};
my @explicit_sub = grep { $_ =~ /^\d+$/ }
keys %{ $lig->{$ligand}->{substituents} };
my @inexplicit_sub = grep { $_ !~ /^\d+$/ }
keys %{ $lig->{$ligand}->{substituents} };
my %explicit_sub = map { $_ => $lig->{$ligand}->{substituents}->{$_} }
@explicit_sub;
my %inexplicit_sub = map { $_ => $lig->{$ligand}->{substituents}->{$_} }
@inexplicit_sub;
#examine the inexplicit sub
open (my $fh, "<$QCHASM/AaronTools/Subs/subs") or die "Cannot open $QCHASM/AaronTools/Subs/subs";
my %subs_record;
while (<$fh>) {
chomp;
if ($_ =~ /[0-9a-zA-Z]/) {
$subs_record{$_} = 1;
}
}
close($fh);
for my $key (keys %inexplicit_sub) {
unless (exists $subs_record{$key}) {
print "The substituent on the ligand $key " .
"Cannot be found in our database " .
"This substituent is skipped.\n";
delete $inexplicit_sub{$key};
}
}
$ligs_subs->{$ligand}->{ligand} = $lig->{$ligand}->{ligand};
$ligs_subs->{$ligand}->{inexp_sub} = \%inexplicit_sub;
$ligs_subs->{$ligand}->{exp_sub} = \%explicit_sub;
$ligs_subs->{$ligand}->{substrate} = {};
$ligs_subs->{$ligand}->{jobs} = {};
$ligs_subs->{$ligand}->{thermo} = {};
for my $sub_ali (keys %{ $sub }) {
my $lig_sub_ali = "$ligand-$sub_ali";
$ligs_subs->{$ligand}->{substrate}->{$lig_sub_ali} = $sub->{$sub_ali};
}
}
}
sub write_status {
my %status;
my @ligands = keys %{ $ligs_subs };
for my $ligand (@ligands) {
my @geos = keys %{ $ligs_subs->{$ligand}->{jobs} };
@status{@geos} = map {$ligs_subs->{$ligand}->{jobs}->{$_}->copy()} @geos;
}
my $string = Data::Dumper->Dump([\%status], ['STATUS']);
open STATUS, ">.status" or die "Cannot open .status file: $!\n";
print STATUS $string;
close STATUS;
}
sub read_status {
my $STATUS;
my $string;
if (-e ".status") {
open STA, "<.status" or die "Cannot read status file: $!\n";
$string = do {local $/; <STA>};
eval $string;
my $submission_template = $template_job;
if( $W_Key->{submission_template} ) {
$submission_template = $W_Key->{submission_template_o};
}
for my $key (keys %{ $STATUS }) {
my ($head) = split(/\//, $key);
($head) = split(/\-/, $head);
$ligs_subs->{$head}->{jobs}->{$key} = $STATUS->{$key};
$ligs_subs->{$head}->{jobs}->{$key}->{Gkey} = $G_Key;
$ligs_subs->{$head}->{jobs}->{$key}->{Wkey} = $W_Key;
$ligs_subs->{$head}->{jobs}->{$key}->{template_job} = $submission_template;
if ($ligs_subs->{$head}->{jobs}->{$key}->{conformers}) {
for my $cf (sort keys %{ $ligs_subs->{$head}->{jobs}->{$key}->{conformers} }) {
$ligs_subs->{$head}->{jobs}->{$key}->{conformers}->{$cf}->{Gkey} = $G_Key;
$ligs_subs->{$head}->{jobs}->{$key}->{conformers}->{$cf}->{Wkey} = $W_Key;
$ligs_subs->{$head}->{jobs}->{$key}->{conformers}->{$cf}->{template_job} = $submission_template;
}
}
}
}
}
#main function to initiate Aaron job
sub init_main {
&read_args();
&check_modules();
print "Preparing to run transition state searches...\n";
#print_message_to_log("Preparing to run transition state searches...\n");
&read_params();
&read_status();
sleep(10);
}
1