File: diffGridBasedScoring.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 (255 lines) | stat: -rw-r--r-- 6,826 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
// ----------------------------------------------------
// $Maintainer: Marcel Schumann $
// $Authors: Marcel Schumann $
// ----------------------------------------------------

#include <BALL/SCORING/COMMON/diffGridBasedScoring.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/DOCKING/COMMON/structurePreparer.h>


using namespace BALL;


DiffGridBasedScoring::DiffGridBasedScoring(AtomContainer& receptor, AtomContainer& ligand, Options& options)
	: GridBasedScoring(receptor, ligand, options)
{
}


DiffGridBasedScoring::DiffGridBasedScoring(AtomContainer& receptor, Vector3& hashgrid_origin, Options& options)
	: GridBasedScoring(receptor, hashgrid_origin, options)
{
}


void DiffGridBasedScoring::setLigand(AtomContainer* sys)
{
	ScoringFunction::setSecondMolecule(*sys);
	//force_field_->setup(ligand_, options_); // calls ForceField::setup() and setup() of each component
}


// overloads ScoringFunction::update() so that precalculated receptor-ligand ScoringComponents will not be updated (because grid will be used instead)
void DiffGridBasedScoring::update()
{
	overlaps_ = 0;
	ligand_intramol_overlaps_ = 0;
	AtomPairVector* ligand_nonbonded = nullptr;
	bool update_ligand_nonbonded = false;

	// Make sure to update pairlists for all atoms, including those belonging to flexible residues.
	HashGrid3<Atom*>* backup_grid = nullptr;
	if (!flexible_residues_.empty())
	{
		backup_grid = hashgrid_;
		hashgrid_ = all_residues_hashgrid_;
	}

	// Check for ligand intramolecular atom clashes
	if (all_ligand_nonbonded_)
	{
		// all_ligand_nonbonded_ contains only interfragment pairs
		if (static_ligand_fragments_.size() > 0)
		{
			ligand_intramol_overlaps_ += checkForAtomOverlaps(all_ligand_nonbonded_);
		}
		else
		{
			ligand_nonbonded = createLigandNonbondedPairVector(0, ligand_intramol_overlaps_);
		}
	}
	if (!all_ligand_nonbonded_) // calculate ligand nonbonded pairs
	{
		ligand_nonbonded = createLigandNonbondedPairVector(0, ligand_intramol_overlaps_);
		update_ligand_nonbonded = true;
	}


	AtomPairVector empty_vector(0);
	AtomPairVector* receptor_ligand = nullptr; // will be used only if there are receptor-ligand components that could not be precalculated

	for (vector<ScoringComponent*> ::iterator it = scoring_components_.begin(); it != scoring_components_.end(); ++it)
	{
		if (!(*it)->isEnabled()) continue;

		if ((*it)->isLigandIntraMolecular())
		{
			if (update_ligand_nonbonded)
			{
				(*it)->update(*ligand_nonbonded);
			}
			else if (!(*it)->isAtomPairwise())
			{
				(*it)->update(empty_vector);
			}
		}
		else
		{
			if ((*it)->isGridable())
			{
				(*it)->update(empty_vector);
			}
			else
			{
				if ((*it)->isAtomPairwise())
				{
					if (!receptor_ligand)
					{
						receptor_ligand = createNonbondedPairVector(hashgrid_, overlaps_, 1);
					}
					(*it)->update(*receptor_ligand);
				}
				else
				{
					(*it)->update(empty_vector);
				}
			}
		}
	}

	delete ligand_nonbonded;
	delete receptor_ligand;

	if (!flexible_residues_.empty())
	{
		hashgrid_ = backup_grid;
	}
}



void DiffGridBasedScoring::testOverlaps(Vector3& position, HashGrid3 < Atom* > * hashg)
{
	Atom a; a.setPosition(position);
	a.setType(1);
	a.setTypeName("C");
	Element e = PTE_::getElement("C");

	a.setElement(e);
	Molecule m;
	setLigand(&m);

	int overlaps = 0;
	if (!hashg) hashg = hashgrid_;
	AtomPairVector* nonbonded_pairs = createNonbondedPairVector(hashg, overlaps, 1);

	std::cout<<e.getVanDerWaalsRadius()<<std::endl;
	std::cout<<overlaps<<" atom overlaps were found at the given position"<<std::endl;
	std::cout<<"neighboring_target_atoms_ = "<<neighboring_target_atoms_<<std::endl;

	delete nonbonded_pairs;
}



