File: lipophilic.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 239,848 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 93
file content (288 lines) | stat: -rw-r--r-- 6,973 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
// ----------------------------------------------------
// $Maintainer: Marcel Schumann $
// $Authors: Slick-development Team, Marcel Schumann $
// ----------------------------------------------------

#include <BALL/SCORING/COMPONENTS/lipophilic.h>
#include <BALL/SYSTEM/timer.h>
#include <BALL/FORMAT/HINFile.h>

using namespace std;
using namespace BALL;


const char* Lipophilic::Option::LIPO_R1_OFFSET = "lipo_r1_offset";
const char* Lipophilic::Option::LIPO_R2_OFFSET = "lipo_r2_offset";
const char* Lipophilic::Option::CREATE_INTERACTIONS_FILE
	 = "LIPO_create_interactions_file";
const char* Lipophilic::Option::VERBOSITY = "verbosity";

const float Lipophilic::Default::LIPO_R1_OFFSET = 0.5;
const float Lipophilic::Default::LIPO_R2_OFFSET = 3.0;
const bool Lipophilic::Default::CREATE_INTERACTIONS_FILE = false;
const Size Lipophilic::Default::VERBOSITY = 0;


Lipophilic::Lipophilic(ScoringFunction& sf)
	:	ScoringComponent(sf),
		possible_lipophilic_interactions_(),
		r1_offset_(0.0),
		r2_offset_(0.0)
{
	setName("Fresno Lipophilic");
	receptor_fresno_types_ = 0;
	ligand_fresno_types_ = 0;
	setup();
}


Lipophilic::Lipophilic(const Lipophilic& fl)
	:	ScoringComponent(fl),
		possible_lipophilic_interactions_(fl.possible_lipophilic_interactions_),
		r1_offset_(fl.r1_offset_),
		r2_offset_(fl.r2_offset_)
{
	receptor_fresno_types_ = 0;
	ligand_fresno_types_ = 0;
	setup();
}


Lipophilic::~Lipophilic()
{
	clear();
}


void Lipophilic::clear()
	throw()
{
	possible_lipophilic_interactions_.clear();
	r1_offset_ = 0.0;
	r2_offset_ = 0.0;
	delete ligand_fresno_types_;
	delete receptor_fresno_types_;
}


bool Lipophilic::setup()
{
	Timer timer;
	timer.start();

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

	//clear the vector of lipophilic interactions
	possible_lipophilic_interactions_.clear();

	Options options = sf->getOptions();

	r1_offset_
		 = options.setDefaultReal(Lipophilic::Option::LIPO_R1_OFFSET,
				Lipophilic::Default::LIPO_R1_OFFSET);
	r2_offset_
		 = options.setDefaultReal(Lipophilic::Option::LIPO_R2_OFFSET,
				Lipophilic::Default::LIPO_R2_OFFSET);
	write_interactions_file_
		 = options.setDefaultBool(Lipophilic::Option::CREATE_INTERACTIONS_FILE,
				Lipophilic::Default::CREATE_INTERACTIONS_FILE);
	verbosity_
		 = options.setDefaultInteger(Lipophilic::Option::VERBOSITY,
				Lipophilic::Default::VERBOSITY);

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

	setupLigand();

	timer.stop();
	Log.info() << "Lipophilic::setup(): "
		<< timer.getCPUTime() << std::endl;

	return true;
}


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


bool Lipophilic::isTypeKnown(Atom* atom)
{
	if (receptor_fresno_types_->getTypeMap()->has(atom)) return true;
	if (ligand_fresno_types_->getTypeMap()->has(atom)) return true;
	return false;
}


Size Lipophilic::getType(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 0;
}



