@Test public void aliphaticMatch() { BondMatcher matcher = BondMatcher.forOrder(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getFlag(ISAROMATIC)).thenReturn(false); when(bond2.getFlag(ISAROMATIC)).thenReturn(false); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); assertTrue(matcher.matches(bond1, bond2)); assertTrue(matcher.matches(bond2, bond1)); }
@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)); }
/** * Create a pattern which can be used to find molecules which contain the * {@code query} structure. * * @param query the substructure to find * @return a pattern for finding the {@code query} */ public static Pattern findSubstructure(IAtomContainer query) { boolean isQuery = query instanceof IQueryAtomContainer; return findSubstructure(query, isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(), isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder()); }
@Test public void queryMatch() { BondMatcher matcher = BondMatcher.forQuery(); IQueryBond bond1 = mock(IQueryBond.class); IBond bond2 = mock(IBond.class); IBond bond3 = mock(IBond.class); when(bond1.matches(bond2)).thenReturn(true); when(bond1.matches(bond3)).thenReturn(false); assertTrue(matcher.matches(bond1, bond2)); assertFalse(matcher.matches(bond1, bond3)); } }
@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 aliphaticStrictMatch() { BondMatcher matcher = BondMatcher.forStrictOrder(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getFlag(ISAROMATIC)).thenReturn(false); when(bond2.getFlag(ISAROMATIC)).thenReturn(false); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); assertTrue(matcher.matches(bond1, bond2)); assertTrue(matcher.matches(bond2, bond1)); }
/** * Verify that for every vertex adjacent to n, there should be at least one * feasible candidate adjacent which can be mapped. If no such candidate * exists the mapping of n -> m is not longer valid. * * @param n query vertex * @param m target vertex * @return mapping is still valid */ private boolean verify(int n, int m) { for (int n_prime : g1[n]) { boolean found = false; for (int m_prime : g2[m]) { if (matrix.get(n_prime, m_prime) && bondMatcher.matches(bond1.get(n, n_prime), bonds2.get(m, m_prime))) { found = true; break; } } if (!found) return false; } return true; }
return true; }, BondMatcher.forOrder());
@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 aliphaticStrictMismatch_aromatic() { BondMatcher matcher = BondMatcher.forStrictOrder(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getFlag(ISAROMATIC)).thenReturn(true); when(bond2.getFlag(ISAROMATIC)).thenReturn(false); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); assertFalse(matcher.matches(bond1, bond2)); assertFalse(matcher.matches(bond2, bond1)); }
@Test public void infeasibleBonds() throws Exception { BondMatcher mock = mock(BondMatcher.class); when(mock.matches(any(IBond.class), any(IBond.class))).thenReturn(false); VFState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), mock); state.m1[0] = 0; state.m1[1] = 1; state.m1[2] = 2; state.m1[3] = 3; state.m1[4] = 4; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { assertFalse(state.feasible(i, j)); } } }
return true; }, BondMatcher.forOrder());
@Test public void aliphaticMismatch_order() { BondMatcher matcher = BondMatcher.forOrder(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getFlag(ISAROMATIC)).thenReturn(false); when(bond2.getFlag(ISAROMATIC)).thenReturn(false); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); assertFalse(matcher.matches(bond1, bond2)); assertFalse(matcher.matches(bond2, bond1)); }
/** * Create a pattern which can be used to find molecules which contain the * {@code query} structure. * * @param query the substructure to find * @return a pattern for finding the {@code query} */ public static Pattern findSubstructure(IAtomContainer query) { boolean isQuery = query instanceof IQueryAtomContainer; return new Ullmann(query, isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(), isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder()); }
@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 aromaticStrictMatch() { BondMatcher matcher = BondMatcher.forStrictOrder(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getFlag(ISAROMATIC)).thenReturn(true); when(bond2.getFlag(ISAROMATIC)).thenReturn(true); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.DOUBLE); assertTrue(matcher.matches(bond1, bond2)); assertTrue(matcher.matches(bond2, bond1)); }
@Test public void infeasibleBonds() throws Exception { BondMatcher mock = mock(BondMatcher.class); when(mock.matches(any(IBond.class), any(IBond.class))).thenReturn(false); VFSubState state = createBenzeneToNaphthalene(AtomMatcher.forAny(), mock); state.m1[0] = 0; state.m1[1] = 1; state.m1[2] = 2; state.m1[3] = 3; state.m1[4] = 4; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { assertFalse(state.feasible(i, j)); } } }
@Test public void aliphaticMismatch_aromatic() { BondMatcher matcher = BondMatcher.forOrder(); IBond bond1 = mock(IBond.class); IBond bond2 = mock(IBond.class); when(bond1.getFlag(ISAROMATIC)).thenReturn(true); when(bond2.getFlag(ISAROMATIC)).thenReturn(false); when(bond1.getOrder()).thenReturn(IBond.Order.SINGLE); when(bond2.getOrder()).thenReturn(IBond.Order.SINGLE); assertTrue(matcher.matches(bond1, bond2)); assertTrue(matcher.matches(bond2, bond1)); }
/** * Create a pattern which can be used to find molecules which are the same * as the {@code query} structure. * * @param query the substructure to find * @return a pattern for finding the {@code query} */ public static Pattern findIdentical(IAtomContainer query) { boolean isQuery = query instanceof IQueryAtomContainer; return findIdentical(query, isQuery ? AtomMatcher.forQuery() : AtomMatcher.forElement(), isQuery ? BondMatcher.forQuery() : BondMatcher.forOrder()); }
@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)); }