diff --git a/modules/mol/mm/examples/gb_example_writing_trajectory.py b/modules/mol/mm/examples/gb_example_writing_trajectory.py index 051f6ebc8015751002729345af0dfd14c96c0ea6..fda1d6f30880919a0afd068f000bdc1072e3f7de 100644 --- a/modules/mol/mm/examples/gb_example_writing_trajectory.py +++ b/modules/mol/mm/examples/gb_example_writing_trajectory.py @@ -10,6 +10,7 @@ settings.forcefield = LoadCHARMMForcefield() settings.nonbonded_cutoff = 8.0 settings.nonbonded_method = NonbondedMethod.CutoffNonPeriodic settings.platform = Platform.CPU +settings.cpu_properties["CpuThreads"] = "2" sim = Simulation(prot,settings) diff --git a/modules/mol/mm/pymod/export_settings.cc b/modules/mol/mm/pymod/export_settings.cc index 518cb4c8e1b1855fe6069f55237ffe511e34476f..d8d868fd628d8ba19e48f135aa8701aae732113f 100644 --- a/modules/mol/mm/pymod/export_settings.cc +++ b/modules/mol/mm/pymod/export_settings.cc @@ -19,6 +19,7 @@ #include <boost/python.hpp> #include <ost/mol/mm/settings.hh> #include <OpenMM.h> //for definition of Integrator +#include <boost/python/suite/indexing/map_indexing_suite.hpp> using namespace boost::python; @@ -75,6 +76,10 @@ void export_Settings() .def_readwrite("forcefield",&ost::mol::mm::Settings::forcefield) .def_readwrite("termini_exceptions",&ost::mol::mm::Settings::termini_exceptions) .def_readwrite("platform",&ost::mol::mm::Settings::platform) + .def_readwrite("reference_properties",&ost::mol::mm::Settings::reference_properties) + .def_readwrite("cpu_properties",&ost::mol::mm::Settings::cpu_properties) + .def_readwrite("cuda_properties",&ost::mol::mm::Settings::cuda_properties) + .def_readwrite("opencl_properties",&ost::mol::mm::Settings::opencl_properties) .def_readwrite("add_thermostat",&ost::mol::mm::Settings::add_thermostat) .def_readwrite("thermostat_temperature",&ost::mol::mm::Settings::thermostat_temperature) .def_readwrite("thermostat_collision_frequency",&ost::mol::mm::Settings::thermostat_collision_frequency) @@ -93,6 +98,10 @@ void export_Settings() ; + class_<ost::mol::mm::PropertyMap>("PropertyMap", no_init) + .def(map_indexing_suite<ost::mol::mm::PropertyMap>()) + ; + boost::python::register_ptr_to_python<ost::mol::mm::SettingsPtr>(); boost::python::register_ptr_to_python<ost::mol::mm::TerminiExceptionsPtr>(); diff --git a/modules/mol/mm/src/settings.hh b/modules/mol/mm/src/settings.hh index ddd3067c04b518d21f6e16500993917f2400fb27..59b43bc79e257d0fac5cf7f1e5e2a88dc2010b3d 100644 --- a/modules/mol/mm/src/settings.hh +++ b/modules/mol/mm/src/settings.hh @@ -64,6 +64,8 @@ private: }; +typedef std::map<String,String> PropertyMap; + struct Settings{ Settings(): add_bonds(true), @@ -92,6 +94,10 @@ struct Settings{ //to assign a forcefield termini_exceptions(new TerminiExceptions), platform(Reference), + reference_properties(), + cpu_properties(), + opencl_properties(), + cuda_properties(), add_thermostat(false), thermostat_temperature(std::numeric_limits<Real>::quiet_NaN()), thermostat_collision_frequency(std::numeric_limits<Real>::quiet_NaN()), @@ -142,6 +148,10 @@ struct Settings{ ForcefieldPtr forcefield; TerminiExceptionsPtr termini_exceptions; Platform platform; + PropertyMap reference_properties; + PropertyMap cpu_properties; + PropertyMap opencl_properties; + PropertyMap cuda_properties; bool add_thermostat; Real thermostat_temperature; Real thermostat_collision_frequency; diff --git a/modules/mol/mm/src/simulation.cc b/modules/mol/mm/src/simulation.cc index 31fd2ec47e0ecc268c2f3ad1b8efe1faec58504c..abcf50d7dffbef464c419ad5bc915264a112cd3c 100644 --- a/modules/mol/mm/src/simulation.cc +++ b/modules/mol/mm/src/simulation.cc @@ -267,22 +267,39 @@ void Simulation::Init(const TopologyPtr top, OpenMM::Platform::loadPluginsFromDirectory (settings->openmm_plugin_directory); OpenMM::Platform* platform; + std::map<String,String> context_properties; switch(settings->platform){ case Reference:{ platform = &OpenMM::Platform::getPlatformByName("Reference"); + for(PropertyMap::iterator i = settings->opencl_properties.begin(); + i != settings->opencl_properties.end(); ++i){ + context_properties[i->first] = i->second; + } break; } case OpenCL:{ platform = &OpenMM::Platform::getPlatformByName("OpenCL"); + for(PropertyMap::iterator i = settings->opencl_properties.begin(); + i != settings->opencl_properties.end(); ++i){ + context_properties[i->first] = i->second; + } break; } case CUDA:{ platform = &OpenMM::Platform::getPlatformByName("CUDA"); + for(PropertyMap::iterator i = settings->cuda_properties.begin(); + i != settings->cuda_properties.end(); ++i){ + context_properties[i->first] = i->second; + } break; } case CPU:{ platform = &OpenMM::Platform::getPlatformByName("CPU"); + for(PropertyMap::iterator i = settings->cpu_properties.begin(); + i != settings->cpu_properties.end(); ++i){ + context_properties[i->first] = i->second; + } break; } default:{ @@ -290,7 +307,7 @@ void Simulation::Init(const TopologyPtr top, } } - context_ = ContextPtr(new OpenMM::Context(*system_,*integrator_,*platform)); + context_ = ContextPtr(new OpenMM::Context(*system_,*integrator_,*platform,context_properties)); ost::mol::AtomHandleList atom_list = ent_.GetAtomList(); std::vector<OpenMM::Vec3> positions;