File: shiftModel1D.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 (302 lines) | stat: -rw-r--r-- 6,648 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

// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/NMR/shiftModel1D.h>
#include <BALL/NMR/shiftModel.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/KERNEL/bond.h>

using namespace std;

namespace BALL
{
	ShiftModel1D::ShiftModel1D() 
		:	ShiftModule(),
			peaks_(),
			origin_(),
			dimension_(),
			spacing_(),
			type_(),
			parameters_(),
			system_(NULL),
			valid_(false),
			compute_shifts_(true)
	{
		// TODO: should we do this? 
			//	registerStandardModules_();
	}

	ShiftModel1D::ShiftModel1D(const String& filename, SPECTRUM_TYPE st, bool compute_shifts) 
		:	ShiftModule(),
			peaks_(),
			origin_(),
			dimension_(),
			spacing_(),
			type_(st),
			parameters_(filename),
			system_(NULL),
			valid_(false),
			compute_shifts_(compute_shifts)
	{
		// TODO: should we do this? 
		//registerStandardModules_();
		init_();
	}

	ShiftModel1D::ShiftModel1D(const String& filename,SPECTRUM_TYPE st, double origin, double dimension, double spacing, bool compute_shifts) 
		:	ShiftModule(),
			peaks_(),
			origin_(origin),
			dimension_(dimension),
			spacing_(spacing),
			type_(st),
			parameters_(filename),
			system_(NULL),
			valid_(false),
			compute_shifts_(compute_shifts)
	{
		//?? should we do this? 
		//registerStandardModules_();
		init_();
	}

	ShiftModel1D::ShiftModel1D(const ShiftModel1D& model)
		:	ShiftModule(),
			peaks_(model.peaks_),
			origin_(model.origin_),
			dimension_(model.dimension_),
			spacing_(model.spacing_),
			type_(model.type_),
			parameters_(model.parameters_),
			system_(NULL),
			valid_(false),
			compute_shifts_(model.compute_shifts_)
	{
		init_();
	}
	
	ShiftModel1D::~ShiftModel1D()
	{
		clear();
	}
	
			
	void ShiftModel1D::clear()
	{
		// model is invalid
		valid_ = false;

		// clear parameters
		parameters_.clear();
		
		peaks_.clear();
		system_ = NULL;
		
	}

	bool  ShiftModel1D::init_()
	{
		valid_ = true;

		// return the current state
		return valid_;

	}

	void ShiftModel1D::setFilename(const String& filename)
	{
		// set the parameter filename 
		parameters_.setFilename(filename);

		// ...and initialize!
		init_();
	}
	
	bool ShiftModel1D::isValid() const
	{
		return valid_;
	}	
	
	bool ShiftModel1D::start()
	{	
		peaks_.clear();
		return true;
	}
	
	bool ShiftModel1D::finish()
	{

		if (!isValid())
		{
			return false;
		}
	
		if (!system_)
		{
			Log.info() << "No valid system found!" << std::endl;
			return false;
		}
		
		// compute the shift model if necessary
		if (compute_shifts_)
		{
			BALL::ShiftModel sm(parameters_.getFilename());
			system_->apply(sm);
		}

		String element = "";
		
		// Peter Bayer proposed as peak width  
		// for H      15Hz
		// for N			10hz
		// for C			5Hz

		// peakwidth is meassured in ppm, since
		// experiments were done in Hz, we convert the values 
		// according to the formular
		// 
		// 		offset [Hz] = offset[ppm] * basic frequency
		//
		// for our prediction we assume a basic frequency of 700 MHz
		float peakwidth = 0.0;
		
		switch(type_)
		{
			case H:
			case H_ON_BACKBONE:
				element = "H";
				//peakwidth = 0.02142; // Peter Bayers estimation
				peakwidth = 0.0032; // this is the former BALL estimation
				break;
			case N:
			case N_BACKBONE:
				element = "N";
				peakwidth = 0.01428;
				break;
			case C:
			case C_BACKBONE:  
				element = "C";
				peakwidth = 0.00714;
				break;
		}
		int counter = 0;

		if (element == "" )
			return true;
		
		for (BALL::ResidueIterator r_it = system_->beginResidue(); +r_it; ++r_it)
		{	
			Atom* atom = NULL;

			for (BALL::AtomIterator at_it = r_it->beginAtom(); +at_it; ++at_it)
			{
				if (hasType_(&(*at_it), type_))
				{
					counter++;
					atom = &(*at_it);
					// we have, get the shift
					float shift = atom->getProperty(BALL::ShiftModule::PROPERTY__SHIFT).getFloat();
					Peak1D peak;
					
					float pos = shift; 
					peak.setPosition(pos);
				
					peak.setWidth(peakwidth);
					peak.setIntensity(peak.getIntensity()+1);
					//setAtom();
					peaks_.push_back(peak);
				}
			}
		}

		std::cout << "Number of considered atoms: "<< counter << std::endl;
		return true;
	}

