1
"""
2
Tests the restraints utilities.
3
"""
4

5 2
import os
6

7 2
import pytest
8

9 2
from paprika.restraints.restraints import *
10 2
from paprika.restraints.utils import *
11

12 2
logger = logging.getLogger(__name__)
13

14

15 2
def test_DAT_restraint():
16
    # Method 1
17 2
    logger.info("### Testing restraint 1, Method 1")
18 2
    rest1 = DAT_restraint()
19 2
    rest1.amber_index = True
20 2
    rest1.continuous_apr = False
21 2
    rest1.auto_apr = False
22 2
    rest1.topology = os.path.join(
23
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
24
    )
25 2
    rest1.mask1 = ":CB6@O,O2,O4,O6,O8,O10"
26 2
    rest1.mask2 = ":BUT@C3"
27 2
    rest1.attach["target"] = 3.0
28 2
    rest1.attach["num_windows"] = 4
29 2
    rest1.attach["fc_initial"] = 0.0
30 2
    rest1.attach["fc_final"] = 3.0
31 2
    rest1.pull["fc"] = rest1.attach["fc_final"]
32 2
    rest1.pull["num_windows"] = 4
33 2
    rest1.pull["target_initial"] = rest1.attach["target"]
34 2
    rest1.pull["target_final"] = 6.0
35 2
    rest1.release["target"] = rest1.pull["target_final"]
36 2
    rest1.release["num_windows"] = rest1.attach["num_windows"]
37 2
    rest1.release["fc_initial"] = rest1.attach["fc_initial"]
38 2
    rest1.release["fc_final"] = rest1.attach["fc_final"]
39 2
    rest1.initialize()
40 2
    assert rest1.index1 == [13, 31, 49, 67, 85, 103]
41 2
    assert rest1.index2 == [119]
42 2
    assert rest1.index3 == None
43 2
    assert rest1.index4 == None
44 2
    assert np.allclose(
45
        rest1.phase["attach"]["force_constants"], np.array([0.0, 1.0, 2.0, 3.0])
46
    )
47 2
    assert np.allclose(rest1.phase["attach"]["targets"], np.array([3.0, 3.0, 3.0, 3.0]))
48 2
    assert np.allclose(
49
        rest1.phase["pull"]["force_constants"], np.array([3.0, 3.0, 3.0, 3.0])
50
    )
51 2
    assert np.allclose(rest1.phase["pull"]["targets"], np.array([3.0, 4.0, 5.0, 6.0]))
52 2
    assert np.allclose(
53
        rest1.phase["release"]["force_constants"], np.array([0.0, 1.0, 2.0, 3.0])
54
    )
55 2
    assert np.allclose(
56
        rest1.phase["release"]["targets"], np.array([6.0, 6.0, 6.0, 6.0])
57
    )
58 2
    window_list = create_window_list([rest1])
59 2
    assert window_list == [
60
        "a000",
61
        "a001",
62
        "a002",
63
        "a003",
64
        "p000",
65
        "p001",
66
        "p002",
67
        "p003",
68
        "r000",
69
        "r001",
70
        "r002",
71
        "r003",
72
    ]
73

74
    # Method 1a
75 2
    logger.info("### Testing restraint 2, Method 1a")
76 2
    rest2 = DAT_restraint()
77 2
    rest2.amber_index = True
78 2
    rest2.continuous_apr = False
79 2
    rest2.auto_apr = False
80 2
    rest2.topology = os.path.join(
81
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
82
    )
83 2
    rest2.mask1 = ":CB6@O,O2,O4,O6,O8,O10"
84 2
    rest2.mask2 = ":BUT@C3"
85 2
    rest2.mask3 = ":BUT@C"
86 2
    rest2.attach["target"] = 180.0
87 2
    rest2.attach["num_windows"] = 4
88 2
    rest2.attach["fc_final"] = 75.0
89 2
    rest2.pull["fc"] = rest2.attach["fc_final"]
90 2
    rest2.pull["num_windows"] = 4
91 2
    rest2.pull["target_final"] = 180.0
92 2
    rest2.release["target"] = rest2.pull["target_final"]
93 2
    rest2.release["num_windows"] = rest2.attach["num_windows"]
94 2
    rest2.release["fc_final"] = rest2.attach["fc_final"]
95 2
    rest2.initialize()
96 2
    assert rest2.index1 == [13, 31, 49, 67, 85, 103]
97 2
    assert rest2.index2 == [119]
98 2
    assert rest2.index3 == [109]
99 2
    assert rest2.index4 == None
