OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
simulation.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 
20 #ifndef OST_MM_SIMULATION_HH
21 #define OST_MM_SIMULATION_HH
22 
23 #include <vector>
24 #include <map>
25 
26 #include <ost/mol/mol.hh>
28 #include <ost/mol/mm/topology.hh>
30 #include <ost/mol/mm/settings.hh>
31 #include <ost/mol/mm/modeller.hh>
32 #include <ost/geom/vec3.hh>
33 #include <ost/mol/mm/observer.hh>
35 #include <ost/mol/mm/steep.hh>
36 
37 #include <time.h>
38 
39 namespace OpenMM{
40  class Integrator;
41  class Context;//hacky way of telling the Context and Integrator
42  //are around.
43  //will be included in source file to avoid
44  //dependencies on external libraries
45 }
46 
47 namespace ost { namespace mol{ namespace mm{
48 
49 class Simulation;
50 
51 typedef boost::shared_ptr<OpenMM::Integrator> IntegratorPtr;
52 typedef boost::shared_ptr<OpenMM::Context> ContextPtr;
53 typedef boost::shared_ptr<Simulation> SimulationPtr;
54 
55 class Simulation {
56 
57 public:
58 
59  Simulation(const ost::mol::EntityHandle& handle,
60  const SettingsPtr settings);
61 
63  const ost::mol::EntityHandle& handle,
64  const SettingsPtr settings);
65 
66  void Save(const String& filename);
67 
68  static SimulationPtr Load(const String& filename, SettingsPtr settings);
69 
70  static bool IsPlatformAvailable(const SettingsPtr settings);
71 
72  ost::mol::EntityHandle GetEntity() { return ent_; }
73 
74  geom::Vec3List GetPositions(bool enforce_periodic_box = false, bool in_angstrom = true);
75 
77 
79 
80  void SetPositions(const geom::Vec3List& positions, bool in_angstrom = true);
81 
82  void SetVelocities(geom::Vec3List& velocities);
83 
84  void UpdatePositions(bool enforce_periodic_box = false);
85 
86  bool ApplySD(Real tolerance = 100, int max_iterations = 1000);
87 
88  void ApplyLBFGS(Real tolerance = 1, int max_iterations = 1000);
89 
90  Real GetEnergy();
91 
93 
95 
96  TopologyPtr GetTopology() { return top_; }
97 
98  void Steps(int steps);
99 
100  void Register(ObserverPtr o);
101 
102  void ResetHarmonicBond(uint index, Real bond_length, Real force_constant);
103 
104  void ResetHarmonicAngle(uint index, Real angle, Real force_constant);
105 
106  void ResetUreyBradleyAngle(uint index, Real angle, Real angle_force_constant, Real bond_length, Real bond_force_constant);
107 
108  void ResetPeriodicDihedral(uint index, int multiplicity, Real phase, Real force_constant);
109 
110  void ResetPeriodicImproper(uint index, int multiplicity, Real phase, Real force_constant);
111 
112  void ResetHarmonicImproper(uint index, Real phase, Real force_constant);
113 
114  void ResetLJPair(uint index, Real sigma, Real epsilon);
115 
116  void ResetDistanceConstraint(uint index, Real constraint_length);
117 
118  void ResetHarmonicPositionRestraint(uint index, const geom::Vec3& ref_position, Real k,
119  Real x_scale = 1.0, Real y_scale = 1.0, Real z_scale = 1.0);
120 
121  void ResetHarmonicDistanceRestraint(uint index, Real length, Real force_constant);
122 
123  void ResetLJ(uint index, Real sigma, Real epsilon);
124 
125  void ResetGBSA(uint index, Real radius, Real scaling);
126 
127  void ResetCharge(uint index, Real charge);
128 
129  void ResetMass(uint index, Real mass);
130 
131  void AddPositionConstraint(uint index);
132 
133  void AddPositionConstraints(const std::vector<uint>& index);
134 
136 
138 
140 
141 private:
142 
143  Simulation() { } //hidden constructor...
144 
145  void Init(const ost::mol::mm::TopologyPtr top,
146  const ost::mol::EntityHandle& ent,
147  const SettingsPtr settings);
148 
149  int TimeToNextNotification();
150 
151  void ReinitializeContext();
152 
153  // loads plugins from directory for OpenMM BUT only once per unique path!
154  static void EnsurePluginsLoaded(const String& plugin_path);
155 
156  SystemPtr system_;
157  IntegratorPtr integrator_;
158  ContextPtr context_;
159  TopologyPtr top_;
160  std::vector<ObserverPtr> observers_;
161  std::vector<int> time_to_notify_;
162  std::map<FuncType,uint> system_force_mapper_;
164  ost::mol::AtomHandleList atom_list_;
165 };
166 
167 }}} //ns
168 
169 #endif
void ResetLJ(uint index, Real sigma, Real epsilon)
boost::shared_ptr< OpenMM::Context > ContextPtr
Definition: simulation.hh:52
void SetVelocities(geom::Vec3List &velocities)
geom::Vec3List GetForces()
void ResetHarmonicBond(uint index, Real bond_length, Real force_constant)
void ResetUreyBradleyAngle(uint index, Real angle, Real angle_force_constant, Real bond_length, Real bond_force_constant)
void Save(const String &filename)
std::string String
Definition: base.hh:54
float Real
Definition: base.hh:44
boost::shared_ptr< Topology > TopologyPtr
Definition: topology.hh:48
boost::shared_ptr< Simulation > SimulationPtr
Definition: simulation.hh:53
void AddPositionConstraints(const std::vector< uint > &index)
bool ApplySD(Real tolerance=100, int max_iterations=1000)
Protein or molecule.
void ResetPeriodicImproper(uint index, int multiplicity, Real phase, Real force_constant)
void ResetHarmonicAngle(uint index, Real angle, Real force_constant)
void ResetHarmonicImproper(uint index, Real phase, Real force_constant)
void ResetPeriodicDihedral(uint index, int multiplicity, Real phase, Real force_constant)
static SimulationPtr Load(const String &filename, SettingsPtr settings)
boost::shared_ptr< Settings > SettingsPtr
Definition: settings.hh:46
void Steps(int steps)
geom::Vec3List GetVelocities()
void ApplyLBFGS(Real tolerance=1, int max_iterations=1000)
void ResetMass(uint index, Real mass)
void ResetGBSA(uint index, Real radius, Real scaling)
ost::mol::EntityHandle GetEntity()
Definition: simulation.hh:72
boost::shared_ptr< OpenMM::System > SystemPtr
geom::Vec3 GetPeriodicBoxExtents()
Three dimensional vector class, using Real precision.
Definition: vec3.hh:43
void ResetDistanceConstraint(uint index, Real constraint_length)
boost::shared_ptr< OpenMM::Integrator > IntegratorPtr
Definition: simulation.hh:49
void UpdatePositions(bool enforce_periodic_box=false)
boost::shared_ptr< Observer > ObserverPtr
Definition: observer.hh:46
void AddPositionConstraint(uint index)
std::vector< AtomHandle > AtomHandleList
void ResetHarmonicPositionRestraint(uint index, const geom::Vec3 &ref_position, Real k, Real x_scale=1.0, Real y_scale=1.0, Real z_scale=1.0)
void ResetHarmonicDistanceRestraint(uint index, Real length, Real force_constant)
static bool IsPlatformAvailable(const SettingsPtr settings)
void Register(ObserverPtr o)
void ResetCharge(uint index, Real charge)
TopologyPtr GetTopology()
Definition: simulation.hh:96
void SetPeriodicBoxExtents(geom::Vec3 &vec)
geom::Vec3List GetPositions(bool enforce_periodic_box=false, bool in_angstrom=true)
void SetPositions(const geom::Vec3List &positions, bool in_angstrom=true)
unsigned int uint
Definition: base.hh:29
void ResetLJPair(uint index, Real sigma, Real epsilon)