File: StructureMapper_test.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 (442 lines) | stat: -rw-r--r-- 12,413 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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>

#include <BALL/STRUCTURE/structureMapper.h>
#include <BALL/KERNEL/atom.h>
#include <BALL/KERNEL/fragment.h>
#include <BALL/KERNEL/system.h>
#include <BALL/MATHS/quaternion.h>
#include <BALL/FORMAT/PDBFile.h>
#include <vector>

START_TEST(StructureMapper)

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;
using std::vector;

StructureMapper*	m;
CHECK(StructureMapper())
	m = new StructureMapper();
	TEST_NOT_EQUAL(m, 0)
RESULT

CHECK(~StructureMapper())
	delete m;
RESULT

Fragment*	frag1 = new Fragment;
Fragment*	frag2 = new Fragment;
Matrix4x4	t;
CHECK(StructureMapper(AtomContainer& A, AtomContainer& B))
	Atom*	atom1 = new Atom;
	Atom*	atom2 = new Atom;
	Atom*	atom3 = new Atom;
	Atom*	atom4 = new Atom;
	Atom*	atom5 = new Atom;
	Atom*	atom6 = new Atom;
	Atom*	atom7 = new Atom;
	Atom*	atom8 = new Atom;
	// create two fragments containing atoms
	frag1->insert(*atom1);
	frag1->insert(*atom2);
	frag1->insert(*atom3);
	frag1->insert(*atom4);
	frag2->insert(*atom5);
	frag2->insert(*atom6);
	frag2->insert(*atom7);
	frag2->insert(*atom8);
	// set coordinates for all atoms
	Vector3	v(0,0,0);
	atom1->setPosition(v);
	v.set(1,1,3);
	atom2->setPosition(v);
	v.set(2,5,3);
	atom3->setPosition(v);
	v.set(2,3,2);
	atom4->setPosition(v);

	Quaternion	q(7,9,12,Constants::PI * 0.6);
	q.normalize();
	t = q.getRotationMatrix(t);

	atom5->setPosition(t * atom1->getPosition());
	atom6->setPosition(t * atom2->getPosition());
	atom7->setPosition(t * atom3->getPosition());
	atom8->setPosition(t * atom4->getPosition());
	atom1->setName("A1");
	atom2->setName("A2");
	atom3->setName("A3");
	atom4->setName("A4");
	atom5->setName("A1");
	atom6->setName("A2");
	atom7->setName("A3");
	atom8->setName("A4");
	m = new StructureMapper(*frag1, *frag2);
	TEST_NOT_EQUAL(m, 0)
RESULT

CHECK(bool mapFragments(const vector<Fragment*>& A, const vector<Fragment*>& B, Matrix4x4* transformation, double upper_bound = 8.0, double lower_bound = 2.5))
	Matrix4x4	map_result;
	vector<Fragment*>	A;
	vector<Fragment*>	B;
	A.push_back(frag1);
	B.push_back(frag2);
	TEST_EQUAL(m->mapFragments(A, B, &map_result), true)
	TEST_REAL_EQUAL(map_result.m11, t.m11)
	TEST_REAL_EQUAL(map_result.m12, t.m12)
	TEST_REAL_EQUAL(map_result.m13, t.m13)
	TEST_REAL_EQUAL(map_result.m14, t.m14)
	TEST_REAL_EQUAL(map_result.m21, t.m21)
	TEST_REAL_EQUAL(map_result.m22, t.m22)
	TEST_REAL_EQUAL(map_result.m23, t.m23)
	TEST_REAL_EQUAL(map_result.m24, t.m24)
	TEST_REAL_EQUAL(map_result.m31, t.m31)
	TEST_REAL_EQUAL(map_result.m32, t.m32)
	TEST_REAL_EQUAL(map_result.m33, t.m33)
	TEST_REAL_EQUAL(map_result.m34, t.m34)
	TEST_REAL_EQUAL(map_result.m41, t.m41)
	TEST_REAL_EQUAL(map_result.m42, t.m42)
	TEST_REAL_EQUAL(map_result.m43, t.m43)
	TEST_REAL_EQUAL(map_result.m44, t.m44)
RESULT

