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.thermodynamics;
39
40 import static java.lang.Boolean.parseBoolean;
41 import static java.lang.Double.parseDouble;
42 import static java.lang.Integer.parseInt;
43 import static java.lang.String.format;
44
45 import ffx.algorithms.thermodynamics.OrthogonalSpaceTempering.Histogram;
46
47 import javax.annotation.Nullable;
48 import java.io.BufferedReader;
49 import java.io.IOException;
50 import java.io.Reader;
51 import java.util.logging.Level;
52 import java.util.logging.Logger;
53
54
55
56
57
58
59
60 public class HistogramReader extends BufferedReader {
61
62 private static final Logger logger = Logger.getLogger(HistogramReader.class.getName());
63
64 private final Histogram histogram;
65
66 private double temperature;
67 private double thetaMass;
68 private double thetaFriction;
69 private double biasMag;
70 private int biasCutoff;
71 private int countInterval;
72 private int lambdaBins;
73 private int dUdLBins;
74 private double mindUdL;
75 private double dUdLBinWidth;
76 private double[][] counts;
77 private boolean metaDynamics = false;
78
79 public HistogramReader(Reader reader) {
80 this(null, reader);
81 }
82
83
84
85
86
87
88
89 public HistogramReader(@Nullable Histogram histogram, Reader reader) {
90 super(reader);
91 this.histogram = histogram;
92 }
93
94 public int getBiasCutoff() {
95 return biasCutoff;
96 }
97
98 public double getBiasMag() {
99 return biasMag;
100 }
101
102 public int getCountInterval() {
103 return countInterval;
104 }
105
106 public double getdUdLBinWidth() {
107 return dUdLBinWidth;
108 }
109
110 public int getLambdaBins() {
111 return lambdaBins;
112 }
113
114 public double getTemperature() {
115 return temperature;
116 }
117
118 public double getThetaFriction() {
119 return thetaFriction;
120 }
121
122 public double getThetaMass() {
123 return thetaMass;
124 }
125
126
127 public void readHistogramFile() {
128 try {
129 temperature = parseDouble(readLine().split(" +")[1]);
130 thetaMass = parseDouble(readLine().split(" +")[1]);
131 thetaFriction = parseDouble(readLine().split(" +")[1]);
132 biasMag = parseDouble(readLine().split(" +")[1]);
133 biasCutoff = parseInt(readLine().split(" +")[1]);
134 countInterval = parseInt(readLine().split(" +")[1]);
135 lambdaBins = parseInt(readLine().split(" +")[1]);
136 dUdLBins = parseInt(readLine().split(" +")[1]);
137 mindUdL = parseDouble(readLine().split(" +")[1]);
138 dUdLBinWidth = parseDouble(readLine().split(" +")[1]);
139 counts = new double[lambdaBins][dUdLBins];
140 int i = 0;
141 String[] toks = readLine().split(" +");
142 if (toks.length == 2) {
143
144 metaDynamics = parseBoolean(toks[1]);
145 } else {
146
147 for (int j = 0; j < dUdLBins; j++) {
148 counts[i][j] = parseDouble(toks[j]);
149 }
150 i++;
151 }
152
153 for (; i < lambdaBins; i++) {
154 String[] countToks = readLine().split(" +");
155 for (int j = 0; j < dUdLBins; j++) {
156 counts[i][j] = parseDouble(countToks[j]);
157 }
158 }
159
160 if (histogram != null) {
161 histogram.dUdLBins = dUdLBins;
162 histogram.mindUdL = mindUdL;
163
164 histogram.allocateRecursionKernel();
165
166 histogram.setRecursionKernel(counts);
167 histogram.setMetaDynamics(metaDynamics);
168 }
169
170 } catch (Exception e) {
171 String message = " Invalid OST Histogram file.";
172 logger.log(Level.SEVERE, message, e);
173 }
174 try {
175 close();
176 } catch (IOException ioe) {
177 String histoName = histogram == null ? "unknown file" : histogram.toString();
178 logger.warning(format(" Failed to close histogram reader for %s", histoName));
179 }
180 }
181
182 }