100 2
    assert np.allclose(
101
        rest2.phase["attach"]["force_constants"], np.array([0.0, 25.0, 50.0, 75.0])
102
    )
103 2
    assert np.allclose(
104
        rest2.phase["attach"]["targets"], np.array([180.0, 180.0, 180.0, 180.0])
105
    )
106 2
    assert np.allclose(
107
        rest2.phase["pull"]["force_constants"], np.array([75.0, 75.0, 75.0, 75.0])
108
    )
109 2
    assert np.allclose(
110
        rest2.phase["pull"]["targets"], np.array([0.0, 60.0, 120.0, 180.0])
111
    )
112 2
    assert np.allclose(
113
        rest2.phase["release"]["force_constants"], np.array([0.0, 25.0, 50.0, 75.0])
114
    )
115 2
    assert np.allclose(
116
        rest2.phase["release"]["targets"], np.array([180.0, 180.0, 180.0, 180.0])
117
    )
118 2
    window_list = create_window_list([rest2])
119 2
    assert window_list == [
120
        "a000",
121
        "a001",
122
        "a002",
123
        "a003",
124
        "p000",
125
        "p001",
126
        "p002",
127
        "p003",
128
        "r000",
129
        "r001",
130
        "r002",
131
        "r003",
132
    ]
133

134
    # Method 2 (Note auto_apr = True)
135 2
    logger.info("### Testing restraint 3, Method 2")
136 2
    rest3 = DAT_restraint()
137 2
    rest3.amber_index = True
138 2
    rest3.continuous_apr = False
139 2
    rest3.auto_apr = True
140 2
    rest3.topology = os.path.join(
141
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
142
    )
143 2
    rest3.mask1 = ":CB6@O2"
144 2
    rest3.mask2 = ":CB6@O"
145 2
    rest3.mask3 = ":BUT@C3"
146 2
    rest3.mask4 = ":BUT@C"
147 2
    rest3.attach["target"] = 90.0
148 2
    rest3.attach["fc_increment"] = 25.0
149 2
    rest3.attach["fc_initial"] = 0.0
150 2
    rest3.attach["fc_final"] = 75.0
151 2
    rest3.pull["target_increment"] = 1.0
152 2
    rest3.pull["target_final"] = 93.0
153 2
    rest3.release["fc_final"] = 75.0
154 2
    rest3.initialize()
155 2
    assert rest3.index1 == [31]
156 2
    assert rest3.index2 == [13]
157 2
    assert rest3.index3 == [119]
158 2
    assert rest3.index4 == [109]
159 2
    assert np.allclose(
160
        rest3.phase["attach"]["force_constants"], np.array([0.0, 25.0, 50.0, 75.0])
161
    )
162 2
    assert np.allclose(
163
        rest3.phase["attach"]["targets"], np.array([90.0, 90.0, 90.0, 90.0])
164
    )
165 2
    assert np.allclose(
166
        rest3.phase["pull"]["force_constants"], np.array([75.0, 75.0, 75.0, 75.0])
167
    )
168 2
    assert np.allclose(
169
        rest3.phase["pull"]["targets"], np.array([90.0, 91.0, 92.0, 93.0])
170
    )
171 2
    assert np.allclose(
172
        rest3.phase["release"]["force_constants"], np.array([0.0, 25.0, 50.0, 75.0])
173
    )
174 2
    assert np.allclose(
175
        rest3.phase["release"]["targets"], np.array([93.0, 93.0, 93.0, 93.0])
176
    )
177 2
    window_list = create_window_list([rest3])
178 2
    assert window_list == [
179
        "a000",
180
        "a001",
181
        "a002",
182
        "a003",
183
        "p000",
184
        "p001",
185
        "p002",
186
        "p003",
187
        "r000",
188
        "r001",
189
        "r002",
190
        "r003",
191
    ]
192

193
    # Method 2a
194 2
    logger.info("### Testing restraint 4, Method 2a")
195 2
    rest4 = DAT_restraint()
196 2
    rest4.amber_index = True
197 2
    rest4.continuous_apr = False
198 2
    rest4.auto_apr = False
199 2
    rest4.topology = os.path.join(
200
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
201
    )
202 2
    rest4.mask1 = ":CB6@O2"
203 2
    rest4.mask2 = ":CB6@O"
204 2
    rest4.mask3 = ":BUT@C3"
205 2
    rest4.mask4 = ":BUT@C"
206 2
    rest4.attach["target"] = 0.0
207 2
    rest4.attach["fc_increment"] = 25.0