CHECK(static Matrix4x4 matchPoints(const Vector3& w1, const Vector3& w2, const Vector3& w3, const Vector3& v1, const Vector3& v2, const Vector3& v3))
	PRECISION(1e-5)
	Vector3 v1(2.0, 2.0, 2.0);
	Vector3 v2(3.0, 2.0, 2.0);
	Vector3 v3(2.0, 3.0, 2.0);

	Vector3 w1(1.0, 1.0, 1.0);
	Vector3 w2(2.0, 1.0, 1.0);
	Vector3 w3(1.0, 2.0, 1.0);

	Matrix4x4 T = StructureMapper::matchPoints(w1, w2, w3, v1, v2, v3);
	STATUS("transformation:\n" << T)
	TEST_REAL_EQUAL(T.m11, 1.0)
	TEST_REAL_EQUAL(T.m12, 0.0)
	TEST_REAL_EQUAL(T.m13, 0.0)
	TEST_REAL_EQUAL(T.m14, 1.0)
	TEST_REAL_EQUAL(T.m21, 0.0)
	TEST_REAL_EQUAL(T.m22, 1.0)
	TEST_REAL_EQUAL(T.m23, 0.0)
	TEST_REAL_EQUAL(T.m24, 1.0)
	TEST_REAL_EQUAL(T.m31, 0.0)
	TEST_REAL_EQUAL(T.m32, 0.0)
	TEST_REAL_EQUAL(T.m33, 1.0)
	TEST_REAL_EQUAL(T.m34, 1.0)
	TEST_REAL_EQUAL(T.m41, 0.0)
	TEST_REAL_EQUAL(T.m42, 0.0)
	TEST_REAL_EQUAL(T.m43, 0.0)
	TEST_REAL_EQUAL(T.m44, 1.0)

	TEST_REAL_EQUAL((T * w1 - v1).getSquareLength(), 0.0)
	TEST_REAL_EQUAL((T * w2 - v2).getSquareLength(), 0.0)
	TEST_REAL_EQUAL((T * w3 - v3).getSquareLength(), 0.0)

	w1.set(5.0, 0.0, 0.0);
	w2.set(5.0, 1.0, 0.0);
	w3.set(5.0, 2.0, 1.0);
	
	T = StructureMapper::matchPoints(w1, w2, w3, v1, v2, v3);
	STATUS("transformation:\n" << T)
	TEST_REAL_EQUAL(T.m11, 0.0)
	TEST_REAL_EQUAL(T.m12, 1.0)
	TEST_REAL_EQUAL(T.m13, 0.0)
	TEST_REAL_EQUAL(T.m14, 2.0)
	TEST_REAL_EQUAL(T.m21, 0.0)
	TEST_REAL_EQUAL(T.m22, 0.0)
	TEST_REAL_EQUAL(T.m23, 1.0)
	TEST_REAL_EQUAL(T.m24, 2.0)
	TEST_REAL_EQUAL(T.m31, 1.0)
	TEST_REAL_EQUAL(T.m32, 0.0)
	TEST_REAL_EQUAL(T.m33, 0.0)
	TEST_REAL_EQUAL(T.m34, -3.0)
	TEST_REAL_EQUAL(T.m41, 0.0)
	TEST_REAL_EQUAL(T.m42, 0.0)
	TEST_REAL_EQUAL(T.m43, 0.0)
	TEST_REAL_EQUAL(T.m44, 1.0)

	TEST_REAL_EQUAL((T * w1 - v1).getSquareLength(), 0.0)
	TEST_REAL_EQUAL((T * w2 - v2).getSquareLength(), 0.0)
	TEST_REAL_EQUAL((T * w3 - v3).getSquareLength(), 4.0)

	// test co-linear case
	w1.set(5.0, 0.0, 0.0);
	w2.set(5.0, 1.0, 0.0);
	w3.set(5.0, 2.0, 0.0);
	
	T = StructureMapper::matchPoints(w1, w2, w3, v1, v2, v3);
	STATUS("transformation:\n" << T)
	TEST_REAL_EQUAL(T.m14, 2.0)
	TEST_REAL_EQUAL(T.m24, -3.0)
	TEST_REAL_EQUAL(T.m34, 2.0)
	TEST_REAL_EQUAL(T.m44, 1.0)

	TEST_REAL_EQUAL((T * w1 - v1).getSquareLength(), 0.0)
	TEST_REAL_EQUAL((T * w2 - v2).getSquareLength(), 0.0)

	// Test some weird pathological case found in 1BNA
	// when using ReconstructFragmentProcessor
	v1.set(17.221, 25.499, 18.629);
	v2.set(18.217, 24.603, 18.897);
	v3.set(19.526, 24.945, 18.571);
	w1.set(22.167, 23.241, 33.694);
	w2.set(21.100, 23.907, 33.243);
	w3.set(20.022, 24.211, 34.147);
	T = StructureMapper::matchPoints(w1, w2, w3, v1, v2, v3);
	STATUS(T)
	TEST_EQUAL(Maths::isNan(T(0,0)), false)
	TEST_EQUAL(Maths::isNan(T(1,0)), false)
	TEST_EQUAL(Maths::isNan(T(2,0)), false)
	TEST_EQUAL(Maths::isNan(T(0,1)), false)
	TEST_EQUAL(Maths::isNan(T(1,1)), false)
	TEST_EQUAL(Maths::isNan(T(2,1)), false)
	TEST_EQUAL(Maths::isNan(T(0,2)), false)
	TEST_EQUAL(Maths::isNan(T(1,2)), false)
	TEST_EQUAL(Maths::isNan(T(2,2)), false)
	TEST_REAL_EQUAL(T(3,3), 1.0)
