From c84a9dd44c93c7c7f36d29408961361b3f3603b6 Mon Sep 17 00:00:00 2001
From: Gabriel Studer <gabriel.studer@unibas.ch>
Date: Wed, 14 Jun 2017 08:30:15 +0200
Subject: [PATCH] add function to get the names of all building blocks present
 in a forcefield

---
 modules/mol/mm/doc/forcefield.rst         |  5 +++++
 modules/mol/mm/pymod/export_forcefield.cc | 11 +++++++++++
 modules/mol/mm/src/forcefield.cc          | 11 +++++++++++
 modules/mol/mm/src/forcefield.hh          |  2 ++
 4 files changed, 29 insertions(+)

diff --git a/modules/mol/mm/doc/forcefield.rst b/modules/mol/mm/doc/forcefield.rst
index 444ff0243..dc21e30d2 100644
--- a/modules/mol/mm/doc/forcefield.rst
+++ b/modules/mol/mm/doc/forcefield.rst
@@ -664,6 +664,11 @@ The Forcefield Class
     :returns:  :class:`BuildingBlock` for this name, invalid if it can't be 
                found
 
+  .. method:: GetBuildingBlockNames()
+
+    :returns:  :class:`list` of all building block names present in that 
+               forcefield
+
 
   .. method:: GetBlockModifier(res_name)
 
diff --git a/modules/mol/mm/pymod/export_forcefield.cc b/modules/mol/mm/pymod/export_forcefield.cc
index 4a36a728e..82c74c6d7 100644
--- a/modules/mol/mm/pymod/export_forcefield.cc
+++ b/modules/mol/mm/pymod/export_forcefield.cc
@@ -47,6 +47,16 @@ boost::python::list WrapGetAtomRenamingRules(ost::mol::mm::ForcefieldPtr p,
   return result;
 }
 
+boost::python::list WrapGetBuildingBlockNames(ost::mol::mm::ForcefieldPtr p) {
+  boost::python::list result;
+  std::vector<String> v_result = p->GetBuildingBlockNames();
+  for(std::vector<String>::iterator it = v_result.begin();
+      it != v_result.end(); ++it) {
+    result.append(*it);
+  }
+  return result;
+}
+
 }
 
 
@@ -58,6 +68,7 @@ void export_Forcefield()
     .def("Save",&ost::mol::mm::Forcefield::Save,(arg("filename")))
     .def("GetBuildingBlock",&ost::mol::mm::Forcefield::GetBuildingBlock,(arg("name")))
     .def("GetBlockModifier",&ost::mol::mm::Forcefield::GetBlockModifier,(arg("name")))
+    .def("GetBuildingBlockNames",&WrapGetBuildingBlockNames)
     .def("GetAtomType",&ost::mol::mm::Forcefield::GetAtomType,(arg("res_name"),arg("atom_name")))
     .def("GetHydrogenConstructor",&ost::mol::mm::Forcefield::GetHydrogenConstructor,(arg("name")))
     .def("GetNTerModifier",&ost::mol::mm::Forcefield::GetNTerModifier,(arg("residue_name"),arg("ter_name")=""))
diff --git a/modules/mol/mm/src/forcefield.cc b/modules/mol/mm/src/forcefield.cc
index af349dbbb..c323277a7 100644
--- a/modules/mol/mm/src/forcefield.cc
+++ b/modules/mol/mm/src/forcefield.cc
@@ -438,6 +438,17 @@ BuildingBlockPtr Forcefield::GetBuildingBlock(const String& name) const{
   return p;
 }
 
+std::vector<String> Forcefield::GetBuildingBlockNames() const {
+
+  std::vector<String> return_vec;
+  for(boost::unordered_map<String,BuildingBlockPtr>::const_iterator i = 
+      building_blocks_.begin(); i != building_blocks_.end(); ++i) {
+    return_vec.push_back(i->first);
+  }
+
+  return return_vec;
+} 
+
 BlockModifierPtr Forcefield::GetBlockModifier(const String& modifier_name) const{
   boost::unordered_map<String,BlockModifierPtr>::const_iterator i = block_modifiers_.find(modifier_name);
   if(i == block_modifiers_.end()) return BlockModifierPtr();
diff --git a/modules/mol/mm/src/forcefield.hh b/modules/mol/mm/src/forcefield.hh
index 2c1950620..6435226e0 100644
--- a/modules/mol/mm/src/forcefield.hh
+++ b/modules/mol/mm/src/forcefield.hh
@@ -82,6 +82,8 @@ public:
 
   BlockModifierPtr GetBlockModifier(const String& modifier_name) const;
 
+  std::vector<String> GetBuildingBlockNames() const;
+
   String GetAtomType(const String& res_name, const String& atom_name) const;
 
   HydrogenConstructorPtr GetHydrogenConstructor(const String& name) const;
-- 
GitLab