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

#include <BALL/SCORING/COMPONENTS/polarity.h>
#include <BALL/SCORING/COMPONENTS/fresnoTypes.h>
#include <BALL/KERNEL/PTE.h>

#include <BALL/SYSTEM/timer.h>


using namespace std;
using namespace BALL;


const double Polarity::POL_ES_THRESHOLD = 0.2;
const double Polarity::LIP_ES_THRESHOLD = 0.1;


Polarity::Polarity(ScoringFunction& sf)
	:	ScoringComponent(sf)
{
	setName("Polarity");
	type_name_ = "pol";
	receptor_fresno_types_ = 0;
	ligand_fresno_types_ = 0;
	gridable_ = false;
	atom_pairwise_ = 0;
	setup();
}


Polarity::Polarity(const Polarity& bp)
	:	ScoringComponent(bp)
{
	setName("Polarity");
	type_name_ = "pol";
	receptor_fresno_types_ = 0;
	ligand_fresno_types_ = 0;
	gridable_ = false;
	atom_pairwise_ = 0;
	setup();
}


Polarity::~Polarity()
{
	delete receptor_fresno_types_;
	delete ligand_fresno_types_;
}


void Polarity::clear()
{
}


bool Polarity::setup()
{
	ScoringFunction* sf = getScoringFunction();
	if (sf == 0)
	{
		Log.error() << "Polarity::setup(): "
			<< "component not bound to force field." << endl;
		return false;
	}

	delete receptor_fresno_types_;
	receptor_fresno_types_ = new FresnoTypes(getScoringFunction()->getReceptor());

	setupLigand();

	return true;
}


void Polarity::setupLigand()
{
	delete ligand_fresno_types_;
	ligand_fresno_types_ = new FresnoTypes(getScoringFunction()->getLigand());
}


Size Polarity::getType_(const Atom* atom)
{
	HashMap<const Atom*, Size>::const_iterator it = receptor_fresno_types_->getTypeMap()->find(atom);
	if (it != receptor_fresno_types_->getTypeMap()->end())
	{
		return it->second;
	}
	it = ligand_fresno_types_->getTypeMap()->find(atom);
	if (it != ligand_fresno_types_->getTypeMap()->end())
	{
		return it->second;
	}
	return FresnoTypes::UNKNOWN;
}


void Polarity::update(const std::vector<std::pair<Atom*, Atom*> >& /* pair_vector */)
{
	// nothing to be done here ...
}


bool Polarity::isPolar_(const Atom* atom)
{
	// if atom is polar, it should (besides the correct Fresno type) also have a significant charge
	if (fabs(atom->getCharge()) < POL_ES_THRESHOLD) return false;

	int type = getType_(atom);
	return (type == FresnoTypes::POLAR)       || (type == FresnoTypes::HBOND_ACCEPTOR)
	    || (type == FresnoTypes::HBOND_DONOR) || (type == FresnoTypes::HBOND_ACCEPTOR_DONOR)
	    || (type == FresnoTypes::HBOND_HYDROGEN);
}


bool Polarity::isLipophilic_(const Atom* atom)
{
	// if atom is lipophilic, it should (besides the correct Fresno type) also have no significant charge
	if (fabs(atom->getCharge()) > LIP_ES_THRESHOLD) return false;

	int type = getType_(atom);
	return type == FresnoTypes::LIPOPHILIC;
}


bool Polarity::isBackboneAtom_(const Atom* atom)
{
	return atom->getName() == "O" || atom->getName() == "N"
	    || atom->getName() == "H" || atom->getName() == "C";
}


