diff --git a/modules/mol/mm/doc/simulation.rst b/modules/mol/mm/doc/simulation.rst index 9d20aac61fa83325437ac4193e793c5e623e8659..bbcf1c8026f823ebcb21633a6505a1b0e8df057d 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 a5d3cae349e83f51c84bc2f95c3b3b052b0b03d4..b4611a680b9e83b085854eb593c238328ec3461e 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 f869d54df2d0bb7e39a80783eb1dee113aa7d049..8288f1a5eadb9560c7108972617b3fce1c0de1e0 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 4b9a8f8aa355f813b9e6651eb1f5670ab797a44b..52aaaa0019761a165bc98e5799d66ab8fb18af0e 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);