208 2
    rest4.attach["fc_final"] = 75.0
209 2
    rest4.pull["fc"] = 75.0
210 2
    rest4.pull["target_increment"] = 1.0
211 2
    rest4.pull["target_final"] = 3.0
212 2
    rest4.release["target"] = 3.0
213 2
    rest4.release["fc_increment"] = 25.0
214 2
    rest4.release["fc_final"] = 75.0
215 2
    rest4.initialize()
216 2
    assert rest4.index1 == [31]
217 2
    assert rest4.index2 == [13]
218 2
    assert rest4.index3 == [119]
219 2
    assert rest4.index4 == [109]
220 2
    assert np.allclose(
221
        rest4.phase["attach"]["force_constants"], np.array([0.0, 25.0, 50.0, 75.0])
222
    )
223 2
    assert np.allclose(rest4.phase["attach"]["targets"], np.array([0.0, 0.0, 0.0, 0.0]))
224 2
    assert np.allclose(
225
        rest4.phase["pull"]["force_constants"], np.array([75.0, 75.0, 75.0, 75.0])
226
    )
227 2
    assert np.allclose(rest4.phase["pull"]["targets"], np.array([0.0, 1.0, 2.0, 3.0]))
228 2
    assert np.allclose(
229
        rest4.phase["release"]["force_constants"], np.array([0.0, 25.0, 50.0, 75.0])
230
    )
231 2
    assert np.allclose(
232
        rest4.phase["release"]["targets"], np.array([3.0, 3.0, 3.0, 3.0])
233
    )
234 2
    window_list = create_window_list([rest4])
235 2
    assert window_list == [
236
        "a000",
237
        "a001",
238
        "a002",
239
        "a003",
240
        "p000",
241
        "p001",
242
        "p002",
243
        "p003",
244
        "r000",
245
        "r001",
246
        "r002",
247
        "r003",
248
    ]
249

250
    # Method 3
251 2
    logger.info("### Testing restraint 5, Method 3")
252 2
    rest5 = DAT_restraint()
253 2
    rest5.amber_index = True
254 2
    rest5.continuous_apr = False
255 2
    rest5.auto_apr = False
256 2
    rest5.topology = os.path.join(
257
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
258
    )
259 2
    rest5.mask1 = ":CB6@O,O2,O4,O6,O8,O10"
260 2
    rest5.mask2 = ":BUT@C*"
261 2
    rest5.attach["target"] = 0.0
262 2
    rest5.attach["fraction_list"] = [0.0, 0.2, 0.5, 1.0]
263 2
    rest5.attach["fc_final"] = 5.0
264 2
    rest5.pull["fc"] = rest5.attach["fc_final"]
265 2
    rest5.pull["fraction_list"] = [0.0, 0.5, 1.0]
266 2
    rest5.pull["target_final"] = 1.0
267 2
    rest5.release["target"] = rest5.pull["target_final"]
268 2
    rest5.release["fraction_list"] = [0.0, 0.3, 0.6, 1.0]
269 2
    rest5.release["fc_final"] = rest5.attach["fc_final"]
270 2
    rest5.initialize()
271 2
    assert rest5.index1 == [13, 31, 49, 67, 85, 103]
272 2
    assert rest5.index2 == [109, 113, 115, 119]
273 2
    assert rest5.index3 == None
274 2
    assert rest5.index4 == None
275 2
    assert np.allclose(
276
        rest5.phase["attach"]["force_constants"], np.array([0.0, 1.0, 2.5, 5.0])
277
    )
278 2
    assert np.allclose(rest5.phase["attach"]["targets"], np.array([0.0, 0.0, 0.0, 0.0]))
279 2
    assert np.allclose(
280
        rest5.phase["pull"]["force_constants"], np.array([5.0, 5.0, 5.0])
281
    )
282 2
    assert np.allclose(rest5.phase["pull"]["targets"], np.array([0.0, 0.5, 1.0]))
283 2
    assert np.allclose(
284
        rest5.phase["release"]["force_constants"], np.array([0.0, 1.5, 3.0, 5.0])
285
    )
286 2
    assert np.allclose(
287
        rest5.phase["release"]["targets"], np.array([1.0, 1.0, 1.0, 1.0])
288
    )
289 2
    window_list = create_window_list([rest5])
290 2
    assert window_list == [
291
        "a000",
292
        "a001",
293
        "a002",
294
        "a003",
295
        "p000",
296
        "p001",
297
        "p002",
298
        "r000",
299
        "r001",
300
        "r002",
301
        "r003",
302
    ]
