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.xray.commands;
39
40 import ffx.algorithms.cli.AlgorithmsCommand;
41 import ffx.numerics.Potential;
42 import ffx.potential.MolecularAssembly;
43 import ffx.potential.bonded.Atom;
44 import ffx.potential.bonded.MSNode;
45 import ffx.potential.bonded.Molecule;
46 import ffx.utilities.FFXBinding;
47 import picocli.CommandLine.Option;
48 import picocli.CommandLine.Command;
49 import picocli.CommandLine.Parameters;
50
51 import java.io.File;
52 import java.util.List;
53
54 import static org.apache.commons.io.FilenameUtils.removeExtension;
55
56
57
58
59
60
61
62
63 @Command(description = " Edit a PDB model for use in refinement.", name = "xray.EditPDB")
64 public class EditPDB extends AlgorithmsCommand {
65
66
67
68
69 @Option(names = {"--rd", "--repaceDeuterium"}, paramLabel = "false", defaultValue = "false",
70 description = "Replace deuterium with hydrogen.")
71 private boolean replaceDeuterium = false;
72
73
74
75
76
77 @Option(names = {"--altLoc", "--saveAltLoc"}, paramLabel = " ", defaultValue = " ",
78 description = "Save a specific alternate location")
79 private Character altLoc = ' ';
80
81
82
83
84 @Option(names = {"-o", "--occupancy"}, paramLabel = "false", defaultValue = "false",
85 description = "If a single alternate conformation is being saved, set occupancy values to 1.0.")
86 private boolean occupancy = false;
87
88
89
90
91 @Parameters(arity = "1", paramLabel = "file", description = "PDB input file.")
92 private String filename;
93
94 private MolecularAssembly[] molecularAssemblies;
95
96
97
98
99 public EditPDB() {
100 super();
101 }
102
103
104
105
106
107
108 public EditPDB(String[] args) {
109 super(args);
110 }
111
112
113
114
115
116
117 public EditPDB(FFXBinding binding) {
118 super(binding);
119 }
120
121
122
123
124 @Override
125 public EditPDB run() {
126
127 if (!init()) {
128 return this;
129 }
130
131 if (filename != null) {
132 molecularAssemblies = algorithmFunctions.openAll(filename);
133 activeAssembly = molecularAssemblies[0];
134 } else if (activeAssembly == null) {
135 logger.info(helpString());
136 return this;
137 } else {
138 molecularAssemblies = new MolecularAssembly[]{activeAssembly};
139 filename = activeAssembly.getFile().getAbsolutePath();
140 }
141
142 logger.info("\n Running xray.EditPDB on " + filename);
143
144 for (MolecularAssembly molecularAssembly : molecularAssemblies) {
145
146 if (replaceDeuterium) {
147 List<Atom> atoms = molecularAssembly.getAtomList();
148 for (Atom atom : atoms) {
149 if (atom.isDeuterium()) {
150 String name = atom.getName().toUpperCase();
151 atom.setName(name.replaceFirst("D", "H"));
152 }
153 }
154 List<MSNode> water = molecularAssembly.getWater();
155 for (MSNode node : water) {
156 Molecule wat = (Molecule) node;
157 wat.setName("HOH");
158 }
159 }
160
161 if (altLoc == ' ' || molecularAssembly.getAlternateLocation().equals(altLoc)) {
162 if (altLoc != ' ') {
163
164 molecularAssembly.setAtomicAltLoc(' ');
165 if (occupancy) {
166
167 molecularAssembly.setOccupancy(1.0);
168 }
169 algorithmFunctions.saveAsPDB(molecularAssembly, new File(filename));
170 }
171 }
172 }
173
174
175 if (altLoc == ' ') {
176 algorithmFunctions.saveAsPDB(molecularAssemblies, new File(filename));
177 }
178 return this;
179 }
180
181 @Override
182 public List<Potential> getPotentials() {
183 return getPotentialsFromAssemblies(molecularAssemblies);
184 }
185 }