File: compute_docking_RMSD.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 (218 lines) | stat: -rwxr-xr-x 6,320 bytes parent folder | download | duplicates (7)
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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/SYSTEM/timer.h>
#include <BALL/KERNEL/protein.h>
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/FORMAT/DCDFile.h>
#include <BALL/STRUCTURE/structureMapper.h>
#include <BALL/MATHS/matrix44.h>
#include <BALL/DOCKING/COMMON/dockResult.h>

#include <iostream>
#include <map>

using namespace std;
using namespace BALL;

int main(int argc, char** argv)
{
	// print usage information
	if (argc < 5)
	{
		Log.error() << "Compute the C_alpha-RMSD values after a rigid docking run." << endl;
		Log.error() << "Usage: " << argv[0] << " reference.pdb docked.pdb dockResult.bdr static_chain_name" << endl;

		return 1;
	}

	map<String, Position> type_map;
	type_map["ALA"] = 0;
	type_map["GLY"] = 1;
	type_map["VAL"] = 2;
	type_map["LEU"] = 3;
	type_map["ILE"] = 4;
	type_map["SER"] = 5;
	type_map["CYS"] = 6;
	type_map["THR"] = 7;
	type_map["MET"] = 8;
	type_map["PHE"] = 9;
	type_map["TYR"] = 10;
	type_map["TRP"] = 11;
	type_map["PRO"] = 12;
	type_map["HIS"] = 13;
	type_map["LYS"] = 14;
	type_map["ARG"] = 15;
	type_map["ASP"] = 16;
	type_map["GLU"] = 17;
	type_map["ASN"] = 18;
	type_map["GLN"] = 19;


	// define two systems and two proteins
	System    reference, docked;
	Protein   static_reference, static_docked;

	// we'll need that one later
	System    docked_backup;

	// and a PDB file to read and write the proteins
	PDBFile   pdb_file;

	// read the proteins
	pdb_file.open(argv[1]);
	Log.info() << "Reading reference " << argv[1] << "... " << flush;
	pdb_file >> reference;
	Log.info() << "Read " << reference.countAtoms() << " atoms." << endl;
	pdb_file.close();

	pdb_file.open(argv[2]);
	Log.info() << "Reading docked " << argv[2] << "... " << flush;
	pdb_file >> docked;
	Log.info() << "Read " << docked.countAtoms() << " atoms." << endl;
	pdb_file.close();

	docked_backup = docked;
	// Find the static chain
	// Remark: insert removes the chain in the original system!
	// that's why we need docked_backup 
	ChainIterator pi = reference.beginChain();
	for (; +pi; ++pi)
	{
		if (pi->getName() == argv[4])
			static_reference.insert(*pi);
	}
	for (pi = docked.beginChain(); +pi; ++pi)
	{
		if (pi->getName() == argv[4])
			static_docked.insert(*pi);
	}

	// map the two static chains
	Matrix4x4       T;
	StructureMapper mapper;
	Size            no_ca;
	double					rmsd;

	Log.info() << "Mapping static chain of " << argv[1] << " onto static chain of " << argv[2] << endl;
	Log.info() << " (this may take a while)..." << endl;

	Timer t;
	t.start();

	// default values
	double upper = 8.0;
	double lower = 4.0;
	double tolerance = 0.6;

	T = mapper.mapProteins(static_reference, static_docked, type_map, no_ca, rmsd, upper, lower, tolerance);

	t.stop();

	if (no_ca < 1)
	{
		Log.info() << "Sorry - couldn't map (no CA atoms?)" << endl;
		return 1;
	}

	Log.info() << "Mapped " << no_ca << " CA atoms." << endl;
	Log.info() << "RMSD (CA only): " << rmsd << " A" << endl;
	Log.info() << endl << "Transformation: " << endl;
	Log.info() << T;

	Log.info() << "Time to map the proteins: " << t.getClockTime() << "s" << endl;
	Log.info() << "Transforming " << argv[1] << endl;

	/** The static chain is still stored in static_..., while the remainder is stored
	 *  in docked and reference.
	 */
	mapper.setTransformation(T);
	reference.apply(mapper);
	static_reference.apply(mapper);

	Log.info() << "Reading the docking results..." << endl;
	DockResult dr;
	dr.readDockResult(argv[3]);
	const ConformationSet* conformation_set = dr.getConformationSet();
	vector<ConformationSet::Conformation> conformations = conformation_set->getScoring();
	Log.info() << "Done." << endl;

	Log.info() << "Computing RMSD values..." << endl;
	SnapShot snap;
	ofstream out("docking_rmsds.txt");
	// Calculate RMSD for each snapshot
	for (Size i=0; i<conformations.size(); ++i)
	{
		// get the whole docked system (static AND mobile chain), to apply the snapshot
		docked = docked_backup;
		snap = (*conformation_set)[i];
		snap.applySnapShot(docked);

		// split static chain from docked since we want to calculate the RMSD for static and mobile sperately
		for (pi = docked.beginChain(); +pi; ++pi)
		{
			if (pi->getName() == argv[4])
				static_docked.insert(*pi);
		}

		rmsd = 0.;          // RMSD for whole complex
		float rmsd_1 = 0.;  // RMSD for mobile chains
		float rmsd_2 = 0.;  // RMSD for static chains
		int count = 0;
		int count_1 = 0;
		int count_2 = 0;

		// calculate RMSD of CA atoms for mobile chains
		AtomIterator docked_atom=docked.beginAtom(), reference_atom=reference.beginAtom();
		while (+docked_atom && +reference_atom)
		{
			while (+docked_atom && docked_atom->getName() != "CA") docked_atom++;
			while (+reference_atom && reference_atom->getName() != "CA") reference_atom++;

			if (+docked_atom && +reference_atom)
			{
				rmsd += (docked_atom->getPosition() - reference_atom->getPosition()).getSquareLength();
				count++;

				rmsd_1 += (docked_atom->getPosition() - reference_atom->getPosition()).getSquareLength();
				count_1++;

				docked_atom++;
				reference_atom++;
			}
		}

		// calculate RMSD of CA atoms for static chains
		docked_atom=static_docked.beginAtom(), reference_atom=static_reference.beginAtom();
		while (+docked_atom && +reference_atom)
		{
			while (+docked_atom && docked_atom->getName() != "CA") docked_atom++;
			while (+reference_atom && reference_atom->getName() != "CA") reference_atom++;

			if (+docked_atom && +reference_atom)
			{
				rmsd += (docked_atom->getPosition() - reference_atom->getPosition()).getSquareLength();
				count++;

				rmsd_2 += (docked_atom->getPosition() - reference_atom->getPosition()).getSquareLength();
				count_2++;

				docked_atom++;
				reference_atom++;
			}
		}

		Log.info() << "***** Snaphot " << i << " *****" << endl;
		Log.info() << "RMSD is " << sqrt(rmsd / count) << " for " << count << " atoms." << endl;
		Log.info() << "RMSD of static protein " << sqrt(rmsd_2 / count_2) << " for " << count_2 << " atoms." << endl;
		Log.info() << "RMSD of mobile protein " << sqrt(rmsd_1 / count_1) << " for " << count_1 << " atoms." << endl;
		Log.info() << endl;

		// write out score of ith snapshot and calculated RMSD
		out << conformations[i].second << " " << sqrt(rmsd/count) << endl;
	}
	Log.info() << "Done." << endl;
	out.close();
	return 0;
}