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.test;
39
40 import ffx.potential.ForceFieldEnergy;
41 import ffx.potential.MolecularAssembly;
42 import ffx.potential.cli.PotentialCommand;
43 import ffx.potential.parameters.ForceField;
44 import ffx.potential.parameters.TitrationUtils;
45 import ffx.potential.parsers.ForceFieldFilter;
46 import ffx.potential.parsers.PDBFilter;
47 import ffx.utilities.FFXBinding;
48 import ffx.utilities.Keyword;
49 import org.apache.commons.configuration2.CompositeConfiguration;
50 import org.apache.commons.io.FilenameUtils;
51 import picocli.CommandLine.Command;
52 import picocli.CommandLine.Option;
53 import picocli.CommandLine.Parameters;
54
55 import java.io.File;
56
57 import static java.lang.String.format;
58
59
60
61
62
63
64
65
66 @Command(description = " Save a PDB file that includes all titrating tautomer hydrogen atoms.",
67 name = "test.SaveAsConstantPhPDB")
68 public class SaveAsConstantPhPDB extends PotentialCommand {
69
70 @Option(names = {"--rt", "--rotamerTitration"}, paramLabel = "false",
71 description = "Prepare PDB for rotamer optimization with titration states.")
72 private boolean rotamerTitration = false;
73
74
75
76
77 @Parameters(arity = "1", paramLabel = "file",
78 description = "The atomic coordinate file in PDB format.")
79 private String filename = null;
80
81
82
83
84 public SaveAsConstantPhPDB() {
85 super();
86 }
87
88
89
90
91
92 public SaveAsConstantPhPDB(FFXBinding binding) {
93 super(binding);
94 }
95
96
97
98
99
100 public SaveAsConstantPhPDB(String[] args) {
101 super(args);
102 }
103
104
105
106
107 @Override
108 public SaveAsConstantPhPDB run() {
109
110 if (!init()) {
111 return this;
112 }
113
114 if (rotamerTitration) {
115 logger.info("\n Adding rotamer optimization with titration protons to : " + filename + "\n");
116 } else {
117 logger.info("\n Adding constant pH protons to: " + filename + "\n");
118 }
119
120
121 File structureFile = new File(filename);
122 int index = filename.lastIndexOf(".");
123 String name = filename.substring(0, index);
124 activeAssembly = new MolecularAssembly(name);
125 activeAssembly.setFile(structureFile);
126
127 CompositeConfiguration properties = Keyword.loadProperties(structureFile);
128 ForceFieldFilter forceFieldFilter = new ForceFieldFilter(properties);
129 ForceField forceField = forceFieldFilter.parse();
130 String[] patches = properties.getStringArray("patch");
131 if (patches != null) {
132 for (String patch : patches) {
133 logger.info(" Attempting to read force field patch from " + patch + ".");
134 CompositeConfiguration patchConfiguration = new CompositeConfiguration();
135 patchConfiguration.addProperty("parameters", patch);
136 forceFieldFilter = new ForceFieldFilter(patchConfiguration);
137 ForceField patchForceField = forceFieldFilter.parse();
138 forceField.append(patchForceField);
139 }
140 }
141 activeAssembly.setForceField(forceField);
142
143 PDBFilter pdbFilter = new PDBFilter(structureFile, activeAssembly, forceField, properties);
144 if (rotamerTitration) {
145 pdbFilter.setRotamerTitration(true);
146 } else {
147 pdbFilter.setConstantPH(true);
148 }
149
150 pdbFilter.readFile();
151 pdbFilter.applyAtomProperties();
152
153 ForceFieldEnergy potential = ForceFieldEnergy.energyFactory(activeAssembly);
154 activeAssembly.setPotential(potential);
155 activeAssembly.finalize(true, forceField);
156
157
158 File saveDir = baseDir;
159 if (saveDir == null || !saveDir.exists() || !saveDir.isDirectory() || !saveDir.canWrite()) {
160 saveDir = new File(FilenameUtils.getFullPath(filename));
161 }
162
163 String dirName = saveDir.getAbsolutePath() + File.separator;
164 String fileName = FilenameUtils.getBaseName(filename);
165 File modelFile = new File(dirName + fileName + ".pdb");
166 modelFile = potentialFunctions.versionFile(modelFile);
167
168 if (!pdbFilter.writeFile(modelFile, false, false, true)) {
169 logger.info(format(" Save failed for %s", activeAssembly));
170 }
171
172 TitrationUtils constantPhUtils = new TitrationUtils(forceField);
173
174 return this;
175 }
176 }