forked from ccsb-scripps/AutoDock-GPU
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.cpp
More file actions
426 lines (396 loc) · 15.2 KB
/
Copy pathsetup.cpp
File metadata and controls
426 lines (396 loc) · 15.2 KB
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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
/*
AutoDock-GPU, an OpenCL implementation of AutoDock 4.2 running a Lamarckian Genetic Algorithm
Copyright (C) 2017 TU Darmstadt, Embedded Systems and Applications Group, Germany. All rights reserved.
For some of the code, Copyright (C) 2019 Computational Structural Biology Center, the Scripps Research Institute.
AutoDock is a Trade Mark of the Scripps Research Institute.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include "filelist.hpp"
#include "processgrid.h"
#include "processligand.h"
#include "processresult.h"
#include "getparameters.h"
#include "setup.hpp"
int preallocated_gridsize(FileList& filelist)
{
if(!filelist.used) return 0;
int gridsize=0;
for(unsigned int i=0; i<filelist.fld_files.size(); i++){
size_t grid_idx = filelist.fld_files[i].grid_idx;
if(grid_idx<filelist.mygrids.size()){
// Filling mygrid according to the gpf file
if (get_gridinfo(filelist.fld_files[i].name.c_str(), &filelist.mygrids[grid_idx]) != 0){
printf("\n\nError in get_gridinfo, stopped job.");
return 1;
}
int curr_size = 4*filelist.mygrids[grid_idx].size_xyz[0]*
filelist.mygrids[grid_idx].size_xyz[1]*
filelist.mygrids[grid_idx].size_xyz[2]*
filelist.mygrids[grid_idx].grid_mapping.size();
if(curr_size>gridsize)
gridsize=curr_size;
}
}
return gridsize;
}
int setup(
Gridinfo* mygrid,
Dockpars* mypars,
Liganddata& myligand_init,
Liganddata& myxrayligand,
FileList& filelist,
int i_file,
int argc,
char* argv[]
)
{
// Filling the filename and coeffs fields of mypars according to command line arguments
if (get_filenames_and_ADcoeffs(&argc, argv, mypars, filelist.used) != 0){
printf("\nError in get_filenames_and_ADcoeffs, stopped job.\n");
return 1;
}
//------------------------------------------------------------
// Testing command line arguments for xml2dlg mode,
// derived atom types, and modified atom type pairs
// since they will be needed at ligand and grid creation
//------------------------------------------------------------
for (int i=1; i<argc-1; i+=2)
{
if (argcmp("filelist", argv[i], 'B'))
i+=mypars->filelist_files-1; // skip ahead in case there are multiple entries here
if (argcmp("xml2dlg", argv[i], 'X'))
i+=mypars->xml_files-1; // skip ahead in case there are multiple entries here
// Argument: derivate atom types
if (argcmp("derivtype", argv [i], 'T'))
{
if(mypars->nr_deriv_atypes==0){
mypars->deriv_atypes=(deriv_atype*)malloc(sizeof(deriv_atype));
if(mypars->deriv_atypes==NULL){
printf("Error: Cannot allocate memory for --derivtype (-T).\n");
exit(1);
}
}
bool success=true;
char* tmp=argv[i+1];
while(success && (*tmp!='\0')){
bool base_exists=false;
char* start_block=tmp;
int nr_start=mypars->nr_deriv_atypes;
int redefine=0;
// count nr of derivative atom types first
while((*tmp!='\0') && (*tmp!='/')){ // do one block at a time
if(*(tmp++)==','){ // this works here as the first character is not a ','
if(base_exists){
printf("Error in --derivtype (-T) %s: only one base name is allowed.\n",argv[i+1]);
success=false;
break;
}
if(tmp-start_block-1>0){ // make sure there is a name (at least one char, we'll test later if it's taken already)
int idx = add_deriv_atype(mypars,start_block,tmp-start_block-1,true);
if(idx==0){
printf("Error in --derivtype (-T) %s: derivative names can only be upto 3 characters long.\n",argv[i+1]);
success=false;
break;
}
// err out for first case of redefined doublets
// - need to wait for the base type to be certain
if(idx<0 && (redefine==0)) redefine=idx;
start_block=tmp;
} else{
printf("Error in --derivtype (-T) %s: derivative names have to be at least one character long.\n",argv[i+1]);
success=false;
break;
}
}
if((*tmp=='=') && ((*(tmp+1)!='\0') || (*(tmp+1)!='/'))){
if(tmp-start_block>0){ // make sure there is a name (at least one char, we'll test later if it's taken already)
int idx = add_deriv_atype(mypars,start_block,tmp-start_block,true);
if(idx==0){
printf("Error in --derivtype (-T) %s: derivative names can only be upto 3 characters long.\n",argv[i+1]);
success=false;
break;
}
// err out for first case of redefined doublets
// - need to wait for the base type to be certain
if(idx<0 && (redefine==0)) redefine=idx;
} else{
printf("Error in --derivtype (-T) %s: derivative names have to be at least one character long.\n",argv[i+1]);
success=false;
break;
}
start_block=tmp+1;
base_exists=true;
}
}
int length=tmp-start_block;
if(length>=4){
printf("Error in --derivtype (-T) %s: base names can only be upto 3 characters long.\n",argv[i+1]);
success=false;
break;
}
if(redefine!=0){
redefine++; // redefine is -i-1 in case of doublet -> i = -(redefine+1)
redefine=-redefine;
if(strncmp(start_block,mypars->deriv_atypes[redefine].base_name,length)!=0){
printf("Error in --derivtype (-T) %s: redefinition of type %s with different base name.\n",argv[i+1],mypars->deriv_atypes[redefine].deriv_name);
success=false;
break;
}
}
for(int idx=nr_start; idx<mypars->nr_deriv_atypes; idx++){
strncpy(mypars->deriv_atypes[idx].base_name,start_block,length);
mypars->deriv_atypes[idx].base_name[length]='\0';
#ifdef DERIVTYPE_INFO
printf("%i: %s=%s\n",mypars->deriv_atypes[idx].nr,mypars->deriv_atypes[idx].deriv_name,mypars->deriv_atypes[idx].base_name);
#endif
}
if(*tmp=='/') // need to go to next char otherwise the two loops will infinite loop (ask me how I knooooooooooooooooooooooooooooooooooooooo
tmp++;
}
if(!success){
printf("Example syntax: --derivtype C1,C2,C3=C/S4=S/H5=HD.\n");
exit(12);
}
}
// Argument: modify pairwise atom type parameters (LJ only at this point)
if (argcmp("modpair", argv [i], 'P'))
{
bool success=true;
char* tmp=argv[i+1];
while(success && (*tmp!='\0')){
mypars->nr_mod_atype_pairs++;
if(mypars->nr_mod_atype_pairs==1)
mypars->mod_atype_pairs=(pair_mod*)malloc(sizeof(pair_mod));
else
mypars->mod_atype_pairs=(pair_mod*)realloc(mypars->mod_atype_pairs, mypars->nr_mod_atype_pairs*sizeof(pair_mod));
if(mypars->mod_atype_pairs==NULL){
printf("Error: Cannot allocate memory for --modpair (-P).\n");
exit(1);
}
pair_mod* curr_pair=&mypars->mod_atype_pairs[mypars->nr_mod_atype_pairs-1];
// find atom type pair to modify
char* first_comma=strchr(tmp,',');
if(first_comma==NULL){
printf("Error in --modpair (-P) %s: no parameters specified (not even a first comma).\n",argv[i+1]);
success=false;
break;
}
char* colon=strchr(tmp,':');
if(colon==NULL){
printf("Error in --modpair (-P) %s: Could not find pair atom type name separator (\":\").\n",argv[i+1]);
success=false;
break;
}
int Alen = colon-tmp;
colon++; // we don't want to include the colon
int Blen = first_comma-colon;
if ((Alen>0) && (Blen>0)){ // we have data between the start, colon, and comma (good start)
if ((Alen<4) && (Blen<4)){
strncpy(curr_pair->A,tmp,Alen);
curr_pair->A[Alen]='\0';
strncpy(curr_pair->B,colon,Blen);
curr_pair->B[Blen]='\0';
} else{
printf("Error in --modpair (-P) %s: pair atom type name(s) are too long (>3 characters).\n",argv[i+1]);
success=false;
break;
}
} else{
printf("Error in --modpair (-P) %s: pair atom type name(s) not specified.\n",argv[i+1]);
success=false;
break;
}
tmp=first_comma+1;
char* start_block=tmp;
curr_pair->nr_parameters=0;
curr_pair->parameters=NULL;
// count nr of derivative atom types first
while((*tmp!='\0') && (*tmp!='/')){ // do one block at a time
tmp++;
if((*tmp==',') || (*tmp=='\0') || (*tmp=='/')){
if(tmp-start_block>0){ // make sure there is a name (at least one char, we'll test later if it's taken already)
float tmpfloat;
sscanf(start_block, "%f", &tmpfloat);
curr_pair->nr_parameters++;
curr_pair->parameters=(float*)realloc(curr_pair->parameters,curr_pair->nr_parameters*sizeof(float));
if(curr_pair->parameters==NULL){
printf("Error: Cannot allocate memory for --modpair (-P).\n");
exit(1);
}
curr_pair->parameters[curr_pair->nr_parameters-1]=tmpfloat;
start_block=tmp+1;
} else{
printf("Error in --modpair (-P) %s: force field parameters should be at least one number long.\n",argv[i+1]);
success=false;
break;
}
}
}
if(*tmp=='/') // need to go to next char otherwise the two loops will infinite loop (ask me how I knooooooooooooooooooooooooooooooooooooooo
tmp++;
#ifdef MODPAIR_INFO
printf("%i: %s:%s",mypars->nr_mod_atype_pairs,curr_pair->A,curr_pair->B);
for(unsigned int idx=0; idx<curr_pair->nr_parameters; idx++)
printf(",%f",curr_pair->parameters[idx]);
printf("\n");
#endif
}
if(!success){
printf("Example syntax: --modpair C1:S4,1.60,1.200,13,7/C1:C3,1.20,0.025.\n");
exit(12);
}
}
}
//------------------------------------------------------------
// Processing receptor and ligand files
//------------------------------------------------------------
// Filling mygrid according to the fld file
if (get_gridinfo(mypars->fldfile, mygrid) != 0)
{
printf("\nError in get_gridinfo, stopped job.\n");
return 1;
}
// Filling the atom types field of myligand according to the grid types
if (init_liganddata(mypars->free_roaming_ligand ? mypars->ligandfile : NULL,
mypars->flexresfile,
&myligand_init,
mygrid,
mypars->nr_deriv_atypes,
mypars->deriv_atypes) != 0)
{
printf("\nError in init_liganddata, stopped job.\n");
return 1;
}
// Filling myligand according to the pdbqt file
if (parse_liganddata(&myligand_init,
mygrid,
mypars->coeffs.AD4_coeff_vdW,
mypars->coeffs.AD4_coeff_hb,
mypars->nr_deriv_atypes,
mypars->deriv_atypes,
mypars->nr_mod_atype_pairs,
mypars->mod_atype_pairs) != 0)
{
printf("\nError in parse_liganddata, stopped job.\n");
return 1;
}
if (mypars->contact_analysis){
// read receptor in case contact analysis is requested and we haven't done so already
if(!filelist.preload_maps){
std::string receptor_name=mygrid->grid_file_path;
if(mygrid->grid_file_path.size()>0) receptor_name+="/";
receptor_name += mygrid->receptor_name + ".pdbqt";
mypars->receptor_atoms = read_receptor(receptor_name.c_str(),mygrid,mypars->receptor_map,mypars->receptor_map_list);
mypars->nr_receptor_atoms = mypars->receptor_atoms.size();
}
// Adding flex res atom information needed for analysis
if(mypars->flexresfile!=NULL){
std::vector<ReceptorAtom> flexresatoms = read_receptor_atoms(mypars->flexresfile);
mypars->receptor_atoms.insert(mypars->receptor_atoms.end(), flexresatoms.begin(), flexresatoms.end());
for(int i=myligand_init.true_ligand_atoms; i<myligand_init.num_of_atoms; i++){
mypars->receptor_atoms[mypars->nr_receptor_atoms+i-myligand_init.true_ligand_atoms].acceptor=myligand_init.acceptor[i];
mypars->receptor_atoms[mypars->nr_receptor_atoms+i-myligand_init.true_ligand_atoms].donor=myligand_init.donor[i];
}
}
}
// Reading the grid files and storing values if not already done
int grid_status;
#ifdef USE_PIPELINE
#pragma omp critical
#endif
grid_status = get_gridvalues(mygrid);
if(grid_status!=0)
{
printf("\nError in get_gridvalues, stopped job.\n");
return 1;
}
//------------------------------------------------------------
// Capturing algorithm parameters (command line args)
//------------------------------------------------------------
if(get_commandpars(&argc, argv, &(mygrid->spacing), mypars, true, (filelist.nfiles>1)?i_file+1:0)<0)
return 1;
Gridinfo mydummygrid;
// if -lxrayfile provided, then read xray ligand data
if (mypars->given_xrayligandfile)
{
if (init_liganddata(mypars->xrayligandfile,
mypars->flexresfile,
&myxrayligand,
mygrid,
mypars->nr_deriv_atypes,
mypars->deriv_atypes) != 0)
{
printf("\nError in init_liganddata, stopped job.\n");
return 1;
}
// Filling myligand according to the pdbqt file
if (parse_liganddata(&myxrayligand,
mygrid,
mypars->coeffs.AD4_coeff_vdW,
mypars->coeffs.AD4_coeff_hb,
mypars->nr_deriv_atypes,
mypars->deriv_atypes,
mypars->nr_mod_atype_pairs,
mypars->mod_atype_pairs) != 0)
{
printf("\nError in parse_liganddata, stopped job.\n");
return 1;
}
}
//------------------------------------------------------------
// Calculating energies of reference ligand if required
//------------------------------------------------------------
if (mypars->reflig_en_required) {
IntraTables tables(&myligand_init, mypars->coeffs.scaled_AD4_coeff_elec, mypars->coeffs.AD4_coeff_desolv, mypars->qasp, mypars->nr_mod_atype_pairs, mypars->mod_atype_pairs);
printf("\n");
if(mypars->given_xrayligandfile)
printf("Reference");
else
printf("Input");
printf(" ligand energies");
#ifdef TOOLMODE
if(mypars->output_contact_analysis) printf(" and contact analysis");
#endif
printf(":\n");
if (mypars->given_xrayligandfile)
ligand_calc_output(stdout,
"",
&tables,
&myxrayligand,
mypars,
mygrid,
#ifdef TOOLMODE
mypars->output_contact_analysis,
#else
false,
#endif
true);
else
ligand_calc_output(stdout,
"",
&tables,
&myligand_init,
mypars,
mygrid,
#ifdef TOOLMODE
mypars->output_contact_analysis,
#else
false,
#endif
true);
}
return 0;
}