diff --git a/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java b/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java index 44e9a15eb41..0c7c1a145c4 100644 --- a/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java +++ b/tool/sdg/src/main/java/org/openscience/cdk/layout/StructureDiagramGenerator.java @@ -2128,6 +2128,25 @@ private void placePositionalVariation(IAtomContainer mol) { // get all atoms connected to the part we will move Set visited = new HashSet<>(); visit(visited, adjlist, atomIdx); + + // gather up other position group + Set newvisit = new HashSet<>(); + do { + newvisit.clear(); + for (Integer idx : visited) { + IAtom visitedAtom = mol.getAtom(idx); + for (Map.Entry, IAtom> e2 : mapping.entries()) { + if (e2.getKey().contains(visitedAtom)) { + int other = idxs.get(e2.getValue()); + if (!visited.contains(other) && newvisit.add(other)) { + visit(newvisit, adjlist, other); + } + } + } + } + visited.addAll(newvisit); + } while (!newvisit.isEmpty()); + IAtomContainer frag = mol.getBuilder().newInstance(IAtomContainer.class); for (Integer visit : visited) frag.addAtom(mol.getAtom(visit));