void DiffGridBasedScoring::updatePrecalculatedScore(Size set)
{
	if (grid_sets_.size() < set)
	{
		String s = "ScoreGridSet no" + String(set) + " has not been defined!";
		throw BALL::Exception::GeneralException(__FILE__, __LINE__, "DiffGridBasedScoring::updatePrecalculatedScore() error", s);
	}
	if (!grid_sets_[set]->getHashGrid())
	{
		String s = "The HashGrid of ScoreGridSet no" + String(set) + " has not been created yet!";
		throw BALL::Exception::GeneralException(__FILE__, __LINE__, "DiffGridBasedScoring::updatePrecalculatedScore() error", s);
	}

	/// use ONLY receptor-ligand nonbonded pairs
	int overlaps = 0;
	AtomPairVector* reclig_nonbonded = createNonbondedPairVector(grid_sets_[set]->getHashGrid(), overlaps, 1);

	score_ = 0;
	if (overlaps == 0)  /// explicit check for sterical clashes!
	{
		for (vector<ScoringComponent*> ::iterator it = scoring_components_.begin(); it != scoring_components_.end(); ++it)
		{
			if (!(*it)->isEnabled())
			{
				continue;
			}

			if (!(*it)->isLigandIntraMolecular() && (*it)->isGridable())
			{
				(*it)->update(*reclig_nonbonded);
				score_ += (*it)->updateScore();
			}
		}
	}
	else
	{
		score_ = overlaps*1e10;
	}

	delete reclig_nonbonded;
}


// Overloads ScoringFunction::updateScore() so that the grid score is used to asses the current receptor-ligand interaction
double DiffGridBasedScoring::updateScore()
{
	if (!store_interactions_ && hasPharmacophoreConstraints_())
	{
		std::cout<<"[info:] enabling storing interaction with PharmacophoreConstraint-residues"<<std::endl;
		enableStoreInteractionsOnlyForPhContraints();
	}
	if (store_interactions_) clearStoredInteractions_();

	/// receptor-ligand contribution, _including_ penalty for atoms outside the ScoreGrid and scaling of the score accoriding to the depth of burial of the ligand candidate
	result_.interaction_score = calculateGridScore();

	/// ligand conformation contribution
	double conf_energy = 0;
	for (vector<ScoringComponent*> ::iterator it = scoring_components_.begin(); it != scoring_components_.end(); it++)
	{
		if (!(*it)->isEnabled()) continue;

		if ((*it)->isLigandIntraMolecular())
		{
			conf_energy += (*it)->updateScore();
		}

		// rec-lig components that could not be precalculated
		else if (!(*it)->isGridable())
		{
			result_.interaction_score += (*it)->updateScore();
		}
	}

	if (static_ligand_fragments_.size() != 0)
	{
		conf_energy += static_ligand_energy_;
	}

	result_.ligand_conformation = conf_energy;
	if (conf_energy < 0)
	{
		conf_energy *= conformation_scale_;
	}

	score_ = conf_energy + result_.interaction_score;

	// backtransform
	if (exp_energy_stddev_ > 0.01) score_ *= exp_energy_stddev_;
	score_ += exp_energy_mean_;

	/// add penalty if ligand candidate lies outside of some ReferenceAreas (if any have been defined by the user)
	score_ += calculateConstraintsScore();


	/// explicit check for sterical clashes!
	if (overlaps_ > 0)
	{
		score_ += overlaps_*1e10;
		result_.interaction_score += overlaps_*1e10;

	}
	if (ligand_intramol_overlaps_ > 0)
	{
		result_.ligand_conformation += ligand_intramol_overlaps_*1e10;
		score_ += ligand_intramol_overlaps_*1e10;
	}

	return score_;
}