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.numerics.estimator;
39
40 import ffx.utilities.Constants;
41 import ffx.utilities.FFXTest;
42 import org.junit.Test;
43
44 import static org.junit.Assert.assertEquals;
45
46 public class MBARHarmonicOscillatorsTest extends FFXTest {
47
48
49
50
51
52
53 @Test
54 public void testMBAROscillators() {
55 double[] O_k = {1, 2, 3, 4};
56 double[] K_k = {.5, 1.0, 1.5, 2};
57 int[] N_k = {10000, 10000, 10000, 10000};
58 double beta = 1.0;
59
60
61 MultistateBennettAcceptanceRatio.HarmonicOscillatorsTestCase testCase = new MultistateBennettAcceptanceRatio.HarmonicOscillatorsTestCase(O_k, K_k, beta);
62
63
64 String setting = "u_kln";
65 Object[] sampleResult = testCase.sample(N_k, setting, (long) 0);
66 double[][][] u_kln = (double[][][]) sampleResult[1];
67 double[] temps = {1 / Constants.R};
68
69 MultistateBennettAcceptanceRatio mbar = new MultistateBennettAcceptanceRatio(O_k, u_kln, temps, 1.0E-7, MultistateBennettAcceptanceRatio.SeedType.ZEROS);
70 double[] mbarFEEstimates = mbar.getMBARFreeEnergies();
71 double[] mbarErrorEstimates = mbar.getFEDifferenceUncertainties();
72 double[][] mbarDiffMatrix = mbar.getUncertaintyMatrix();
73 double[] mbarFEExpected = new double[]{0.0, 0.3468272332334239, 0.554882810046907, 0.6909139007747198};
74 double[] mbarErrorExpected = new double[]{0.00647778279366289, 0.006176323555016366, 0.008170508071621832};
75 double[][] mbarDiffMatrixExpected = new double[][]{
76 {0.0, 0.00647778279366289, 0.010874539771152386, 0.01568591641036036},
77 {0.005859375, 0.0, 0.006176323555016366, 0.012881744099875898},
78 {0.010697706201272776, 0.00647778279366289, 0.0, 0.008170508071621832},
79 {0.015563845166512918, 0.013028968812623373, 0.008170508071621832, 0.0}
80 };
81
82
83 for (int i = 0; i < mbarFEExpected.length; i++) {
84 assertEquals(mbarFEExpected[i], mbarFEEstimates[i], 1.0E-1);
85 }
86 for (int i = 0; i < mbarErrorExpected.length; i++) {
87 assertEquals(mbarErrorExpected[i], mbarErrorEstimates[i], 1.0E-1);
88 }
89 for (int i = 0; i < mbarDiffMatrixExpected.length; i++) {
90 for (int j = 0; j < mbarDiffMatrixExpected[i].length; j++) {
91 assertEquals(mbarDiffMatrixExpected[i][j], mbarDiffMatrix[i][j], 1.0E-1);
92 }
93 }
94
95 String[] testResults = MultistateBennettAcceptanceRatio.testMBARMethods();
96 for (String testResult : testResults) {
97 assertEquals("PASS", testResult);
98 }
99 }
100 }