	Processor::Result ShiftModel1D::operator () (Composite& composite)
	{

		Processor::Result result = Processor::CONTINUE;

                if (!system_ && RTTI::isKindOf<Atom>(&composite))
		{
			Atom* atom = dynamic_cast<Atom*>(&composite);
                        if  (RTTI::isKindOf<System>(&atom->getRoot()))
			{	
				system_ = dynamic_cast<System*>(&(atom->getRoot()));
			}
		}
		return result;
	}


	void ShiftModel1D::operator >> (Spectrum1D& spectrum)
  {
     // this overwrites the parameter
  	spectrum = Spectrum1D(peaks_, origin_, dimension_, spacing_);

  }

	
	bool ShiftModel1D::hasType_(Atom* a, SPECTRUM_TYPE type)
	{
		bool ret = false;
		switch (type)
		{
			case H:
				if (a->getElement() == PTE[Element::H])
					ret = true;
				 //if (   (a->getName().hasSubstring("HG")) || (a->getName().hasSubstring("HD")) 
					//	|| (a->getName().hasSubstring("HB")) || (a->getName().hasSubstring("HA"))
					//	|| (a->getName().hasSubstring("HE")) || (a->getName().hasSubstring("HH")) 
					//	|| (a->getName().hasSubstring("HZ")))
				 //	ret = true;
				break;
			case C:
				if  (a->getElement() ==  PTE[Element::C])
					ret = true;
			//	if (   (a->getName().hasSubstring("CA")) || (a->getName().hasSubstring("CB")) 
			//			|| (a->getName().hasSubstring("CD")) || (a->getName().hasSubstring("CE")) 
			//			|| (a->getName().hasSubstring("CH")) || (a->getName().hasSubstring("CG")) || (a->getName().hasSubstring("CZ")) )
			////		ret = true;
				break;
			case N:	
				if  (a->getElement() ==  PTE[Element::N])
					ret = true;
 				//if (   (a->getName() == "N") || (a->getName().hasSubstring("ND")) || (a->getName().hasSubstring("NE")) 
				//	 	|| (a->getName().hasSubstring("NH")) || (a->getName().hasSubstring("NZ"))  )
				//	ret = true;
				break;
			case H_ON_BACKBONE: //check, whether the given atom is of type hydrogen and whether it is bound to a backbone C or N
				if (a->getElement() == PTE[Element::H])
				{
					// is it bound to a backbone C or N??
					Atom::BondIterator b_it = a->beginBond();
					for (; !ret && +b_it; ++b_it)
					{	
						if (    b_it->getType()!=(Bond::TYPE__HYDROGEN) 
								&& (b_it->getPartner(*a)->getName()=="N" || b_it->getPartner(*a)->getName()=="CA" || b_it->getPartner(*a)->getName()=="C"))
						{
							ret = true;
						}
					}
				}
				break;
			case C_BACKBONE:
				if  (a->getName() == "CA" || a->getName() == "C" )
					ret = true;
				break;
			case N_BACKBONE:
				if (a->getName() == "N")
						ret = true;
				break;
		}
		
		return ret;
	}


	
}