File: SideChainGridBuilder.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 239,928 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (224 lines) | stat: -rwxr-xr-x 6,535 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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/FORMAT/PDBFile.h>
#include <BALL/FORMAT/molFileFactory.h>
#include <BALL/FORMAT/commandlineParser.h>
#include <BALL/DOCKING/COMMON/structurePreparer.h>
#include <BALL/DOCKING/COMMON/dockingAlgorithm.h>
#include <BALL/COMMON/exception.h>
#include <BALL/DATATYPE/options.h>
#include <BALL/SCORING/COMMON/gridBasedScoring.h>
#include <BALL/SCORING/FUNCTIONS/gridedPLP.h>
#include <BALL/SCORING/FUNCTIONS/gridedMM.h>
#include <BALL/STRUCTURE/fragmentDB.h>
#include <BALL/STRUCTURE/rotamerLibrary.h>
#include <BALL/STRUCTURE/peptideBuilder.h>
#include "version.h"


using namespace BALL;
using namespace std;

GridBasedScoring* createScoringFunction(AtomContainer* receptor, AtomContainer* ref_ligand, String scoring_type, list<Constraint*>* constraints, Options* option)
{
	GridBasedScoring* gbs = 0;
	if (scoring_type == "GridedMM")
	{
		gbs = new GridedMM(*receptor, *ref_ligand, *option);
	}
	else if (scoring_type == "GridedPLP")
	{
		gbs = new GridedPLP(*receptor, *ref_ligand, *option);
	}
	for (list < Constraint* > ::iterator it = constraints->begin(); it != constraints->end(); it++)
	{
		gbs->constraints.push_back(*it);
		(*it)->setScoringFunction(gbs);
	}
	return gbs;
}


