OpenMMContextImpl.h 6.07 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
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef OPENMM_OPENMMCONTEXTIMPL_H_
#define OPENMM_OPENMMCONTEXTIMPL_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 "Kernel.h"
#include "Platform.h"
#include "Stream.h"
#include <map>
#include <vector>

namespace OpenMM {

class ForceImpl;
class Integrator;
class OpenMMContext;
class System;

/**
 * This is the internal implementation of an OpenMMContext.
 */

52
class OPENMM_EXPORT OpenMMContextImpl {
53
54
55
56
public:
    /**
     * Create an OpenMMContextImpl for an OpenMMContext;
     */
57
    OpenMMContextImpl(OpenMMContext& owner, System& system, Integrator& integrator, Platform* platform);
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    ~OpenMMContextImpl();
    /**
     * Get the OpenMMContext for which this is the implementation.
     */
    OpenMMContext& getOwner() {
        return owner;
    }
    /**
     * Get System being simulated in this context.
     */
    System& getSystem() {
        return system;
    }
    /**
     * Get Integrator being used to by this context.
     */
    Integrator& getIntegrator() {
        return integrator;
    }
    /**
     * Get the Platform implementation being used for computations.
     */
    Platform& getPlatform() {
        return *platform;
    }
    /**
Peter Eastman's avatar
Peter Eastman committed
84
     * Get the Stream containing the current position of each particle.
85
86
87
88
89
     */
    Stream& getPositions() {
        return positions;
    }
    /**
Peter Eastman's avatar
Peter Eastman committed
90
     * Get the Stream containing the current velocity of each particle.
91
92
93
94
95
     */
    Stream& getVelocities() {
        return velocities;
    }
    /**
Peter Eastman's avatar
Peter Eastman committed
96
     * Get the Stream containing the force on each particle that was calculated by
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
     * the most recent call to calcForces().
     */
    Stream& getForces() {
        return forces;
    }
    /**
     * Get the current time (in picoseconds).
     */
    double getTime() const {
        return time;
    }
    /**
     * Set the current time (in picoseconds).
     */
    void setTime(double t) {
        time = t;
    }
    /**
     * Get the value of an adjustable parameter.  If there is no parameter with the specified name, this
     * throws an exception.
     * 
     * @param name the name of the parameter to get
     */
    double getParameter(std::string name);
    /**
     * Set the value of an adjustable parameter.  If there is no parameter with the specified name, this
     * throws an exception.
     * 
     * @param name  the name of the parameter to set
     * @param value the value of the parameter
     */
    void setParameter(std::string name, double value);
    /**
     * Recalculate all of the forces in the system.  After calling this, use getForces() to retrieve
     * the forces that were calculated.
     */
    void calcForces();
    /**
135
     * Calculate the kinetic energy of the system (in kJ/mol).
136
137
138
     */
    double calcKineticEnergy();
    /**
139
     * Calculate the potential energy of the system (in kJ/mol).
140
141
142
143
144
145
146
147
148
149
150
     */
    double calcPotentialEnergy();
    /**
     * This should be called at the start of each time step.  It calls updateContextState() on each
     * ForceImpl in the system, allowing them to modify the values of state variables.
     */
    void updateContextState();
    /**
     * Delete all ForceImpl objects that have been created and create new ones.
     */
    void reinitialize();
151
152
153
154
155
156
157
158
    /**
     * Get the platform-specific data stored in this context.
     */
    void* getPlatformData();
    /**
     * Set the platform-specific data stored in this context.
     */
    void setPlatformData(void* data);
159
160
161
162
163
164
165
166
167
168
169
private:
    friend class OpenMMContext;
    OpenMMContext& owner;
    System& system;
    Integrator& integrator;
    std::vector<ForceImpl*> forceImpls;
    double time;
    std::map<std::string, double> parameters;
    Platform* platform;
    Stream positions, velocities, forces;
    Kernel kineticEnergyKernel;
170
    void* platformData;
171
172
173
174
175
};

} // namespace OpenMM

#endif /*OPENMM_OPENMMCONTEXTIMPL_H_*/