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.AlgorithmListener;
41 import ffx.algorithms.cli.AlgorithmsCommand;
42 import ffx.algorithms.cli.DynamicsOptions;
43 import ffx.algorithms.dynamics.MolecularDynamics;
44 import ffx.numerics.Potential;
45 import ffx.potential.MolecularAssembly;
46 import ffx.potential.cli.AtomSelectionOptions;
47 import ffx.potential.cli.WriteoutOptions;
48 import ffx.utilities.FFXBinding;
49 import ffx.xray.DiffractionData;
50 import ffx.xray.RefinementEnergy;
51 import ffx.xray.cli.XrayOptions;
52 import ffx.xray.refine.RefinementMode;
53 import org.apache.commons.configuration2.CompositeConfiguration;
54 import org.apache.commons.io.FilenameUtils;
55 import picocli.CommandLine.Command;
56 import picocli.CommandLine.Mixin;
57 import picocli.CommandLine.Option;
58 import picocli.CommandLine.Parameters;
59
60 import java.io.File;
61 import java.util.Collections;
62 import java.util.List;
63
64
65
66
67
68
69
70
71 @Command(description = " Run Dynamics on an X-ray target.", name = "xray.Dynamics")
72 public class Dynamics extends AlgorithmsCommand implements AlgorithmListener {
73
74 @Mixin
75 private XrayOptions xrayOptions;
76
77 @Mixin
78 private DynamicsOptions dynamicsOptions;
79
80 @Mixin
81 AtomSelectionOptions atomSelectionOptions;
82
83 @Mixin
84 private WriteoutOptions writeoutOptions;
85
86
87
88
89 @Option(names = {"--mtz"}, paramLabel = "false",
90 description = "Write out an MTZ containing structure factor coefficients.")
91 private boolean mtz = false;
92
93
94
95
96 @Parameters(arity = "1..*", paramLabel = "files", description = "PDB and Diffraction input files.")
97 private List<String> filenames;
98
99 private MolecularAssembly[] molecularAssemblies;
100 private DiffractionData diffractionData;
101 private RefinementEnergy refinementEnergy;
102
103
104
105
106 public Dynamics() {
107 super();
108 }
109
110
111
112
113
114
115 public Dynamics(String[] args) {
116 super(args);
117 }
118
119
120
121
122
123
124 public Dynamics(FFXBinding binding) {
125 super(binding);
126 }
127
128 @Override
129 public Dynamics run() {
130
131 if (!init()) {
132 return this;
133 }
134
135 dynamicsOptions.init();
136 xrayOptions.init();
137
138 String filename;
139 if (filenames != null && !filenames.isEmpty()) {
140
141 molecularAssemblies = algorithmFunctions.openAll(filenames.getFirst());
142 activeAssembly = molecularAssemblies[0];
143 } else if (activeAssembly == null) {
144 logger.info(helpString());
145 return this;
146 } else {
147 molecularAssemblies = new MolecularAssembly[]{activeAssembly};
148 }
149
150
151 filename = activeAssembly.getFile().getAbsolutePath();
152
153
154 for (MolecularAssembly molecularAssembly : molecularAssemblies) {
155 atomSelectionOptions.setActiveAtoms(molecularAssembly);
156 }
157
158 logger.info("\n Running xray.Dynamics on " + filename);
159
160
161 CompositeConfiguration properties = activeAssembly.getProperties();
162 xrayOptions.setProperties(parseResult, properties);
163
164
165 diffractionData = xrayOptions.getDiffractionData(filenames, molecularAssemblies, properties);
166 refinementEnergy = xrayOptions.toXrayEnergy(diffractionData);
167
168
169 algorithmFunctions.energy(molecularAssemblies);
170
171
172 File dyn = null;
173 if (xrayOptions.refinementMode == RefinementMode.COORDINATES) {
174 dyn = new File(FilenameUtils.removeExtension(filename) + ".dyn");
175 if (!dyn.exists()) {
176 dyn = null;
177 }
178 }
179
180 MolecularDynamics molecularDynamics = dynamicsOptions.getDynamics(writeoutOptions,
181 refinementEnergy, activeAssembly, this);
182 refinementEnergy.setThermostat(molecularDynamics.getThermostat());
183 boolean initVelocities = true;
184 molecularDynamics.dynamic(dynamicsOptions.getSteps(), dynamicsOptions.getDt(), dynamicsOptions.getReport(),
185 dynamicsOptions.getWrite(), dynamicsOptions.getTemperature(), initVelocities, dyn);
186
187
188 diffractionData.scaleBulkFit();
189 diffractionData.printStats();
190
191
192 algorithmFunctions.energy(molecularAssemblies);
193
194 logger.info(" ");
195 diffractionData.writeModel(FilenameUtils.removeExtension(filename) + ".pdb");
196
197 if (mtz) {
198 diffractionData.writeData(FilenameUtils.removeExtension(filename) + ".mtz");
199 }
200
201 return this;
202 }
203
204 @Override
205 public List<Potential> getPotentials() {
206 return getPotentialsFromAssemblies(molecularAssemblies);
207 }
208
209 @Override
210 public boolean destroyPotentials() {
211 return diffractionData == null ? true : diffractionData.destroy();
212 }
213
214 @Override
215 public boolean algorithmUpdate(MolecularAssembly active) {
216 logger.info(" R/Rfree " + diffractionData.printOptimizationUpdate());
217 return true;
218 }
219 }