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 package ffx.potential;
39
40 import java.util.Arrays;
41
42 import static ffx.utilities.Constants.KCAL_TO_GRAM_ANG2_PER_PS2;
43 import static java.lang.System.arraycopy;
44
45
46
47
48 public class SystemState {
49
50
51
52
53 protected final int numberOfVariables;
54
55
56
57 protected final double[] x;
58
59
60
61 protected final double[] v;
62
63
64
65 protected final double[] a;
66
67
68
69 protected final double[] aPrevious;
70
71
72
73 protected final double[] gradient;
74
75
76
77 protected final double[] mass;
78
79
80
81 double temperature;
82
83
84
85 double kineticEnergy;
86
87
88
89 double potentialEnergy;
90
91
92
93
94
95
96 public SystemState(int numberOfVariables) {
97 this.numberOfVariables = numberOfVariables;
98 x = new double[numberOfVariables];
99 v = new double[numberOfVariables];
100 a = new double[numberOfVariables];
101 aPrevious = new double[numberOfVariables];
102 gradient = new double[numberOfVariables];
103 mass = new double[numberOfVariables];
104 }
105
106
107
108
109 public UnmodifiableState getUnmodifiableState() {
110 return new UnmodifiableState(x, v, a, aPrevious, mass, gradient, kineticEnergy,
111 potentialEnergy, temperature);
112 }
113
114
115
116
117
118
119 public int getNumberOfVariables() {
120 return numberOfVariables;
121 }
122
123
124
125
126
127
128 public void revertState(UnmodifiableState state) {
129 assert (state.x().length == numberOfVariables);
130 arraycopy(state.x(), 0, x, 0, numberOfVariables);
131 arraycopy(state.v(), 0, v, 0, numberOfVariables);
132 arraycopy(state.a(), 0, a, 0, numberOfVariables);
133 arraycopy(state.aPrevious(), 0, aPrevious, 0, numberOfVariables);
134 arraycopy(state.mass(), 0, mass, 0, numberOfVariables);
135 arraycopy(state.gradient(), 0, gradient, 0, numberOfVariables);
136 kineticEnergy = state.kineticEnergy();
137 potentialEnergy = state.potentialEnergy();
138 temperature = state.temperature();
139 }
140
141
142
143
144
145
146 public void setMass(double[] mass) {
147 assert (mass.length == numberOfVariables);
148 arraycopy(mass, 0, this.mass, 0, numberOfVariables);
149 }
150
151
152
153
154
155
156 public void setCoordinates(double[] x) {
157 assert (x.length == numberOfVariables);
158 arraycopy(x, 0, this.x, 0, numberOfVariables);
159 }
160
161
162
163
164
165
166 public void setVelocities(double[] v) {
167 assert (v.length == numberOfVariables);
168 arraycopy(v, 0, this.v, 0, numberOfVariables);
169 }
170
171
172
173
174
175
176 public void setAccelerations(double[] a) {
177 assert (a.length == numberOfVariables);
178 arraycopy(a, 0, this.a, 0, numberOfVariables);
179 }
180
181
182
183
184
185
186 public void setPreviousAccelerations(double[] aPrevious) {
187 assert (aPrevious.length == numberOfVariables);
188 arraycopy(aPrevious, 0, this.aPrevious, 0, numberOfVariables);
189 }
190
191
192
193
194
195
196 public double[] x() {
197 return x;
198 }
199
200
201
202
203
204
205 public double[] v() {
206 return v;
207 }
208
209
210
211
212
213
214 public double[] a() {
215 return a;
216 }
217
218
219
220
221
222
223 public double[] aPrevious() {
224 return aPrevious;
225 }
226
227
228
229
230
231
232 public double[] getMass() {
233 return mass;
234 }
235
236
237
238
239
240
241 public double[] gradient() {
242 return gradient;
243 }
244
245
246
247
248
249
250 public double[] getCoordinatesCopy() {
251 return Arrays.copyOf(x, numberOfVariables);
252 }
253
254
255
256
257 public void copyAccelerationsToPrevious() {
258 arraycopy(a, 0, aPrevious, 0, numberOfVariables);
259 }
260
261
262
263
264
265
266 public void setTemperature(double temperature) {
267 this.temperature = temperature;
268 }
269
270
271
272
273
274
275 public void setKineticEnergy(double kineticEnergy) {
276 this.kineticEnergy = kineticEnergy;
277 }
278
279
280
281
282
283
284 public void setPotentialEnergy(double potentialEnergy) {
285 this.potentialEnergy = potentialEnergy;
286 }
287
288
289
290
291 public double getTemperature() {
292 return temperature;
293 }
294
295
296
297
298 public double getKineticEnergy() {
299 return kineticEnergy;
300 }
301
302
303
304
305 public double getPotentialEnergy() {
306 return potentialEnergy;
307 }
308
309
310
311
312 public double getTotalEnergy() {
313 return kineticEnergy + potentialEnergy;
314 }
315
316
317
318
319
320
321 public double getKineticEnergyFromVelocities() {
322 double e = 0.0;
323 for (int i = 0; i < numberOfVariables; i++) {
324 double m = mass[i];
325 if (m > 0.0) {
326 double velocity = v[i];
327 double v2 = velocity * velocity;
328 e += m * v2;
329 }
330 }
331 e *= 0.5 / KCAL_TO_GRAM_ANG2_PER_PS2;
332 return e;
333 }
334
335 }