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