void Lipophilic::update(const AtomPairVector& pair_vector)
{
	possible_lipophilic_interactions_.clear();

	for (AtomPairVector::const_iterator it = pair_vector.begin(); it != pair_vector.end(); it++)
	{
		if (isTypeKnown(it->first))
		{
			if (getType(it->first) == FresnoTypes::LIPOPHILIC)
			{
				if (isTypeKnown(it->second))
				{
					if (getType(it->second) == FresnoTypes::LIPOPHILIC)
					{
						possible_lipophilic_interactions_.push_back(*it);
						if (verbosity_ >= 10)
						{
							Log.info() << "found possible lipophilic int.: "
									<< it->first->getFullName() << "..." << it->second->getFullName()
									<< " (length: "
									<< (it->first->getPosition() - it->second->getPosition()).getLength()
									<< " A) "
									<< endl;
						}
					}
				}
			}
		}
	}

	if (verbosity_ > 2)
	{
		Log.info() << "Lipophilic update statistics:" << endl;
		Log.info() << "Found " << possible_lipophilic_interactions_.size()
				<< " possible lipophilic interactions" << endl << endl;
	}
}



double Lipophilic::updateScore()
{
	Timer timer;
	timer.start();

	Molecule interactions_molecule;

	score_ = 0.0;
	float val = 0.0;
	float distance;
	float R1;
	float R2;
	const Atom* atom1;
	const Atom* atom2;


	for (AtomPairVector::const_iterator it = possible_lipophilic_interactions_.begin();
		it != possible_lipophilic_interactions_.end(); ++it)
	{
		atom1 = it->first;
		atom2 = it->second;

		R1 = atom1->getRadius() + atom2->getRadius() + r1_offset_;
		R2 = R1 + r2_offset_;

		distance = (atom1->getPosition() - atom2->getPosition()).getLength();

		// if the distance is too large, the product of g1 and g2 is zero, so
		// we can skip the rest

		if (distance <= R2)
		{
			// we could possibly speed up the next step by using the fact that the
			// difference between R1 and R2 is constant
			val = base_function_->calculate(distance, R1, R2);
			if (verbosity_ >= 1)
			{
				Log.info() << "LI: " << val << " "<< atom1->getFullName() << " " << endl;
				if (atom1->getResidue() != 0)
				{
					Log.info() << "[" << atom1->getResidue()->getID() << "]";
				}
				Log.info() << "..." << atom2->getFullName() << " " << endl;
				if (atom2->getResidue() != 0)
				{
					Log.info() << "[" << atom2->getResidue()->getID() << "]";
				}
				Log.info() << " (d " << distance << ", R1 " << R1
					<< ", R2 " << R2 << ")" << endl;
			}

			if (write_interactions_file_)
			{
				Atom* atom_ptr_L1 = new Atom();
				atom_ptr_L1->setElement(atom1->getElement());
				atom_ptr_L1->setName("L1");
				atom_ptr_L1->setPosition(atom1->getPosition());
				atom_ptr_L1->setCharge(val);

				Atom* atom_ptr_L2 = new Atom();
				atom_ptr_L2->setElement(atom2->getElement());
				atom_ptr_L2->setName("L2");
				atom_ptr_L2->setPosition(atom2->getPosition());
				atom_ptr_L2->setCharge(val);

				atom_ptr_L1->createBond(*atom_ptr_L2);

				interactions_molecule.insert(*atom_ptr_L1);
				interactions_molecule.insert(*atom_ptr_L2);
			}

			score_ += val;
		}
	}

	if (write_interactions_file_)
	{
		HINFile debug_file("LIPO_debug.hin", std::ios::out);
		debug_file << interactions_molecule;
		debug_file.close();
	}

	if (verbosity_ > 0)
	{
		Log.info() << "LIPO: score is " << score_ << endl;
	}

	timer.stop();

	if (verbosity_ > 1)
	{
		Log.info() << "Lipophilic::updateScore(): "
			<< timer.getCPUTime() << " s" << std::endl;
	}

	// we want a negative score for a good pose, thus we will use the negative of the value computed above
	score_ *= -1;

	/*
	scaleScore();
	return score_;
	*/

	return getScaledScore();
}