"vscode:/vscode.git/clone" did not exist on "fc48a467a7859616bf66607117cae93d5a4803f4"
ReferenceDynamics.cpp 8.83 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

/* Portions copyright (c) 2006 Stanford University and Simbios.
 * Contributors: Pande Group
 *
 * 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.
 */

25
#include <cstring>
26
27
#include <sstream>

28
#include "SimTKOpenMMUtilities.h"
29
30
#include "ReferenceDynamics.h"

31
32
#include <cstdio>

33
using std::vector;
34
using namespace OpenMM;
35

36

37
38
39
40
41
42
43
44
45
46
/**---------------------------------------------------------------------------------------

   ReferenceDynamics constructor

   @param numberOfAtoms  number of atoms
   @param deltaT         delta t for dynamics
   @param temperature    temperature

   --------------------------------------------------------------------------------------- */

47
ReferenceDynamics::ReferenceDynamics(int numberOfAtoms,  RealOpenMM deltaT, RealOpenMM temperature) : 
48
49
50
51
52
53
54
55
56
57
58
59
                  _numberOfAtoms(numberOfAtoms), _deltaT(deltaT), _temperature(temperature) {

   // ---------------------------------------------------------------------------------------

   // static const char* methodName = "\nReferenceDynamics::ReferenceDynamics";

   static const RealOpenMM one        =  1.0;

   // ---------------------------------------------------------------------------------------

   _timeStep             = 0;

60
61
   _ownReferenceConstraint = false;
   _referenceConstraint    = NULL;
62
63
64
65
66
67
68
69
}

/**---------------------------------------------------------------------------------------

   ReferenceDynamics destructor

   --------------------------------------------------------------------------------------- */

70
ReferenceDynamics::~ReferenceDynamics() {
71
72
73
74
75
76
77

   // ---------------------------------------------------------------------------------------

   // static const char* methodName = "\nReferenceDynamics::~ReferenceDynamics";

   // ---------------------------------------------------------------------------------------

78
   if (_ownReferenceConstraint) {
79
      delete _referenceConstraint;
80
81
82
83
84
85
86
87
88
89
90
   }
}

/**---------------------------------------------------------------------------------------

   Get number of atoms

   @return number of atoms

   --------------------------------------------------------------------------------------- */

91
int ReferenceDynamics::getNumberOfAtoms() const {
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

   // ---------------------------------------------------------------------------------------

   // static const char* methodName  = "\nReferenceDynamics::getNumberOfAtoms";

   // ---------------------------------------------------------------------------------------

   return _numberOfAtoms;
}

/**---------------------------------------------------------------------------------------

   Get time step

   @return time step

   --------------------------------------------------------------------------------------- */

110
int ReferenceDynamics::getTimeStep() const {
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

   // ---------------------------------------------------------------------------------------

   // static const char* methodName  = "\nReferenceDynamics::getTimeStep";

   // ---------------------------------------------------------------------------------------

   return _timeStep;
}

/**---------------------------------------------------------------------------------------

   Increment time step

   @return incremented time step

   --------------------------------------------------------------------------------------- */

129
int ReferenceDynamics::incrementTimeStep() {
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147

   // ---------------------------------------------------------------------------------------

   // static const char* methodName  = "\nReferenceDynamics::getTimeStep";

   // ---------------------------------------------------------------------------------------

   return (++_timeStep);
}

/**---------------------------------------------------------------------------------------

   Get delta t

   @return deltaT

   --------------------------------------------------------------------------------------- */

148
RealOpenMM ReferenceDynamics::getDeltaT() const {
149
150
151
152
153
154
155
156
157
158

   // ---------------------------------------------------------------------------------------

   // static const char* methodName  = "\nReferenceDynamics::getDeltaT";

   // ---------------------------------------------------------------------------------------

   return _deltaT;
}

159
160
161
162
163
164
/**---------------------------------------------------------------------------------------

   Set delta t

   --------------------------------------------------------------------------------------- */

165
void ReferenceDynamics::setDeltaT(RealOpenMM deltaT) {
166
167
168
169
170
171
172
173
174
175

   // ---------------------------------------------------------------------------------------

   // static const char* methodName  = "\nReferenceDynamics::setDeltaT";

   // ---------------------------------------------------------------------------------------

   _deltaT = deltaT;
}

176
177
178
179
180
181
182
183
/**---------------------------------------------------------------------------------------

   Get temperature

   @return temperature

   --------------------------------------------------------------------------------------- */

184
RealOpenMM ReferenceDynamics::getTemperature() const {
185
186
187
188
189
190
191
192
193
194
195
196

   // ---------------------------------------------------------------------------------------

   // static const char* methodName  = "\nReferenceDynamics::getTemperature";

   // ---------------------------------------------------------------------------------------

   return _temperature;
}

/**---------------------------------------------------------------------------------------

197
   Get ReferenceConstraint
198

199
   @return ReferenceConstraint  object
200
201
202

   --------------------------------------------------------------------------------------- */

203
ReferenceConstraintAlgorithm* ReferenceDynamics::getReferenceConstraintAlgorithm() const {
204
205
206

   // ---------------------------------------------------------------------------------------

207
   // static const char* methodName  = "\nReferenceDynamics::getReferenceConstraint";
208
209
210

   // ---------------------------------------------------------------------------------------

211
   return _referenceConstraint;
212
213
214
215
}

/**---------------------------------------------------------------------------------------

216
   Set ReferenceConstraint
217

218
   @param referenceConstraint  ReferenceConstraint object
219
220
221

   --------------------------------------------------------------------------------------- */

222
void ReferenceDynamics::setReferenceConstraintAlgorithm(ReferenceConstraintAlgorithm* referenceConstraint) {
223
224
225

   // ---------------------------------------------------------------------------------------

226
   // static const char* methodName  = "\nReferenceDynamics::setReferenceConstraint";
227
228
229
230
231

   // ---------------------------------------------------------------------------------------

   // delete if own

232
   if (_referenceConstraint && _ownReferenceConstraint) {
233
      delete _referenceConstraint;
234
235
   }

236
237
   _referenceConstraint = referenceConstraint;
   _ownReferenceConstraint = 0;
238
239
240
241
}

/**---------------------------------------------------------------------------------------

242
   Update -- driver routine for performing dynamics update of coordinates
243
244
   and velocities

245
   @param system              the System to be integrated
246
247
248
249
   @param atomCoordinates     atom coordinates
   @param velocities          velocities
   @param forces              forces
   @param masses              atom masses
250
   @param tolerance           the constraint tolerance
251
252
253

   --------------------------------------------------------------------------------------- */

254
void ReferenceDynamics::update(const OpenMM::System& system, vector<RealVec>& atomCoordinates,
255
                               vector<RealVec>& velocities, vector<RealVec>& forces, vector<RealOpenMM>& masses, RealOpenMM tolerance) {
256
257
258
259
260
261
262
263
264
265

   // ---------------------------------------------------------------------------------------

   static const char* methodName      = "\nReferenceDynamics::update";

   static const RealOpenMM zero       =  0.0;
   static const RealOpenMM one        =  1.0;

   // ---------------------------------------------------------------------------------------
}