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.realspace.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.potential.cli.WriteoutOptions;
48 import ffx.realspace.cli.RealSpaceOptions;
49 import ffx.utilities.FFXBinding;
50 import ffx.xray.RefinementEnergy;
51 import org.apache.commons.io.FilenameUtils;
52 import picocli.CommandLine.Command;
53 import picocli.CommandLine.Mixin;
54 import picocli.CommandLine.Parameters;
55
56 import java.io.File;
57 import java.util.Collections;
58 import java.util.List;
59
60
61
62
63
64
65
66
67 @Command(description = " Simulated annealing on a Real Space target.", name = "realspace.Anneal")
68 public class Anneal extends AlgorithmsCommand {
69
70 @Mixin
71 private AnnealOptions annealOptions;
72
73 @Mixin
74 private AtomSelectionOptions atomSelectionOptions;
75
76 @Mixin
77 private DynamicsOptions dynamicsOptions;
78
79 @Mixin
80 private RealSpaceOptions realSpaceOptions;
81
82 @Mixin
83 private WriteoutOptions writeoutOptions;
84
85
86
87
88 @Parameters(arity = "1..*", paramLabel = "files", description = "PDB and Real Space input files.")
89 private List<String> filenames;
90
91 private RefinementEnergy refinementEnergy;
92
93
94
95
96 public Anneal() {
97 super();
98 }
99
100
101
102
103
104 public Anneal(String[] args) {
105 super(args);
106 }
107
108
109
110
111
112 public Anneal(FFXBinding binding) {
113 super(binding);
114 }
115
116 @Override
117 public Anneal run() {
118
119 if (!init()) {
120 return this;
121 }
122
123 dynamicsOptions.init();
124
125 String filename;
126 if (filenames != null && !filenames.isEmpty()) {
127 activeAssembly = algorithmFunctions.open(filenames.get(0));
128 filename = filenames.get(0);
129 } else if (activeAssembly == null) {
130 logger.info(helpString());
131 return this;
132 } else {
133 filename = activeAssembly.getFile().getAbsolutePath();
134 }
135 MolecularAssembly[] molecularAssemblies = new MolecularAssembly[]{activeAssembly};
136
137 logger.info(
138 "\n Running simulated annealing on on real-space target including " + filename + "\n");
139
140
141 atomSelectionOptions.setActiveAtoms(activeAssembly);
142
143
144 Potential potential = realSpaceOptions.toRealSpaceEnergy(filenames, molecularAssemblies);
145
146
147 algorithmFunctions.energy(activeAssembly);
148
149
150 File dyn = new File(FilenameUtils.removeExtension(filename) + ".dyn");
151 if (!dyn.exists()) {
152 dyn = null;
153 }
154
155 SimulatedAnnealing simulatedAnnealing =
156 annealOptions.createAnnealer(dynamicsOptions, activeAssembly,
157 potential, algorithmListener, dyn);
158
159 simulatedAnnealing.setPrintInterval(dynamicsOptions.getReport());
160 simulatedAnnealing.setSaveFrequency(dynamicsOptions.getWrite());
161 simulatedAnnealing.setRestartFrequency(dynamicsOptions.getCheckpoint());
162 simulatedAnnealing.setTrajectorySteps(dynamicsOptions.getTrajSteps());
163
164 simulatedAnnealing.anneal();
165
166 if (baseDir == null || !baseDir.exists() || !baseDir.isDirectory() || !baseDir.canWrite()) {
167 baseDir = new File(FilenameUtils.getFullPath(filename));
168 }
169
170 String dirName = baseDir.toString() + File.separator;
171 String fileName = FilenameUtils.getName(filename);
172 fileName = FilenameUtils.removeExtension(fileName);
173
174 writeoutOptions.saveFile(String.format("%s%s", dirName, fileName), algorithmFunctions, activeAssembly);
175
176 return this;
177 }
178
179 @Override
180 public List<Potential> getPotentials() {
181 return refinementEnergy == null ? Collections.emptyList() : Collections.singletonList((Potential) refinementEnergy);
182 }
183 }