Skip to content

Commit 0e41b05

Browse files
committed
Moved TetrahedralChirality from data to core.
- added missing TestMethod/-Class annotation - made TetrahedralChirality getBuilder() settable via a setBuilder() - updated the IChemObjectBuilder implementations to instantiate this class via that builder - added a unit test in AbstractChemObjectBuilderTest to test that the properly build TetrahedralChirality instances Signed-off-by: Rajarshi Guha <rajarshi.guha@gmail.com> Conflicts: src/test/org/openscience/cdk/AbstractChemObjectBuilderTest.java src/test/org/openscience/cdk/modulesuites/McoreTests.java Change-Id: Iae7ed5dfc75d902d4cde5fc80bdea9de84379884 Signed-off-by: John May <john.wilkinsonmay@gmail.com>
1 parent aa0f969 commit 0e41b05

9 files changed

Lines changed: 132 additions & 9 deletions

File tree

src/main/org/openscience/cdk/DefaultChemObjectBuilder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,13 @@
6868
import org.openscience.cdk.interfaces.IRingSet;
6969
import org.openscience.cdk.interfaces.ISingleElectron;
7070
import org.openscience.cdk.interfaces.IStrand;
71+
import org.openscience.cdk.interfaces.ITetrahedralChirality;
72+
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
7173
import org.openscience.cdk.protein.data.PDBAtom;
7274
import org.openscience.cdk.protein.data.PDBMonomer;
7375
import org.openscience.cdk.protein.data.PDBPolymer;
7476
import org.openscience.cdk.protein.data.PDBStructure;
77+
import org.openscience.cdk.stereo.TetrahedralChirality;
7578

