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.bonded;
39
40 import java.io.Serial;
41 import java.util.Enumeration;
42 import java.util.List;
43 import javax.swing.tree.TreeNode;
44 import org.jogamp.java3d.BranchGroup;
45
46
47
48
49
50
51
52 public class Joint extends MSNode {
53
54 @Serial
55 private static final long serialVersionUID = 1L;
56
57
58 private final MSGroup group1;
59
60 private final MSGroup group2;
61
62
63 public Joint() {
64 super("Joint");
65 group1 = group2 = null;
66 }
67
68
69
70
71
72
73 public Joint(String name) {
74 super(name);
75 group1 = group2 = null;
76 }
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 public Joint(MSGroup group1, MSGroup group2, MSNode bondNode, MSNode angleNode,
96 MSNode stretchBendNode, MSNode ureyBradleyNode, MSNode outOfPlaneNode, MSNode torsionNode,
97 MSNode improperTorsionNode, MSNode stretchTorsionNode, MSNode angleTorsionNode,
98 MSNode piOrbitalTorsionNode, MSNode torsionTorsionNode) {
99 super(group1 + " " + group2);
100 this.group1 = group1;
101 this.group2 = group2;
102 if (bondNode != null && bondNode.getChildCount() != 0) {
103 add(bondNode);
104 }
105 if (angleNode != null && angleNode.getChildCount() != 0) {
106 add(angleNode);
107 }
108 if (stretchBendNode != null && stretchBendNode.getChildCount() != 0) {
109 add(stretchBendNode);
110 }
111 if (ureyBradleyNode != null && ureyBradleyNode.getChildCount() != 0) {
112 add(ureyBradleyNode);
113 }
114 if (outOfPlaneNode != null && outOfPlaneNode.getChildCount() != 0) {
115 add(outOfPlaneNode);
116 }
117 if (torsionNode != null && torsionNode.getChildCount() != 0) {
118 add(torsionNode);
119 }
120 if (improperTorsionNode != null && improperTorsionNode.getChildCount() != 0) {
121 add(improperTorsionNode);
122 }
123 if (stretchTorsionNode != null && stretchTorsionNode.getChildCount() != 0) {
124 add(stretchTorsionNode);
125 }
126 if (angleTorsionNode != null && angleTorsionNode.getChildCount() != 0) {
127 add(angleTorsionNode);
128 }
129 if (piOrbitalTorsionNode != null && piOrbitalTorsionNode.getChildCount() != 0) {
130 add(piOrbitalTorsionNode);
131 }
132 if (torsionTorsionNode != null && torsionTorsionNode.getChildCount() != 0) {
133 add(torsionTorsionNode);
134 }
135 refresh(null, null, null, null, null,
136 null, null, null, null, null, null);
137 }
138
139
140
141
142
143
144 public void merge(Joint j) {
145 if (!((group1 == j.group1 && group2 == j.group2)
146 || (group2 == j.group1 && group1 == j.group2))) {
147 return;
148 }
149 refresh(j.getNode(Bond.class), j.getNode(Angle.class), j.getNode(StretchBend.class),
150 j.getNode(UreyBradley.class), j.getNode(OutOfPlaneBend.class), j.getNode(Torsion.class),
151 j.getNode(ImproperTorsion.class), j.getNode(StretchTorsion.class),
152 j.getNode(AngleTorsion.class), j.getNode(PiOrbitalTorsion.class),
153 j.getNode(TorsionTorsion.class));
154 }
155
156
157
158
159
160
161 public void setColor(RendererCache.ColorModel newColorModel) {
162 MSNode bonds = getNode(Bond.class);
163 if (bonds == null) {
164 return;
165 }
166 for (Enumeration<TreeNode> e = bonds.children(); e.hasMoreElements(); ) {
167 Bond b = (Bond) e.nextElement();
168 b.setColor(b.getAtom(0));
169 b.setColor(b.getAtom(1));
170 }
171 }
172
173
174 @Override
175 public void setView(RendererCache.ViewModel newViewModel, List<BranchGroup> newShapes) {
176 MSNode bonds = getNode(Bond.class);
177 if (bonds == null) {
178 return;
179 }
180 for (Enumeration<TreeNode> e = bonds.children(); e.hasMoreElements(); ) {
181 Bond b = (Bond) e.nextElement();
182 b.setView(newViewModel, newShapes);
183 }
184 }
185
186
187
188
189
190
191 @Override
192 public String toString() {
193 return getName();
194 }
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211 private void refresh(MSNode bonds, MSNode angles, MSNode stretchBends, MSNode ureyBradleys,
212 MSNode outOfPlaneBends, MSNode torsions, MSNode improperTorsions, MSNode stretchTorsions,
213 MSNode angleTorsions, MSNode piOrbitalTorsions, MSNode torsionTorsions) {
214
215
216 for (Enumeration<TreeNode> e = children(); e.hasMoreElements(); ) {
217 MSNode jointChild = (MSNode) e.nextElement();
218 if (jointChild.getChildCount() == 0) {
219 jointChild.removeFromParent();
220 continue;
221 }
222 MSNode node = (MSNode) jointChild.getChildAt(0);
223
224 if (node instanceof Bond) {
225 addAll("Bonds", jointChild, bonds);
226 bonds = null;
227 } else if (node instanceof Angle) {
228 addAll("Angles", jointChild, angles);
229 angles = null;
230 } else if (node instanceof StretchBend) {
231 addAll("Stretch-Bends", jointChild, stretchBends);
232 stretchBends = null;
233 } else if (node instanceof UreyBradley) {
234 addAll("Urey-Bradleys", jointChild, ureyBradleys);
235 ureyBradleys = null;
236 } else if (node instanceof OutOfPlaneBend) {
237 addAll("Out-of-Plane Bends", jointChild, outOfPlaneBends);
238 outOfPlaneBends = null;
239 } else if (node instanceof Torsion) {
240 addAll("Torsional Angles", jointChild, torsions);
241 torsions = null;
242 } else if (node instanceof ImproperTorsion) {
243 addAll("Improper Torsions", jointChild, improperTorsions);
244 improperTorsions = null;
245 } else if (node instanceof StretchTorsion) {
246 addAll("Stretch-Torsions", jointChild, stretchTorsions);
247 stretchTorsions = null;
248 } else if (node instanceof AngleTorsion) {
249 addAll("Angle-Torsions", jointChild, angleTorsions);
250 angleTorsions = null;
251 } else if (node instanceof PiOrbitalTorsion) {
252 addAll("Pi-Orbital Torsions", jointChild, piOrbitalTorsions);
253 piOrbitalTorsions = null;
254 } else if (node instanceof TorsionTorsion) {
255 addAll("Torsion-Torsions", jointChild, torsionTorsions);
256 torsionTorsions = null;
257 }
258 }
259
260 if (bonds != null) {
261 add(bonds);
262 }
263 if (angles != null) {
264 add(angles);
265 }
266 if (stretchBends != null) {
267 add(stretchBends);
268 }
269 if (ureyBradleys != null) {
270 add(ureyBradleys);
271 }
272 if (outOfPlaneBends != null) {
273 add(outOfPlaneBends);
274 }
275 if (torsions != null) {
276 add(torsions);
277 }
278 if (improperTorsions != null) {
279 add(improperTorsions);
280 }
281 if (stretchTorsions != null) {
282 add(stretchTorsions);
283 }
284 if (angleTorsions != null) {
285 add(angleTorsions);
286 }
287 if (piOrbitalTorsions != null) {
288 add(piOrbitalTorsions);
289 }
290 if (torsionTorsions != null) {
291 add(torsionTorsions);
292 }
293 }
294
295
296
297
298
299
300
301
302 private void addAll(String name, MSNode parent, MSNode node) {
303 if (node == null) {
304 return;
305 }
306 for (MSNode bond : node.getChildList()) {
307 parent.add(bond);
308 }
309 parent.setName(name + " (" + parent.getChildCount() + ")");
310 }
311
312
313
314
315
316
317
318 private MSNode getNode(Class<? extends BondedTerm> clazz) {
319 for (Enumeration<TreeNode> e = children(); e.hasMoreElements(); ) {
320 MSNode m = (MSNode) e.nextElement();
321 TreeNode node = m.getChildAt(0);
322 if (node.getClass().equals(clazz)) {
323 return m;
324 }
325 }
326 return null;
327 }
328
329 }