File: DockResultFile_test.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (190 lines) | stat: -rw-r--r-- 4,457 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
#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>

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

#include <BALL/FORMAT/dockResultFile.h>
#include <BALL/DOCKING/COMMON/flexibleMolecule.h>
#include <BALL/DOCKING/COMMON/conformation.h>
#include <BALL/DOCKING/COMMON/result.h>
#include <BALL/FORMAT/SDFile.h>
#include <BALL/KERNEL/forEach.h>
#include <BALL/KERNEL/bondIterator.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/KERNEL/atom.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/KERNEL/system.h>
#include <BALL/KERNEL/molecule.h>
#include <BALL/MATHS/vector3.h>
#include <BALL/STRUCTURE/defaultProcessors.h>
#include <BALL/STRUCTURE/geometricTransformations.h>

#include <iostream>
///////////////////////////

using namespace BALL;
using namespace std;
using BALL::DockResultFile;
using BALL::Ligand;
using BALL::Result;
using BALL::Conformation;

bool compareMolecules(Molecule& mol1, Molecule& mol2)
{
	if(mol1.countAtoms()!=mol2.countAtoms())
		return false;
	if(mol1.countBonds()!=mol2.countBonds())
		return false;

	AtomIterator ai;
	vector<Vector3> pos1;
	vector<float> q1;
	BALL_FOREACH_ATOM(mol1, ai)
	{
		pos1.push_back(ai->getPosition());
		q1.push_back(ai->getCharge());
	}

	vector<Vector3> pos2;
	vector<float> q2;
	BALL_FOREACH_ATOM(mol2, ai)
	{
		pos2.push_back(ai->getPosition());
		q2.push_back(ai->getCharge());
	}

	for(unsigned int i=0;i<pos1.size();i++)
	{
		if( fabs(pos1[i].x-pos2[i].x)>1e-8 )
			return false;
		if( fabs(pos1[i].y-pos2[i].y)>1e-8 )
			return false;
		if( fabs(pos1[i].z-pos2[i].z)>1e-8 )
			return false;
		if( fabs(q1[i]-q2[i])>1e-8 )
			return false;
	}



	AtomBondIterator bi;

	vector<String> pairs1;
	BALL_FOREACH_BOND(mol1, ai, bi)
    {
	Bond* bnd = &(*bi);
	const Atom* at1 = bnd->getFirstAtom();
	const Atom* at2 = bnd->getSecondAtom();
	String pair = at1->getElement().getSymbol()+"-"+String(bnd->getOrder())+"-"+at2->getElement().getSymbol();
		pairs1.push_back(pair);
    }

	vector<String> pairs2;
	BALL_FOREACH_BOND(mol2, ai, bi)
    {
	Bond* bnd = &(*bi);
	const Atom* at1 = bnd->getFirstAtom();
	const Atom* at2 = bnd->getSecondAtom();
	String pair = at1->getElement().getSymbol()+"-"+String(bnd->getOrder())+"-"+at2->getElement().getSymbol();
		pairs2.push_back(pair);
    }

	if(pairs1.size()!=pairs2.size())
		return false;
	for(unsigned int i=0;i<pairs1.size();i++)
		if(pairs1[i]!=pairs2[i])
			return false;

	return true;
}


START_TEST(DockResultFile)

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


CHECK(read/write DockResultFile)



        SDFile f(BALL_TEST_DATA_PATH(QSAR_test.sdf));
		Molecule* mol;
		String tmpfile;
		File::createTemporaryFilename(tmpfile);
		DockResultFile df(tmpfile,File::MODE_OUT);
		vector<Molecule*> mols;
		int id=0;
		while((mol = f.read()) != NULL)
		{
			// skip this molecule because its
			// conformation is contained twice
			// in this set
			if(mol->getName()=="THIOL_4")
				continue;
			mol->setProperty("ID",String(id));
			df.write(*mol);
			mols.push_back(mol);
			id++;
		}
		df.close();



		// now iterate molecule-by-molecule over the file
		DockResultFile dfin(tmpfile,File::MODE_IN);
		Molecule* mol2;
		unsigned int i=0;
		while( (mol2 = dfin.read()) )
		{
			bool cmp = compareMolecules(*mols[i],*mol2);
			TEST_EQUAL(cmp,true)
			TEST_EQUAL(mol2->getProperty("ID").getString(),mols[i]->getProperty("ID").getString())
			delete mol2;
			i++;
		}
		dfin.close();



		DockResultFile dfin2(tmpfile,File::MODE_IN);
		Ligand* lig = dfin2.readLigand();
		TEST_EQUAL(lig->hasConformation("f5fdd18549299b09eedbe0131fb46fbc02b10efb"),true)
		TEST_EQUAL(lig->getConformationId(0),"f5fdd18549299b09eedbe0131fb46fbc02b10efb")
		TEST_EQUAL(lig->getNumberOfConformations(),1)
		delete lig;
		dfin2.close();



		// now iterate ligand-by-ligand over the file
		DockResultFile dfin3(tmpfile,File::MODE_IN);
		i=0;
		while( (lig=dfin3.readLigand()) )
		{
			Molecule* mol = lig->getConformer(0);
			bool cmp = compareMolecules(*mols[i],*mol);
			TEST_EQUAL(cmp,true)

			// there is no second conformer so returned
			// pointer should be NULL
			TEST_EQUAL(lig->getConformer(1),0)
			delete mol;
			delete lig;
			i++;
		}
		dfin3.close();


		File::remove(tmpfile);
		for(unsigned int i=0;i<mols.size();i++)
			delete mols[i];

RESULT



/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST