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.xray.parsers;
39
40 import static org.apache.commons.io.FilenameUtils.isExtension;
41 import static org.apache.commons.io.FilenameUtils.removeExtension;
42
43 import ffx.potential.MolecularAssembly;
44 import java.io.File;
45 import java.io.IOException;
46 import java.nio.file.Path;
47 import java.nio.file.Paths;
48 import java.util.logging.Logger;
49
50
51
52
53
54
55
56 public class DiffractionFile {
57
58 private static final Logger logger = Logger.getLogger(DiffractionFile.class.getName());
59
60 private final String fileName;
61 private final double weight;
62 private final boolean neutron;
63 private final DiffractionFileFilter diffractionFilter;
64
65
66
67
68
69
70 public DiffractionFile(String filename) {
71 this(filename, 1.0, false);
72 }
73
74
75
76
77
78
79
80 public DiffractionFile(String filename, double weight) {
81 this(filename, weight, false);
82 }
83
84
85
86
87
88
89
90
91 public DiffractionFile(String filename, double weight, boolean neutron) {
92 File tmp = new File(filename);
93 if (!tmp.exists()) {
94 logger.severe(" Data file: " + filename + " not found!");
95 }
96
97 if (isExtension(filename, "mtz")) {
98 diffractionFilter = new MTZFilter();
99 } else if (isExtension(filename, new String[] {"cif", "ent", "sf"})) {
100 diffractionFilter = new CIFFilter();
101 } else if (isExtension(filename, new String[] {"cns", "hkl"})) {
102 diffractionFilter = new CNSFilter();
103 } else {
104 diffractionFilter = null;
105 }
106
107 if (diffractionFilter == null) {
108 logger.severe(
109 "input data file format not recognized!\n Please use an appropriate file extension: [MTZ: mtz] [CIF: cif, ent, sf] [CNS: cns, hkl] to identify your data file type!");
110 }
111
112 this.fileName = filename;
113 this.weight = weight;
114 this.neutron = neutron;
115 }
116
117
118
119
120
121
122
123
124 public DiffractionFile(MolecularAssembly[] assembly) {
125 this(assembly[0], 1.0, false);
126 }
127
128
129
130
131
132
133
134 public DiffractionFile(MolecularAssembly[] assembly, double weight) {
135 this(assembly[0], weight, false);
136 }
137
138
139
140
141
142
143
144
145 public DiffractionFile(MolecularAssembly[] assembly, double weight, boolean neutron) {
146 this(assembly[0], weight, neutron);
147 }
148
149
150
151
152
153
154
155
156 public DiffractionFile(MolecularAssembly assembly) {
157 this(assembly, 1.0, false);
158 }
159
160
161
162
163
164
165
166
167
168 public DiffractionFile(MolecularAssembly assembly, double weight) {
169 this(assembly, weight, false);
170 }
171
172
173
174
175
176
177
178
179
180
181 public DiffractionFile(MolecularAssembly assembly, double weight, boolean neutron) {
182 String name = removeExtension(assembly.getFile().getPath());
183
184 File tmp = new File(name + ".mtz");
185 if (tmp.exists()) {
186
187 diffractionFilter = new MTZFilter();
188 } else {
189 tmp = new File(name + ".cif");
190 if (tmp.exists()) {
191
192 diffractionFilter = new CIFFilter();
193 } else {
194 tmp = new File(name + ".ent");
195 if (tmp.exists()) {
196
197 diffractionFilter = new CIFFilter();
198 } else {
199 tmp = new File(name + ".sf");
200 if (tmp.exists()) {
201
202 diffractionFilter = new CIFFilter();
203 } else {
204 tmp = new File(name + ".cns");
205 if (tmp.exists()) {
206
207 diffractionFilter = new CNSFilter();
208 } else {
209 tmp = new File(name + ".hkl");
210 if (tmp.exists()) {
211
212 diffractionFilter = new CNSFilter();
213 } else {
214 logger.severe("no input data found!");
215 diffractionFilter = null;
216 }
217 }
218 }
219 }
220 }
221 }
222 String filenameHolder;
223 try {
224 Path filepath = Paths.get(tmp.getCanonicalPath());
225 Path pwdPath = Paths.get(new File("").getCanonicalPath());
226 filenameHolder = pwdPath.relativize(filepath).toString();
227 } catch (IOException ex) {
228 logger.warning(
229 " Relative path to provided data file could not be resolved: using data file name instead.");
230 filenameHolder = tmp.getName();
231 }
232 this.fileName = filenameHolder;
233 this.weight = weight;
234 this.neutron = neutron;
235 }
236
237
238
239
240
241
242 public DiffractionFileFilter getDiffractionfilter() {
243 return diffractionFilter;
244 }
245
246
247
248
249
250
251 public String getFilename() {
252 return fileName;
253 }
254
255
256
257
258
259
260 public double getWeight() {
261 return weight;
262 }
263
264
265
266
267
268
269 public boolean isNeutron() {
270 return neutron;
271 }
272 }