From b327739cd0e73037d6510f53a8199bc5656f5dc6 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Fri, 30 Mar 2012 16:40:06 -0400
Subject: [PATCH] Added a function to calculate a density entity overlap by
 calculating for each atom in the entity the value of the density in its
 position

---
 .../alg/pymod/export_structure_analysis.cc    |  1 +
 modules/mol/alg/src/structure_analysis.cc     | 21 +++++++++++++------
 modules/mol/alg/src/structure_analysis.hh     |  1 +
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/modules/mol/alg/pymod/export_structure_analysis.cc b/modules/mol/alg/pymod/export_structure_analysis.cc
index 4a07ad568..5a9131094 100644
--- a/modules/mol/alg/pymod/export_structure_analysis.cc
+++ b/modules/mol/alg/pymod/export_structure_analysis.cc
@@ -28,5 +28,6 @@ void export_StructureAnalysis()
 {
   def("GetPosListFromView",&GetPosListFromView, (arg("view")));
   def("CalculateAverageAgreementWithDensityMap",&CalculateAverageAgreementWithDensityMap,(arg("pos_list"),arg("density_map")));
+  def("CalculateAgreementWithDensityMap",&CalculateAgreementWithDensityMap,(arg("pos_list"),arg("density_map")));
   def("WrapEntityInPeriodicCell",&WrapEntityInPeriodicCell,(arg("Entity"),arg("cell_center"),arg("nasis_vec")));
 }
\ No newline at end of file
diff --git a/modules/mol/alg/src/structure_analysis.cc b/modules/mol/alg/src/structure_analysis.cc
index f4d4a50ba..73bfca844 100644
--- a/modules/mol/alg/src/structure_analysis.cc
+++ b/modules/mol/alg/src/structure_analysis.cc
@@ -38,15 +38,24 @@ geom::Vec3List GetPosListFromView(const EntityView& view){
   }
   return vl;
 }    
-  
-Real CalculateAverageAgreementWithDensityMap(const geom::Vec3List& vl, img::MapHandle& density_map){
-  Real sum,v;
-  sum=0;
+
+std::vector<Real> CalculateAgreementWithDensityMap(const geom::Vec3List& vl, img::MapHandle& density_map){
   CheckHandleValidity(density_map);
+  std::vector<Real> v;
+  v.reserve(vl.size());
   for (geom::Vec3List::const_iterator v1=vl.begin(),e=vl.end(); v1!=e; ++v1) {
     img::Point p(density_map.CoordToIndex(*v1));
-    v=density_map.GetReal(p);
-    sum=sum+v;
+    v.push_back(density_map.GetReal(p));
+  }
+  return v;
+}
+  
+Real CalculateAverageAgreementWithDensityMap(const geom::Vec3List& vl, img::MapHandle& density_map){
+  CheckHandleValidity(density_map);
+  std::vector<Real> v=CalculateAgreementWithDensityMap(vl, density_map);
+  Real sum=0.0;
+  for (std::vector<Real>::const_iterator i=v.begin(),e=v.end(); i!=e; ++i) {
+    sum=sum+*i;
   }
   return sum/float(vl.size());
 }
diff --git a/modules/mol/alg/src/structure_analysis.hh b/modules/mol/alg/src/structure_analysis.hh
index 529357037..798dc0973 100644
--- a/modules/mol/alg/src/structure_analysis.hh
+++ b/modules/mol/alg/src/structure_analysis.hh
@@ -32,6 +32,7 @@
 
 namespace ost { namespace mol { namespace alg {
   geom::Vec3List DLLEXPORT_OST_MOL_ALG GetPosListFromView(const EntityView& view);
+  std::vector<Real> DLLEXPORT_OST_MOL_ALG CalculateAgreementWithDensityMap(const geom::Vec3List& vl, img::MapHandle& density_map);
   Real DLLEXPORT_OST_MOL_ALG CalculateAverageAgreementWithDensityMap(const geom::Vec3List& vl, img::MapHandle& density_map);
   void DLLEXPORT_OST_MOL_ALG WrapEntityInPeriodicCell(EntityHandle eh, const geom::Vec3 cell_center, const geom::Vec3 basis_vec);
 }}}//ns
-- 
GitLab