Skip to content
Snippets Groups Projects
Commit 5d1a865b authored by Studer Gabriel's avatar Studer Gabriel
Browse files

allow to set platform specific properties e.g. to control the number

of threads in the cpu platform
parent a7c19248
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ settings.forcefield = LoadCHARMMForcefield() ...@@ -10,6 +10,7 @@ settings.forcefield = LoadCHARMMForcefield()
settings.nonbonded_cutoff = 8.0 settings.nonbonded_cutoff = 8.0
settings.nonbonded_method = NonbondedMethod.CutoffNonPeriodic settings.nonbonded_method = NonbondedMethod.CutoffNonPeriodic
settings.platform = Platform.CPU settings.platform = Platform.CPU
settings.cpu_properties["CpuThreads"] = "2"
sim = Simulation(prot,settings) sim = Simulation(prot,settings)
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <boost/python.hpp> #include <boost/python.hpp>
#include <ost/mol/mm/settings.hh> #include <ost/mol/mm/settings.hh>
#include <OpenMM.h> //for definition of Integrator #include <OpenMM.h> //for definition of Integrator
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
using namespace boost::python; using namespace boost::python;
...@@ -75,6 +76,10 @@ void export_Settings() ...@@ -75,6 +76,10 @@ void export_Settings()
.def_readwrite("forcefield",&ost::mol::mm::Settings::forcefield) .def_readwrite("forcefield",&ost::mol::mm::Settings::forcefield)
.def_readwrite("termini_exceptions",&ost::mol::mm::Settings::termini_exceptions) .def_readwrite("termini_exceptions",&ost::mol::mm::Settings::termini_exceptions)
.def_readwrite("platform",&ost::mol::mm::Settings::platform) .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("add_thermostat",&ost::mol::mm::Settings::add_thermostat)
.def_readwrite("thermostat_temperature",&ost::mol::mm::Settings::thermostat_temperature) .def_readwrite("thermostat_temperature",&ost::mol::mm::Settings::thermostat_temperature)
.def_readwrite("thermostat_collision_frequency",&ost::mol::mm::Settings::thermostat_collision_frequency) .def_readwrite("thermostat_collision_frequency",&ost::mol::mm::Settings::thermostat_collision_frequency)
...@@ -93,6 +98,10 @@ void export_Settings() ...@@ -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::SettingsPtr>();
boost::python::register_ptr_to_python<ost::mol::mm::TerminiExceptionsPtr>(); boost::python::register_ptr_to_python<ost::mol::mm::TerminiExceptionsPtr>();
......
...@@ -64,6 +64,8 @@ private: ...@@ -64,6 +64,8 @@ private:
}; };
typedef std::map<String,String> PropertyMap;
struct Settings{ struct Settings{
Settings(): add_bonds(true), Settings(): add_bonds(true),
...@@ -92,6 +94,10 @@ struct Settings{ ...@@ -92,6 +94,10 @@ struct Settings{
//to assign a forcefield //to assign a forcefield
termini_exceptions(new TerminiExceptions), termini_exceptions(new TerminiExceptions),
platform(Reference), platform(Reference),
reference_properties(),
cpu_properties(),
opencl_properties(),
cuda_properties(),
add_thermostat(false), add_thermostat(false),
thermostat_temperature(std::numeric_limits<Real>::quiet_NaN()), thermostat_temperature(std::numeric_limits<Real>::quiet_NaN()),
thermostat_collision_frequency(std::numeric_limits<Real>::quiet_NaN()), thermostat_collision_frequency(std::numeric_limits<Real>::quiet_NaN()),
...@@ -142,6 +148,10 @@ struct Settings{ ...@@ -142,6 +148,10 @@ struct Settings{
ForcefieldPtr forcefield; ForcefieldPtr forcefield;
TerminiExceptionsPtr termini_exceptions; TerminiExceptionsPtr termini_exceptions;
Platform platform; Platform platform;
PropertyMap reference_properties;
PropertyMap cpu_properties;
PropertyMap opencl_properties;
PropertyMap cuda_properties;
bool add_thermostat; bool add_thermostat;
Real thermostat_temperature; Real thermostat_temperature;
Real thermostat_collision_frequency; Real thermostat_collision_frequency;
......
...@@ -267,22 +267,39 @@ void Simulation::Init(const TopologyPtr top, ...@@ -267,22 +267,39 @@ void Simulation::Init(const TopologyPtr top,
OpenMM::Platform::loadPluginsFromDirectory (settings->openmm_plugin_directory); OpenMM::Platform::loadPluginsFromDirectory (settings->openmm_plugin_directory);
OpenMM::Platform* platform; OpenMM::Platform* platform;
std::map<String,String> context_properties;
switch(settings->platform){ switch(settings->platform){
case Reference:{ case Reference:{
platform = &OpenMM::Platform::getPlatformByName("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; break;
} }
case OpenCL:{ case OpenCL:{
platform = &OpenMM::Platform::getPlatformByName("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; break;
} }
case CUDA:{ case CUDA:{
platform = &OpenMM::Platform::getPlatformByName("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; break;
} }
case CPU:{ case CPU:{
platform = &OpenMM::Platform::getPlatformByName("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; break;
} }
default:{ default:{
...@@ -290,7 +307,7 @@ void Simulation::Init(const TopologyPtr top, ...@@ -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(); ost::mol::AtomHandleList atom_list = ent_.GetAtomList();
std::vector<OpenMM::Vec3> positions; std::vector<OpenMM::Vec3> positions;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment