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.algorithms.commands;
39
40 import ffx.algorithms.commands.test.OSTGradient;
41 import ffx.algorithms.misc.AlgorithmsTest;
42 import org.apache.commons.math3.util.FastMath;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.junit.runners.Parameterized;
46 import org.junit.runners.Parameterized.Parameters;
47
48 import java.util.Arrays;
49 import java.util.Collection;
50
51 import static java.lang.Math.random;
52 import static org.apache.commons.math3.util.FastMath.floor;
53 import static org.junit.Assert.assertEquals;
54
55
56
57
58 @RunWith(Parameterized.class)
59 public class OSTGradientTest extends AlgorithmsTest {
60
61 private final String info;
62 private final String filename;
63 private final int nAtoms;
64 private final double tolerance = 1.0e-2;
65
66 public OSTGradientTest(final String info, final String filename, final int nAtoms) {
67 this.info = info;
68 this.filename = filename;
69 this.nAtoms = nAtoms;
70 }
71
72 @Parameters
73 public static Collection<Object[]> data() {
74 return Arrays.asList(
75 new Object[][]{
76 {
77 "C23 OST Test",
78 "compound23.xyz",
79 43
80 }
81 });
82 }
83
84 @Test
85 public void testOSTBiasHelp() {
86
87 String[] args = {"-h"};
88 binding.setVariable("args", args);
89
90
91 OSTGradient ostGradient = new OSTGradient(binding).run();
92 algorithmsScript = ostGradient;
93 }
94
95 @Test
96 public void testOSTGradient() {
97
98 final double lambda = random();
99 final int atomID = (int) floor(FastMath.random() * nAtoms) + 1;
100
101
102 String[] args = {
103 "--ac", "ALL",
104 "-l", Double.toString(lambda),
105 "--ga", Integer.toString(atomID),
106 getResourcePath(filename)
107 };
108 binding.setVariable("args", args);
109
110
111 OSTGradient ostGradient = new OSTGradient(binding).run();
112 algorithmsScript = ostGradient;
113
114 double dUdLError = ostGradient.dUdLError;
115 double nFailures = ostGradient.nFailures;
116
117
118 assertEquals(info + ": dUdL error for atom " + atomID + " at lambda " + args[4] + ": ", 0.0, dUdLError, tolerance);
119 assertEquals(info + ": Number of coordinate gradient errors for atom " + atomID + " at lambda " + args[4] + ": ", 0, nFailures, 0);
120 }
121
122 @Test
123 public void testMetaDynamicsGradient() {
124
125 double lambda = random();
126 int atomID = (int) floor(FastMath.random() * nAtoms) + 1;
127
128
129 String[] args = {
130 "--ac", "ALL",
131 "--meta",
132 "-l", Double.toString(lambda),
133 "--ga", Integer.toString(atomID),
134 getResourcePath(filename)
135 };
136 binding.setVariable("args", args);
137
138
139 OSTGradient ostGradient = new OSTGradient(binding).run();
140 algorithmsScript = ostGradient;
141
142 double dUdLError = ostGradient.dUdLError;
143 double nFailures = ostGradient.nFailures;
144
145
146 assertEquals(info + ": dUdL error for atom " + args[6] + " at lambda " + args[4] + ": ", 0.0, dUdLError, tolerance);
147 assertEquals(info + ": Number of coordinate gradient errors for atom " + args[6] + " at lambda " + args[4] + ": ", 0, nFailures, 0);
148 }
149 }