File: SLICK.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (449 lines) | stat: -rw-r--r-- 13,785 bytes parent folder | download | duplicates (4)
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
// $Id: SLICK.C,v 1.1 2006/05/21 18:17:15 anker Exp $
//
// Implement the SLICK scoring function

#include <BALL/SCORING/FUNCTIONS/slickEnergy.h>
#include <BALL/SCORING/FUNCTIONS/slickScore.h>
#include <BALL/SCORING/COMPONENTS/vanDerWaalsSlick.h>
#include <BALL/SCORING/COMPONENTS/polarSolvation.h>
#include <BALL/SCORING/COMPONENTS/nonpolarSolvation.h>

#include <BALL/FORMAT/commandlineParser.h>
#include <BALL/FORMAT/HINFile.h>
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/STRUCTURE/fragmentDB.h>
#include <BALL/STRUCTURE/residueChecker.h>
#include <BALL/STRUCTURE/defaultProcessors.h>
#include <BALL/MOLMEC/COMMON/radiusRuleProcessor.h>
#include <BALL/MOLMEC/COMMON/chargeRuleProcessor.h>
#include <BALL/MOLMEC/COMMON/assignTypes.h>
#include <BALL/SYSTEM/path.h>
#include <BALL/DATATYPE/stringHashSet.h>
#include "version.h"

#include <BALL/KERNEL/PTE.h>

#include <ctime>

#define OLD_DATAFILE_FORMAT 1


using namespace BALL;
using namespace std;