303

304
    # Method 4
305 2
    logger.info("### Testing restraint 6, Method 4")
306 2
    rest6 = DAT_restraint()
307 2
    rest6.amber_index = True
308 2
    rest6.continuous_apr = False
309 2
    rest6.auto_apr = False
310 2
    rest6.topology = os.path.join(
311
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
312
    )
313 2
    rest6.mask1 = ":CB6@O,O2,O4,O6,O8,O10"
314 2
    rest6.mask2 = ":BUT@C*"
315 2
    rest6.attach["target"] = 0.0
316 2
    rest6.attach["fraction_increment"] = 0.25
317 2
    rest6.attach["fc_final"] = 5.0
318 2
    rest6.pull["fc"] = rest6.attach["fc_final"]
319 2
    rest6.pull["fraction_increment"] = 0.5
320 2
    rest6.pull["target_final"] = 1.0
321 2
    rest6.release["target"] = rest6.pull["target_final"]
322 2
    rest6.release["fraction_increment"] = 0.33
323 2
    rest6.release["fc_final"] = rest6.attach["fc_final"]
324 2
    rest6.initialize()
325 2
    assert rest6.index1 == [13, 31, 49, 67, 85, 103]
326 2
    assert rest6.index2 == [109, 113, 115, 119]
327 2
    assert rest6.index3 == None
328 2
    assert rest6.index4 == None
329 2
    assert np.allclose(
330
        rest6.phase["attach"]["force_constants"], np.array([0.0, 1.25, 2.5, 3.75, 5.0])
331
    )
332 2
    assert np.allclose(
333
        rest6.phase["attach"]["targets"], np.array([0.0, 0.0, 0.0, 0.0, 0.0])
334
    )
335 2
    assert np.allclose(
336
        rest6.phase["pull"]["force_constants"], np.array([5.0, 5.0, 5.0])
337
    )
338 2
    assert np.allclose(rest6.phase["pull"]["targets"], np.array([0.0, 0.5, 1.0]))
339
    ### Note, the 6.6 in the following test is wrong ... needs to get fixed.
340 2
    assert np.allclose(
341
        rest6.phase["release"]["force_constants"], np.array([0.0, 1.65, 3.3, 4.95, 6.6])
342
    )
343 2
    assert np.allclose(
344
        rest6.phase["release"]["targets"], np.array([1.0, 1.0, 1.0, 1.0, 1.0])
345
    )
346 2
    window_list = create_window_list([rest6])
347 2
    assert window_list == [
348
        "a000",
349
        "a001",
350
        "a002",
351
        "a003",
352
        "a004",
353
        "p000",
354
        "p001",
355
        "p002",
356
        "r000",
357
        "r001",
358
        "r002",
359
        "r003",
360
        "r004",
361
    ]
362

363
    # Method 5 (Note continuous_apr = True)
364 2
    logger.info("### Testing restraint 7, Method 5")
365 2
    rest7 = DAT_restraint()
366 2
    rest7.amber_index = True
367 2
    rest7.continuous_apr = True
368 2
    rest7.auto_apr = False
369 2
    rest7.topology = os.path.join(
370
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
371
    )
372 2
    rest7.mask1 = ":1@O,O1,:BUT@H1"
373 2
    rest7.mask2 = ":CB6@N"
374 2
    rest7.attach["target"] = 0.0
375 2
    rest7.attach["fc_list"] = [0.0, 0.5, 1.0, 2.0]
376 2
    rest7.pull["fc"] = 2.0
377 2
    rest7.pull["target_list"] = [0.0, 0.5, 1.0, 1.5]
378 2
    rest7.release["target"] = 1.5
379 2
    rest7.release["fc_list"] = [0.0, 0.66, 1.2, 2.0]
380 2
    rest7.initialize()
381 2
    assert rest7.index1 == [13, 14, 111]
382 2
    assert rest7.index2 == [3]
383 2
    assert rest7.index3 == None
384 2
    assert rest7.index4 == None
385 2
    assert np.allclose(
386
        rest7.phase["attach"]["force_constants"], np.array([0.0, 0.5, 1.0, 2.0])
387
    )
388 2
    assert np.allclose(rest7.phase["attach"]["targets"], np.array([0.0, 0.0, 0.0, 0.0]))
389 2
    assert np.allclose(
390
        rest7.phase["pull"]["force_constants"], np.array([2.0, 2.0, 2.0, 2.0])
391
    )
