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.openmm;
39
40 import com.sun.jna.Memory;
41 import com.sun.jna.Pointer;
42 import com.sun.jna.ptr.PointerByReference;
43
44 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_destroy;
45 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_findPlatform;
46 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getDefaultPluginsDirectory;
47 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getName;
48 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getNumPlatforms;
49 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getOpenMMVersion;
50 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPlatform;
51 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPlatformByName;
52 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPlatform_1;
53 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPluginLoadFailures;
54 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPropertyDefaultValue;
55 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPropertyNames;
56 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getPropertyValue;
57 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_getSpeed;
58 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_loadPluginLibrary;
59 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_loadPluginsFromDirectory;
60 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_registerPlatform;
61 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_setPropertyDefaultValue;
62 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_setPropertyValue;
63 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_supportsDoublePrecision;
64 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Platform_supportsKernels;
65
66
67
68
69
70
71
72 public class Platform {
73
74
75
76
77 private PointerByReference pointer;
78
79
80
81
82
83
84 public Platform(PointerByReference pointer) {
85 this.pointer = pointer;
86 }
87
88
89
90
91
92
93 public Platform(String platformName) {
94 pointer = OpenMM_Platform_getPlatformByName(platformName);
95 }
96
97
98
99
100 public Platform() {
101 pointer = null;
102 }
103
104
105
106
107 public void destroy() {
108 if (pointer != null) {
109 OpenMM_Platform_destroy(pointer);
110 pointer = null;
111 }
112 }
113
114
115
116
117
118
119
120 public static Platform findPlatform(StringArray kernelNames) {
121 PointerByReference platformPointer = OpenMM_Platform_findPlatform(kernelNames.getPointer());
122 return new Platform(platformPointer);
123 }
124
125
126
127
128
129
130 public static String getDefaultPluginsDirectory() {
131 Pointer directory = OpenMM_Platform_getDefaultPluginsDirectory();
132 return directory.getString(0);
133 }
134
135
136
137
138
139
140 public String getName() {
141 Pointer name = OpenMM_Platform_getName(pointer);
142 return name.getString(0);
143 }
144
145
146
147
148
149
150 public static int getNumPlatforms() {
151 return OpenMM_Platform_getNumPlatforms();
152 }
153
154
155
156
157
158
159 public static String getOpenMMVersion() {
160 Pointer version = OpenMM_Platform_getOpenMMVersion();
161 return version.getString(0);
162 }
163
164
165
166
167
168
169 public PointerByReference getPointer() {
170 return pointer;
171 }
172
173
174
175
176
177
178
179 public static Platform getPlatform(int index) {
180 PointerByReference platformPointer = OpenMM_Platform_getPlatform(index);
181 return new Platform(platformPointer);
182 }
183
184
185
186
187
188
189
190 public static Platform getPlatform_1(String name) {
191 PointerByReference platformPointer = OpenMM_Platform_getPlatform_1(name);
192 return new Platform(platformPointer);
193 }
194
195
196
197
198
199
200 public static StringArray getPluginLoadFailures() {
201 return new StringArray(OpenMM_Platform_getPluginLoadFailures());
202 }
203
204
205
206
207
208
209
210 public String getPropertyDefaultValue(String property) {
211 Pointer propertyPointer = pointerForString(property);
212 Pointer value = OpenMM_Platform_getPropertyDefaultValue(pointer, propertyPointer);
213 if (value == null) {
214 return null;
215 }
216 return value.getString(0);
217 }
218
219
220
221
222
223
224 public StringArray getPropertyNames() {
225 return new StringArray(OpenMM_Platform_getPropertyNames(pointer));
226 }
227
228
229
230
231
232
233
234
235 public String getPropertyValue(Context context, String property) {
236 Pointer propertyPointer = pointerForString(property);
237 Pointer value = OpenMM_Platform_getPropertyValue(pointer, context.getPointer(), propertyPointer);
238 if (value == null) {
239 return null;
240 }
241 return value.getString(0);
242 }
243
244
245
246
247
248
249 public double getSpeed() {
250 return OpenMM_Platform_getSpeed(pointer);
251 }
252
253
254
255
256
257
258
259 public static StringArray loadPluginsFromDirectory(String directory) {
260 return new StringArray(OpenMM_Platform_loadPluginsFromDirectory(directory));
261 }
262
263
264
265
266
267
268 public static void loadPluginLibrary(String file) {
269 OpenMM_Platform_loadPluginLibrary(file);
270 }
271
272
273
274
275
276
277 public static void registerPlatform(Platform platform) {
278 OpenMM_Platform_registerPlatform(platform.getPointer());
279 }
280
281
282
283
284
285
286
287 public void setPropertyDefaultValue(String property, String value) {
288 Pointer propertyPointer = pointerForString(property);
289 Pointer valuePointer = pointerForString(value);
290 OpenMM_Platform_setPropertyDefaultValue(pointer, propertyPointer, valuePointer);
291 }
292
293
294
295
296
297
298
299
300 public void setPropertyValue(Context context, String property, String value) {
301 Pointer propertyPointer = pointerForString(property);
302 Pointer valuePointer = pointerForString(value);
303 OpenMM_Platform_setPropertyValue(pointer, context.getPointer(), propertyPointer, valuePointer);
304 }
305
306
307
308
309
310
311 public boolean supportsDoublePrecision() {
312 int result = OpenMM_Platform_supportsDoublePrecision(pointer);
313 return result != 0;
314 }
315
316
317
318
319
320
321
322 public boolean supportsKernels(StringArray kernelNames) {
323 int result = OpenMM_Platform_supportsKernels(pointer, kernelNames.getPointer());
324 return result != 0;
325 }
326
327
328
329
330
331
332
333 private static Pointer pointerForString(String string) {
334 Pointer pointer = new Memory(string.length() + 1);
335 pointer.setString(0, string);
336 return pointer;
337 }
338 }