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.DynamicsOptions;
42 import ffx.algorithms.dynamics.MolecularDynamics;
43 import ffx.numerics.Potential;
44 import ffx.potential.MolecularAssembly;
45 import ffx.potential.cli.AtomSelectionOptions;
46 import ffx.potential.cli.WriteoutOptions;
47 import ffx.realspace.cli.RealSpaceOptions;
48 import ffx.utilities.FFXBinding;
49 import ffx.xray.RefinementEnergy;
50 import org.apache.commons.io.FilenameUtils;
51 import picocli.CommandLine.Command;
52 import picocli.CommandLine.Mixin;
53 import picocli.CommandLine.Parameters;
54
55 import java.io.File;
56 import java.util.Collections;
57 import java.util.List;
58
59 import static ffx.utilities.TinkerUtils.version;
60
61
62
63
64
65
66
67
68 @Command(description = " Molecular dynamics on a Real Space target.", name = "realspace.Dynamics")
69 public class Dynamics extends AlgorithmsCommand {
70
71 @Mixin
72 private AtomSelectionOptions atomSelectionOptions;
73
74 @Mixin
75 private DynamicsOptions dynamicsOptions;
76
77 @Mixin
78 private RealSpaceOptions realSpaceOptions;
79
80 @Mixin
81 private WriteoutOptions writeoutOptions;
82
83
84
85
86 @Parameters(arity = "1..*", paramLabel = "files", description = "PDB and Real Space input files.")
87 private List<String> filenames;
88
89 private RefinementEnergy refinementEnergy;
90
91
92
93
94 public Dynamics() {
95 super();
96 }
97
98
99
100
101
102 public Dynamics(String[] args) {
103 super(args);
104 }
105
106
107
108
109
110 public Dynamics(FFXBinding binding) {
111 super(binding);
112 }
113
114 @Override
115 public Dynamics run() {
116
117 if (!init()) {
118 return this;
119 }
120
121 dynamicsOptions.init();
122
123 String filename;
124 if (filenames != null && !filenames.isEmpty()) {
125 activeAssembly = algorithmFunctions.open(filenames.get(0));
126 filename = filenames.get(0);
127 } else if (activeAssembly == null) {
128 logger.info(helpString());
129 return this;
130 } else {
131 filename = activeAssembly.getFile().getAbsolutePath();
132 }
133 MolecularAssembly[] molecularAssemblies = new MolecularAssembly[]{activeAssembly};
134
135 logger.info("\n Running Real Space Dynamics on " + filename);
136
137 atomSelectionOptions.setActiveAtoms(activeAssembly);
138
139
140 refinementEnergy = realSpaceOptions.toRealSpaceEnergy(filenames, molecularAssemblies);
141
142
143 algorithmFunctions.energy(activeAssembly);
144
145
146 File dyn = new File(FilenameUtils.removeExtension(filename) + ".dyn");
147 if (!dyn.exists()) {
148 dyn = null;
149 }
150
151 MolecularDynamics molDyn = dynamicsOptions.getDynamics(writeoutOptions, refinementEnergy, activeAssembly, algorithmListener);
152 refinementEnergy.setThermostat(molDyn.getThermostat());
153
154
155 boolean initVelocities = true;
156 molDyn.dynamic(dynamicsOptions.getSteps(), dynamicsOptions.getDt(), dynamicsOptions.getReport(),
157 dynamicsOptions.getWrite(), dynamicsOptions.getTemperature(), initVelocities, dyn);
158
159
160 algorithmFunctions.energy(activeAssembly);
161
162 File file = version(new File(FilenameUtils.removeExtension(filename) + ".pdb"));
163 algorithmFunctions.saveAsPDB(molecularAssemblies, file);
164
165 return this;
166 }
167
168 @Override
169 public List<Potential> getPotentials() {
170 return refinementEnergy == null ?
171 Collections.emptyList() :
172 Collections.singletonList((Potential) refinementEnergy);
173 }
174 }