7679
/**
7780
* A helper class to instantiate a {@link ICDKObject} for the original CDK
@@ -167,6 +170,18 @@ public <T extends ICDKObject>T newInstance(
167170
if (params.length == 0) return (T)new PDBStructure();
168171
} else if (clazz.isAssignableFrom(IMolecularFormula.class)) {
169172
if (params.length == 0) return (T)new MolecularFormula();
173+
} else if (clazz.isAssignableFrom(ITetrahedralChirality.class)) {
174+
System.out.println(params.length);
175+
if (params.length == 3 &&
176+
params[0] instanceof IAtom &&
177+
params[1] instanceof IAtom[] &&
178+
params[2] instanceof Stereo) {
179+
TetrahedralChirality chirality = new TetrahedralChirality(
180+
(IAtom)params[0], (IAtom[])params[1], (Stereo)params[2]
181+
);
182+
chirality.setBuilder(this);
183+
return (T)chirality;
184+
}
170185
} else if (clazz.isAssignableFrom(IMolecularFormulaSet.class)) {
171186
if (params.length == 0) return (T)new MolecularFormulaSet();
172187
if (params.length == 1 &&

src/main/org/openscience/cdk/debug/DebugChemObjectBuilder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
import org.openscience.cdk.interfaces.IRingSet;
6666
import org.openscience.cdk.interfaces.ISingleElectron;
6767
import org.openscience.cdk.interfaces.IStrand;
68+
import org.openscience.cdk.interfaces.ITetrahedralChirality;
69+
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
70+
import org.openscience.cdk.stereo.TetrahedralChirality;
6871

6972
/**
7073
* A helper class to instantiate a {@link IChemObject} for the original CDK
@@ -371,6 +374,18 @@ public <T extends ICDKObject>T newInstance(
371374
if (params.length == 1 &&
372375
params[0] instanceof IMolecularFormula)
373376
return (T)new DebugAdductFormula((IMolecularFormula)params[0]);
377+
} else if (clazz.isAssignableFrom(ITetrahedralChirality.class)) {
378+
System.out.println(params.length);
379+
if (params.length == 3 &&
380+
params[0] instanceof IAtom &&
381+
params[1] instanceof IAtom[] &&
382+
params[2] instanceof Stereo) {
383+
TetrahedralChirality chirality = new TetrahedralChirality(
384+
(IAtom)params[0], (IAtom[])params[1], (Stereo)params[2]
385+
);
386+
chirality.setBuilder(this);
387+
return (T)chirality;
388+
}
374389
}
375390

376391
throw new IllegalArgumentException(getNoConstructorFoundMessage(clazz));

src/main/org/openscience/cdk/nonotify/NoNotificationChemObjectBuilder.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
import org.openscience.cdk.interfaces.IRingSet;
6666
import org.openscience.cdk.interfaces.ISingleElectron;
6767
import org.openscience.cdk.interfaces.IStrand;
68+
import org.openscience.cdk.interfaces.ITetrahedralChirality;
69+
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
70+
import org.openscience.cdk.stereo.TetrahedralChirality;
6871

6972
/**
7073
* A helper class to instantiate a {@link IChemObject} for the original CDK
@@ -371,6 +374,18 @@ public <T extends ICDKObject>T newInstance(
371374
if (params.length == 1 &&
372375
params[0] instanceof IMolecularFormula)
373376
return (T)new NNMolecularFormulaSet((IMolecularFormula)params[0]);
377+
} else if (clazz.isAssignableFrom(ITetrahedralChirality.class)) {
378+
System.out.println(params.length);
379+
if (params.length == 3 &&
380+
params[0] instanceof IAtom &&
381+
params[1] instanceof IAtom[] &&
382+
params[2] instanceof Stereo) {
383+
TetrahedralChirality chirality = new TetrahedralChirality(
384+
(IAtom)params[0], (IAtom[])params[1], (Stereo)params[2]
385+
);
386+
chirality.setBuilder(this);
387+
return (T)chirality;
388+
}
374389
} else if (clazz.isAssignableFrom(IAdductFormula.class)) {
375390
if (params.length == 0) return (T)new NNAdductFormula();
376391
if (params.length == 1 &&

src/main/org/openscience/cdk/silent/SilentChemObjectBuilder.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.openscience.cdk.interfaces.IChemFile;
3939
import org.openscience.cdk.interfaces.IChemModel;
4040
import org.openscience.cdk.interfaces.IChemObject;
41+
import org.openscience.cdk.interfaces.IChemObjectBuilder;
4142
import org.openscience.cdk.interfaces.IChemSequence;
4243
import org.openscience.cdk.interfaces.ICrystal;
4344
import org.openscience.cdk.interfaces.IElectronContainer;
@@ -51,7 +52,6 @@
5152
import org.openscience.cdk.interfaces.IMolecule;
5253
import org.openscience.cdk.interfaces.IMoleculeSet;
5354
import org.openscience.cdk.interfaces.IMonomer;
54-
import org.openscience.cdk.interfaces.IChemObjectBuilder;
5555
import org.openscience.cdk.interfaces.IPDBAtom;
5656
import org.openscience.cdk.interfaces.IPDBMonomer;
5757
import org.openscience.cdk.interfaces.IPDBPolymer;
@@ -65,6 +65,9 @@
6565
import org.openscience.cdk.interfaces.IRingSet;
6666
import org.openscience.cdk.interfaces.ISingleElectron;
6767
import org.openscience.cdk.interfaces.IStrand;
68+
import org.openscience.cdk.interfaces.ITetrahedralChirality;
69+
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
70+
import org.openscience.cdk.stereo.TetrahedralChirality;
6871

6972
/**
7073
* A helper class to instantiate a {@link ICDKObject} for the original CDK
@@ -170,6 +173,18 @@ public <T extends ICDKObject>T newInstance(
170173
if (params.length == 1 &&
171174
params[0] instanceof IMolecularFormula)
172175
return (T)new AdductFormula((IMolecularFormula)params[0]);
176+
} else if (clazz.isAssignableFrom(ITetrahedralChirality.class)) {
177+
System.out.println(params.length);
178+
if (params.length == 3 &&
179+
params[0] instanceof IAtom &&
180+
params[1] instanceof IAtom[] &&
181+
params[2] instanceof Stereo) {
182+
TetrahedralChirality chirality = new TetrahedralChirality(
183+
(IAtom)params[0], (IAtom[])params[1], (Stereo)params[2]
184+
);
185+
chirality.setBuilder(this);
186+
return (T)chirality;
187+
}
173188
}
174189

175190
throw new IllegalArgumentException(getNoConstructorFoundMessage(clazz));

src/main/org/openscience/cdk/stereo/TetrahedralChirality.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
*/
2323
package org.openscience.cdk.stereo;
2424