392 2
    assert np.allclose(rest7.phase["pull"]["targets"], np.array([0.0, 0.5, 1.0, 1.5]))
393 2
    assert np.allclose(
394
        rest7.phase["release"]["force_constants"], np.array([0.0, 0.66, 1.2, 2.0])
395
    )
396 2
    assert np.allclose(
397
        rest7.phase["release"]["targets"], np.array([1.5, 1.5, 1.5, 1.5])
398
    )
399 2
    window_list = create_window_list([rest7])
400 2
    assert window_list == [
401
        "a000",
402
        "a001",
403
        "a002",
404
        "p000",
405
        "p001",
406
        "p002",
407
        "p003",
408
        "r001",
409
        "r002",
410
        "r003",
411
    ]
412

413
    # Just Attach
414 2
    logger.info("### Testing restraint 8, just attach")
415 2
    rest8 = DAT_restraint()
416 2
    rest8.amber_index = True
417 2
    rest8.continuous_apr = False
418 2
    rest8.auto_apr = False
419 2
    rest8.topology = os.path.join(
420
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
421
    )
422 2
    rest8.mask1 = ":CB6@O"
423 2
    rest8.mask2 = ":BUT@C3"
424 2
    rest8.attach["target"] = 0.0
425 2
    rest8.attach["num_windows"] = 4
426 2
    rest8.attach["fc_initial"] = 0.0
427 2
    rest8.attach["fc_final"] = 3.0
428 2
    rest8.initialize()
429 2
    assert rest8.index1 == [13]
430 2
    assert rest8.index2 == [119]
431 2
    assert rest8.index3 == None
432 2
    assert rest8.index4 == None
433 2
    assert np.allclose(
434
        rest8.phase["attach"]["force_constants"], np.array([0.0, 1.0, 2.0, 3.0])
435
    )
436 2
    assert np.allclose(rest8.phase["attach"]["targets"], np.array([0.0, 0.0, 0.0, 0.0]))
437 2
    assert rest8.phase["pull"]["force_constants"] == None
438 2
    assert rest8.phase["pull"]["targets"] == None
439 2
    assert rest8.phase["release"]["force_constants"] == None
440 2
    assert rest8.phase["release"]["targets"] == None
441 2
    window_list = create_window_list([rest8])
442 2
    assert window_list == ["a000", "a001", "a002", "a003"]
443

444
    # Just Pull
445 2
    logger.info("### Testing restraint 9, just pull")
446 2
    rest9 = DAT_restraint()
447 2
    rest9.amber_index = True
448 2
    rest9.continuous_apr = False
449 2
    rest9.auto_apr = False
450 2
    rest9.topology = os.path.join(
451
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
452
    )
453 2
    rest9.mask1 = ":CB6@O"
454 2
    rest9.mask2 = ":BUT@C3"
455 2
    rest9.pull["fc"] = 3.0
456 2
    rest9.pull["num_windows"] = 4
457 2
    rest9.pull["target_initial"] = 0.0
458 2
    rest9.pull["target_final"] = 3.0
459 2
    rest9.initialize()
460 2
    assert rest9.index1 == [13]
461 2
    assert rest9.index2 == [119]
462 2
    assert rest9.index3 == None
463 2
    assert rest9.index4 == None
464 2
    assert rest9.phase["attach"]["force_constants"] == None
465 2
    assert rest9.phase["attach"]["targets"] == None
466 2
    assert np.allclose(
467
        rest9.phase["pull"]["force_constants"], np.array([3.0, 3.0, 3.0, 3.0])
468
    )
469 2
    assert np.allclose(rest9.phase["pull"]["targets"], np.array([0.0, 1.0, 2.0, 3.0]))
470 2
    assert rest9.phase["release"]["force_constants"] == None
471 2
    assert rest9.phase["release"]["targets"] == None
472 2
    window_list = create_window_list([rest9])
473 2
    assert window_list == ["p000", "p001", "p002", "p003"]
474

475
    # Just Release
476 2
    logger.info("### Testing restraint 10, just release")
477 2
    rest10 = DAT_restraint()
478 2
    rest10.amber_index = True
479 2
    rest10.continuous_apr = False
480 2
    rest10.auto_apr = False
481 2
    rest10.topology = os.path.join(
482
        os.path.dirname(__file__), "../data/cb6-but/cb6-but-notcentered.pdb"
483
    )
484 2
    rest10.mask1 = ":CB6@O"
485 2
    rest10.mask2 = ":BUT@C3"
486 2
    rest10.release["target"] = 0.0
