|
33 | 33 | import org.openscience.cdk.CDKConstants; |
34 | 34 | import org.openscience.cdk.exception.NoSuchAtomException; |
35 | 35 | import org.openscience.cdk.sgroup.Sgroup; |
| 36 | +import org.openscience.cdk.sgroup.SgroupBracket; |
| 37 | +import org.openscience.cdk.sgroup.SgroupKey; |
36 | 38 | import org.openscience.cdk.sgroup.SgroupType; |
37 | 39 | import org.openscience.cdk.stereo.DoubleBondStereochemistry; |
38 | 40 | import org.openscience.cdk.stereo.TetrahedralChirality; |
@@ -3202,6 +3204,57 @@ public void changeConnectedAtomsAfterAddBond() { |
3202 | 3204 | assertTrue(clonedSgroup.getBonds().contains(clone.getBond(1))); |
3203 | 3205 | } |
3204 | 3206 |
|
| 3207 | + @Test public void cloneSgroupsBrackets() throws CloneNotSupportedException { |
| 3208 | + IAtomContainer mol = (IAtomContainer) newChemObject(); |
| 3209 | + IAtom a1 = mol.getBuilder().newAtom(); |
| 3210 | + IAtom a2 = mol.getBuilder().newAtom(); |
| 3211 | + IAtom a3 = mol.getBuilder().newAtom(); |
| 3212 | + IBond b1 = mol.getBuilder().newBond(); |
| 3213 | + IBond b2 = mol.getBuilder().newBond(); |
| 3214 | + b1.setAtom(a1, 0); |
| 3215 | + b1.setAtom(a2, 1); |
| 3216 | + b2.setAtom(a2, 0); |
| 3217 | + b2.setAtom(a3, 1); |
| 3218 | + mol.addAtom(a1); |
| 3219 | + mol.addAtom(a2); |
| 3220 | + mol.addAtom(a3); |
| 3221 | + mol.addBond(b1); |
| 3222 | + mol.addBond(b2); |
| 3223 | + Sgroup sgroup = new Sgroup(); |
| 3224 | + sgroup.setType(SgroupType.CtabStructureRepeatUnit); |
| 3225 | + sgroup.setSubscript("n"); |
| 3226 | + sgroup.addAtom(a2); |
| 3227 | + sgroup.addBond(b1); |
| 3228 | + sgroup.addBond(b2); |
| 3229 | + SgroupBracket bracket1 = new SgroupBracket(0, 1, 2, 3); |
| 3230 | + SgroupBracket bracket2 = new SgroupBracket(1, 2, 3, 4); |
| 3231 | + sgroup.addBracket(bracket1); |
| 3232 | + sgroup.addBracket(bracket2); |
| 3233 | + mol.setProperty(CDKConstants.CTAB_SGROUPS, |
| 3234 | + Collections.singletonList(sgroup)); |
| 3235 | + IAtomContainer clone = mol.clone(); |
| 3236 | + Collection<Sgroup> sgroups = clone.getProperty(CDKConstants.CTAB_SGROUPS); |
| 3237 | + assertNotNull(sgroups); |
| 3238 | + assertThat(sgroups.size(), is(1)); |
| 3239 | + Sgroup clonedSgroup = sgroups.iterator().next(); |
| 3240 | + assertThat(clonedSgroup.getType(), is(SgroupType.CtabStructureRepeatUnit)); |
| 3241 | + assertThat(clonedSgroup.getSubscript(), is("n")); |
| 3242 | + assertFalse(clonedSgroup.getAtoms().contains(a2)); |
| 3243 | + assertFalse(clonedSgroup.getBonds().contains(b1)); |
| 3244 | + assertFalse(clonedSgroup.getBonds().contains(b2)); |
| 3245 | + assertTrue(clonedSgroup.getAtoms().contains(clone.getAtom(1))); |
| 3246 | + assertTrue(clonedSgroup.getBonds().contains(clone.getBond(0))); |
| 3247 | + assertTrue(clonedSgroup.getBonds().contains(clone.getBond(1))); |
| 3248 | + List<SgroupBracket> brackets = clonedSgroup.getValue(SgroupKey.CtabBracket); |
| 3249 | + assertThat(brackets.size(), is(2)); |
| 3250 | + assertThat(brackets.get(0), is(not(sameInstance(bracket1)))); |
| 3251 | + assertThat(brackets.get(1), is(not(sameInstance(bracket2)))); |
| 3252 | + assertEquals(brackets.get(0).getFirstPoint(), new Point2d(0, 1), 0.01); |
| 3253 | + assertEquals(brackets.get(0).getSecondPoint(), new Point2d(2, 3), 0.01); |
| 3254 | + assertEquals(brackets.get(1).getFirstPoint(), new Point2d(1, 2), 0.01); |
| 3255 | + assertEquals(brackets.get(1).getSecondPoint(), new Point2d(3, 4), 0.01); |
| 3256 | + } |
| 3257 | + |
3205 | 3258 | @Test |
3206 | 3259 | public void getSelfBond() { |
3207 | 3260 | IAtomContainer mol = (IAtomContainer) newChemObject(); |
|
0 commit comments