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