From 186b35ba973500dbf0fbd0f9cab85f67a6898991 Mon Sep 17 00:00:00 2001 From: maclean Date: Thu, 22 Nov 2012 12:56:19 +0000 Subject: [PATCH] Additional patch that calls refine before returning the automorphism partition Signed-off-by: John May --- .../cdk/group/AtomDiscretePartitionRefiner.java | 13 +++++++++++++ .../cdk/group/BondDiscretePartitionRefiner.java | 13 +++++++++++++ .../cdk/group/AtomDiscretePartitionRefinerTest.java | 11 +++++++++++ .../cdk/group/BondDiscretePartitionRefinerTest.java | 12 ++++++++++++ 4 files changed, 49 insertions(+) diff --git a/src/main/org/openscience/cdk/group/AtomDiscretePartitionRefiner.java b/src/main/org/openscience/cdk/group/AtomDiscretePartitionRefiner.java index 96ba856d62a..d853d6c1204 100644 --- a/src/main/org/openscience/cdk/group/AtomDiscretePartitionRefiner.java +++ b/src/main/org/openscience/cdk/group/AtomDiscretePartitionRefiner.java @@ -293,6 +293,19 @@ public PermutationGroup getAutomorphismGroup( super.refine(initialPartition); return super.getAutomorphismGroup(); } + + /** + * Get the automorphism partition (equivalence classes) of the atoms. + * + * @param atomContainer the molecule to calculate equivalence classes for + * @return a partition of the atoms into equivalence classes + */ + @TestMethod("getAutomorphismPartitionTest") + public Partition getAutomorphismPartition(IAtomContainer atomContainer) { + setup(atomContainer); + super.refine(getElementPartition(atomContainer)); + return super.getAutomorphismPartition(); + } /** * Makes a lookup table for the connection between atoms, to avoid looking diff --git a/src/main/org/openscience/cdk/group/BondDiscretePartitionRefiner.java b/src/main/org/openscience/cdk/group/BondDiscretePartitionRefiner.java index a4775adc970..3aee1db96b2 100644 --- a/src/main/org/openscience/cdk/group/BondDiscretePartitionRefiner.java +++ b/src/main/org/openscience/cdk/group/BondDiscretePartitionRefiner.java @@ -290,6 +290,19 @@ public PermutationGroup getAutomorphismGroup( return super.getAutomorphismGroup(); } + /** + * Get the automorphism partition (equivalence classes) of the bonds. + * + * @param atomContainer the molecule to calculate equivalence classes for + * @return a partition of the bonds into equivalence classes + */ + @TestMethod("getAutomorphismPartitionTest") + public Partition getAutomorphismPartition(IAtomContainer atomContainer) { + setup(atomContainer); + super.refine(getBondPartition(atomContainer)); + return super.getAutomorphismPartition(); + } + private void setup(IAtomContainer atomContainer) { // have to setup the connection table before making the group // otherwise the size may be wrong diff --git a/src/test/org/openscience/cdk/group/AtomDiscretePartitionRefinerTest.java b/src/test/org/openscience/cdk/group/AtomDiscretePartitionRefinerTest.java index c194019b6b1..b33ffe30876 100644 --- a/src/test/org/openscience/cdk/group/AtomDiscretePartitionRefinerTest.java +++ b/src/test/org/openscience/cdk/group/AtomDiscretePartitionRefinerTest.java @@ -191,6 +191,17 @@ public void getConnectivityTest() { Assert.assertEquals(orderN, refiner.getConnectivity(1, 2)); } + @Test + public void getAutomorphismPartitionTest() { + String acpString = "C0C1C2C3C4C5C6C7C8C9 0:1(2),1:2(1),2:3(2),3:4(1)," + + "4:5(2),5:6(1),6:7(2),7:8(1),8:9(2),5:9(1),0:9(1)"; + IAtomContainer ac = AtomContainerPrinter.fromString(acpString, builder); + AtomDiscretePartitionRefiner refiner = new AtomDiscretePartitionRefiner(); + Partition autP = refiner.getAutomorphismPartition(ac); + Partition expected = Partition.fromString("0|1|2|3|4|5|6|7|8|9"); + Assert.assertEquals(expected, autP); + } + // NOTE : the following tests are from bug 1250 by Luis F. de Figueiredo // and mostly test for aromatic bonds diff --git a/src/test/org/openscience/cdk/group/BondDiscretePartitionRefinerTest.java b/src/test/org/openscience/cdk/group/BondDiscretePartitionRefinerTest.java index 6d68c510038..d1d6081d392 100644 --- a/src/test/org/openscience/cdk/group/BondDiscretePartitionRefinerTest.java +++ b/src/test/org/openscience/cdk/group/BondDiscretePartitionRefinerTest.java @@ -185,6 +185,17 @@ public void getConnectivityTest() { Assert.assertEquals(1, refiner.getConnectivity(0, 1)); } + @Test + public void getAutomorphismPartitionTest() { + String acpString = "C0C1C2C3C4C5C6C7C8C9 0:1(2),1:2(1),2:3(2),3:4(1)," + + "4:5(2),5:6(1),6:7(2),7:8(1),8:9(2),5:9(1),0:9(1)"; + IAtomContainer ac = AtomContainerPrinter.fromString(acpString, builder); + BondDiscretePartitionRefiner refiner = new BondDiscretePartitionRefiner(); + Partition autP = refiner.getAutomorphismPartition(ac); + Partition expected = Partition.fromString("0|1|2|3|4|5|6|7|8|9|10"); + Assert.assertEquals(expected, autP); + } + // NOTE : the following tests are from bug 1250 by Luis F. de Figueiredo // and mostly test for aromatic bonds @@ -193,6 +204,7 @@ public void testAzulene() throws Exception { IAtomContainer mol = MoleculeFactory.makeAzulene(); Assert.assertNotNull("Created molecule was null", mol); + AtomContainerPrinter.print(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); CDKHueckelAromaticityDetector.detectAromaticity(mol);