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.bonded.Atom;
41 import ffx.potential.bonded.Polymer;
42 import ffx.potential.bonded.Residue;
43 import ffx.potential.cli.PotentialCommand;
44 import ffx.potential.parsers.PDBFilter;
45 import ffx.potential.parsers.SystemFilter;
46 import ffx.utilities.FFXBinding;
47 import picocli.CommandLine.Command;
48 import picocli.CommandLine.Option;
49 import picocli.CommandLine.Parameters;
50
51 import java.util.List;
52
53 import static java.lang.String.format;
54
55
56
57
58
59
60
61 @Command(name = "WriteRestraints", description = " Log position restraints for a PDB file.")
62 public class WriteRestraints extends PotentialCommand {
63
64 @Option(names = {"--chain", "-c"}, description = "Single character chain name.")
65 private String chain = null;
66
67 @Option(names = {"-k", "--forceConstant"}, defaultValue = "100.0", paramLabel = "100.0",
68 description = "The force constant (kcal/mol/A^2).")
69 private double forceConstant = 100.0;
70
71 @Option(names = {"-d", "--flatBottom"}, defaultValue = "0.0", paramLabel = "0.0",
72 description = "The flat bottom distance in Angstroms.")
73 private double fbDistance = 0.0;
74
75 @Option(names = {"--eh", "--excludeHydrogen"}, defaultValue = "false", paramLabel = "false",
76 description = "Exclude writing restraints for hydrogen atoms.")
77 private boolean excludeHydrogen = false;
78
79 @Option(names = {"--ca", "--cAlphas"}, defaultValue = "false", paramLabel = "false",
80 description = "Only write restraints for alpha carbons and/or phosphorus's.")
81 private boolean onlyCalphas = false;
82
83 @Option(names = {"-s", "--select"}, defaultValue = "1", paramLabel = "1",
84 description = "Select every ith matching restraint and ignore the rest.")
85 private int select = 1;
86
87 @Parameters(arity = "1", paramLabel = "file",
88 description = "The atomic coordinate file in XYZ or PDB format.")
89 private String filename = null;
90
91 public WriteRestraints() { super(); }
92 public WriteRestraints(FFXBinding binding) { super(binding); }
93 public WriteRestraints(String[] args) { super(args); }
94
95 @Override
96 public WriteRestraints run() {
97 if (!init()) {
98 return this;
99 }
100
101
102 activeAssembly = getActiveAssembly(filename);
103 if (activeAssembly == null) {
104 logger.info(helpString());
105 return this;
106 }
107 filename = activeAssembly.getFile().getAbsolutePath();
108
109 logger.info("\n Writing restraints for " + filename + "\n");
110
111 SystemFilter systemFilter = potentialFunctions.getFilter();
112 int count = 0;
113
114 if (systemFilter instanceof PDBFilter) {
115 Polymer[] polymers = activeAssembly.getChains();
116 for (Polymer polymer : polymers) {
117 if (chain != null && !chain.isEmpty()) {
118 char requested = Character.toUpperCase(chain.charAt(0));
119 Character chainID = polymer.getChainID();
120 char current = (chainID == null) ? '?' : Character.toUpperCase(chainID);
121 if (current != requested) {
122 logger.info(" Skipping chain " + current);
123 continue;
124 } else {
125 logger.info(" Restraints for chain " + current);
126 }
127 }
128 java.util.List<Residue> residues = polymer.getResidues();
129 for (Residue residue : residues) {
130 if (onlyCalphas) {
131
132 Atom atom = residue.getAtomByName("CA", true);
133 if (atom == null) {
134 atom = residue.getAtomByName("P", true);
135 }
136 if (atom == null) {
137 continue;
138 }
139 if (count % select == 0) {
140 writeRestraints(atom);
141 }
142 count++;
143 } else {
144 List<Atom> atoms = residue.getAtomList();
145 for (Atom atom : atoms) {
146 if (excludeHydrogen && atom.isHydrogen()) {
147 continue;
148 }
149 if (count % select == 0) {
150 writeRestraints(atom);
151 }
152 count++;
153 }
154 }
155 }
156 }
157 } else {
158 Atom[] atoms = activeAssembly.getAtomArray();
159 for (Atom atom : atoms) {
160 if (excludeHydrogen && atom.isHydrogen()) {
161 continue;
162 }
163 if (count % select == 0) {
164 writeRestraints(atom);
165 }
166 count++;
167 }
168 }
169
170 return this;
171 }
172
173 private void writeRestraints(Atom atom) {
174 double x = atom.getX();
175 double y = atom.getY();
176 double z = atom.getZ();
177 logger.info(format("restrain-position %4d %19.15f %19.15f %19.15f %12.8f %12.8f",
178 atom.getIndex(), x, y, z, forceConstant, fbDistance));
179 }
180 }