int main(int argc, char** argv)
{
	Path path;
	String tmp;
	String configuration_string = "";

	CommandlineParser parpars("SLICK", "scoring protein-carbohydrate interactions", VERSION, String(__DATE__), "Scoring");
	parpars.registerFlag("E", "compute only SLICKEnergy");
	parpars.registerFlag("S", "compute only SLICKScore");
	parpars.registerFlag("u", "unite atoms");
	parpars.registerFlag("n", "read radius rules for the nonpolar solvation from FILE");
	parpars.registerFlag("N", "scale nonpolar radii by FACTOR");
	parpars.registerFlag("log", "write log file");
	parpars.registerMandatoryInputFile("rec", "input receptor file");
	parpars.registerMandatoryInputFile("lig", "input ligand file");
	parpars.registerOptionalInputFile("cr", "charge rules");
	parpars.registerOptionalInputFile("pr", "radius rules for the polar solvation");
	parpars.registerOptionalInputFile("lj", "use FILE for LJ parameters");
	parpars.registerOptionalInputFile("op", "read options from FILE (command line overrides!)");
	parpars.registerOptionalIntegerParameter("v", "verbosity to level");
	parpars.registerOptionalDoubleParameter("s", "scaling factor for receptor charges");
	parpars.registerOptionalDoubleParameter("t", "scaling factor for ligand charges");
	parpars.setSupportedFormats("rec","PDB");
	parpars.setSupportedFormats("lig","HIN");
	parpars.setSupportedFormats("cr","rul");
	parpars.setSupportedFormats("pr","rul");
	parpars.setSupportedFormats("lj","rul");
	parpars.setSupportedFormats("op", "ini");

	String man = "This tool calculates the SLICKEnergy / SLICK Score for protein-carbohydrate complexes.";
	parpars.setToolManual(man);

	parpars.parse(argc, argv);

	Options options;
	ScoringFunction::getDefaultOptions(options);

	unsigned int verbosity = 0;
	if (parpars.get("v") != CommandlineParser::NOT_FOUND)
	{
		verbosity = parpars.get("v").toInt();
		options.setInteger("verbosity", verbosity);
	}

	float receptor_charge_scaling_factor = 1.0f;
	if (parpars.get("s") != CommandlineParser::NOT_FOUND)
	{
		receptor_charge_scaling_factor = parpars.get("s").toFloat();
		configuration_string += "scale_receptor_charges " + parpars.get("s") + "\n";
	}

	float ligand_charge_scaling_factor = 1.0f;
	if (parpars.get("t") != CommandlineParser::NOT_FOUND)
	{
		ligand_charge_scaling_factor = parpars.get("t").toFloat();
		configuration_string += "scale_ligand_charges " + parpars.get("t") + "\n";
	}

	String protein_file_name = parpars.get("rec");
	if (protein_file_name == CommandlineParser::NOT_FOUND)
	{
		Log.error() << "Missing protein file name." << endl;
		return 1;
	}
	configuration_string += "protein_file_name " + protein_file_name + "\n";

	String ligand_file_name = parpars.get("lig");
	if (ligand_file_name == CommandlineParser::NOT_FOUND)
	{
		Log.error() << "Missing ligand file name." << endl;
		return 1;
	}
	configuration_string += "ligand_file_name " + ligand_file_name + "\n";

	if (verbosity > 0)
	{
		Log.info() << "Initializing residue checker." << endl;
	}
	FragmentDB db("fragments/Fragments.db");
	ResidueChecker check(db);


	time_t rawtime;
	time(&rawtime);
	String time_string("start: " + String(asctime(localtime(&rawtime))));

	// now load the molecules and assign radii and charges depending on
	// what the user wants
	System system;

	PDBFile protein_file(protein_file_name);
	protein_file >> system;
	protein_file.close();
	Molecule* protein = system.getMolecule(0);

	if (verbosity > 0)
	{
		Log.info() << "Normalizing names (protein)." << endl;
	}
	system.apply(db.normalize_names);

	if (verbosity > 0)
	{
		Log.info() << "Building bonds (protein)." << endl;
	}
	system.apply(db.build_bonds);

	HINFile ligand_hin_file;
	ligand_hin_file.open(ligand_file_name);
	ligand_hin_file >> system;
	ligand_hin_file.close();
	Molecule* ligand = system.getMolecule(1);


	// Read and apply charge rules
	String charge_rule_file_name = parpars.get("cr");
	if (charge_rule_file_name == CommandlineParser::NOT_FOUND)
	{
		charge_rule_file_name = "solvation/PARSE+ions.rul";
	}
	else
	{
		configuration_string += "use_charge_rules " + charge_rule_file_name + "\n";

		tmp = path.find(charge_rule_file_name);
		if (tmp != "")
		{
			charge_rule_file_name = tmp;
		}

		if (verbosity > 0)
		{
			Log.info() << "Using " << charge_rule_file_name << " as charge rule file" << endl;
		}

		INIFile charge_ini(charge_rule_file_name);
		charge_ini.read();
		ChargeRuleProcessor charge_rules(charge_ini);
		system.apply(charge_rules);
	}


	// Read and apply polar charge rules
	String polar_radius_rule_file_name = parpars.get("pr");
	if (polar_radius_rule_file_name == CommandlineParser::NOT_FOUND)
	{
		polar_radius_rule_file_name = "solvation/PARSE+ions.rul";
	}
	else
	{
		configuration_string += "use_polar_radius_rules " + polar_radius_rule_file_name + "\n";

		tmp = path.find(polar_radius_rule_file_name);
		if (tmp != "")
		{
			polar_radius_rule_file_name = tmp;
		}
		if (verbosity > 0)
		{
			Log.info() << "Using " << polar_radius_rule_file_name << " as polar radius rule file" << endl;
		}

		INIFile radius_ini(polar_radius_rule_file_name);
		radius_ini.read();
		RadiusRuleProcessor radius_rules(radius_ini);
		system.apply(radius_rules);
	}

	if (verbosity > 8)
	{
		Log.info() << "system statistics:" << endl;
		Log.info() << "molecules: " << system.countMolecules() << endl;
		Log.info() << "proteins:  " << system.countProteins() << endl;
		Log.info() << "fragments: " << system.countFragments() << endl;
		Log.info() << "atoms:     " << system.countAtoms() << endl;
	}


	// check for uassigned type names
	AtomIterator it;
	int count = 0;
	for (it = system.beginAtom(); +it; ++it)
	{
		count++;
		if (it->getElement().getSymbol() == "?")
		{
			Log.info() << "Got symbol \"?\": " << it->getFullName() << endl;
		}
		if (it->getCharge() > 8.0)
		{
			Log.error() << "Mysterious charge: " << it->getCharge() << "\t"
				<< it->getFullName() << "\t" << count << "\t" << it->getElement().getSymbol() << endl;
		}
	}

	// scale charges
	if (verbosity > 0)
	{
		Log.info() << "Scaling receptor charges by " << receptor_charge_scaling_factor << endl;
	}
	if (parpars.has("s"))
	{
		for (it = protein->beginAtom(); +it; ++it)
		{
			it->setCharge(it->getCharge() * receptor_charge_scaling_factor);
		}
	}

	if (verbosity > 0)
	{
		Log.info() << "Scaling ligand charges by " << ligand_charge_scaling_factor << endl;
	}
	if (parpars.has("t"))
	{
		for (it = ligand->beginAtom(); +it; ++it)
		{
			it->setCharge(it->getCharge() * ligand_charge_scaling_factor);
		}
	}


	String options_file_name = parpars.get("op");
	if (options_file_name != CommandlineParser::NOT_FOUND)
	{
		options.readOptionFile(options_file_name);
		configuration_string += "read_options_file " + options_file_name;
	}

	String lj_parameter_file_name = parpars.get("lj");
	if (lj_parameter_file_name == CommandlineParser::NOT_FOUND)
	{
		lj_parameter_file_name = "Amber/amber94gly.ini";
	}
	else
	{
		configuration_string = configuration_string + "lj_parameter_file_name " + lj_parameter_file_name;
	}

	options.set(VanDerWaalsSlick::Option::LENNARD_JONES_FILE, lj_parameter_file_name);

	if (parpars.has("u"))
	{
		options.setBool(PolarSolvation::Option::UNITE_ATOMS, true);
		cout << "Uniting atoms." << endl;
		configuration_string += "unite_atoms true\n";
	}
	else
	{
		options.setBool(PolarSolvation::Option::UNITE_ATOMS, false);
		cout << "Not uniting atoms." << endl;
	}

	String nonpolar_radius_rule_file_name = parpars.get("n");
	if (nonpolar_radius_rule_file_name == CommandlineParser::NOT_FOUND)
	{
		nonpolar_radius_rule_file_name = "solvation/bondi.rul";
	}
	else
	{
		cout << "Using " << nonpolar_radius_rule_file_name << " for nonpolar radii" << endl;
		configuration_string += "use_nonpolar_radius_rules " + nonpolar_radius_rule_file_name + "\n";

		options.setBool(NonpolarSolvation::Option::NONPOLAR_OVERWRITE_RADII, true);
		options.set(NonpolarSolvation::Option::NONPOLAR_RADIUS_RULES, nonpolar_radius_rule_file_name);
	}



	float score = 0.0f;

	if (!parpars.has("S"))
	{
		configuration_string = configuration_string + "calculate_energy\n";

		SLICKEnergy slick(*protein, *ligand, options);
		score = slick.calculateScore();

		cout << endl << "SLICK/energy is " << score << " kJ/mol" << endl;

		if (verbosity > 1)
		{
			cout << endl << "Scores (w/o coefficients)" << endl << endl;
			cout << "Hydrogen bonds     " << slick.getHydrogenBondScore() << endl;
			cout << "CHPI               " << slick.getCHPIScore() << endl;
			cout << "VanDerWaalsSlick   " << slick.getVDWScore() << endl;
			cout << "Nonpolar solvation " << slick.getNonpolarSolvationScore() << endl;
			cout << "Polar Solvation    " << slick.getPolarSolvationScore() << endl;
		}

#ifdef OLD_DATAFILE_FORMAT
		String dat_file_name;
		String component;
		File datfile;

		component = "SLICKenergy";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << score << " " << component << endl;
		datfile.close();

		component = "HB";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getHydrogenBondScore()
			<< " " << component << endl;
		datfile.close();

		component = "CHPISlick";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getCHPIScore()
			<< " " << component << endl;
		datfile.close();

		component = "VDW5";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getVDWScore()
			<< " " << component << endl;
		datfile.close();

		component = "NONPOLAR2";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getNonpolarSolvationScore()
			<< " " << component << endl;
		datfile.close();

		component = "DESOLV4";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getPolarSolvationScore()
			<< " " << component << endl;
		datfile.close();
#endif

		time(&rawtime);
		time_string = time_string + String("stop:  " + String(asctime(localtime(&rawtime))));

		if (parpars.has("log"))
		{
			File logfile("SLICKenergy.log", std::ios::out);
			logfile << configuration_string << endl;
			logfile << time_string << endl;
			logfile.close();
		}
	}


	if (!parpars.has("E"))
	{
		configuration_string = configuration_string + "calculate_score\n";

		SLICKScore slick(*protein, *ligand, options);
		score = slick.calculateScore();

		cout << endl << "SLICK/score is " << score << " (arb. units)" << endl;

		if (verbosity > 1)
		{
			cout << endl << "Scores (w/o coefficients)" << endl << endl;
			cout << "Hydrogen bonds     " << slick.getHydrogenBondScore() << endl;
			cout << "CHPI               " << slick.getCHPIScore() << endl;
			cout << "VanDerWaalsSlick   " << slick.getVDWScore() << endl;
			cout << "Electrostatic int. " << slick.getPolarSolvationScore() << endl;
		}

#ifdef OLD_DATAFILE_FORMAT
		String dat_file_name;
		String component;
		File datfile;

		component = "SLICKenergy";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << score << " " << component << endl;
		datfile.close();

		component = "HB";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getHydrogenBondScore() << " " << component << endl;
		datfile.close();

		component = "CHPISlick";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getCHPIScore() << " " << component << endl;
		datfile.close();

		component = "VDW5";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getVDWScore() << " " << component << endl;
		datfile.close();

		component = "COULOMB";
		dat_file_name = component + ".dat";
		datfile.open(dat_file_name, std::ios::out);
		datfile << protein_file_name << " " << ligand_file_name << " " << slick.getPolarSolvationScore() << " " << component << endl;
		datfile.close();
#endif

		time(&rawtime);
		time_string = time_string + String("stop:  " + String(asctime(localtime(&rawtime))));

		if (parpars.has("log"))
		{
			File logfile("SLICKscore.log", std::ios::out);
			logfile << configuration_string << endl;
			logfile << time_string << endl;
			logfile.close();
		}
	}
}