From 184b98cf85248e2c68bd66a6b355261a8704bc87 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Fri, 18 May 2012 11:42:26 -0400
Subject: [PATCH] Added several functions from the CoordFrame level to
 structure_analysis.py python module

---
 modules/mol/alg/pymod/structure_analysis.py  | 69 ++++++++++++++++++++
 modules/mol/base/pymod/export_coord_frame.cc |  2 +
 2 files changed, 71 insertions(+)

diff --git a/modules/mol/alg/pymod/structure_analysis.py b/modules/mol/alg/pymod/structure_analysis.py
index 4b575466b..662ed914d 100644
--- a/modules/mol/alg/pymod/structure_analysis.py
+++ b/modules/mol/alg/pymod/structure_analysis.py
@@ -15,3 +15,72 @@ def GetFrameFromEntity(eh):
   """
   return ost.mol.CreateCoordFrame(eh.GetAtomPosList())
   
+def GetDistanceBetwCenterOfMass(sele1,sele2):
+  """
+  This function calculates the distance between the centers of mass
+  of sele1 and sele2, two selections from the same Entity.
+  Input:
+    sele1 : EntityView
+    sele2 : EntityView
+  """
+  if not sele1.IsValid() and sele2.IsValid():
+    print 'invalid view'
+    return
+  eh=sele1.GetHandle()
+  if not eh==sele2.GetHandle():
+    print 'The two views must be from the same entity'
+    return
+  f=GetFrameFromEntity(eh)
+  return f.GetDistanceBetwCenterOfMass(sele1,sele2)
+
+def GetMinDistanceBetweenViews(sele1,sele2):
+  """
+  This function calculates the minimal distance between
+  sele1 and sele2, two selections from the same Entity.
+  Input:
+    sele1 : EntityView
+    sele2 : EntityView
+  """
+  if not sele1.IsValid() and sele2.IsValid():
+    print 'invalid view'
+    return
+  eh=sele1.GetHandle()
+  if not eh==sele2.GetHandle():
+    print 'The two views must be from the same entity'
+    return
+  f=GetFrameFromEntity(eh)
+  return f.GetMinDistance(sele1,sele2)
+
+def GetMinDistBetwCenterOfMassAndView(sele1,sele2):
+  """
+  This function calculates the minimal distance between sele2 and
+  the center of mass of sele1, two selections from the same Entity.
+  Input:
+    sele1 : EntityView from which the center of mass is taken
+    sele2 : EntityView
+  """
+  if not sele1.IsValid() and sele2.IsValid():
+    print 'invalid view'
+    return
+  eh=sele1.GetHandle()
+  if not eh==sele2.GetHandle():
+    print 'The two views must be from the same entity'
+    return
+  f=GetFrameFromEntity(eh)
+  return f.GetMinDistBetwCenterOfMassAndView(sele1,sele2)
+  
+
+def GetAlphaHelixContent(sele1):
+  """
+  This function calculates the content of alpha helix in a view.
+  All residues in the view have to ordered and adjacent (no gaps allowed)
+  Input:
+    sele1 : EntityView
+  """
+  if not sele1.IsValid():
+    print 'invalid view'
+    return
+  eh=sele1.GetHandle()
+  f=GetFrameFromEntity(eh)
+  return f.GetAlphaHelixContent(sele1)
+
diff --git a/modules/mol/base/pymod/export_coord_frame.cc b/modules/mol/base/pymod/export_coord_frame.cc
index 3f760c65c..93f80a7e7 100644
--- a/modules/mol/base/pymod/export_coord_frame.cc
+++ b/modules/mol/base/pymod/export_coord_frame.cc
@@ -34,6 +34,7 @@ Real (CoordFrame::*get_angle)(const AtomHandle& a1, const AtomHandle& a2, const
 Real (CoordFrame::*get_dihedral)(const AtomHandle& a1, const AtomHandle& a2, const AtomHandle& a3, const AtomHandle& a4) = &CoordFrame::GetDihedralAngle;
 geom::Vec3 (CoordFrame::*get_cm)(const mol::EntityView& sele) = &CoordFrame::GetCenterOfMassPos;
 Real (CoordFrame::*get_dist_cm)(const mol::EntityView& sele1, const mol::EntityView& sele2) = &CoordFrame::GetDistanceBetwCenterOfMass;
+Real (CoordFrame::*get_min_dist_cm_v)(const mol::EntityView& sele1, const mol::EntityView& sele2) = &CoordFrame::GetMinDistBetwCenterOfMassAndView;
 Real (CoordFrame::*get_rmsd)(const mol::EntityView& Reference_View, const mol::EntityView& sele_View) = &CoordFrame::GetRMSD;
 Real (CoordFrame::*get_min_dist)(const mol::EntityView& view1, const mol::EntityView& view2) = &CoordFrame::GetMinDistance;
 Real (CoordFrame::*get_alpha)(const mol::EntityView& segment) = &CoordFrame::GetAlphaHelixContent;
@@ -49,6 +50,7 @@ void export_CoordFrame()
     .def("GetDihedralAngle", get_dihedral)
     .def("GetCenterOfMassPos", get_cm)
     .def("GetDistanceBetwCenterOfMass", get_dist_cm)
+    .def("GetMinDistBetwCenterOfMassAndView", get_min_dist_cm_v)
     .def("GetRMSD",get_rmsd)
     .def("GetMinDistance",get_min_dist)
     .def("GetODRLine",&geom::Vec3List::GetODRLine)
-- 
GitLab