From 7ef92de58c98739fbfec20662adf8b7290ded6fa Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Thu, 24 Oct 2013 12:38:15 -0400
Subject: [PATCH] Added function to extract the matrix of pairwise distances
 between the atoms in two different views

---
 modules/mol/alg/pymod/export_structure_analysis.cc |  1 +
 modules/mol/alg/src/structure_analysis.cc          | 13 +++++++++++++
 modules/mol/alg/src/structure_analysis.hh          |  1 +
 3 files changed, 15 insertions(+)

diff --git a/modules/mol/alg/pymod/export_structure_analysis.cc b/modules/mol/alg/pymod/export_structure_analysis.cc
index 707006e3b..2a84fe027 100644
--- a/modules/mol/alg/pymod/export_structure_analysis.cc
+++ b/modules/mol/alg/pymod/export_structure_analysis.cc
@@ -32,4 +32,5 @@ void export_StructureAnalysis()
   def("CalculateAgreementWithDensityMap",&CalculateAgreementWithDensityMap,(arg("pos_list"),arg("density_map")));
 #endif
   def("WrapEntityInPeriodicCell",&WrapEntityInPeriodicCell,(arg("Entity"),arg("cell_center"),arg("ucell_size"),arg("ucell_angles")=geom::Vec3(),arg("group_res")=true));
+  def("PariwiseDistanceMatrix",&PariwiseDistanceMatrix,(arg("EntityView1"),arg("EntityView2")));
 }
diff --git a/modules/mol/alg/src/structure_analysis.cc b/modules/mol/alg/src/structure_analysis.cc
index 98d433339..b8c6f10ba 100644
--- a/modules/mol/alg/src/structure_analysis.cc
+++ b/modules/mol/alg/src/structure_analysis.cc
@@ -59,6 +59,19 @@ Real CalculateAverageAgreementWithDensityMap(const geom::Vec3List& vl, img::MapH
   }
   return sum/float(vl.size());
 }
+  
+std::vector< std::vector<Real> > PariwiseDistanceMatrix(const EntityView view1, const EntityView view2){
+  std::vector< std::vector<Real> > dist_mat;
+  unsigned int n1=view1.GetAtomCount(),n2=view2.GetAtomCount();
+  dist_mat.resize(n1,std::vector<Real>(n2,0));
+  AtomViewList atoms1=view1.GetAtomList(),atoms2=view2.GetAtomList();
+  for (unsigned int i=0; i!=n1; ++i){
+    for (unsigned int j=0; j!=n2; ++j) {
+      dist_mat[i][j]=geom::Distance(atoms1[i].GetPos(),atoms2[j].GetPos());
+    }
+  }
+  return dist_mat;
+}
 
 #endif
 void DLLEXPORT_OST_MOL_ALG WrapEntityInPeriodicCell(EntityHandle eh, const geom::Vec3 cell_center, const geom::Vec3 ucell_size, \
diff --git a/modules/mol/alg/src/structure_analysis.hh b/modules/mol/alg/src/structure_analysis.hh
index bafd70887..f7cb48540 100644
--- a/modules/mol/alg/src/structure_analysis.hh
+++ b/modules/mol/alg/src/structure_analysis.hh
@@ -38,5 +38,6 @@ namespace ost { namespace mol { namespace alg {
   Real DLLEXPORT_OST_MOL_ALG CalculateAverageAgreementWithDensityMap(const geom::Vec3List& vl, img::MapHandle& density_map);
 #endif
   void DLLEXPORT_OST_MOL_ALG WrapEntityInPeriodicCell(EntityHandle eh, const geom::Vec3 cell_center, const geom::Vec3 ucell_size, const geom::Vec3 ucell_angles=geom::Vec3(), bool group_res=true);
+  std::vector< std::vector<Real> > DLLEXPORT_OST_MOL_ALG PariwiseDistanceMatrix(const EntityView view1, const EntityView view2);
 }}}//ns
 #endif
-- 
GitLab