File: PocketDetector.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 (232 lines) | stat: -rwxr-xr-x 7,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
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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/STRUCTURE/bindingPocketProcessor.h>
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/FORMAT/molFileFactory.h>
#include <BALL/FORMAT/commandlineParser.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/DOCKING/COMMON/constraints.h>
#include <BALL/DOCKING/COMMON/dockingAlgorithm.h>
#include "version.h"
#include <iostream>

using namespace std;
using namespace BALL;
//using namespace BALL::Docking;

void createReferenceArea(const vector<vector<std::pair<Vector3, double> > >& layers, const Vector3& ref_center, ReferenceArea*& ref_area, String filename, Molecule* ligand)
{
	Molecule mol;

	multimap<double, Vector3> dist_to_position;

	for (Size i = 0; i < layers.size(); i++)
	{
		for (Size j = 0; j < layers[i].size(); j++)
		{
			double dist = layers[i][j].first.getDistance(ref_center);
			if (dist < 12)
			{
				dist_to_position.insert(make_pair(dist, layers[i][j].first));
			}
		}
	}

	if (dist_to_position.empty())
	{
		Log.error() << "[Error:] No surface points in the neighborhood of the reference ligand found. Please check the location of your reference ligand!" << endl;
		exit(1);
	}

	Vector3 origin = ref_center - Vector3(10, 10, 10);
	HashGrid3<Vector3> grid(origin, 20, 20, 20, 2);

	// add pocket-point that is nearest to the geometrical center of the reference ligand to the grid
	multimap<double, Vector3>::iterator it = dist_to_position.begin();
	grid.insert(it->second, it->second);
	it++;

	for (; it != dist_to_position.end(); it++)
	{
		HashGridBox3<Vector3>* current_box = grid.getBox(it->second);
		Position x, y, z;
		grid.getIndices(*current_box, x, y, z);
		if (x > 1) x--;
		if (y > 1) y--;
		if (z > 1) z--;

		// search pocket-points near the current one
		bool found_nearby_point = 0;
		for (Size i = x; i < x+3 && i < 20; i++)
		{
			for (Size j = y; j < y+3 && j < 20; j++)
			{
				for (Size k = z; k < z+3 && k < 20; k++)
				{
					const HashGridBox3<Vector3>* box = grid.getBox(i, j, k);

					for (HashGridBox3 < Vector3 > ::ConstDataIterator b_it = box->beginData();
						+b_it; b_it++)
					{
						if (it->second.getDistance(*b_it) < 1.5)
						{
							found_nearby_point = true;
							break;
						}
					}
				}
			}
		}

		if (found_nearby_point)
		{
			current_box->insert(it->second);
			if (filename != "")
			{
				Atom* atom = new Atom;
				atom->setElement(PTE_::getElement(Element::CARBON));
				atom->setPosition(it->second);
				mol.insert(*atom);
			}
		}
	}

	if (filename != "")
	{
		GenericMolFile* output = MolFileFactory::open(filename, ios::out, "mol2");
		*output << mol;
		delete output;
	}

	// find min and max
	double min_x = 9999; double max_x = -9999;
	double min_y = 9999; double max_y = -9999;
	double min_z = 9999; double max_z = -9999;
	for (HashGrid3 < Vector3 > ::BoxIterator it = grid.beginBox(); it != grid.endBox(); it++)
	{
		for (HashGridBox3<Vector3>::ConstDataIterator b_it = it->beginData();
		+b_it; b_it++)
		{
			const Vector3& p = *b_it;
			if (p[0] < min_x) min_x = p[0];
			if (p[0] > max_x) max_x = p[0];
			if (p[1] < min_y) min_y = p[1];
			if (p[1] > max_y) max_y = p[1];
			if (p[2] < min_z) min_z = p[2];
			if (p[2] > max_z) max_z = p[2];
		}
	}

	// check size of detected pocket
	double volume = (max_x-min_x)*(max_y-min_y)*(max_z-min_z);
	if (volume < 100)
	{
		Log.level(20)<<"Detected pocket is very small ( < 100A^3) and therefore rejected."<<endl;
		ref_area = 0;
		return;
	}

	Vector3 p1(min_x, min_y, min_z);
	Vector3 p2(max_x, min_y, min_z);
	Vector3 p3(max_x, max_y, min_z);
	Vector3 p4(max_x, max_y, max_z);
	ref_area = new ReferenceArea(p1, p2, p3, p4, true, 0.5, 1e11);

	ref_area->calculateScore(ligand);
	double fraction = ref_area->getContainedAtoms();
	Log.level(10)<<"Fraction of atoms of reference ligand located in detected binding pocket: "<<fraction<<endl;

	ref_area->setNumberDesiredAtoms(fraction);
	ref_area->setName("Pocket found by PocketDetector");
}


