File: NMRDescriptors.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 (453 lines) | stat: -rw-r--r-- 10,414 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
450
451
452
453
#include <BALL/QSAR/NMRDescriptors.h>
#include <BALL/KERNEL/atom.h>
#include <BALL/STRUCTURE/geometricProperties.h>
#include <BALL/MATHS/analyticalGeometry.h>

#define FLOAT_VALUE_NA 3600. //TODO

namespace BALL
{

	void calculateResidueChiAngles
		(const Protein& protein, HashMap<const Residue*, float>& residue_angles)
	{
		for (ChainConstIterator chain_it = protein.beginChain(); +chain_it; ++chain_it)
		{
			calculateResidueChiAngles(*chain_it, residue_angles);
		}
	}
	
	void calculateResidueChiAngles
		(const Chain& fragment, HashMap<const Residue*,float>& residue_angles)
	{
		float angle = 0;// FLOAT_VALUE_NA;
		
		// extract all residues: iterate over all composites and
		// check whether they are Residues
		ResidueConstIterator	it = fragment.beginResidue();
		for (; +it; ++it)
		{
			angle = calculateResidueChiAngles(*it);
			residue_angles.insert(std::pair<const Residue*, float>(&*it, angle));
		}
	}

	//TODO switch to real Angle
	float calculateResidueChiAngles(const Residue& residue)
	{
		// some variables
		Atom const* N = 0;
		Atom const* CA = 0;
		Atom const* CB = 0;
		Atom const* X = 0;

		int num_of_atoms = 0;
		float angle =  0;//FLOAT_VALUE_NA;
	
		String residue_name = residue.getName();

		// we assume that GLY has no typical CHI_1 - angle
		if (residue_name == "GLY" )
		{	
			return angle;
		}

		AtomConstIterator r_it = residue.beginAtom();
		for (; r_it != residue.endAtom(); ++r_it)
		{	
			String name = r_it->getName();
			if (name == "N")
			{
				N = &(*r_it);
				num_of_atoms += 1;
			}
			else if (name == "CA")
			{
				CA = &(*r_it);
				num_of_atoms += 1;
			}
			else if (name == "CB")
			{ 
				CB = &(*r_it);
				num_of_atoms += 1;
			}
		}

		if (num_of_atoms != 3)
		{
			Log.info() << "calculateResidueChiAngles: Torsion angle of " << residue_name<< std::endl;
			return angle;
		}

		// determine the missing atom X
		/* Sidechain dihedral angle chi1 is defined
			 (for non-Gly residues) as follows:

				Chi1:	N(i)-CA(i)-CB(i)-X(i)

				where X is the following atom for the following
				residue types:

				X				Residue type
				----		----------------------------
				HB1			Ala (for models with protons,labelled 1HB in PDB files).
				SG			Cys
				CG			Asp, Glu, Phe, His, Lys, Leu, Met,
				Asn, Pro, Gln, Arg, Trp, Tyr
				CG1			Ile, Val
				OG			Ser
				OG1			Thr

		In order to be conform with ShiftX we leave out GLY and ALA
		*/
		
		if (residue_name == "GLY")
		{ 
			Log.info() << "calculateResidueChiAngles: Torsion angle of a Glycine could not be computed!" << std::endl;
			return angle;
		}
		else if (residue_name == "ALA")
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "HB1" || r_it->getName() == "1HB")
				{
					X = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if (residue_name == "CYS")
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "SG")
				{
					X = &(*r_it);	
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if (residue_name == "ASP" || residue_name ==  "GLU" || 
				residue_name == "PHE" || residue_name ==  "HIS" || 
				residue_name == "LYS" || residue_name ==  "LEU" ||
				residue_name == "MET" || residue_name ==  "ASN" ||
				residue_name == "PRO" || residue_name ==  "GLN" ||
				residue_name == "ARG" || residue_name ==  "TRP" ||  residue_name == "TYR")
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "CG")
				{
					X = &(*r_it);	
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if (residue_name == "VAL" || residue_name ==  "ILE")
		{									
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "CG1")
				{
					X = &(*r_it); 	
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if (residue_name == "SER") 
		{									
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "OG")
				{
					X = &(*r_it);	
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if (residue_name == "THR") 
		{									
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "OG1")
				{
					X = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}

		if (num_of_atoms != 4)
		{
			Log.info() << "calculateResidueChiAngles: Chi torsion angle of " << residue.getID() << "-"<<  residue.getName() << " could not be computed!" << std::endl;
			return angle;
		}

		Vector3 a = N->getPosition();
		Vector3 b = CA->getPosition();
		Vector3 c = CB->getPosition();
		Vector3 d = X->getPosition();

		//angle = getTorsionAngle(a.x, a.y, a.z, b.x, b.y, b.z, 
		//											 c.x, c.y, c.z, d.x, d.y, d.z)*180./Constants::PI;

		angle = calculateTorsionAngle(*N,*CA,*CB,*X).toRadian();
		while (angle < 0.)
		{
			angle = angle + 2*BALL::Constants::PI;
		}

		return angle; // TODO return real angle
	}



	void calculateResidueChi2Angles
		(const Protein& protein, HashMap<const Residue*, float>& residue_angles)
	{
		for (ChainConstIterator chain_it = protein.beginChain(); +chain_it; ++chain_it)
		{
			calculateResidueChi2Angles(*chain_it, residue_angles);
		}
	}


	void calculateResidueChi2Angles
		(const Chain& fragment, HashMap<const Residue*,float>& residue_angles)
	{
		float angle = 0; //FLOAT_VALUE_NA;
		
		// extract all residues: iterate over all composites and
		// check whether they are Residues
		ResidueConstIterator	it = fragment.beginResidue();
		for (; +it; ++it)
		{
			angle =  calculateResidueChi2Angles(*it);
			residue_angles.insert(std::pair<const Residue*, float>(&*it, angle));
		}
	}


	//TODO switch to real Angle
	float calculateResidueChi2Angles(const Residue& residue) 
	{
		// some variables	
		Atom const* CA = 0;
		Atom const* CB = 0;
		Atom const* CG = 0;
		Atom const* XG = 0;

		int num_of_atoms = 0;
		float angle = 0; // FLOAT_VALUE_NA;
		String residue_name = residue.getName();

		// GLY, ALA, SER and CYS have no typical CHI2 - angle
		if ( 	 (residue_name == "ALA") 
				|| (residue_name == "GLY") 
				|| (residue_name == "SER") 
				|| (residue_name == "CYS"))
		{
			Log.info() << "calculateResidueChi2Angles: Chi torsion angle of " << residue.getID() << "-"<< residue.getName() << " could not be computed!" << std::endl;
			return angle;
		}

		//  Sidechain dihedral angle chi2 is defined as follows:
		//  
		// 	Chi2:	CA(i)-CB(i)-CG(i)-XG(i)
		//  where XG is the following atom for the following
		//	residue types:
		//
		//	CG     XG     residue 
		//	-------------------------------------
		// 	CG     CD     PRO, GLN,  GLU, LYS, ARG
		// 		     CD1    LEU,TRP,PHE,TYR, 
		//  		   OD1    ASN, ASP
		//  		   ND1		HIS	 
		//         SD     MET 
		//  CG1    CD1    ILE
		//         1HG1   VAL
		//	CG2	   (1HG2   VAL)
		//				 1HG2		THR
		//	
		//  Note: in some amino acids the atom names can be switched, i.e.
		// 				for chi2 in amino acids PHE:  CD1 <-> CD2
		//          				              TYR:  CD1 <-> CD2
		//        	        			 	      ASP:  OD1 <-> OD2


		AtomConstIterator r_it = residue.beginAtom();
		for (; r_it != residue.endAtom(); ++r_it)
		{	
			String name = r_it->getName();
			if (name == "CA")
			{
				CA = &(*r_it);
				num_of_atoms += 1;
			}
			else if (name == "CB")
			{ 
				CB = &(*r_it);
				num_of_atoms += 1;	
			}
			if (name == "CG")
			{
				CG = &(*r_it);
				num_of_atoms += 1;
			}
		}

		//look for XG
		if (   (residue_name == "ARG") || (residue_name == "GLN") 
				|| (residue_name == "GLU") || (residue_name == "LYS") 
				|| (residue_name == "PRO"))
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "CD")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if ( (residue_name == "ASN") || (residue_name == "ASP") )
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "OD1")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if ( (residue_name == "LEU") || (residue_name == "TRP") 
				||(residue_name == "PHE") || (residue_name == "TYR") )
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "CD1")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}	
		else if (residue_name == "HIS") 
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "ND1")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}
		else if(residue_name == "MET") 	
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "SD")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
					break;
				}
			}
		}
		// we have to take special care about ILE, VAL and THR
		else if(residue_name == "ILE") 	
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "CG1")
				{
					CG = &(*r_it);
					num_of_atoms += 1;
				}
				else if (r_it->getName() == "CD1")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
				}
			}
		}
		else if(residue_name == "VAL") 	
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "1HG1")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
				}
				else if (r_it->getName() == "CG1")
				{
					CG = &(*r_it);
					num_of_atoms += 1;
				}
			}
		}
		else if(residue_name == "THR") 	
		{
			r_it = residue.beginAtom();
			for (;r_it != residue.endAtom(); ++r_it)
			{	
				if (r_it->getName() == "1HG2")
				{
					XG = &(*r_it);
					num_of_atoms += 1;
				}
				else if (r_it->getName() == "CG2")
				{
					CG = &(*r_it);
					num_of_atoms += 1;
				}
			}
		} 

		if (num_of_atoms != 4)
		{
			Log.info() << "calculateResidueChi2Angles: Chi torsion angle of " << residue.getID() << "-"<<  residue.getName() << " could not be computed!" << std::endl;
			return angle;
		}

		Vector3 a = CA->getPosition();
		Vector3 b = CB->getPosition();
		Vector3 c = CG->getPosition();
		Vector3 d = XG->getPosition();

		angle = calculateTorsionAngle(*CA,*CB,*CG,*XG).toRadian();
		while (angle < 0.)
		{
			angle = angle + 2*BALL::Constants::PI;
		}
		return angle; // TODO return real angle
	}
}