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.cli;
39
40 import static ffx.utilities.StringUtils.parseAtomRanges;
41
42 import ffx.potential.MolecularAssembly;
43 import ffx.potential.bonded.Atom;
44
45 import java.util.List;
46 import java.util.function.BiConsumer;
47 import java.util.logging.Logger;
48 import javax.annotation.Nonnull;
49 import javax.annotation.Nullable;
50
51 import picocli.CommandLine.ArgGroup;
52 import picocli.CommandLine.Option;
53
54
55
56
57
58
59
60 public class AtomSelectionOptions {
61
62 private static final Logger logger = Logger.getLogger(AtomSelectionOptions.class.getName());
63
64
65
66
67 @ArgGroup(heading = "%n Atom Selection Options%n", validate = false)
68 private final AtomSelectionOptionGroup group = new AtomSelectionOptionGroup();
69
70 public static void actOnAtoms(@Nonnull MolecularAssembly assembly, @Nullable String selection,
71 @Nonnull BiConsumer<Atom, Boolean> action, @Nonnull String description) {
72 if (selection == null || selection.equalsIgnoreCase("")) {
73
74 return;
75 }
76
77 Atom[] atoms = assembly.getAtomArray();
78
79
80 if (selection.equalsIgnoreCase("NONE")) {
81 for (Atom atom : atoms) {
82 action.accept(atom, false);
83 }
84 logger.info(" No atoms are " + description + ".\n");
85 return;
86 }
87
88
89 if (selection.equalsIgnoreCase("ALL")) {
90 for (Atom atom : atoms) {
91 action.accept(atom, true);
92 }
93 logger.info(" All atoms are " + description + ".\n");
94 return;
95 }
96
97
98 int nAtoms = atoms.length;
99 for (Atom atom : atoms) {
100 action.accept(atom, false);
101 }
102
103 List<Integer> atomRanges = parseAtomRanges(description, selection, nAtoms);
104 for (int i : atomRanges) {
105 action.accept(atoms[i], true);
106 }
107 logger.info("\n " + description + " atoms set to: " + selection);
108
109 }
110
111
112
113
114
115
116 public String getActiveAtoms() {
117 return group.activeAtoms;
118 }
119
120
121
122
123
124
125 public void setActiveAtoms(MolecularAssembly molecularAssembly) {
126
127 setInactive(molecularAssembly);
128
129
130 setActive(molecularAssembly);
131 }
132
133
134
135
136
137
138 public String getInactiveAtoms() {
139 return group.inactiveAtoms;
140 }
141
142
143
144
145
146
147 public boolean isAtomSelectionSet() {
148 if (group.activeAtoms != null && !group.activeAtoms.isEmpty()) {
149 return true;
150 }
151 return group.inactiveAtoms != null && !group.inactiveAtoms.isEmpty();
152 }
153
154 private void setInactive(MolecularAssembly assembly) {
155 actOnAtoms(assembly, getInactiveAtoms(), (Atom a, Boolean b) -> a.setActive(!b), "Inactive");
156 }
157
158 private void setActive(MolecularAssembly assembly) {
159 actOnAtoms(assembly, getActiveAtoms(), Atom::setActive, "Active");
160 }
161
162
163
164
165 private static class AtomSelectionOptionGroup {
166
167
168
169
170 @Option(names = {"--aa",
171 "--active"}, paramLabel = "<selection>", defaultValue = "",
172 description = "Ranges of active atoms [NONE, ALL, Range(s): 1-3,6-N].")
173 public String activeAtoms = "";
174
175
176
177
178 @Option(names = {"--ia",
179 "--inactive"}, paramLabel = "<selection>", defaultValue = "",
180 description = "Ranges of inactive atoms [NONE, ALL, Range(s): 1-3,6-N].")
181 public String inactiveAtoms = "";
182 }
183 }