487 2
    rest10.release["num_windows"] = 3
488 2
    rest10.release["fc_initial"] = 0.0
489 2
    rest10.release["fc_final"] = 2.0
490 2
    rest10.initialize()
491 2
    assert rest10.index1 == [13]
492 2
    assert rest10.index2 == [119]
493 2
    assert rest10.index3 == None
494 2
    assert rest10.index4 == None
495 2
    assert rest10.phase["attach"]["force_constants"] == None
496 2
    assert rest10.phase["attach"]["targets"] == None
497 2
    assert rest10.phase["pull"]["force_constants"] == None
498 2
    assert rest10.phase["pull"]["targets"] == None
499 2
    assert np.allclose(
500
        rest10.phase["release"]["force_constants"], np.array([0.0, 1.0, 2.0])
501
    )
502 2
    assert np.allclose(rest10.phase["release"]["targets"], np.array([0.0, 0.0, 0.0]))
503 2
    window_list = create_window_list([rest10])
504 2
    assert window_list == ["r000", "r001", "r002"]
505

506
    # Test inconsistent continuous_apr:
507 2
    with pytest.raises(Exception) as e_info:
508 2
        window_list = create_window_list([rest7, rest8])
509

510
    # Test inconsistent windows:
511 2
    with pytest.raises(Exception) as e_info:
512 2
        window_list = create_window_list([rest1, rest10])
513

514

515 2
def test_get_restraint_values():
516
    # Test Harmonic restraint
517 2
    attach_fractions = np.linspace(0, 1.0, 25)
518 2
    initial_distance = 2.65
519 2
    pull_distances = np.linspace(0 + initial_distance, 16.0 + initial_distance, 40)
520

521 2
    restraint = DAT_restraint()
522 2
    restraint.continuous_apr = True
523 2
    restraint.amber_index = True
524 2
    restraint.topology = os.path.join(
525
        os.path.dirname(__file__), "../data/k-cl/k-cl.pdb"
526
    )
527 2
    restraint.mask1 = "@K+"
528 2
    restraint.mask2 = "@Cl-"
529

530 2
    restraint.attach["target"] = initial_distance
531 2
    restraint.attach["fraction_list"] = attach_fractions
532 2
    restraint.attach["fc_final"] = 10.0
533

534 2
    restraint.pull["fc"] = restraint.attach["fc_final"]
535 2
    restraint.pull["target_list"] = pull_distances
536

537 2
    restraint.initialize()
538

539 2
    restraint_values = get_restraint_values(restraint, "attach", 0)
540 2
    assert restraint_values["r1"] == 0.0
541 2
    assert restraint_values["r2"] == 2.65
542 2
    assert restraint_values["r3"] == 2.65
543 2
    assert restraint_values["r4"] == 999.0
544 2
    assert restraint_values["rk2"] == 0.0
545 2
    assert restraint_values["rk3"] == 0.0
546

547 2
    restraint_values = get_restraint_values(restraint, "pull", 0)
548 2
    assert restraint_values["r1"] == 0.0
549 2
    assert restraint_values["r2"] == 2.65
550 2
    assert restraint_values["r3"] == 2.65
551 2
    assert restraint_values["r4"] == 999.0
552 2
    assert restraint_values["rk2"] == 10.0
553 2
    assert restraint_values["rk3"] == 10.0
554

555
    # Test custom values
556 2
    wall = DAT_restraint()
557 2
    wall.auto_apr = False
558 2
    wall.amber_index = True
559 2
    wall.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
560 2
    wall.mask1 = "@K+"
561 2
    wall.mask2 = "@Cl-"
562

563 2
    wall.attach["fc_initial"] = 1.0
564 2
    wall.attach["fc_final"] = 1.0
565

566 2
    wall.custom_restraint_values["rk2"] = 1.0
567 2
    wall.custom_restraint_values["rk3"] = 1.0
568 2
    wall.custom_restraint_values["r2"] = 0.0
569 2
    wall.custom_restraint_values["r3"] = 3.5
570

571 2
    wall.attach["target"] = 3.5
572 2
    wall.attach["num_windows"] = len(attach_fractions)
573

574 2
    wall.initialize()
575

576 2
    restraint_values = get_restraint_values(wall, "attach", 0)
577 2
    assert restraint_values["r1"] == 0.0
578 2
    assert restraint_values["r2"] == 0.0
579 2
    assert restraint_values["r3"] == 3.5
580 2
    assert restraint_values["r4"] == 999.0
581 2
    assert restraint_values["rk2"] == 1.0
