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.algorithms.commands.test;
39
40 import ffx.algorithms.cli.AlgorithmsCommand;
41 import ffx.algorithms.misc.GenerateRotamers;
42 import ffx.potential.MolecularAssembly;
43 import ffx.potential.bonded.Polymer;
44 import ffx.potential.bonded.Residue;
45 import ffx.potential.bonded.RotamerLibrary;
46 import ffx.utilities.FFXBinding;
47 import org.apache.commons.io.FilenameUtils;
48 import picocli.CommandLine.Command;
49 import picocli.CommandLine.Option;
50 import picocli.CommandLine.Parameters;
51
52 import java.io.File;
53 import java.util.List;
54
55
56
57
58
59
60
61
62
63
64
65 @Command(description = " Apply a set of torsions to a system.", name = "test.ApplyTorsions")
66 public class ApplyTorsions extends AlgorithmsCommand {
67
68
69
70
71 @Option(names = {"-c", "--chain"}, paramLabel = " ",
72 description = "Single character chain name (default is \" \").")
73 private String chain = " ";
74
75
76
77 @Option(names = {"-r", "--resID"}, paramLabel = "1",
78 description = "Residue number.")
79 private int resID = 1;
80
81
82
83 @Option(names = {"-t", "--torsionSets"}, paramLabel = "0,0:180,0", arity = "1..*", split = ":",
84 description = "Torsion sets to apply (torsions comma-separated, sets colon-separated).")
85 private String[] torSets = null;
86
87
88
89 @Option(names = {"-n", "--nChi"}, paramLabel = "1",
90 description = "Number of torsions (unspecified torsions are filled with 0).")
91 private int nChi = 1;
92
93
94
95 @Option(names = {"-v", "--videoFile"},
96 description = "File to print torsion snapshots to.")
97 private String vidFileName = null;
98
99
100
101 @Parameters(arity = "1", paramLabel = "files",
102 description = "XYZ or PDB input files.")
103 private List<String> filenames = null;
104
105
106
107
108 public ApplyTorsions() {
109 super();
110 }
111
112
113
114
115
116 public ApplyTorsions(FFXBinding binding) {
117 super(binding);
118 }
119
120
121
122
123
124 public ApplyTorsions(String[] args) {
125 super(args);
126 }
127
128
129
130
131 @Override
132 public ApplyTorsions run() {
133
134 if (!init()) {
135 return this;
136 }
137
138 String modelFilename;
139 if (filenames != null && !filenames.isEmpty()) {
140 MolecularAssembly[] assemblies = new MolecularAssembly[]{algorithmFunctions.open(filenames.get(0))};
141 activeAssembly = assemblies[0];
142 modelFilename = filenames.get(0);
143 } else if (activeAssembly == null) {
144 logger.info(helpString());
145 return this;
146 } else {
147 modelFilename = activeAssembly.getFile().getAbsolutePath();
148 }
149
150 String newName = FilenameUtils.getBaseName(modelFilename);
151
152 String videoFile;
153 if (vidFileName != null) {
154 videoFile = vidFileName;
155 } else {
156 videoFile = newName + "_rots.pdb";
157 }
158
159 File outFile = new File(newName + ".rotout.tmp");
160 outFile.deleteOnExit();
161
162 logger.info("\n Saving torsions for residue number " + resID + " of chain " + chain + ".");
163
164 RotamerLibrary.initializeDefaultAtomicCoordinates(activeAssembly.getChains());
165 Polymer polymer = activeAssembly.getChain(chain);
166 if (polymer == null) {
167 logger.info(" Polymer " + chain + " does not exist.");
168 return this;
169 }
170 Residue residue = polymer.getResidue(resID);
171 if (residue == null) {
172 logger.info(" Residue " + resID + " does not exist.");
173 return this;
174 }
175
176 GenerateRotamers generateRotamers = new GenerateRotamers(activeAssembly,
177 activeAssembly.getPotentialEnergy(), residue, outFile, nChi, algorithmListener);
178 generateRotamers.setVideo(videoFile);
179
180 if (torSets != null) {
181 generateRotamers.applyAndSaveTorsions(torSets);
182 } else {
183 logger.info(" No torsion sets specified. Use -t option to apply torsions.");
184 }
185
186 return this;
187 }
188 }