int main (int argc, char **argv)
{
	CommandlineParser parpars("PocketDetector", "detect binding pocket", VERSION, String(__DATE__), "Docking");
	parpars.registerMandatoryInputFile("rec", "receptor pdb-file");
	parpars.registerMandatoryInputFile("rl", "reference ligand");
	parpars.registerMandatoryOutputFile("o", "output file");
	parpars.registerOptionalInputFile(DockingAlgorithm::OPTION_FILE_PARAMETER_NAME, "input ini file");
	parpars.registerOptionalOutputFile("mol_out", "output file for pseudo-atoms describing pocket (for visualization purposes)");

	String man = "This tool tries to detect the binding pocket in which the reference ligand is located.\nTherefore, probe atoms are placed above the protein surface at positions of relative deep burial. The cluster of probe atoms around the geometric center of the reference ligand is used for the description of the binding pocket.\n\nAs input we need:\n\
    * a file containing a protonated protein in pdb-format. Furthermore, it should contain only relevant (i.e. strongly bound) water molecules as detected by WaterFinder.\n\
    * a file containing a reference ligand.\n\
      This reference ligand should be located in the binding pocket.\n\
      Supported formats are mol2, sdf or drf (DockResultFile, xml-based).\n\nOutput of this tool is a docking configuration file that contains the description of the detected binding pocket. This file should in following pipeline steps be specified for docking and rescoring.";

	parpars.setToolManual(man);
	parpars.setSupportedFormats("rec","pdb");
	parpars.setSupportedFormats("rl",MolFileFactory::getSupportedFormats());
	parpars.setSupportedFormats(DockingAlgorithm::OPTION_FILE_PARAMETER_NAME,"ini");
	parpars.setSupportedFormats("o","ini");
	parpars.setSupportedFormats("mol_out",MolFileFactory::getSupportedFormats());
	parpars.parse(argc, argv);

	PDBFile input(parpars.get("rec"));
	Protein p;
	input >> p;

	GenericMolFile* input2 = MolFileFactory::open(parpars.get("rl"));
	Molecule* ligand = input2->read();
	delete input2;
	Vector3 lig_center(0, 0, 0);
	Size no_atoms = 0;
	for (AtomConstIterator it = ligand->beginAtom(); +it; ++it, no_atoms++)
	{
		lig_center += it->getPosition();
	}
	lig_center /= no_atoms;

	BindingPocketProcessor bpp;
	p.apply(bpp);

	Molecule mol;

	const vector<vector<std::pair<Vector3, double> > >& layers = bpp.getLayers();

/*
	cout<<"number of layers = "<<layers.size()<<endl;
	for (Size i = 0; i < layers.size(); i++)
	{
		for (Size j = 0; j < layers[i].size(); j++)
		{
			double dist = layers[i][j].first.getDistance(lig_center);
			if (dist < 12)
			{
				Atom* atom = new Atom;
				atom->setElement(PTE_::getElement(i));
				atom->setPosition(layers[i][j].first);
				mol.insert(*atom);
			}
		}
	}

	GenericMolFile* output = MolFileFactory::open("probeatoms.mol2", ios::out);
	*output << mol;
	delete output;
*/


	Options option;
	list<Constraint*> constraints;
	if (parpars.has(DockingAlgorithm::OPTION_FILE_PARAMETER_NAME))
	{
		DockingAlgorithm::readOptionFile(parpars.get(DockingAlgorithm::OPTION_FILE_PARAMETER_NAME), option, constraints, ligand);
	}
	String outmol_filename = "";
	if (parpars.has("mol_out"))
	{
		outmol_filename = parpars.get("mol_out");
	}
	ReferenceArea* ref_area = NULL;
	createReferenceArea(layers, lig_center, ref_area, outmol_filename, ligand);
	if (ref_area) constraints.push_back(ref_area);
	DockingAlgorithm::writeOptionFile(parpars.get("o"), option, constraints);
	if (ref_area) delete ref_area;

	return 0;
}