RESULT

CHECK(double calculateRMSD())
	Fragment f1,f2;
	Atom a1,a2,b1,b2;
	a1.setName("a1");
	a2.setName("a2");
	b1.setName("b1");
	b2.setName("b2");
	a1.setPosition(Vector3(1,0,0));
	b1.setPosition(Vector3(0,-1,0));
	f1.insert(a1);
	f1.insert(b1);
	f2.insert(a2);
	f2.insert(b2);
	StructureMapper m(f1,f2);
	TEST_REAL_EQUAL(m.calculateRMSD(), 1.0)
RESULT

CHECK((Matrix4x4 mapProteins(Protein& P1, Protein& P2, map<String, Size>& type_map, Size& no_matched_ca, double& rmsd, double upper_bound = 8.0, double lower_bound = 4.0, double tolerance = 0.6)))
  // ???
RESULT

CHECK((Size mapResiduesByBackbone(const list<Residue*>& l1, const list<Residue*>& l2)))
  // ???
RESULT

CHECK((StructureMapper::AtomBijection calculateFragmentBijection(const vector<Fragment*>& A, const vector<Fragment*>& B)))
  // ???
RESULT

CHECK(bool calculateTransformation())
  // ???
RESULT

CHECK((static Matrix4x4 matchBackboneAtoms(const Residue& r1, const Residue& r2)))
  // ???
RESULT

CHECK((vector<vector<Fragment*>& searchPattern(vector<Fragment*>& pattern, AtomContainer& composite, double max_rmsd = 4.0, double max_center_tolerance = 2.0, double upper_bound = 8.0, double lower_bound = 4.0)))
  // ???
RESULT

CHECK(const AtomBijection& getBijection() const)
	// not much to be tested here...
	StructureMapper sm;
	TEST_EQUAL(sm.getBijection().size(), 0)
RESULT

