OpenMMContext.h 6.95 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef OPENMM_OPENMMCONTEXT_H_
#define OPENMM_OPENMMCONTEXT_H_

/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include "Integrator.h"
#include "State.h"
#include "System.h"
#include <string>
#include <vector>
40
#include "internal/windowsExport.h"
41
42
43
44
45

namespace OpenMM {

class OpenMMContextImpl;
class Vec3;
46
class Platform;
47
48
49
50
51
52

/**
 * An OpenMMContext stores the complete state of a simulation.  More specifically, it includes:
 * 
 * <ul>
 * <li>The current time</li>
Peter Eastman's avatar
Peter Eastman committed
53
54
 * <li>The position of each particle</li>
 * <li>The velocity of each particle</li>
55
56
57
58
59
60
 * <li>The values of configurable parameters defined by Force objects in the System</li>
 * </ul>
 * 
 * You can retrieve a snapshot of the current state at any time by calling getState().  This
 * allows you to record the state of the simulation at various points, either for analysis
 * or for checkpointing.  getState() can also be used to retrieve the current forces on each
Peter Eastman's avatar
Peter Eastman committed
61
 * particle and the current energy of the System.
62
63
 */

64
class OPENMM_EXPORT OpenMMContext {
65
66
67
68
69
70
71
72
public:
    /**
     * Construct a new OpenMMContext in which to run a simulation.
     * 
     * @param system      the System which will be simulated
     * @param integrator  the Integrator which will be used to simulate the System
     */
    OpenMMContext(System& system, Integrator& integrator);
73
74
75
76
77
78
79
80
81
    /**
     * Construct a new OpenMMContext in which to run a simulation, explicitly specifying what Platform should be used
     * to perform calculations.
     * 
     * @param system      the System which will be simulated
     * @param integrator  the Integrator which will be used to simulate the System
     * @param platform    the Platform to use for calculations
     */
    OpenMMContext(System& system, Integrator& integrator, Platform& platform);
82
    ~OpenMMContext();
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    /**
     * Get System being simulated in this context.
     */
    const System& getSystem() const;
    /**
     * Get System being simulated in this context.
     */
    System& getSystem();
    /**
     * Get Integrator being used to by this context.
     */
    const Integrator& getIntegrator() const;
    /**
     * Get Integrator being used to by this context.
     */
    Integrator& getIntegrator();
99
100
101
102
103
104
105
106
    /**
     * Get the Platform being used for calculations.
     */
    const Platform& getPlatform() const;
    /**
     * Get the Platform being used for calculations.
     */
    Platform& getPlatform();
107
108
109
110
111
112
    /**
     * Get a State object recording the current state information stored in this context.
     * 
     * @param types the set of data types which should be stored in the State object.  This
     * should be a union of DataType values, e.g. (State::Positions | State::Velocities).
     */
113
    State getState(int types) const;
114
115
116
117
118
119
120
121
122
    /**
     * Get the current time of the simulation (in picoseconds).
     */
    double getTime();
    /**
     * Set the current time of the simulation (in picoseconds).
     */
    void setTime(double time);
    /**
Peter Eastman's avatar
Peter Eastman committed
123
     * Set the positions of all particles in the System (measured in nm).
124
     * 
Peter Eastman's avatar
Peter Eastman committed
125
126
     * @param positions   a vector whose length equals the number of particles in the System.  The i'th element
     * contains the position of the i'th particle.
127
128
129
     */
    void setPositions(const std::vector<Vec3>& positions);
    /**
Peter Eastman's avatar
Peter Eastman committed
130
     * Set the velocities of all particles in the System (measured in nm/picosecond).
131
     * 
Peter Eastman's avatar
Peter Eastman committed
132
133
     * @param velocities  a vector whose length equals the number of particles in the System.  The i'th element
     * contains the velocity of the i'th particle.
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
     */
    void setVelocities(const std::vector<Vec3>& velocities);
    /**
     * Get the value of an adjustable parameter defined by a Force object in the System.
     * 
     * @param name the name of the parameter to get
     */
    double getParameter(std::string name);
    /**
     * Set the value of an adjustable parameter defined by a Force object in the System.
     * 
     * @param name  the name of the parameter to set
     * @param value the value of the parameter
     */
    void setParameter(std::string name, double value);
    /**
     * When an OpenMMContext is created, it may cache information about the System being simulated
     * and the Force objects contained in it.  This means that, if the System or Forces are then
     * modified, the OpenMMContext might not see all of the changes.  Call reinitialize() to force
     * the OpenMMContext to rebuild its internal representation of the System and pick up any changes
     * that have been made.
     * 
     * This is an expensive operation, so you should try to avoid calling it too frequently.
     */
    void reinitialize();
private:
    OpenMMContextImpl* impl;
};

} // namespace OpenMM

#endif /*OPENMM_OPENMMCONTEXT_H_*/