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.potential.commands;
39
40 import ffx.potential.cli.PotentialCommand;
41 import ffx.potential.cli.SaveOptions;
42 import ffx.potential.parsers.SystemFilter;
43 import ffx.potential.utils.PotentialsUtils;
44 import ffx.utilities.FFXBinding;
45 import picocli.CommandLine.Command;
46 import picocli.CommandLine.Mixin;
47 import picocli.CommandLine.Option;
48 import picocli.CommandLine.Parameters;
49
50 import java.io.File;
51
52 import static org.apache.commons.io.FilenameUtils.getExtension;
53 import static org.apache.commons.io.FilenameUtils.getName;
54 import static org.apache.commons.io.FilenameUtils.removeExtension;
55
56
57
58
59
60
61
62 @Command(name = "SaveAsP1", description = " Expand the system to P1 and then save it.")
63 public class SaveAsP1 extends PotentialCommand {
64
65 @Mixin
66 private SaveOptions saveOptions = new SaveOptions();
67
68
69 @Option(names = {"--lmn", "--replicatesVector"}, paramLabel = "", defaultValue = "",
70 description = "Dimension of replicates crystal (e.g., \"2,2,2\" for a 2 x 2 x 2).")
71 private String lmn = "";
72
73
74 @Parameters(arity = "1", paramLabel = "file",
75 description = "The atomic coordinate file in PDB or XYZ format.")
76 private String filename = null;
77
78 public SaveAsP1() { super(); }
79 public SaveAsP1(FFXBinding binding) { super(binding); }
80 public SaveAsP1(String[] args) { super(args); }
81
82 @Override
83 public SaveAsP1 run() {
84 if (!init()) {
85 return this;
86 }
87
88 activeAssembly = getActiveAssembly(filename);
89 if (activeAssembly == null) {
90 logger.info(helpString());
91 return this;
92 }
93
94
95 filename = activeAssembly.getFile().getAbsolutePath();
96
97 logger.info("\n Expanding to P1 for " + filename);
98
99
100 String dirString = getBaseDirString(filename);
101
102 String name = getName(filename);
103 String ext = getExtension(name);
104 name = removeExtension(name);
105
106 String[] tokens = lmn.trim().replaceAll(" +", "").split(",");
107 int numTokens = tokens.length;
108 int[] replicatesVector = new int[3];
109 boolean noReplicate;
110 if (numTokens == 0 || (numTokens == 1 && tokens[0].isEmpty())) {
111 noReplicate = true;
112 } else if (numTokens == 1) {
113 noReplicate = false;
114 replicatesVector[0] = Integer.parseInt(tokens[0]);
115 replicatesVector[1] = Integer.parseInt(tokens[0]);
116 replicatesVector[2] = Integer.parseInt(tokens[0]);
117 } else if (numTokens == 3) {
118 noReplicate = false;
119 replicatesVector[0] = Integer.parseInt(tokens[0]);
120 replicatesVector[1] = Integer.parseInt(tokens[1]);
121 replicatesVector[2] = Integer.parseInt(tokens[2]);
122 } else {
123 logger.warning(" Replicates indices could not be parsed (should be a comma separated list of integers). Saving as P1.");
124 noReplicate = true;
125 }
126
127 if (ext.toUpperCase().contains("XYZ")) {
128 File saveLocation = SystemFilter.version(new File(dirString + name + ".xyz"));
129 logger.info(" Saving P1 file to: " + saveLocation);
130 if (noReplicate) {
131 potentialFunctions.saveAsXYZinP1(activeAssembly, saveLocation);
132 } else {
133 potentialFunctions.saveAsXYZasReplicates(activeAssembly, saveLocation, replicatesVector);
134 }
135 } else {
136 File saveLocation = SystemFilter.version(new File(dirString + name + ".pdb"));
137 logger.info(" Saving symmetry mates file to: " + saveLocation);
138 if (noReplicate) {
139 potentialFunctions.saveAsPDBinP1(activeAssembly, saveLocation);
140 } else {
141 if (potentialFunctions instanceof PotentialsUtils) {
142
143 ((PotentialsUtils) potentialFunctions).saveAsPDBinP1(activeAssembly, saveLocation, replicatesVector);
144 }
145 }
146 }
147 return this;
148 }
149 }