From 2f3a3a686f25d038bad078b699ff82cbf0fb4c28 Mon Sep 17 00:00:00 2001 From: Gerardo Tauriello <gerardo.tauriello@unibas.ch> Date: Thu, 3 Nov 2016 15:08:35 +0100 Subject: [PATCH] Added static Simulation::IsPlatformAvailable method to check OpenMM platforms. --- modules/mol/mm/doc/simulation.rst | 14 +++++++++++++- modules/mol/mm/pymod/export_simulation.cc | 6 +++++- modules/mol/mm/src/simulation.cc | 18 ++++++++++++++++++ modules/mol/mm/src/simulation.hh | 2 ++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/modules/mol/mm/doc/simulation.rst b/modules/mol/mm/doc/simulation.rst index 9d20aac61..bbcf1c802 100644 --- a/modules/mol/mm/doc/simulation.rst +++ b/modules/mol/mm/doc/simulation.rst @@ -60,7 +60,7 @@ mapped back to the attached structure at any time. :param filename: Filename :type filename: :class:`str` - .. method:: Load(filename) + .. staticmethod:: Load(filename) Loads a dumped simulation from disk. You have to make sure, that the provided settings are consistent with those from the saved simulation. Undefined @@ -72,6 +72,18 @@ mapped back to the attached structure at any time. :type filename: :class:`str` :type settings: :class:`Settings` + .. staticmethod:: IsPlatformAvailable(settings) + + :return: True, if platform defined in *settings* is available. Otherwise, + construction of a simulation object will fail with these settings. + :rtype: :class:`bool` + + :param settings: Controls the parametrization of this class. + Only :attr:`Settings.openmm_plugin_directory`, + :attr:`Settings.custom_plugin_directory` and + :attr:`Settings.platform` are relevant. + :type settings: :class:`Settings` + .. method:: ApplyLBFGS([tolerance=1.0,max_iterations=1000]) Run minimization using the Limited-memory Broyden–Fletcher–Goldfarb–Shanno diff --git a/modules/mol/mm/pymod/export_simulation.cc b/modules/mol/mm/pymod/export_simulation.cc index a5d3cae34..b4611a680 100644 --- a/modules/mol/mm/pymod/export_simulation.cc +++ b/modules/mol/mm/pymod/export_simulation.cc @@ -52,7 +52,11 @@ void export_Simulation() .def(init<const ost::mol::EntityHandle, const ost::mol::mm::SettingsPtr>()) .def(init<const ost::mol::mm::TopologyPtr,const ost::mol::EntityHandle&,const ost::mol::mm::SettingsPtr>()) .def("Save",&ost::mol::mm::Simulation::Save,(arg("filename"))) - .def("Load",&ost::mol::mm::Simulation::Load,(arg("filename"))).staticmethod("Load") + .def("Load",&ost::mol::mm::Simulation::Load,(arg("filename"))) + .staticmethod("Load") + .def("IsPlatformAvailable",&ost::mol::mm::Simulation::IsPlatformAvailable, + (arg("settings"))) + .staticmethod("IsPlatformAvailable") .def("Steps",&ost::mol::mm::Simulation::Steps,(arg("steps"))) .def("GetPositions",&ost::mol::mm::Simulation::GetPositions,(arg("enforce_periodic_box")=false, arg("in_angstrom")=true)) .def("GetVelocities",&ost::mol::mm::Simulation::GetVelocities) diff --git a/modules/mol/mm/src/simulation.cc b/modules/mol/mm/src/simulation.cc index f869d54df..8288f1a5e 100644 --- a/modules/mol/mm/src/simulation.cc +++ b/modules/mol/mm/src/simulation.cc @@ -267,6 +267,24 @@ SimulationPtr Simulation::Load(const String& filename, SettingsPtr settings){ } +bool Simulation::IsPlatformAvailable(const SettingsPtr settings) { + // load settings-dependent plugin directories + EnsurePluginsLoaded(settings->openmm_plugin_directory); + EnsurePluginsLoaded(settings->custom_plugin_directory); + // check if OpenMM platform exists by checking all (this is fast..) + const Platform platform_id = settings->platform; + for (int i = 0; i < OpenMM::Platform::getNumPlatforms(); ++i) { + OpenMM::Platform& platform = OpenMM::Platform::getPlatform(i); + if ( (platform_id == Reference && platform.getName() == "Reference") + || (platform_id == OpenCL && platform.getName() == "OpenCL") + || (platform_id == CUDA && platform.getName() == "CUDA") + || (platform_id == CPU && platform.getName() == "CPU")) { + return true; + } + } + return false; +} + void Simulation::EnsurePluginsLoaded(const String& plugin_path) { // note: this is guaranteed to be constructed on first use only static std::set<String> already_loaded; diff --git a/modules/mol/mm/src/simulation.hh b/modules/mol/mm/src/simulation.hh index 4b9a8f8aa..52aaaa001 100644 --- a/modules/mol/mm/src/simulation.hh +++ b/modules/mol/mm/src/simulation.hh @@ -67,6 +67,8 @@ public: static SimulationPtr Load(const String& filename, SettingsPtr settings); + static bool IsPlatformAvailable(const SettingsPtr settings); + ost::mol::EntityHandle GetEntity() { return ent_; } geom::Vec3List GetPositions(bool enforce_periodic_box = false, bool in_angstrom = true); -- GitLab