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.MinimizeOptions;
42 import ffx.potential.MolecularAssembly;
43 import ffx.potential.cli.AtomSelectionOptions;
44 import ffx.realspace.RealSpaceData;
45 import ffx.realspace.cli.RealSpaceOptions;
46 import ffx.realspace.parsers.RealSpaceFile;
47 import ffx.utilities.FFXBinding;
48 import ffx.xray.RefinementMinimize;
49 import org.apache.commons.io.FilenameUtils;
50 import picocli.CommandLine.Command;
51 import picocli.CommandLine.Mixin;
52 import picocli.CommandLine.Parameters;
53
54 import java.io.File;
55 import java.util.List;
56
57 import static ffx.utilities.TinkerUtils.version;
58
59
60
61
62
63
64
65
66 @Command(description = " Minimization on a Real Space target.", name = "realspace.Minimize")
67 public class Minimize extends AlgorithmsCommand {
68
69 @Mixin
70 private MinimizeOptions minimizeOptions;
71
72 @Mixin
73 private RealSpaceOptions realSpaceOptions;
74
75 @Mixin
76 private AtomSelectionOptions atomSelectionOptions;
77
78
79
80
81 @Parameters(arity = "1..*", paramLabel = "files", description = "PDB and Real Space input files.")
82 private List<String> filenames;
83 private MolecularAssembly[] molecularAssemblies;
84 private RealSpaceData realspaceData;
85
86
87
88
89 public Minimize() {
90 super();
91 }
92
93
94
95
96
97 public Minimize(String[] args) {
98 super(args);
99 }
100
101
102
103
104
105 public Minimize(FFXBinding binding) {
106 super(binding);
107 }
108
109 @Override
110 public Minimize run() {
111
112 if (!init()) {
113 return this;
114 }
115
116 String filename;
117 if (filenames != null && !filenames.isEmpty()) {
118 activeAssembly = algorithmFunctions.open(filenames.get(0));
119 filename = filenames.get(0);
120 } else if (activeAssembly == null) {
121 logger.info(helpString());
122 return this;
123 } else {
124 filename = activeAssembly.getFile().getAbsolutePath();
125 }
126 molecularAssemblies = new MolecularAssembly[]{activeAssembly};
127
128 logger.info("\n Running Real Space Minimization on " + filename);
129
130
131 atomSelectionOptions.setActiveAtoms(activeAssembly);
132
133 RealSpaceFile[] mapFiles =
134 realSpaceOptions.processData(filenames, activeAssembly).toArray(new RealSpaceFile[0]);
135 realspaceData = new RealSpaceData(molecularAssemblies, activeAssembly.getProperties(),
136 activeAssembly.getParallelTeam(), mapFiles);
137
138
139 algorithmFunctions.energy(activeAssembly);
140
141 RefinementMinimize refinementMinimize = new RefinementMinimize(realspaceData,
142 realSpaceOptions.refinementMode);
143
144 int nBFGS = minimizeOptions.getNBFGS();
145 double eps = minimizeOptions.getEps();
146 int maxiter = minimizeOptions.getIterations();
147 if (eps < 0.0) {
148 eps = 1.0;
149 }
150
151 if (maxiter < Integer.MAX_VALUE) {
152 logger.info(String.
153 format("\n RMS gradient convergence criteria: %8.5f, Maximum iterations %d", eps,
154 maxiter));
155 } else {
156 logger.info(String.format("\n RMS gradient convergence criteria: %8.5f", eps));
157 }
158
159 refinementMinimize.minimize(nBFGS, eps, maxiter);
160
161
162 algorithmFunctions.energy(activeAssembly);
163
164 File file = version(new File(FilenameUtils.removeExtension(filename) + ".pdb"));
165 algorithmFunctions.saveAsPDB(molecularAssemblies, file);
166
167 return this;
168 }
169
170 @Override
171 public boolean destroyPotentials() {
172 boolean destroyedSuccess = true;
173 if (molecularAssemblies != null) {
174 if (realspaceData != null) {
175 destroyedSuccess = realspaceData.destroy();
176 }
177 for (int i = 1; i < molecularAssemblies.length; i++) {
178 destroyedSuccess = destroyedSuccess && molecularAssemblies[i].getPotentialEnergy().destroy();
179 }
180 }
181 return destroyedSuccess;
182 }
183 }