From 4b4401eadf74f62c278dd1b04498af57b2ea5e2b Mon Sep 17 00:00:00 2001 From: Gerardo Tauriello <gerardo.tauriello@unibas.ch> Date: Wed, 26 Oct 2016 17:47:41 +0200 Subject: [PATCH] OpenMM plugin folders are only loaded once per path per execution. --- modules/mol/mm/src/simulation.cc | 10 ++++++++++ modules/mol/mm/src/simulation.hh | 3 +++ 2 files changed, 13 insertions(+) diff --git a/modules/mol/mm/src/simulation.cc b/modules/mol/mm/src/simulation.cc index 570bbaf80..7a3d4d2d3 100644 --- a/modules/mol/mm/src/simulation.cc +++ b/modules/mol/mm/src/simulation.cc @@ -267,6 +267,16 @@ SimulationPtr Simulation::Load(const String& filename, SettingsPtr settings){ } +void Simulation::EnsurePluginsLoaded(const String& plugin_path) { + // note: this is guaranteed to be constructed on first use only + static std::set<String> already_loaded; + if (already_loaded.find(plugin_path) == already_loaded.end()) { + // not loaded yet: load directory, but only once! + OpenMM::Platform::loadPluginsFromDirectory(plugin_path); + already_loaded.insert(plugin_path); + } +} + void Simulation::Init(const TopologyPtr top, const SettingsPtr settings){ diff --git a/modules/mol/mm/src/simulation.hh b/modules/mol/mm/src/simulation.hh index 9abe038bd..4b9a8f8aa 100644 --- a/modules/mol/mm/src/simulation.hh +++ b/modules/mol/mm/src/simulation.hh @@ -145,6 +145,9 @@ private: int TimeToNextNotification(); + // loads plugins from directory for OpenMM BUT only once per unique path! + static void EnsurePluginsLoaded(const String& plugin_path); + SystemPtr system_; IntegratorPtr integrator_; ContextPtr context_; -- GitLab