int main(int argc, char* argv[])
{
	CommandlineParser parpars("SideChainGridBuilder", "build side chain grid", VERSION, String(__DATE__), "Docking");
	parpars.registerMandatoryInputFile("param", "parameter file");
	parpars.registerMandatoryStringParameter("d", "output directory");
	parpars.setSupportedFormats("param", "ini");
	parpars.setToolManual("This tool precalculates a side chain grid.");

	parpars.parse(argc, argv);

	//Log.setMinLevel(cout, 10);

	Options option;
	list<Constraint*> constraints;

	if (parpars.get("param") == CommandlineParser::NOT_FOUND)
	{
		cout<<"[Error:] ini file must be given" << std::endl;
		exit (1);
	}

	String inifile = parpars.get("param");
	DockingAlgorithm::readOptionFile(inifile, option, constraints);
	String scoring_type = option.get("scoring_type");
	String grid_file = option.get("grid_file");

	// Support for using one and the same config-file for grid precalculation and docking
	String precalc_nonbonded_cuttoff = option.get("nonbonded_cutoff_precalculation");
	if (precalc_nonbonded_cuttoff != "")
	{
		option.set("nonbonded_cutoff", precalc_nonbonded_cuttoff);
	}

	if (scoring_type == "")
	{
		cout<<"[Error:] scoring_type must be specified in the config-file!"<<endl;
		exit(1);
	}
	if (scoring_type != "GridedMM" && scoring_type != "GridedPLP")
	{
		cout<<"[Error:] specified scoring_type is not grid-based, so no grid can be build for it!"<<endl;
		exit(1);
	}
	String par_file = option.get("filename");
	if (par_file == "" && !scoring_type.hasSubstring("GH"))
	{
		cout<<"[Error:] 'filename' for force-field parameter file must be specified in the config-file  !"<<endl;
		return(1);
	}
	if (grid_file == "")
	{
		cout<<"'grid_file' must be specified in the config-file  !"<<endl;
		return(1);
	}

	StructurePreparer* sp;
	bool use_PLP = 0;
	if (scoring_type.hasSubstring("PLP"))
	{
		use_PLP = 1;
		sp = new StructurePreparer("PLP");
	}
	else
	{
		use_PLP = 0;
		sp = new StructurePreparer;
	}

	String at = option.get("atom_types");
	set<String> types;
	if (!use_PLP && at != "")
	{
		Size no = at.countFields(", ");
		for (Size i = 0; i < no; i++)
		{
			String type_i = at.getField(i, ", ");
			type_i.trim();
			types.insert(type_i);
		}
	}

	// Angles are irrelevant, since we construct only single amino acids
	Angle angle(0);

	if (parpars.get("d") == CommandlineParser::NOT_FOUND)
	{
		cout<<"[Error:] out directory must be given" << std::endl;
		exit (1);
	}

	String prefix = parpars.get("d");
	prefix += "/";

	FragmentDB frag_db("fragments/Fragments.db");
	RotamerLibrary rotamer_lib("rotamers/bbind02.May.lib", frag_db);
	String one_letter_codes = "ARNDCQEGHILKMFPSTWYV";

	for (Size i = 0; i < 20; i++)
	{
		Peptides::PeptideBuilder pb(one_letter_codes[i], angle, angle, angle);
		pb.setFragmentDB(&frag_db);
		Protein* protein_template = pb.construct();
		sp->prepare(protein_template, par_file);

		Residue* residue = protein_template->getResidue(0);
		ResidueRotamerSet* rotamer_set = rotamer_lib.getRotamerSet(*residue);

		if (!rotamer_set) // GLY and ALA have no rotamers
		{
			cout<<"No rotamers for "<<residue->getName()<<" found."<<endl;
			continue;
		}

		// Remove atoms that are not part of the residue templates
		for (AtomIterator atom_it = protein_template->beginAtom(); +atom_it; atom_it++)
		{
			const String& name = atom_it->getName();
			if (name == "1H" || name == "2H" || name == "3H" || name == "OXT")
			{
				atom_it->select();
			}
		}
		protein_template->removeSelected();

		// Do for each rotamer of the current amino acid
		for (ResidueRotamerSet::ConstIterator it = rotamer_set->begin(); it != rotamer_set->end(); it++)
		{
			rotamer_set->setRotamer(*residue, *it);
			Protein protein = *protein_template; // make a copy

			/// Remove backbone atoms!!
			/// Grids should only contain contributions for side-chains!
			for (AtomIterator atom_it = protein.beginAtom(); +atom_it; atom_it++)
			{
				const String& name = atom_it->getName();
				if (name == "N" || name == "O" || name == "CA" || name == "C"
				||name == "HA")
				{
					atom_it->select();
				}
			}
			protein.removeSelected();


			GridBasedScoring* gbs = createScoringFunction(&protein, &protein, scoring_type, &constraints, &option);
			gbs->setAtomTypeNames(types);

			String name = residue->getName()+"_";
			name += String((int)it->chi1)+"_";
			name += String((int)it->chi2)+"_";
			name += String((int)it->chi3)+"_";
			name += String((int)it->chi4);

			cout<<endl<<"---- Will now precalculate grids for "<<name<<" ...  ------------"<<endl<<flush;

			// Make sure that atoms lying outside of the grids for flexible side-chains will not be penalized during docking/scoring.
			vector<ScoreGridSet*>* gridsets = gbs->getScoreGridSets();
			for (Size i = 0; i < gridsets->size(); i++)
			{
				gridsets->at(i)->setParameters(0, 0, 0);
			}

			gbs->precalculateGrids();

			gbs->saveGridSetsToFile(prefix+name+".bngrd", name);
			PDBFile out(prefix+name+".pdb", ios::out);
			out << *protein_template; // include backbone atoms into pdb-file, because they will be needed for mapping later
			out.close();
			delete gbs;
		}
		delete protein_template;
	}


	for (list < Constraint* > ::iterator it = constraints.begin(); it != constraints.end(); it++)
	{
		delete *it;
	}
	delete sp;
	return 0;
}