582 2
    assert restraint_values["rk3"] == 1.0
583

584 2
    wall = DAT_restraint()
585 2
    wall.auto_apr = False
586 2
    wall.amber_index = True
587 2
    wall.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
588 2
    wall.mask1 = "@K+"
589 2
    wall.mask2 = "@Cl-"
590

591 2
    wall.attach["fc_initial"] = 1.0
592 2
    wall.attach["fc_final"] = 1.0
593

594 2
    wall.custom_restraint_values["rk2"] = 1.0
595 2
    wall.custom_restraint_values["rk3"] = 1.0
596 2
    wall.custom_restraint_values["r2"] = 3.5
597 2
    wall.custom_restraint_values["r3"] = 0.0
598

599 2
    wall.attach["target"] = 3.5
600 2
    wall.attach["num_windows"] = len(attach_fractions)
601

602 2
    wall.initialize()
603

604 2
    restraint_values = get_restraint_values(wall, "attach", 0)
605 2
    assert restraint_values["r1"] == 0.0
606 2
    assert restraint_values["r2"] == 3.5
607 2
    assert restraint_values["r3"] == 0.0
608 2
    assert restraint_values["r4"] == 999.0
609 2
    assert restraint_values["rk2"] == 1.0
610 2
    assert restraint_values["rk3"] == 1.0
611

612

613 2
def test_get_bias_potential_type():
614
    # Test Harmonic restraint
615 2
    attach_fractions = np.linspace(0, 1.0, 25)
616 2
    initial_distance = 2.65
617 2
    pull_distances = np.linspace(0 + initial_distance, 16.0 + initial_distance, 40)
618

619 2
    restraint = DAT_restraint()
620 2
    restraint.continuous_apr = True
621 2
    restraint.amber_index = True
622 2
    restraint.topology = os.path.join(
623
        os.path.dirname(__file__), "../data/k-cl/k-cl.pdb"
624
    )
625 2
    restraint.mask1 = "@K+"
626 2
    restraint.mask2 = "@Cl-"
627

628 2
    restraint.attach["target"] = initial_distance
629 2
    restraint.attach["fraction_list"] = attach_fractions
630 2
    restraint.attach["fc_final"] = 10.0
631

632 2
    restraint.pull["fc"] = restraint.attach["fc_final"]
633 2
    restraint.pull["target_list"] = pull_distances
634

635 2
    restraint.initialize()
636

637 2
    assert get_bias_potential_type(restraint, "attach", 0) == "restraint"
638 2
    assert get_bias_potential_type(restraint, "pull", 0) == "restraint"
639

640
    # Test upper wall restraint (1)
641 2
    upper = DAT_restraint()
642 2
    upper.auto_apr = False
643 2
    upper.amber_index = True
644 2
    upper.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
645 2
    upper.mask1 = "@K+"
646 2
    upper.mask2 = "@Cl-"
647

648 2
    upper.attach["fc_initial"] = 1.0
649 2
    upper.attach["fc_final"] = 1.0
650

651 2
    upper.custom_restraint_values["rk2"] = 1.0
652 2
    upper.custom_restraint_values["rk3"] = 1.0
653 2
    upper.custom_restraint_values["r2"] = 0.0
654 2
    upper.custom_restraint_values["r3"] = 3.5
655

656 2
    upper.attach["target"] = 3.5
657 2
    upper.attach["num_windows"] = len(attach_fractions)
658

659 2
    upper.initialize()
660

661 2
    assert get_bias_potential_type(upper, "attach", 0) == "upper_walls"
662 2
    assert get_bias_potential_type(upper, "attach", 1) == "upper_walls"
663

664
    # Test upper wall restraint (2)
665 2
    upper = DAT_restraint()
666 2
    upper.auto_apr = False
667 2
    upper.amber_index = True
668 2
    upper.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
669 2
    upper.mask1 = "@K+"
670 2
    upper.mask2 = "@Cl-"
671

672 2
    upper.attach["fc_initial"] = 1.0
673 2
    upper.attach["fc_final"] = 1.0
674

675 2
    upper.custom_restraint_values["rk2"] = 0.0
676 2
    upper.custom_restraint_values["rk3"] = 1.0
677 2
    upper.custom_restraint_values["r2"] = 3.5
678 2
    upper.custom_restraint_values["r3"] = 3.5
679

680 2
    upper.attach["target"] = 3.5
681 2
    upper.attach["num_windows"] = len(attach_fractions)
682

683 2
    upper.initialize()
684

