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.commands;
39
40 import ffx.algorithms.cli.AlgorithmsCommand;
41 import ffx.numerics.Potential;
42 import ffx.potential.MolecularAssembly;
43 import ffx.potential.bonded.Atom;
44 import ffx.potential.cli.AtomSelectionOptions;
45 import ffx.utilities.FFXBinding;
46 import ffx.xray.DiffractionData;
47 import ffx.xray.cli.XrayOptions;
48 import org.apache.commons.configuration2.CompositeConfiguration;
49 import picocli.CommandLine.Command;
50 import picocli.CommandLine.Mixin;
51 import picocli.CommandLine.Option;
52 import picocli.CommandLine.Parameters;
53
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.List;
57 import java.util.stream.Collectors;
58
59 import static java.lang.String.format;
60 import static org.apache.commons.io.FilenameUtils.removeExtension;
61
62
63
64
65
66
67
68
69 @Command(description = " Compare the PDB model to the diffraction data.", name = "xray.ModelvsData")
70 public class ModelvsData extends AlgorithmsCommand {
71
72 @Mixin
73 private XrayOptions xrayOptions;
74
75 @Mixin
76 AtomSelectionOptions atomSelectionOptions;
77
78
79
80
81 @Option(names = {"-p", "--maps"}, paramLabel = "false",
82 description = "Output sigmaA weighted 2Fo-Fc and Fo-Fc maps.")
83 private boolean maps = false;
84
85
86
87
88 @Option(names = {"-n", "--normalize"}, paramLabel = "false",
89 description = "Normalize maps to a standard deviation of 1.0.")
90 private boolean normalize = false;
91
92
93
94
95 @Option(names = {"-t", "--timings"}, paramLabel = "false",
96 description = "Perform FFT timings.")
97 private boolean timings = false;
98
99
100
101
102 @Option(names = {"-w", "--mtz"}, paramLabel = "false",
103 description = "write out MTZ containing structure factor coefficients.")
104 private boolean mtz = false;
105
106
107
108
109 @Parameters(arity = "1..*", paramLabel = "files", description = "PDB and Diffraction input files.")
110 private List<String> filenames;
111 private DiffractionData diffractionData;
112 private MolecularAssembly[] molecularAssemblies;
113
114
115
116
117 public ModelvsData() {
118 super();
119 }
120
121
122
123
124
125
126 public ModelvsData(String[] args) {
127 super(args);
128 }
129
130
131
132
133
134
135 public ModelvsData(FFXBinding binding) {
136 super(binding);
137 }
138
139 @Override
140 public ModelvsData run() {
141
142 if (!init()) {
143 return this;
144 }
145
146 xrayOptions.init();
147
148 String filename;
149 if (filenames != null && !filenames.isEmpty()) {
150
151 molecularAssemblies = algorithmFunctions.openAll(filenames.get(0));
152 activeAssembly = molecularAssemblies[0];
153 filename = filenames.get(0);
154 } else if (activeAssembly == null) {
155 logger.info(helpString());
156 return this;
157 } else {
158 molecularAssemblies = new MolecularAssembly[]{activeAssembly};
159 filename = activeAssembly.getFile().getAbsolutePath();
160 }
161
162 logger.info(format("\n Running xray.ModelvsData on %s", filename));
163
164
165 for (MolecularAssembly molecularAssembly : molecularAssemblies) {
166 atomSelectionOptions.setActiveAtoms(molecularAssembly);
167 }
168
169
170 CompositeConfiguration properties = activeAssembly.getProperties();
171 xrayOptions.setProperties(parseResult, properties);
172
173
174 diffractionData = xrayOptions.getDiffractionData(filenames, molecularAssemblies, properties);
175
176 boolean useHydrogen = properties.getBoolean("use-hydrogen", true);
177 if (!useHydrogen) {
178 Atom[] atoms = activeAssembly.getAtomArray();
179 for (Atom atom : atoms) {
180 if (atom.isHydrogen()) {
181 atom.setOccupancy(0.0);
182
183 }
184 }
185 }
186
187 diffractionData.scaleBulkFit();
188 diffractionData.printStats();
189 algorithmFunctions.energy(molecularAssemblies);
190
191 if (mtz) {
192 diffractionData.writeData(removeExtension(filename) + "_ffx.mtz");
193 }
194
195 if (maps) {
196 diffractionData.writeMaps(removeExtension(filename), normalize);
197 }
198
199 if (timings) {
200 diffractionData.timings();
201 }
202
203 return this;
204 }
205
206 @Override
207 public List<Potential> getPotentials() {
208 return getPotentialsFromAssemblies(molecularAssemblies);
209 }
210
211 @Override
212 public boolean destroyPotentials() {
213 return diffractionData == null ? true : diffractionData.destroy();
214 }
215 }