From 926a99e5cfe1179e71b17c5d53efd93ba6d33334 Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Tue, 8 Mar 2011 11:32:55 +0100
Subject: [PATCH] fix for BZDNG-219 (bracketed-within query ignores not)

---
 modules/mol/base/src/impl/query_impl.cc | 7 +++++--
 modules/mol/base/src/query_state.cc     | 2 +-
 modules/mol/base/tests/test_query.cc    | 9 ++++++---
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/modules/mol/base/src/impl/query_impl.cc b/modules/mol/base/src/impl/query_impl.cc
index 463daac1c..a7935dae1 100644
--- a/modules/mol/base/src/impl/query_impl.cc
+++ b/modules/mol/base/src/impl/query_impl.cc
@@ -1037,7 +1037,7 @@ Node* QueryImpl::ParseWithinExpr(QueryLexer& lexer) {
       geom::Vec3 point;
       if (this->ParsePoint(lexer, point)) {
         ParamType pt(WithinParam(point, rv*rv));
-        CompOP comp_op= COP_LE;
+        CompOP comp_op=COP_LE;
         if (inversion_stack_.back())
           comp_op=COP_GE;
         SelNode* within_node=new SelNode(Prop(Prop::WITHIN, Prop::VEC_DIST,
@@ -1077,8 +1077,11 @@ Node* QueryImpl::ParseWithinExpr(QueryLexer& lexer) {
     ParamType pt(WithinParam(bracketed_expr_.size()-1, rv*rv));    
     inversion_stack_.pop_back();    
     CompOP comp_op= COP_LE;
-    if (inversion_stack_.back())
+    if (inversion_stack_.back()) {
+      std::cout << "INV" << std::endl;
       comp_op=COP_GE;
+    }
+      
     SelNode* within_node=new SelNode(Prop(Prop::WITHIN, Prop::VEC_DIST,
                                           Prop::ATOM), 
                                      comp_op, pt);
diff --git a/modules/mol/base/src/query_state.cc b/modules/mol/base/src/query_state.cc
index 2f04aeecc..ad6ab0f12 100644
--- a/modules/mol/base/src/query_state.cc
+++ b/modules/mol/base/src/query_state.cc
@@ -72,7 +72,7 @@ bool QueryState::do_within(const geom::Vec3& pos, const impl::WithinParam& p,
         if (geom::Dot(d, d) <= p.GetRadiusSquare()) {
           return true;
         }
-      } else if (geom::Dot(d, d) > p.GetRadiusSquare()) {
+      } else if (geom::Dot(d, d) < p.GetRadiusSquare()) {
         return false;
       }
     }
diff --git a/modules/mol/base/tests/test_query.cc b/modules/mol/base/tests/test_query.cc
index e8d56b6a1..25d0284e6 100644
--- a/modules/mol/base/tests/test_query.cc
+++ b/modules/mol/base/tests/test_query.cc
@@ -76,13 +76,13 @@ void ensure_counts(EntityHandle e, const String& qs, int cc, int rc, int ac) {
   BOOST_CHECK_NO_THROW(v=e.Select(qs));
   BOOST_CHECK_MESSAGE(v.GetChainCount()==cc,
                       "wrong chain count " << v.GetChainCount()
-                      << " for query String " << qs);
+                      << " for query string " << qs);
   BOOST_CHECK_MESSAGE(v.GetResidueCount()==rc,
                       "wrong residue count " << v.GetResidueCount() <<
-                      " for query String " << qs);
+                      " for query string " << qs);
   BOOST_CHECK_MESSAGE(v.GetAtomCount()==ac,
                       "wrong atom count " << v.GetAtomCount() <<
-                      " for query String " << qs);
+                      " for query string " << qs);
 }
 
 void ensure_counts_v(EntityView src, const String& qs,
@@ -208,6 +208,9 @@ BOOST_AUTO_TEST_CASE(test_query_eval)
   ensure_counts(e, "rtype=C", 1, 3, 27);
   ensure_counts(e, "not (aname=CA and not aname=CA)", 1, 3, 27);
   ensure_counts(e, "3 <> {21.5,35,57.0}", 1, 2, 5);
+  ensure_counts(e, "not 3 <> {21.5,35,57.0}", 1, 3, 22);
+  ensure_counts(e, "3 <> {21.5,35,57} and not 0.5 <> {21.5,35,57} ", 1, 2, 4);
+  ensure_counts(e, "not 0.5 <> [rnum=3]", 1, 2, 19);
   ensure_counts(e, "1 <> {0,0,0}", 0, 0, 0);
   ensure_counts(e, "gatestpropa:0=1", 1, 1, 1);
   ensure_counts(e, "gatestpropa:1.0=1", 1, 3, 27);
-- 
GitLab