Skip to content

Commit 1a17c9c

Browse files
committed
Need to set in the map/create function of IStereoElement, also add some tests to ensure behavior is correct.
1 parent 45aeef3 commit 1a17c9c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

base/core/src/main/java/org/openscience/cdk/stereo/AbstractStereo.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,9 @@ public IStereoElement<F, C> map(Map<IChemObject, IChemObject> chemobjs) {
179179
// no change, return self
180180
if (newfocus == focus && newcarriers == carriers)
181181
return this;
182-
return create(newfocus, newcarriers, value);
182+
IStereoElement<F, C> se = create(newfocus, newcarriers, value);
183+
se.setGroupInfo(getGroupInfo());
184+
return se;
183185
}
184186

185187
protected abstract IStereoElement<F,C> create(F focus, List<C> carriers, int cfg);

base/test-standard/src/test/java/org/openscience/cdk/tools/manipulator/AtomContainerManipulatorTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.openscience.cdk.sgroup.Sgroup;
4848
import org.openscience.cdk.silent.PseudoAtom;
4949
import org.openscience.cdk.silent.SilentChemObjectBuilder;
50+
import org.openscience.cdk.smiles.SmiFlavor;
5051
import org.openscience.cdk.smiles.SmilesGenerator;
5152
import org.openscience.cdk.smiles.SmilesParser;
5253
import org.openscience.cdk.stereo.TetrahedralChirality;
@@ -1289,6 +1290,18 @@ public void testSgroupSuppressionSRUCrossingBond() throws Exception {
12891290
"CCC[H] |Sg:n:2:n:ht|");
12901291
}
12911292

1293+
@Test
1294+
public void keepStereoGroup() throws Exception {
1295+
assertRemoveH("C[C@]([H])(O)CC |o1:1|",
1296+
"C[C@H](O)CC |o1:1|");
1297+
}
1298+
1299+
@Test
1300+
public void keepStereoGroup2() throws Exception {
1301+
assertAddH("C[C@H](O)CC |o1:1|",
1302+
"C([C@](O[H])(C(C([H])([H])[H])([H])[H])[H])([H])([H])[H] |o1:1|");
1303+
}
1304+
12921305
@Test
12931306
public void molecularWeight() throws InvalidSmilesException, IOException {
12941307
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
@@ -1331,7 +1344,16 @@ static void assertRemoveH(String smiIn, String smiExp) throws Exception {
13311344
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
13321345
IAtomContainer m = smipar.parseSmiles(smiIn);
13331346

1334-
String smiAct = new SmilesGenerator().create(AtomContainerManipulator.removeHydrogens(m));
1347+
String smiAct = new SmilesGenerator(SmiFlavor.Default).create(AtomContainerManipulator.removeHydrogens(m));
1348+
1349+
assertThat(smiAct, is(smiExp));
1350+
}
1351+
1352+
static void assertAddH(String smiIn, String smiExp) throws Exception {
1353+
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
1354+
IAtomContainer m = smipar.parseSmiles(smiIn);
1355+
AtomContainerManipulator.convertImplicitToExplicitHydrogens(m);
1356+
String smiAct = new SmilesGenerator(SmiFlavor.Default).create(m);
13351357

13361358
assertThat(smiAct, is(smiExp));
13371359
}

0 commit comments

Comments
 (0)