double Polarity::updateScore()
{
	score_ = 0.0;
	//float val = 0.0;
	//float distance;
	//float R1;
	//float R2;

	const HashGrid3<Atom*>* hashgrid = scoring_function_->getHashGrid();
	int radius = 1;
	Size no_neighbor_cells = (Size)pow((double)(radius*2+1), 3);  // radius of 1 cell == > 3 cells on each axis

	double total_sum = 0;
	AtomPairVector::const_iterator it;
	for (AtomIterator it = scoring_function_->getLigand()->beginAtom(); +it; it++)
	{
		int no_positive_contacts = 0;
		int no_negative_contacts = 0;
		bool ligandatom_is_lipophilic = isLipophilic_(&*it);

		if (!ligandatom_is_lipophilic)
		{
			continue;
		}

		const HashGridBox3<Atom*>* box = hashgrid->getBox(it->getPosition());

		// ligand atom lies outside of grid
		if (!box) continue;

		Position pos_x, pos_y, pos_z;
		hashgrid->getIndices(*box, pos_x, pos_y, pos_z);

		// indices in HashGrid, where the search for interacting target atoms should begin ( != position of ligand atom)
		int i = ((int)pos_x)-radius; if (i < 0){i = 0; }
		int j0 = ((int)pos_y)-radius; if (j0 < 0){j0 = 0; }
		int k0 = ((int)pos_z)-radius; if (k0 < 0){k0 = 0; }
		int x_size = (int)hashgrid->getSizeX();
		int y_size = (int)hashgrid->getSizeY();
		int z_size = (int)hashgrid->getSizeZ();

		for (; i <= ((int)pos_x)+radius && i < x_size; i++)
		{
			for (int j = j0; j <= ((int)pos_y)+radius && j < y_size; j++)
			{
				for (int k = k0; k <= ((int)pos_z)+radius && k < z_size; k++)
				{
					const HashGridBox3<Atom*>* box = hashgrid->getBox(i, j, k);
					if (!box->isEmpty())
					{
						double cell_score = 0;

						for (HashGridBox3 < Atom* > ::ConstDataIterator d_it = box->beginData(); d_it != box->endData(); d_it++)
						{
							if (isBackboneAtom_(*d_it)) continue;
							bool rec_polar = isPolar_(*d_it);
							bool rec_lipophilic = 0;
							if (!rec_polar) rec_lipophilic = isLipophilic_(*d_it);

							if (!rec_polar && ! rec_lipophilic) continue;

							double distance = ((*d_it)->getPosition()-it->getPosition()).getLength();
							if (distance > (*d_it)->getElement().getVanDerWaalsRadius()+it->getElement().getVanDerWaalsRadius()+1.5) continue;

							double val;
							if (distance > 1) val = 1/distance;
							else val = 1;

							// lipophilic--lipophilic interaction; else polar rec. -- lipophilic ligand atom
							if (rec_lipophilic)
							{
								val *= -1;
							}

							cell_score += val;
							total_sum += val;

							if (scoring_function_->storeInteractionsEnabled())
							{
								val = scaleScore(val);
								it->addInteraction(*d_it, "pol", val);
								(*d_it)->addInteraction(&*it, "pol", val);
							}
						}

						if (cell_score < -0.1) no_positive_contacts++;
						else if (cell_score > 0.1) no_negative_contacts++;
					}
					// if there is no neighboring receptor atom, there will be water ...
// 					else if(i!=pos_x||j!=pos_y||k!=pos_z)
// 					{
// 						if(ligandatom_is_lipophilic)
// 						{
// 							no_negative_contacts++;
// 							double scaled_atom_score = 1.0/no_neighbor_cells;
// 							scaleScore(scaled_atom_score);
// 							total_sum += scaled_atom_score;
// 							it->addInteraction("pol",scaled_atom_score);
// 						}
// 					}
				}
			}
		}
		score_ += (no_negative_contacts-no_positive_contacts)/((double)no_neighbor_cells);
		//cout<<it->getFullName()<<" : "<<no_negative_contacts<<", "<<no_positive_contacts<<"  "<<(no_negative_contacts-no_positive_contacts)/((double)no_neighbor_cells)<<endl;
	}

// 	scaleScore();

//	cout<<"polarity: total sum="<<total_sum<<endl;
//	cout<<"polarity: score="<<score_<<endl;

// 	return score_;

	return getScaledScore();
}