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