@Test public void next() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); Iterator<int[]> it = new StateStream(state); assertThat(it.next(), is(new int[]{0, 1, 2, 7, 8, 9})); assertThat(it.next(), is(new int[]{0, 9, 8, 7, 2, 1})); assertThat(it.next(), is(new int[]{1, 0, 9, 8, 7, 2})); assertThat(it.next(), is(new int[]{1, 2, 7, 8, 9, 0})); assertThat(it.next(), is(new int[]{2, 1, 0, 9, 8, 7})); assertThat(it.next(), is(new int[]{2, 3, 4, 5, 6, 7})); assertThat(it.next(), is(new int[]{2, 7, 6, 5, 4, 3})); assertThat(it.next(), is(new int[]{2, 7, 8, 9, 0, 1})); assertThat(it.next(), is(new int[]{3, 2, 7, 6, 5, 4})); assertThat(it.next(), is(new int[]{3, 4, 5, 6, 7, 2})); assertThat(it.next(), is(new int[]{4, 3, 2, 7, 6, 5})); assertThat(it.next(), is(new int[]{4, 5, 6, 7, 2, 3})); assertThat(it.next(), is(new int[]{5, 4, 3, 2, 7, 6})); assertThat(it.next(), is(new int[]{5, 6, 7, 2, 3, 4})); assertThat(it.next(), is(new int[]{6, 5, 4, 3, 2, 7})); assertThat(it.next(), is(new int[]{6, 7, 2, 3, 4, 5})); assertThat(it.next(), is(new int[]{7, 2, 1, 0, 9, 8})); assertThat(it.next(), is(new int[]{7, 2, 3, 4, 5, 6})); assertThat(it.next(), is(new int[]{7, 6, 5, 4, 3, 2})); assertThat(it.next(), is(new int[]{7, 8, 9, 0, 1, 2})); assertThat(it.next(), is(new int[]{8, 7, 2, 1, 0, 9})); assertThat(it.next(), is(new int[]{8, 9, 0, 1, 2, 7})); assertThat(it.next(), is(new int[]{9, 0, 1, 2, 7, 8})); assertThat(it.next(), is(new int[]{9, 8, 7, 2, 1, 0})); }
@Test public void testNextN() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.nextN(0), is(0)); state.size = 1; assertThat(state.nextN(0), is(1)); state.size = 2; assertThat(state.nextN(0), is(2)); }
@Test public void testNextM() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.nextM(0, -1), is(0)); assertThat(state.nextM(0, 0), is(1)); assertThat(state.nextM(0, 1), is(2)); state.m2[1] = 0; // 1 has been mapped and should be skipped over assertThat(state.nextM(0, 0), is(2)); }
@Test public void hasNext2() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); int cnt = 0; Iterator<int[]> it = new StateStream(state); while (it.hasNext()) { assertNotNull(it.next()); cnt++; } assertThat(cnt, is(24)); }
@Test public void accessors() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); state.size = 1; assertThat(state.size(), is(1)); assertThat(state.nMax(), is(state.g1.length)); assertThat(state.mMax(), is(state.g2.length)); }
/** * Atom-atom mapping of the input molecule to the bare container constructed from the InChI connection table. * This makes it possible to map the positions of the mobile hydrogens in the InChI back to the input molecule. * @param inchiMolGraph molecule (bare) as defined in InChI * @param mol user input molecule * @throws CDKException */ private void mapInputMoleculeToInchiMolgraph(IAtomContainer inchiMolGraph, IAtomContainer mol) throws CDKException { Iterator<Map<IAtom, IAtom>> iter = org.openscience.cdk.isomorphism.VentoFoggia.findIdentical(inchiMolGraph, AtomMatcher.forElement(), BondMatcher.forAny()) .matchAll(mol) .limit(1) .toAtomMap() .iterator(); if (iter.hasNext()) { for (Map.Entry<IAtom,IAtom> e : iter.next().entrySet()) { IAtom src = e.getKey(); IAtom dst = e.getValue(); String position = src.getID(); dst.setID(position); LOGGER.debug("Mapped InChI ", src.getSymbol(), " ", src.getID(), " to ", dst.getSymbol(), " " + dst.getID()); } } else { throw new IllegalArgumentException(CANSMI.create(inchiMolGraph) + " " + CANSMI.create(mol)); } }
@Test public void mapping() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); state.m1[0] = 1; state.m1[1] = 2; assertThat(state.mapping(), is(state.m1)); assertThat(state.mapping(), is(not(sameInstance(state.m1)))); }
@Test(expected = UnsupportedOperationException.class) public void remove() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); Iterator<int[]> it = new StateStream(state); it.remove(); }
@Test public void hasNext() throws Exception { VFSubState state = createNaphthaleneToBenzene(AtomMatcher.forAny(), BondMatcher.forAny()); Iterator<int[]> it = new StateStream(state); assertFalse(it.hasNext()); }
@Test public void anyMatch() { BondMatcher matcher = BondMatcher.forAny(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); IBond bond3 = mock(IBond.class); assertTrue(matcher.matches(bond1, bond2)); assertTrue(matcher.matches(bond2, bond1)); assertTrue(matcher.matches(bond1, bond3)); assertTrue(matcher.matches(bond1, null)); assertTrue(matcher.matches(null, null)); }
@Test public void add() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.matrix.fix(), is(new int[][]{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
@Test public void infeasibleTerminalCount() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertTrue(state.feasible(0, 0)); // 0,0 is feasible // XXX: depends on molecule order not changing state.t1[1] = 1; state.t1[5] = 1; assertFalse(state.feasible(0, 0)); // 0,0 is infeasible }
@Test public void infeasibleRemainCount() throws Exception { VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertTrue(state.feasible(0, 0)); // 0,0 is feasible // XXX: depends on molecule order not changing state.m1[1] = 1; state.m1[5] = 5; state.t2[1] = 1; state.t2[9] = 1; assertFalse(state.feasible(0, 0)); // 0,0 is infeasible }
@Test public void remove() throws Exception { UllmannState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertThat(state.matrix.fix(), is(new int[][]{{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
@Test public void infeasibleTerminalCount() throws Exception { VFState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), BondMatcher.forAny()); assertTrue(state.feasible(4, 4)); // 4, 4 is feasible state.add(0, 0); state.add(1, 1); state.add(2, 2); state.add(3, 3); assertFalse(state.feasible(4, 4)); // 4, 4 is infeasible }