From 6fd32068b70685c72a4c79296e6b47861a23a3e3 Mon Sep 17 00:00:00 2001
From: Niklaus Johner <nij2003@med.cornell.edu>
Date: Fri, 15 Mar 2013 19:09:56 -0400
Subject: [PATCH] Added the possibility to wrap an entity in a periodic cell on
 a per-atom base instead of per-residue base in
 mol::alg::structure_analysis::WrapEntityInPeriodicCell

---
 modules/mol/alg/src/structure_analysis.cc | 32 ++++++++++++++---------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/modules/mol/alg/src/structure_analysis.cc b/modules/mol/alg/src/structure_analysis.cc
index de7a176b1..c2d02f0ad 100644
--- a/modules/mol/alg/src/structure_analysis.cc
+++ b/modules/mol/alg/src/structure_analysis.cc
@@ -63,10 +63,10 @@ Real CalculateAverageAgreementWithDensityMap(const geom::Vec3List& vl, img::MapH
 #endif
 void DLLEXPORT_OST_MOL_ALG WrapEntityInPeriodicCell(EntityHandle eh, const geom::Vec3 cell_center, const geom::Vec3 basis_vec, bool group_residues){
   mol::XCSEditor edi=eh.EditXCS(mol::BUFFERED_EDIT);
-  geom::Vec3 cm,wrapped_cm,shift;
-  ResidueHandleList residues=eh.GetResidueList();
-  unsigned int n_residues=eh.GetResidueCount();
   if (group_residues) {
+    geom::Vec3 cm,wrapped_cm,shift;
+    ResidueHandleList residues=eh.GetResidueList();
+    unsigned int n_residues=eh.GetResidueCount();
     for (unsigned int i=0; i<n_residues; ++i) {
       ResidueHandle r=residues[i];
       AtomHandleList atoms=r.GetAtomList();
@@ -75,17 +75,23 @@ void DLLEXPORT_OST_MOL_ALG WrapEntityInPeriodicCell(EntityHandle eh, const geom:
         edi.SetAtomPos((*a),geom::WrapVec3((*a).GetPos(),ref_pos,basis_vec));
       }
     }
+    for (unsigned int i=0; i<n_residues; ++i) {
+      ResidueHandle r=residues[i];
+      cm=r.GetCenterOfMass();
+      wrapped_cm=geom::WrapVec3(cm,cell_center,basis_vec);
+      if (wrapped_cm==cm) continue;
+      AtomHandleList atoms=r.GetAtomList();
+      unsigned int n_atoms=r.GetAtomCount();
+      shift=wrapped_cm-cm;
+      for (unsigned int j=0; j<n_atoms; ++j) {
+        edi.SetAtomPos(atoms[j],atoms[j].GetPos()+shift);
+      }
+    }
   }
-  for (unsigned int i=0; i<n_residues; ++i) {
-    ResidueHandle r=residues[i];
-    cm=r.GetCenterOfMass();
-    wrapped_cm=geom::WrapVec3(cm,cell_center,basis_vec);
-    if (wrapped_cm==cm) continue;
-    AtomHandleList atoms=r.GetAtomList();
-    unsigned int n_atoms=r.GetAtomCount();
-    shift=wrapped_cm-cm;
-    for (unsigned int j=0; j<n_atoms; ++j) {
-      edi.SetAtomPos(atoms[j],atoms[j].GetPos()+shift);
+  else {
+    AtomHandleList atoms=eh.GetAtomList();
+    for (AtomHandleList::iterator a=atoms.begin(), e=atoms.end(); a!=e; ++a) {
+      edi.SetAtomPos((*a),geom::WrapVec3((*a).GetPos(),cell_center,basis_vec));
     }
   }
 }
-- 
GitLab