From 43e0abc2779109cec369acd3f87ebf5fd9f0f4fb Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Mon, 27 May 2019 12:11:31 +0200
Subject: [PATCH] Delete residues/chains that don't contain atoms after molck
 cleanup by default

---
 modules/mol/alg/doc/molalg.rst        |  6 +++++-
 modules/mol/alg/pymod/export_molck.cc |  2 +-
 modules/mol/alg/src/molck.cc          | 10 ++++++++--
 modules/mol/alg/src/molck.hh          |  3 ++-
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/modules/mol/alg/doc/molalg.rst b/modules/mol/alg/doc/molalg.rst
index 51de4cca6..cf72694bc 100644
--- a/modules/mol/alg/doc/molalg.rst
+++ b/modules/mol/alg/doc/molalg.rst
@@ -1877,7 +1877,7 @@ API
   The API here is set such that the functions modify the passed structure *ent*
   in-place. If this is not ok, please work on a copy of the structure.
 
-.. function:: Molck(ent, lib, settings)
+.. function:: Molck(ent, lib, settings, [prune=True])
 
   Runs Molck on provided entity.
 
@@ -1887,6 +1887,10 @@ API
   :type lib: :class:`~ost.conop.CompoundLib`
   :param settings: Molck settings
   :type settings: :class:`MolckSettings`
+  :param prune: Whether to remove residues/chains that don't contain atoms 
+                anymore after Molck cleanup
+  :type prune: `bool` 
+
 
 
 .. function:: MapNonStandardResidues(ent, lib)
diff --git a/modules/mol/alg/pymod/export_molck.cc b/modules/mol/alg/pymod/export_molck.cc
index e5e27dac5..c626a6ce3 100644
--- a/modules/mol/alg/pymod/export_molck.cc
+++ b/modules/mol/alg/pymod/export_molck.cc
@@ -133,5 +133,5 @@ void export_Molck()
 
   def("CleanUpElementColumn", &CleanUpElementColumn, (arg("ent"), arg("lib")));
 
-  def("Molck", &Molck, (arg("ent"), arg("lib"), arg("settings")));
+  def("Molck", &Molck, (arg("ent"), arg("lib"), arg("settings"), arg("prune")=true));
 }
diff --git a/modules/mol/alg/src/molck.cc b/modules/mol/alg/src/molck.cc
index 1eaf1988a..1a140b559 100644
--- a/modules/mol/alg/src/molck.cc
+++ b/modules/mol/alg/src/molck.cc
@@ -174,7 +174,8 @@ void CleanUpElementColumn(EntityHandle& ent, CompoundLibPtr lib){
 
 void Molck(ost::mol::EntityHandle& ent,
            ost::conop::CompoundLibPtr lib,
-           const MolckSettings& settings = MolckSettings()){
+           const MolckSettings& settings,
+           bool prune) {
 
   if(!lib) {
     throw ost::Error("Require valid compound library!");
@@ -193,7 +194,12 @@ void Molck(ost::mol::EntityHandle& ent,
               settings.colored);
   if (settings.assign_elem)  {
     CleanUpElementColumn(ent, lib);
-  }          
+  } 
+
+  if(prune) {
+    ost::mol::XCSEditor edi = ent.EditXCS();
+    edi.Prune();
+  }         
 }
 
 }}} // ns
\ No newline at end of file
diff --git a/modules/mol/alg/src/molck.hh b/modules/mol/alg/src/molck.hh
index b25b1b81e..f021ef7ec 100644
--- a/modules/mol/alg/src/molck.hh
+++ b/modules/mol/alg/src/molck.hh
@@ -97,7 +97,8 @@ void CleanUpElementColumn(ost::mol::EntityHandle& ent,
 
 void Molck(ost::mol::EntityHandle& ent,
            ost::conop::CompoundLibPtr lib,
-           const MolckSettings& settings);
+           const MolckSettings& settings,
+           bool prune = true);
 
 
 }}} // namespace
-- 
GitLab