CHECK(void calculateDefaultBijection())
	{
		AtomContainer ac1;
		Residue* r1 = new Residue;
		Residue* r2 = new Residue;
		ac1.insert(*r1);
		ac1.insert(*r2);
		r1->setName("RES1");
		r2->setName("RES2");
		PDBAtom* a1 = new PDBAtom;
		PDBAtom* a2 = new PDBAtom;
		PDBAtom* a3 = new PDBAtom;
		PDBAtom* a4 = new PDBAtom;
		a1->setName("A1");
		a2->setName("A2");
		a3->setName("A3");
		a4->setName("A4");
		r1->insert(*a1);
		r1->insert(*a2);
		r2->insert(*a3);
		r2->insert(*a4);

		AtomContainer ac2;
		Residue* r3 = new Residue;
		Residue* r4 = new Residue;
		ac2.insert(*r3);
		ac2.insert(*r4);
		r3->setName("RES1");
		r4->setName("RES2");
		PDBAtom* a5 = new PDBAtom;
		PDBAtom* a6 = new PDBAtom;
		PDBAtom* a7 = new PDBAtom;
		PDBAtom* a8 = new PDBAtom;
		a5->setName("A4");
		a6->setName("A3");
		a7->setName("A2");
		a8->setName("A1");
		r4->insert(*a6);
		r4->insert(*a5);
		r3->insert(*a8);
		r3->insert(*a7);

		StructureMapper sm(ac1, ac2);
		sm.calculateDefaultBijection();
		TEST_EQUAL(sm.getBijection().size(), 4)
		ABORT_IF(sm.getBijection().size() != 4)

		const AtomBijection& b = sm.getBijection();
		TEST_EQUAL(b[0].first->getFullName(), b[0].second->getFullName())
		TEST_NOT_EQUAL(b[0].first, b[0].second)
		TEST_EQUAL(b[1].first->getFullName(), b[1].second->getFullName())
		TEST_NOT_EQUAL(b[1].first, b[1].second)
		TEST_EQUAL(b[2].first->getFullName(), b[2].second->getFullName())
		TEST_NOT_EQUAL(b[2].first, b[2].second)
		TEST_EQUAL(b[3].first->getFullName(), b[3].second->getFullName())
		TEST_NOT_EQUAL(b[3].first, b[3].second)
	}

	{
		AtomContainer ac1;
		Residue* r1 = new Residue;
		Residue* r2 = new Residue;
		ac1.insert(*r1);
		ac1.insert(*r2);
		r1->setName("RES1");
		r2->setName("RES2");
		PDBAtom* a1 = new PDBAtom;
		PDBAtom* a2 = new PDBAtom;
		PDBAtom* a3 = new PDBAtom;
		PDBAtom* a4 = new PDBAtom;
		a1->setName("A1");
		a2->setName("A2");
		a3->setName("A3");
		a4->setName("A4");
		r1->insert(*a1);
		r1->insert(*a2);
		r2->insert(*a3);
		r2->insert(*a4);

		AtomContainer ac2;
		Residue* r3 = new Residue;
		Residue* r4 = new Residue;
		ac2.insert(*r3);
		ac2.insert(*r4);
		r4->setName("RES1");
		r3->setName("RES2");
		PDBAtom* a5 = new PDBAtom;
		PDBAtom* a6 = new PDBAtom;
		PDBAtom* a7 = new PDBAtom;
		PDBAtom* a8 = new PDBAtom;
		a5->setName("A4");
		a6->setName("A3");
		a7->setName("A2");
		a8->setName("A1");
		r4->insert(*a6);
		r4->insert(*a5);
		r3->insert(*a8);
		r3->insert(*a7);

		StructureMapper sm(ac1, ac2);
		sm.calculateDefaultBijection();
		TEST_EQUAL(sm.getBijection().size(), 4)
		ABORT_IF(sm.getBijection().size() != 4)

		const AtomBijection& b = sm.getBijection();
		TEST_EQUAL(b[0].first->getName(), b[0].second->getName())
		TEST_NOT_EQUAL(b[0].first->getFullName(), b[0].second->getFullName())
		TEST_NOT_EQUAL(b[0].first, b[0].second)
		TEST_EQUAL(b[1].first->getName(), b[1].second->getName())
		TEST_NOT_EQUAL(b[1].first->getFullName(), b[1].second->getFullName())
		TEST_NOT_EQUAL(b[1].first, b[1].second)
		TEST_EQUAL(b[2].first->getName(), b[2].second->getName())
		TEST_NOT_EQUAL(b[2].first->getFullName(), b[2].second->getFullName())
		TEST_NOT_EQUAL(b[2].first, b[2].second)
		TEST_EQUAL(b[3].first->getName(), b[3].second->getName())
		TEST_NOT_EQUAL(b[3].first->getFullName(), b[3].second->getFullName())
		TEST_NOT_EQUAL(b[3].first, b[3].second)
	}

	// test for unnamed atoms -- they should be mapped by order only.
	{
		Molecule m1;
		Atom* a1 = new Atom;
		Atom* a2 = new Atom;
		Atom* a3 = new Atom;
		Atom* a4 = new Atom;
		a1->setName("A1");
		a2->setName("A2");
		a3->setName("A3");
		a4->setName("A4");
		m1.insert(*a1);
		m1.insert(*a2);
		m1.insert(*a3);
		m1.insert(*a4);

		Molecule m2;
		Atom* a5 = new Atom;
		Atom* a6 = new Atom;
		Atom* a7 = new Atom;
		Atom* a8 = new Atom;
		a5->setName("B1");
		a6->setName("B2");
		a7->setName("B3");
		a8->setName("B4");
		m2.insert(*a8);
		m2.insert(*a7);
		m2.insert(*a6);
		m2.insert(*a5);

		StructureMapper sm(m1, m2);
		sm.calculateDefaultBijection();
		TEST_EQUAL(sm.getBijection().size(), 4)
		ABORT_IF(sm.getBijection().size() != 4)

		const AtomBijection& b = sm.getBijection();
		TEST_EQUAL(b[0].first->getName(), "A1")
		TEST_EQUAL(b[0].second->getName(), "B4")
		TEST_EQUAL(b[1].first->getName(), "A2")
		TEST_EQUAL(b[1].second->getName(), "B3")
		TEST_EQUAL(b[2].first->getName(), "A3")
		TEST_EQUAL(b[2].second->getName(), "B2")
		TEST_EQUAL(b[3].first->getName(), "A4")
		TEST_EQUAL(b[3].second->getName(), "B1")
	}

RESULT

CHECK((void set(AtomContainer& A, AtomContainer& B)))
  // ???
RESULT

CHECK(RSMD for two bptis)
	System s1, s2;
	PDBFile pf(BALL_TEST_DATA_PATH(StructureMapper_test.pdb));
	pf >> s1;
	pf >> s2;
	StructureMapper sm(s1, s2);	
	STATUS("Number of atoms in s1: " << s1.countAtoms())
	STATUS("Number of atoms in s2: " << s2.countAtoms())
	TEST_REAL_EQUAL(sm.calculateRMSD(), 0.0)
RESULT
delete frag1;
delete frag2;
delete m;

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

END_TEST