AtomRefinable implements Refinable { @Override public Partition getInitialPartition() { if (ignoreElements) { int n = atomContainer.getAtomCount(); return Partition.unit(n); } Map<String, SortedSet<Integer>> cellMap = new HashMap<String, SortedSet<Integer>>(); int numberOfAtoms = atomContainer.getAtomCount(); for (int atomIndex = 0; atomIndex < numberOfAtoms; atomIndex++) { String symbol = atomContainer.getAtom(atomIndex).getSymbol(); SortedSet<Integer> cell; if (cellMap.containsKey(symbol)) { cell = cellMap.get(symbol); } else { cell = new TreeSet<Integer>(); cellMap.put(symbol, cell); } cell.add(atomIndex); } List<String> atomSymbols = new ArrayList<String>(cellMap.keySet()); Collections.sort(atomSymbols); Partition elementPartition = new Partition(); for (String key : atomSymbols) { SortedSet<Integer> cell = cellMap.get(key); elementPartition.addCell(cell); } return elementPartition; } AtomRefinable(IAtomContainer atomContainer);  AtomRefinable(IAtomContainer atomContainer, boolean ignoreElements, boolean ignoreBondOrders); @Override Invariant neighboursInBlock(Set<Integer> block, int vertexIndex); @Override int getVertexCount(); @Override int getConnectivity(int vertexI, int vertexJ); @Override Partition getInitialPartition();  }
@Test public void getElementPartitionTest() { String acpString = "C0N1C2P3C4N5"; Partition expected = Partition.fromString("0,2,4|1,5|3"); IAtomContainer ac = AtomContainerPrinter.fromString(acpString, builder); AtomRefinable refinable = new AtomRefinable(ac); Partition elPartition = refinable.getInitialPartition(); Assert.assertEquals(expected, elPartition); }
@Test public void oddEvenElementPartitionTest() { IAtomContainer ac = makeAtomContainer("CNCNCN"); Partition expected = Partition.fromString("0,2,4|1,3,5"); AtomRefinable refinable = new AtomRefinable(ac); Partition elPartition = refinable.getInitialPartition(); Assert.assertEquals(expected, elPartition); }
@Test public void orderedElementPartitionTest() { IAtomContainer ac = makeAtomContainer("CCCCNNNNOOOO"); Partition expected = Partition.fromString("0,1,2,3|4,5,6,7|8,9,10,11"); AtomRefinable refinable = new AtomRefinable(ac); Partition elPartition = refinable.getInitialPartition(); Assert.assertEquals(expected, elPartition); }
@Test public void disorderedElementPartitionTest() { IAtomContainer ac = makeAtomContainer("NNNNCCCCOOOO"); Partition expected = Partition.fromString("4,5,6,7|0,1,2,3|8,9,10,11"); AtomRefinable refinable = new AtomRefinable(ac); Partition elPartition = refinable.getInitialPartition(); Assert.assertEquals(expected, elPartition); }