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.numerics.Potential;
41 import ffx.potential.MolecularAssembly;
42 import ffx.potential.cli.PotentialCommand;
43 import ffx.potential.parsers.CIFFilter;
44 import ffx.potential.parsers.SystemFilter;
45 import ffx.utilities.FFXBinding;
46 import picocli.CommandLine.Command;
47 import picocli.CommandLine.Option;
48 import picocli.CommandLine.Parameters;
49
50 import java.io.File;
51 import java.util.ArrayList;
52 import java.util.List;
53
54 import static org.apache.commons.io.FilenameUtils.getExtension;
55 import static org.apache.commons.io.FilenameUtils.getName;
56 import static org.apache.commons.io.FilenameUtils.removeExtension;
57
58
59
60
61
62
63
64 @Command(name = "ImportCIF", description = " Convert a CIF file to PDB/XYZ format.")
65 public class ImportCIF extends PotentialCommand {
66
67
68 @Option(names = {"--zp", "--zPrime"}, paramLabel = "-1", defaultValue = "-1",
69 description = "Specify Z' when writing a CIF file.")
70 private int zPrime = -1;
71
72
73 @Option(names = {"--sg", "--spaceGroupNumber"}, paramLabel = "-1", defaultValue = "-1",
74 description = "Override the CIF space group.")
75 private int sgNum = -1;
76
77
78 @Option(names = {"--name", "--spaceGroupName"}, paramLabel = "", defaultValue = "",
79 description = "Override the CIF space group.")
80 private String sgName = "";
81
82
83 @Option(names = {"--bt", "--bondTolerance"}, paramLabel = "0.2", defaultValue = "0.2",
84 description = "Tolerance added to covalent radius to determine if atoms should be bonded.")
85 private double bondTolerance = 0.2;
86
87
88 @Option(names = {"--fl", "--fixLattice"}, defaultValue = "false",
89 description = "Override CIF parameters to satisfy lattice conditions (Otherwise error).")
90 private boolean fixLattice = false;
91
92
93 @Option(names = {"--sc", "--saveCIF"}, defaultValue = "false",
94 description = "Attempt to save file in CIF format (input(s) in XYZ format).")
95 private boolean saveCIF = false;
96
97
98 @Option(names = {"--ca", "--cifAppend"}, defaultValue = "false",
99 description = "Append structures.")
100 private boolean cifAppend = false;
101
102
103 @Parameters(arity = "1..2", paramLabel = "files",
104 description = "A CIF file and a PDB or XYZ file (already parameterized) containing one of each molecule from the CIF.")
105 private List<String> filenames = null;
106
107
108 public String[] createdFiles = null;
109
110 public ImportCIF() { super(); }
111 public ImportCIF(FFXBinding binding) { super(binding); }
112 public ImportCIF(String[] args) { super(args); }
113
114 @Override
115 public ImportCIF run() {
116
117 System.setProperty("cdk.logging.level", "fatal");
118
119 System.setProperty("vdwterm", "false");
120
121 if (!init()) {
122 return this;
123 }
124
125 if (filenames != null) {
126 int fileInputs = filenames.size();
127 System.clearProperty("mpoleterm");
128 File saveFile;
129 String dirString = getBaseDirString(filenames.get(0));
130 String name = removeExtension(getName(filenames.get(0)));
131
132 if (saveCIF) {
133
134 MolecularAssembly[] opened = potentialFunctions.openAll(filenames.toArray(new String[0]));
135 SystemFilter systemFilter = potentialFunctions.getFilter();
136 if (systemFilter == null) {
137 logger.warning(" No systems were opened to save as CIF.");
138 return this;
139 }
140 do {
141 activeAssembly = systemFilter.getActiveMolecularSystem();
142 saveFile = new File(dirString + name + ".cif");
143 CIFFilter cifFilter = new CIFFilter(saveFile, activeAssembly, activeAssembly.getForceField(), activeAssembly.getProperties(), true);
144 cifFilter.setBondTolerance(bondTolerance);
145 cifFilter.setFixLattice(fixLattice);
146 cifFilter.setSgName(sgName);
147 cifFilter.setSgNum(sgNum);
148 cifFilter.setZprime(zPrime);
149 if (cifFilter.writeFile(saveFile, cifAppend)) {
150 createdFiles = cifFilter.getCreatedFileNames();
151 } else {
152 logger.warning(" Assembly " + activeAssembly.getName() + " was not successful...");
153 }
154 } while (systemFilter.readNext());
155 } else if (fileInputs == 2) {
156
157 getActiveAssembly(filenames.get(1));
158 String ext = getExtension(filenames.get(1));
159 saveFile = new File(dirString + name + "." + ext);
160 CIFFilter cifFilter = new CIFFilter(saveFile, activeAssembly, activeAssembly.getForceField(), activeAssembly.getProperties(), false);
161 cifFilter.setBondTolerance(bondTolerance);
162 cifFilter.setFixLattice(fixLattice);
163 cifFilter.setSgName(sgName);
164 cifFilter.setSgNum(sgNum);
165 cifFilter.setZprime(zPrime);
166 if (cifFilter.readFile()) {
167 createdFiles = cifFilter.getCreatedFileNames();
168 } else {
169 logger.info(" Error occurred during conversion.");
170 }
171 } else {
172 logger.info(helpString());
173 logger.info(" Expected 2 files as input to convert CIF file(s).");
174 return this;
175 }
176 } else {
177 logger.info(helpString());
178 logger.info(" Expected 1 or 2 file(s) as input to ImportCIF.");
179 return this;
180 }
181
182 return this;
183 }
184
185 @Override
186 public List<Potential> getPotentials() {
187 return new ArrayList<>();
188 }
189 }