25-
import org.openscience.cdk.DefaultChemObjectBuilder;
25+
import org.openscience.cdk.annotations.TestClass;
26+
import org.openscience.cdk.annotations.TestMethod;
2627
import org.openscience.cdk.interfaces.IAtom;
2728
import org.openscience.cdk.interfaces.IChemObjectBuilder;
2829
import org.openscience.cdk.interfaces.ITetrahedralChirality;
@@ -31,16 +32,26 @@
3132
* Stereochemistry specification for quadrivalent atoms. See {@link ITetrahedralChirality} for
3233
* further details.
3334
*
34-
* @cdk.module data
35+
* @cdk.module core
3536
*
3637
* @see org.openscience.cdk.interfaces.ITetrahedralChirality
3738
*/
39+
@TestClass("org.openscience.cdk.stereo.TetrahedralChiralityTest")
3840
public class TetrahedralChirality implements ITetrahedralChirality {
3941

4042
private IAtom chiralAtom;
4143
private IAtom[] ligandAtoms;
4244
private Stereo stereo;
45+
private IChemObjectBuilder builder;
4346

47+
/**
48+
* Constructor to create a new {@link ITetrahedralChirality} implementation instance.
49+
*
50+
* @param chiralAtom The chiral {@link IAtom}.
51+
* @param ligandAtoms The ligand atoms around the chiral atom.
52+
* @param chirality The {@link Stereo} chirality.
53+
*/
54+
@TestMethod("testTetrahedralChirality_IAtom_arrayIAtom_ITetrahedralChirality_Stereo")
4455
public TetrahedralChirality(IAtom chiralAtom, IAtom[] ligandAtoms, Stereo chirality) {
4556
this.chiralAtom = chiralAtom;
4657
this.ligandAtoms = ligandAtoms;
@@ -52,6 +63,7 @@ public TetrahedralChirality(IAtom chiralAtom, IAtom[] ligandAtoms, Stereo chiral
5263
*
5364
* @return an array of four {@link IAtom}s.
5465
*/
66+
@TestMethod("testGetLigands")
5567
public IAtom[] getLigands() {
5668
IAtom[] arrayCopy = new IAtom[4];
5769
System.arraycopy(ligandAtoms, 0, arrayCopy, 0, 4);
@@ -63,6 +75,7 @@ public IAtom[] getLigands() {
6375
*
6476
* @return the chiral {@link IAtom}.
6577
*/
78+
@TestMethod("testGetChiralAtom")
6679
public IAtom getChiralAtom() {
6780
return chiralAtom;
6881
}
@@ -72,14 +85,34 @@ public IAtom getChiralAtom() {
7285
*
7386
* @return the {@link ITetrahedralChirality.Stereo} for this stereo element.
7487
*/
88+
@TestMethod("testGetStereo")
7589
public Stereo getStereo() {
7690
return stereo;
7791
}
7892

93+
/**
94+
* Sets a new {@link IChemObjectBuilder}.
95+
*
96+
* @param builder the new {@link IChemObjectBuilder} to be returned
97+
* @see #getBuilder()
98+
*/
99+
@TestMethod("testBuilder")
100+
public void setBuilder(IChemObjectBuilder builder) {
101+
this.builder = builder;
102+
}
103+
104+
/** {@inheritDoc} */
105+
@TestMethod("testBuilder")
79106
public IChemObjectBuilder getBuilder() {
80-
return DefaultChemObjectBuilder.getInstance();
107+
return builder;
81108
}
82109

110+
/**
111+
* Returns a {@link String} representation of this chiral element.
112+
*
113+
* @return the String representation
114+
*/
115+
@TestMethod("testToString")
83116
public String toString() {
84117
StringBuilder builder = new StringBuilder();
85118
builder.append("Tetrahedral{").append(this.hashCode()).append(", ");

src/test/org/openscience/cdk/AbstractChemObjectBuilderTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
import org.openscience.cdk.interfaces.IRingSet;
6363
import org.openscience.cdk.interfaces.ISingleElectron;
6464
import org.openscience.cdk.interfaces.IStrand;
65+
import org.openscience.cdk.interfaces.ITetrahedralChirality;
66+
import org.openscience.cdk.interfaces.IBond.Order;
67+
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
6568

6669
/**
6770
* Checks the functionality of {@link IChemObjectBuilder} implementations.
@@ -689,4 +692,30 @@ public void testNewBond_IAtom_IMolecule() {
689692
Assert.assertTrue("But got this message instead: " + message, message.contains("Candidates are"));
690693
}
691694
}
695+
696+
@Test public void testNewTetrahedralChirality() {
697+
IChemObjectBuilder builder = rootObject.getBuilder();
698+
IMolecule molecule = builder.newInstance(IMolecule.class);
699+
molecule.addAtom(builder.newInstance(IAtom.class, "Cl"));
700+
molecule.addAtom(builder.newInstance(IAtom.class, "C"));
701+
molecule.addAtom(builder.newInstance(IAtom.class, "Br"));
702+
molecule.addAtom(builder.newInstance(IAtom.class, "I"));
703+
molecule.addAtom(builder.newInstance(IAtom.class, "H"));
704+
molecule.addBond(0, 1, Order.SINGLE);
705+
molecule.addBond(1, 2, Order.SINGLE);
706+
molecule.addBond(1, 3, Order.SINGLE);
707+
molecule.addBond(1, 4, Order.SINGLE);
708+
IAtom[] ligands = new IAtom[] {
709+
molecule.getAtom(4),
710+
molecule.getAtom(3),
711+
molecule.getAtom(2),
712+
molecule.getAtom(0)
713+
};
714+
ITetrahedralChirality chirality = builder.newInstance(
715+
ITetrahedralChirality.class,
716+
molecule.getAtom(1), ligands, Stereo.CLOCKWISE
717+
);
718+
Assert.assertNotNull(chirality);
719+
Assert.assertEquals(builder, chirality.getBuilder());
720+
}
692721
}

src/test/org/openscience/cdk/modulesuites/McoreTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.openscience.cdk.graph.SpanningTreeTest;
4949
import org.openscience.cdk.graph.matrix.AdjacencyMatrixTest;
5050
import org.openscience.cdk.stereo.DoubleBondStereochemistryTest;
51+
import org.openscience.cdk.stereo.TetrahedralChiralityTest;
5152
import org.openscience.cdk.tools.DataFeaturesTest;
5253
import org.openscience.cdk.tools.LoggingToolFactoryTest;
5354
import org.openscience.cdk.tools.SystemOutLoggingToolTest;
@@ -106,6 +107,7 @@
106107
AdjacencyMatrixTest.class,
107108
PathToolsTest.class,
108109
DoubleBondStereochemistryTest.class,
110+
TetrahedralChiralityTest.class,
109111
SpanningTreeTest.class
110112
})
111113
public class McoreTests {}

src/test/org/openscience/cdk/modulesuites/MdataTests.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import org.openscience.cdk.protein.data.PDBMonomerTest;
7070
import org.openscience.cdk.protein.data.PDBPolymerTest;
7171
import org.openscience.cdk.protein.data.PDBStructureTest;
72-
import org.openscience.cdk.stereo.TetrahedralChiralityTest;
7372

7473
/**
7574
* TestSuite that runs all the sample tests.
@@ -119,8 +118,6 @@
119118
AdductFormulaTest.class,
120119
MolecularFormulaSetTest.class,
121120
MolecularFormulaTest.class,
122-
123-
TetrahedralChiralityTest.class,
124121

125122
// test from test.event
126123
ChemObjectChangeEventTest.class,

src/test/org/openscience/cdk/stereo/TetrahedralChiralityTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.openscience.cdk.interfaces.ITetrahedralChirality.Stereo;
3636

3737
/**
38-
* @cdk.module test-data
38+
* @cdk.module test-core
3939
*/
4040
public class TetrahedralChiralityTest extends CDKTestCase {
4141

@@ -71,10 +71,12 @@ public void testTetrahedralChirality_IAtom_arrayIAtom_ITetrahedralChirality_Ster
7171
}
7272

7373
@Test
74-
public void testGetBuilder() {
74+
public void testBuilder() {
7575
TetrahedralChirality chirality = new TetrahedralChirality(
7676
molecule.getAtom(1), ligands, Stereo.CLOCKWISE
7777
);
78+
Assert.assertNull(chirality.getBuilder());
79+
chirality.setBuilder(DefaultChemObjectBuilder.getInstance());
7880
Assert.assertEquals(
7981
DefaultChemObjectBuilder.getInstance(),
8082
chirality.getBuilder()

0 commit comments

Comments
 (0)