| #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::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);
|
|
|
| }
|
|
|
| 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) {
|
|
|
| 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);
|
|
|
| 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;
|
|
|
| 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]++;
|
| }
|
|
|
|
|
| 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);
|
|
|
| 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) {
|
| 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) {
|
| 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);
|
|
|
| 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) {
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| return 0;
|
| }
|
|
|