File size: 14,695 Bytes
8efb4bd | 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 | #include "GeomScore.h"
#include "Logger.h"
RangeParams::RangeParams(const std::vector<int>& wts) {
ranges.push_back(-3.6);
ranges.push_back(-2.2);
ranges.push_back(-1.0);
ranges.push_back(1.0);
weights.insert(weights.begin(), wts.begin(), wts.end());
}
//-------------------------------- GeomScore class -----------------------------
GeomScore::GeomScore(const Surface& lowLevel, MoleculeGrid* grid,
const std::vector<int>& wts, float penetration_thr, float ns_thr, float d, float gridMargins) :
grid_(grid), rangeParams(wts),
penetrationThr_(penetration_thr), divNsThr(1.0/ns_thr),
density(d), tree(lowLevel, density, gridMargins)
{}
GeomScore::GeomScore(const Surface& lowLevel,
const std::vector<int>& wts, float penetration_thr, float ns_thr, float d, float gridMargins) :
grid_(NULL), rangeParams(wts),
penetrationThr_(penetration_thr), divNsThr(1.0/ns_thr),
density(d), tree(lowLevel, density, gridMargins)
{}
GeomScore::GeomScore(MoleculeGrid* grid,
const std::vector<int>& wts, float penetration_thr, float ns_thr, float d, float gridMargins) :
grid_(grid), rangeParams(wts),
penetrationThr_(penetration_thr), divNsThr(1.0/ns_thr),
density(d)
{}
void GeomScore::buildTree() {
tree.buildTree();
}
void GeomScore::buildTree(const std::vector<bool>& as) {
tree.buildTree(as);
// countActiveSitePoints(as);
}
float GeomScore::maxPenetration(const RigidTrans3& trans) {
float maxPenetration=MAX_FLOAT;
Level& highLevel = tree.getLevel(tree.size()-1);
std::stack<const Node *> st;
for (unsigned int i=0; i< highLevel.size(); i++)
st.push(&highLevel[i]);
while (!st.empty()) {
const Node *node = st.top();
st.pop();
float dist = grid_->getDist(trans*(node->position()));
if (dist != MAX_FLOAT) {
if (node->getLevel() == 0) {
if (dist < maxPenetration)
maxPenetration = dist;
continue;
}
if (dist - node->getRadius() <= maxPenetration) {
const std::vector<const Node *>& lowLevelPointers = node->getChildren();
for (unsigned int i=0; i<lowLevelPointers.size(); i++)
st.push(lowLevelPointers[i]);
}
}
}
return maxPenetration;
}
bool GeomScore::isPenetrating(const RigidTrans3& trans) {
Level& highLevel = tree.getLevel(tree.size()-1);
std::stack<const Node *> st;
for(unsigned int i=0; i< highLevel.size(); i++) {
float dist = grid_->getDist(trans*(highLevel[i].position()));
if(dist < penetrationThr_) {
return true;
} else {
st.push(&highLevel[i]);
}
}
while(!st.empty()) {
const Node *node = st.top();
st.pop();
float dist = grid_->getDist(trans*(node->position()));
if(dist < penetrationThr_)
return true;
if(node->getLevel() != 0) {
// check if dist - pointRadius is more then thr
if(dist - node->getRadius() <= penetrationThr_) {
const std::vector<const Node *>& lowLevelPointers = node->getChildren();
for(unsigned int i=0; i< lowLevelPointers.size(); i++)
st.push(lowLevelPointers[i]);
}
}
}
return false;
}
bool GeomScore::fastIsPenetrating(const RigidTrans3& trans) {
Level& highLevel = tree.getLevel(tree.size()-1);
std::stack<const Node *> st;
for(unsigned int i=0; i< highLevel.size(); i++) {
float dist = grid_->getDist(trans*(highLevel[i].position()));
if(dist < penetrationThr_) {
return true;
}
}
return false;
}
void GeomScore::getInterface(const RigidTrans3& trans, float low_thr, float high_thr,
std::vector<const SurfacePoint*>& interface) {
Level& highLevel = tree.getLevel(tree.size()-1);
std::stack<const Node *> st;
for (unsigned int i=0; i< highLevel.size(); i++)
st.push(&highLevel[i]);
while (!st.empty()) {
const Node *node = st.top();
st.pop();
float dist = grid_->getDist(trans*(node->position()));
if (dist == MAX_FLOAT) continue;
if (node->getLevel() == 0) {
if (dist > low_thr && dist < high_thr)
interface.push_back(node->getPoint());
continue;
}
if (dist - node->getRadius() > low_thr && dist + node->getRadius() < high_thr) {
node2interface(node, interface);
continue;
}
const std::vector<const Node *>& lowLevelPointers = node->getChildren();
for (unsigned int i=0; i<lowLevelPointers.size(); i++)
st.push(lowLevelPointers[i]);
}
}
void GeomScore::node2interface(const Node* node, std::vector<const SurfacePoint*>& interface) {
std::stack<const Node *> st;
st.push(node);
while (!st.empty()) {
const Node *node = st.top();
st.pop();
if (node->getLevel() == 0) {
interface.push_back(node->getPoint());
continue;
}
const std::vector<const Node *>& lowLevelPointers = node->getChildren();
for (unsigned int i=0; i<lowLevelPointers.size(); i++)
st.push(lowLevelPointers[i]);
}
}
int GeomScore::score(const RigidTrans3& trans) {
std::vector<unsigned int> pointsInRanges(rangeParams.weights.size(),0);
scoreRanges(trans, pointsInRanges);
//calculate total, based on weights
int score=0;
for(unsigned int i=0; i<rangeParams.weights.size(); i++)
score+= (pointsInRanges[i]*rangeParams.weights[i]);
if(score <= 0)
return -1;
if(((float)pointsInRanges[pointsInRanges.size()-2])/score > divNsThr) {
return -1;
}
return score;
}
int GeomScore::score(const RigidTrans3& trans, const Surface& surface, float& penetration) {
std::vector<unsigned int> pointsInRanges(rangeParams.weights.size(),0);
penetration = MAX_FLOAT;
// count number of points
for(unsigned int i=0; i<surface.size(); i++) {
float dist = grid_->getDist(trans * (surface[i].position()));
if(dist < penetrationThr_)
return -1;
if(dist < penetration)
penetration = dist;
unsigned int range = rangeParams.findRange(dist);
pointsInRanges[range]++;
}
//calculate total, based on weights
int score=0;
for(unsigned int i=0; i<rangeParams.weights.size(); i++)
score+= (pointsInRanges[i]*rangeParams.weights[i]);
if(score <= 0)
return -1;
if(((float)pointsInRanges[pointsInRanges.size()-2])/score > divNsThr) {
return -1;
}
return score;
}
int GeomScore::score(const RigidTrans3& trans, float& asRatio, int& asScore) {
std::vector<unsigned int> pointsInRanges(rangeParams.weights.size(),0);
std::vector<unsigned int> asInRanges(rangeParams.weights.size(),0);
scoreRanges(trans, pointsInRanges, asInRanges);
//calculate total, based on weights
int score=0;
int interfaceCount = 0;
int asInterfaceCount = 0;
asScore=0;
for(unsigned int i=0; i<rangeParams.weights.size(); i++) {
score+= (pointsInRanges[i]*rangeParams.weights[i]);
asScore+= (asInRanges[i]*rangeParams.weights[i]);
if(i < rangeParams.weights.size() -1 ) {
interfaceCount+= pointsInRanges[i];
asInterfaceCount+= asInRanges[i];
}
}
if(interfaceCount == 0) {
asRatio = 0;
} else {
asRatio = ((float)asInterfaceCount)/interfaceCount;
}
if(score <= 0)
return -1;
if(((float)pointsInRanges[pointsInRanges.size()-2])/score > divNsThr) {
return -1;
}
return score;
}
void GeomScore::scoreRanges(const RigidTrans3& trans, std::vector<unsigned int>& pointsInRanges) {
Level& highLevel = tree.getLevel(tree.size()-1);
std::stack<const Node *> st;
for (unsigned int i=0; i< highLevel.size(); i++)
st.push(&highLevel[i]);
while (!st.empty()) {
const Node *node = st.top();
st.pop();
float dist = grid_->getDist(trans*(node->position()));
if (dist == MAX_FLOAT) { //add to last range
pointsInRanges[pointsInRanges.size()-1]+=node->getSubtreeSize();
continue;
}
unsigned int range = rangeParams.findRange(dist);
if (node->getLevel() == 0) {
pointsInRanges[range]++;
continue;
}
unsigned int range1 = rangeParams.findRange(dist + node->getRadius());
unsigned int range2 = rangeParams.findRange(dist - node->getRadius());
if (range == range1 && range == range2) {
pointsInRanges[range] += node->getSubtreeSize();
continue;
}
const std::vector<const Node *>& lowLevelPointers = node->getChildren();
for (unsigned int i=0; i<lowLevelPointers.size(); i++)
st.push(lowLevelPointers[i]);
}
}
void GeomScore::scoreRanges(const RigidTrans3& trans, std::vector<unsigned int>& pointsInRanges,
std::vector<unsigned int>& asInRanges) {
Level& highLevel = tree.getLevel(tree.size()-1);
std::stack<const Node *> st;
for (unsigned int i=0; i< highLevel.size(); i++)
st.push(&highLevel[i]);
while (!st.empty()) {
const Node *node = st.top();
st.pop();
Vector3 point = trans*(node->position());
float dist = grid_->getDist(point);
if (dist == MAX_FLOAT) { //add to last range
pointsInRanges[pointsInRanges.size()-1]+=node->getSubtreeSize();
asInRanges[asInRanges.size()-1]+=node->getAsNum();
continue;
}
unsigned int range = rangeParams.findRange(dist);
if (node->getLevel() == 0) {
pointsInRanges[range]++;
asInRanges[range]+=node->getAsNum();
continue;
}
unsigned int range1 = rangeParams.findRange(dist + node->getRadius());
unsigned int range2 = rangeParams.findRange(dist - node->getRadius());
if (range == range1 && range == range2) {
pointsInRanges[range]+=node->getSubtreeSize();
asInRanges[range]+=node->getAsNum();
continue;
}
const std::vector<const Node *>& lowLevelPointers = node->getChildren();
for (unsigned int i=0; i< lowLevelPointers.size(); i++)
st.push(lowLevelPointers[i]);
}
}
ScoreData GeomScore::fullScore(const RigidTrans3& trans, bool as) {
ScoreData scoreData;
std::vector<unsigned int> pointsInRanges(rangeParams.weights.size(),0);
if (as) {
std::vector<unsigned int> asInRanges(rangeParams.weights.size(),0);
scoreRanges(trans, pointsInRanges, asInRanges);
for (unsigned int i=0; i<rangeParams.weights.size()-1; i++) {
scoreData.score+= (pointsInRanges[i] * rangeParams.weights[i]);
scoreData.asScore+= (asInRanges[i] * rangeParams.weights[i]);
scoreData.interfaceArea+= pointsInRanges[i];
}
asInRanges.clear();
} else {
scoreRanges(trans, pointsInRanges);
for (unsigned int i=0; i<rangeParams.weights.size()-1; i++) {
scoreData.score+= (pointsInRanges[i] * rangeParams.weights[i]);
scoreData.interfaceArea+= pointsInRanges[i];
}
}
scoreData.interfaceArea/=density;
scoreData.maxPenetration = maxPenetration(trans);
pointsInRanges.clear();
return scoreData;
}
float GeomScore::computePropensity(const RigidTrans3& trans) {
std::vector<unsigned int> pointsInRanges(rangeParams.weights.size(),0);
std::vector<unsigned int> asInRanges(rangeParams.weights.size(),0);
scoreRanges(trans, pointsInRanges, asInRanges);
//calculate total, based on weights
int score=0;
int asScore=0;
for (unsigned int i=0; i<rangeParams.weights.size()-1; i++) {
score+= pointsInRanges[i];
asScore+= asInRanges[i];
}
float prop = ((float)asScore/score)/((float)tree.getAsPointsNumber()/tree.getLevel(0).size());
return prop;
}
int GeomScore::refineTrans(const RigidTrans3& trans, RigidTrans3& newTrans) {
/*
float Tmag = 0.1;
float Rmag = 0.05;
// compute ligand interface points
std::vector<const SurfacePoint*> interface;
getInterface(trans, -2.0, 1.5, interface); //add thr - which??
Logger::debugMessage() << "interface size: " << interface.size() << " trans " << trans << endl;
std::vector<Vector3> interfacePoints(interface.size());
std::vector<Vector3> virtualPoints(interface.size());
MyMatch matchList;
Vector3 centerOfRotation;
for (unsigned int i=0; i<interface.size(); i++) {
interfacePoints[i] = interface[i]->position();
centerOfRotation += interfacePoints[i];
matchList.add(i,i);
}
centerOfRotation /= interface.size();
RigidTrans3 bestTrans;
RigidTrans3 currTrans = trans;
int currScore=1000000;
int oldScore = score(trans);
MMonteCarlo::init(oldScore);
newTrans = trans;
int nums = 0;
while (nums < 1000) {
currTrans = newTrans;
nums++;
//Logger::debugMessage() << "oldScore: " << oldScore;
for (unsigned int i=0; i<interface.size(); i++) {
Vector3 point = newTrans * interfacePoints[i];
float dist = grid_->getDist(point);
virtualPoints[i] = point + dist*(interface[i]->normal());
if (dist == 0.00)
matchList.setScore(i,10.0);
else
matchList.setScore(i,1/fabs(dist));
}
matchList.calculateBestFit(virtualPoints, interfacePoints);
newTrans = matchList.rigidTrans();
//oldScore = currScore;
currScore = score(newTrans);
MMonteCarlo::MMC_acceptance mmc_accept = MMonteCarlo::step(currScore);
if (mmc_accept == MMonteCarlo::ACCEPT_LOWEST) {
bestTrans = newTrans;
}
if (mmc_accept == MMonteCarlo::REJECT) {
float delta_TR[6] = {0.0};
delta_TR[0] = MMonteCarlo::getGaussianRandomNumber() * Tmag;
delta_TR[1] = MMonteCarlo::getGaussianRandomNumber() * Tmag;
delta_TR[2] = MMonteCarlo::getGaussianRandomNumber() * Tmag;
delta_TR[3] = MMonteCarlo::getGaussianRandomNumber() * Rmag;
delta_TR[4] = MMonteCarlo::getGaussianRandomNumber() * Rmag;
delta_TR[5] = MMonteCarlo::getGaussianRandomNumber() * Rmag;
Vector3 rotVec(delta_TR[3],delta_TR[4],delta_TR[5]);
Vector3 transVec(delta_TR[0],delta_TR[1],delta_TR[2]);
RigidTrans3 delta_rt3(rotVec,transVec);
const Matrix3 &delta_mat3 = delta_rt3.rotation();
RigidTrans3 delta_rt3_COR(delta_mat3,centerOfRotation-delta_mat3*centerOfRotation+delta_rt3.translation());
newTrans = delta_rt3_COR*currTrans;
}
//Logger::debugMessage() << " RMSD: " << matchList.rmsd() << " newTrans " << newTrans << " newScore " << currScore << endl;
}
newTrans = bestTrans;
//Logger::debugMessage() << "oldScore: " << oldScore << " newScore " << currScore << endl;
return currScore;*/
return 0;
}
|