685 2
    assert get_bias_potential_type(upper, "attach", 0) == "upper_walls"
686 2
    assert get_bias_potential_type(upper, "attach", 1) == "upper_walls"
687

688
    # Test upper wall restraint (3)
689 2
    upper = DAT_restraint()
690 2
    upper.auto_apr = False
691 2
    upper.amber_index = True
692 2
    upper.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
693 2
    upper.mask1 = "@K+"
694 2
    upper.mask2 = "@Cl-"
695

696 2
    upper.attach["fc_initial"] = 1.0
697 2
    upper.attach["fc_final"] = 1.0
698

699 2
    upper.custom_restraint_values["rk2"] = 0.0
700 2
    upper.custom_restraint_values["rk3"] = 1.0
701 2
    upper.custom_restraint_values["r2"] = 0.0
702 2
    upper.custom_restraint_values["r3"] = 3.5
703

704 2
    upper.attach["target"] = 3.5
705 2
    upper.attach["num_windows"] = len(attach_fractions)
706

707 2
    upper.initialize()
708

709 2
    assert get_bias_potential_type(upper, "attach", 0) == "upper_walls"
710 2
    assert get_bias_potential_type(upper, "attach", 1) == "upper_walls"
711

712
    # Test lower wall restraint (1)
713 2
    lower = DAT_restraint()
714 2
    lower.auto_apr = False
715 2
    lower.amber_index = True
716 2
    lower.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
717 2
    lower.mask1 = "@K+"
718 2
    lower.mask2 = "@Cl-"
719

720 2
    lower.attach["fc_initial"] = 1.0
721 2
    lower.attach["fc_final"] = 1.0
722

723 2
    lower.custom_restraint_values["rk2"] = 1.0
724 2
    lower.custom_restraint_values["rk3"] = 1.0
725 2
    lower.custom_restraint_values["r2"] = 3.5
726 2
    lower.custom_restraint_values["r3"] = 0.0
727

728 2
    lower.attach["target"] = 3.5
729 2
    lower.attach["num_windows"] = len(attach_fractions)
730

731 2
    lower.initialize()
732

733 2
    assert get_bias_potential_type(lower, "attach", 0) == "lower_walls"
734 2
    assert get_bias_potential_type(lower, "attach", 1) == "lower_walls"
735

736
    # Test lower wall restraint (2)
737 2
    lower = DAT_restraint()
738 2
    lower.auto_apr = False
739 2
    lower.amber_index = True
740 2
    lower.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
741 2
    lower.mask1 = "@K+"
742 2
    lower.mask2 = "@Cl-"
743

744 2
    lower.attach["fc_initial"] = 1.0
745 2
    lower.attach["fc_final"] = 1.0
746

747 2
    lower.custom_restraint_values["rk2"] = 1.0
748 2
    lower.custom_restraint_values["rk3"] = 0.0
749 2
    lower.custom_restraint_values["r2"] = 3.5
750 2
    lower.custom_restraint_values["r3"] = 3.5
751

752 2
    lower.attach["target"] = 3.5
753 2
    lower.attach["num_windows"] = len(attach_fractions)
754

755 2
    lower.initialize()
756

757 2
    assert get_bias_potential_type(lower, "attach", 0) == "lower_walls"
758 2
    assert get_bias_potential_type(lower, "attach", 1) == "lower_walls"
759

760
    # Test lower wall restraint (3)
761 2
    lower = DAT_restraint()
762 2
    lower.auto_apr = False
763 2
    lower.amber_index = True
764 2
    lower.topology = os.path.join(os.path.dirname(__file__), "../data/k-cl/k-cl.pdb")
765 2
    lower.mask1 = "@K+"
766 2
    lower.mask2 = "@Cl-"
767

768 2
    lower.attach["fc_initial"] = 1.0
769 2
    lower.attach["fc_final"] = 1.0
770

771 2
    lower.custom_restraint_values["rk2"] = 1.0
772 2
    lower.custom_restraint_values["rk3"] = 0.0
773 2
    lower.custom_restraint_values["r2"] = 3.5
774 2
    lower.custom_restraint_values["r3"] = 6.5
775

776 2
    lower.attach["target"] = 3.5
777 2
    lower.attach["num_windows"] = len(attach_fractions)
778

779 2
    lower.initialize()
780

781 2
    assert get_bias_potential_type(lower, "attach", 0) == "lower_walls"
782 2
    assert get_bias_potential_type(lower, "attach", 1) == "lower_walls"

Read our documentation on viewing source code .

Loading