public void HasNext() { var state = CreateNaphthaleneToBenzene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); var it = new StateStream(state); Assert.IsFalse(it.Any()); }
/// <summary> /// Create a pattern which can be used to find molecules which contain the /// <paramref name="query"/> structure. /// </summary> /// <param name="query">the substructure to find</param> /// <returns>a pattern for finding the <paramref name="query"/></returns> public static new Pattern CreateSubstructureFinder(IAtomContainer query) { bool isQuery = query is IQueryAtomContainer; return(new Ullmann(query, isQuery ? AtomMatcher.CreateQueryMatcher() : AtomMatcher.CreateElementMatcher(), isQuery ? BondMatcher.CreateQueryMatcher() : BondMatcher.CreateOrderMatcher())); }
public void Next() { var state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); var it = new StateStream(state).GetEnumerator(); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 0, 1, 2, 7, 8, 9 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 0, 9, 8, 7, 2, 1 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 1, 0, 9, 8, 7, 2 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 1, 2, 7, 8, 9, 0 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 2, 1, 0, 9, 8, 7 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 2, 3, 4, 5, 6, 7 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 2, 7, 6, 5, 4, 3 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 2, 7, 8, 9, 0, 1 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 3, 2, 7, 6, 5, 4 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 3, 4, 5, 6, 7, 2 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 4, 3, 2, 7, 6, 5 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 4, 5, 6, 7, 2, 3 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 5, 4, 3, 2, 7, 6 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 5, 6, 7, 2, 3, 4 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 6, 5, 4, 3, 2, 7 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 6, 7, 2, 3, 4, 5 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 7, 2, 1, 0, 9, 8 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 7, 2, 3, 4, 5, 6 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 7, 6, 5, 4, 3, 2 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 7, 8, 9, 0, 1, 2 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 8, 7, 2, 1, 0, 9 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 8, 9, 0, 1, 2, 7 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 9, 0, 1, 2, 7, 8 }, it.Current)); it.MoveNext(); Assert.IsTrue(Compares.AreDeepEqual(new int[] { 9, 8, 7, 2, 1, 0 }, it.Current)); it.MoveNext(); }
/// <summary> /// Create a state for matching subgraphs using the Ullmann refinement /// procedure. /// </summary> /// <param name="container1">query container</param> /// <param name="container2">target container</param> /// <param name="g1">query container adjacency list</param> /// <param name="g2">target container adjacency list</param> /// <param name="bonds1">query container bond map</param> /// <param name="bonds2">target container bond map</param> /// <param name="atomMatcher">method of matching atom semantics</param> /// <param name="bondMatcher">method of matching bond semantics</param> public UllmannState(IAtomContainer container1, IAtomContainer container2, int[][] g1, int[][] g2, EdgeToBondMap bonds1, EdgeToBondMap bonds2, AtomMatcher atomMatcher, BondMatcher bondMatcher) { this.bondMatcher = bondMatcher; this.g1 = g1; this.g2 = g2; this.bond1 = bonds1; this.bonds2 = bonds2; this.m1 = new int[g1.Length]; this.m2 = new int[g2.Length]; Arrays.Fill(m1, UNMAPPED); Arrays.Fill(m2, UNMAPPED); // build up compatibility matrix matrix = new CompatibilityMatrix(g1.Length, g2.Length); for (int i = 0; i < g1.Length; i++) { for (int j = 0; j < g2.Length; j++) { if (g1[i].Length <= g2[j].Length && atomMatcher.Matches(container1.Atoms[i], container2.Atoms[j])) { matrix.Set1(i, j); } } } }
/// <summary> /// Create a pattern which can be used to find molecules which are the same /// as the <paramref name="query"/> structure. /// </summary> /// <param name="query">the substructure to find</param> /// <returns>a pattern for finding the <paramref name="query"/></returns> public static new Pattern CreateIdenticalFinder(IAtomContainer query) { bool isQuery = query is IQueryAtomContainer; return(CreateIdenticalFinder(query, isQuery ? AtomMatcher.CreateQueryMatcher() : AtomMatcher.CreateElementMatcher(), isQuery ? BondMatcher.CreateQueryMatcher() : BondMatcher.CreateOrderMatcher())); }
/// <summary> /// Non-public constructor for-now the atom/bond semantics are fixed. /// </summary> /// <param name="query">the query structure</param> /// <param name="atomMatcher">how atoms should be matched</param> /// <param name="bondMatcher">how bonds should be matched</param> private Ullmann(IAtomContainer query, AtomMatcher atomMatcher, BondMatcher bondMatcher) { this.query = query; this.atomMatcher = atomMatcher; this.bondMatcher = bondMatcher; this.bonds1 = EdgeToBondMap.WithSpaceFor(query); this.g1 = GraphUtil.ToAdjList(query, bonds1); DetermineFilters(query); }
public void ElementPseudo() { AtomMatcher matcher = AtomMatcher.CreateElementMatcher(); var m_atom1 = new Mock <IPseudoAtom>(); var m_atom2 = new Mock <IPseudoAtom>(); Assert.IsTrue(matcher.Matches(m_atom1.Object, m_atom2.Object)); Assert.IsTrue(matcher.Matches(m_atom2.Object, m_atom1.Object)); }
public void Accessors() { UllmannState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); state.size = 1; Assert.AreEqual(state.Count, 1); Assert.AreEqual(state.NMax(), state.g1.Length); Assert.AreEqual(state.MMax(), state.g2.Length); }
public void Mapping() { UllmannState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); state.m1[0] = 1; state.m1[1] = 2; Assert.IsTrue(Compares.AreDeepEqual(state.m1, state.Mapping())); Assert.AreNotSame(state.m1, state.Mapping()); }
public void TestNextM() { UllmannState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); Assert.AreEqual(state.NextM(0, -1), 0); Assert.AreEqual(state.NextM(0, 0), 1); Assert.AreEqual(state.NextM(0, 1), 2); state.m2[1] = 0; // 1 has been mapped and should be skipped over Assert.AreEqual(state.NextM(0, 0), 2); }
/// <summary> /// Non-public constructor for-now the atom/bond semantics are fixed. /// </summary> /// <param name="query">the query structure</param> /// <param name="atomMatcher">how atoms should be matched</param> /// <param name="bondMatcher">how bonds should be matched</param> /// <param name="substructure">substructure search</param> private VentoFoggia(IAtomContainer query, AtomMatcher atomMatcher, BondMatcher bondMatcher, bool substructure) { this.query = query; this.atomMatcher = atomMatcher; this.bondMatcher = bondMatcher; this.bonds1 = EdgeToBondMap.WithSpaceFor(query); this.g1 = GraphUtil.ToAdjList(query, bonds1); this.subgraph = substructure; DetermineFilters(query); }
public void InfeasibleTerminalCount() { VFSubState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); Assert.IsTrue(state.Feasible(0, 0)); // 0,0 is feasible // XXX: depends on molecule order not changing state.t1[1] = 1; state.t1[5] = 1; Assert.IsFalse(state.Feasible(0, 0)); // 0,0 is infeasible }
public void TestNextN() { UllmannState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); Assert.AreEqual(state.NextN(0), 0); state.size = 1; Assert.AreEqual(state.NextN(0), 1); state.size = 2; Assert.AreEqual(state.NextN(0), 2); }
public void ElementMismatch() { AtomMatcher matcher = AtomMatcher.CreateElementMatcher(); var m_atom1 = new Mock <IAtom>(); var m_atom2 = new Mock <IAtom>(); m_atom1.SetupGet(n => n.AtomicNumber).Returns(6); m_atom2.SetupGet(n => n.AtomicNumber).Returns(8); Assert.IsFalse(matcher.Matches(m_atom1.Object, m_atom2.Object)); Assert.IsFalse(matcher.Matches(m_atom2.Object, m_atom1.Object)); }
/// <summary> /// Create a state for matching benzene to naphthalene Benzene: /// InChI=1/C6H6/c1-2-4-6-5-3-1/h1-6H Naphthalene: InChI=1/C10H8/c1-2-6-10-8-4-3-7-9(10)5-1/h1-8H /// </summary> UllmannState CreateBenzeneToNaphthalene(AtomMatcher atomMatcher, BondMatcher bondMatcher) { IAtomContainer container1 = TestMoleculeFactory.MakeBenzene(); IAtomContainer container2 = TestMoleculeFactory.MakeNaphthalene(); EdgeToBondMap bonds1 = EdgeToBondMap.WithSpaceFor(container1); EdgeToBondMap bonds2 = EdgeToBondMap.WithSpaceFor(container2); int[][] g1 = GraphUtil.ToAdjList(container1, bonds1); int[][] g2 = GraphUtil.ToAdjList(container2, bonds2); return(new UllmannState(container1, container2, g1, g2, bonds1, bonds2, atomMatcher, bondMatcher)); }
public void InfeasibleTerminalCount() { VFState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); Assert.IsTrue(state.Feasible(4, 4)); // 4, 4 is feasible state.Add(0, 0); state.Add(1, 1); state.Add(2, 2); state.Add(3, 3); Assert.IsFalse(state.Feasible(4, 4)); // 4, 4 is infeasible }
/// <summary> /// Create a VF state for matching isomorphisms. The query is passed first /// and should read as, find container1 in container2. /// </summary> /// <param name="container1">the molecule to search for (query)</param> /// <param name="container2">the molecule to search in (target)</param> /// <param name="g1">adjacency list of the query</param> /// <param name="g2">adjacency list of the target</param> /// <param name="bonds1">bond lookup of the query</param> /// <param name="bonds2">bond lookup of the target</param> /// <param name="atomMatcher">what semantic attributes (symbol, charge, query) determines atoms to be compatible</param> /// <param name="bondMatcher">what semantic attributes (order/aromatic, query) determines bonds to be compatible</param> public VFState(IAtomContainer container1, IAtomContainer container2, int[][] g1, int[][] g2, EdgeToBondMap bonds1, EdgeToBondMap bonds2, AtomMatcher atomMatcher, BondMatcher bondMatcher) : base(g1, g2) { this.container1 = container1; this.container2 = container2; this.bonds1 = bonds1; this.bonds2 = bonds2; this.atomMatcher = atomMatcher; this.bondMatcher = bondMatcher; }
public void QueryMatch() { AtomMatcher matcher = AtomMatcher.CreateQueryMatcher(); var m_atom1 = new Mock <IQueryAtom>(); var m_atom2 = new Mock <IAtom>(); var m_atom3 = new Mock <IAtom>(); m_atom1.Setup(n => n.Matches(m_atom2.Object)).Returns(true); m_atom1.Setup(n => n.Matches(m_atom3.Object)).Returns(false); Assert.IsTrue(matcher.Matches(m_atom1.Object, m_atom2.Object)); Assert.IsFalse(matcher.Matches(m_atom1.Object, m_atom3.Object)); }
/// <summary> /// Create a match for the following parameters. /// </summary> /// <param name="container1">query structure</param> /// <param name="container2">target structure</param> /// <param name="g1">query adjacency list</param> /// <param name="g2">target adjacency list</param> /// <param name="bonds1">query bond map</param> /// <param name="bonds2">target bond map</param> /// <param name="atomMatcher">how atoms are matched</param> /// <param name="bondMatcher">how bonds are matched</param> public UllmannIterable(IAtomContainer container1, IAtomContainer container2, int[][] g1, int[][] g2, EdgeToBondMap bonds1, EdgeToBondMap bonds2, AtomMatcher atomMatcher, BondMatcher bondMatcher) { this.container1 = container1; this.container2 = container2; this.g1 = g1; this.g2 = g2; this.bonds1 = bonds1; this.bonds2 = bonds2; this.atomMatcher = atomMatcher; this.bondMatcher = bondMatcher; }
public void HasNext2() { var state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); int cnt = 0; var it = new StateStream(state); foreach (var i in it) { Assert.IsNotNull(i); cnt++; } Assert.AreEqual(24, cnt); }
/// <summary> /// Create a match for the following parameters. /// </summary> /// <param name="container1">query structure</param> /// <param name="container2">target structure</param> /// <param name="g1">query adjacency list</param> /// <param name="g2">target adjacency list</param> /// <param name="bonds1">query bond map</param> /// <param name="bonds2">target bond map</param> /// <param name="atomMatcher">how atoms are matched</param> /// <param name="bondMatcher">how bonds are matched</param> /// <param name="subgraph">perform subgraph search</param> public VFIterable(IAtomContainer container1, IAtomContainer container2, int[][] g1, int[][] g2, EdgeToBondMap bonds1, EdgeToBondMap bonds2, AtomMatcher atomMatcher, BondMatcher bondMatcher, bool subgraph) { this.container1 = container1; this.container2 = container2; this.g1 = g1; this.g2 = g2; this.bonds1 = bonds1; this.bonds2 = bonds2; this.atomMatcher = atomMatcher; this.bondMatcher = bondMatcher; this.subgraph = subgraph; }
public void InfeasibleAtoms() { var m = new Mock <AtomMatcher>(); AtomMatcher mock = m.Object; m.Setup(n => n.Matches(It.IsAny <IAtom>(), It.IsAny <IAtom>())).Returns(false); VFSubState state = CreateBenzeneToNaphthalene(mock, new Mock <BondMatcher>().Object); for (int i = 0; i < state.NMax(); i++) { for (int j = 0; j < state.MMax(); j++) { Assert.IsFalse(state.Feasible(i, j)); } } }
public void AnyMatch() { AtomMatcher matcher = AtomMatcher.CreateAnyMatcher(); var m_atom1 = new Mock <IAtom>(); var m_atom2 = new Mock <IAtom>(); var m_atom3 = new Mock <IAtom>(); m_atom1.SetupGet(n => n.AtomicNumber).Returns(6); m_atom2.SetupGet(n => n.AtomicNumber).Returns(7); m_atom3.SetupGet(n => n.AtomicNumber).Returns(8); Assert.IsTrue(matcher.Matches(m_atom1.Object, m_atom2.Object)); Assert.IsTrue(matcher.Matches(m_atom2.Object, m_atom1.Object)); Assert.IsTrue(matcher.Matches(m_atom1.Object, m_atom3.Object)); Assert.IsTrue(matcher.Matches(m_atom3.Object, m_atom1.Object)); Assert.IsTrue(matcher.Matches(m_atom2.Object, m_atom3.Object)); Assert.IsTrue(matcher.Matches(m_atom1.Object, null)); Assert.IsTrue(matcher.Matches(null, null)); }
public void InfeasibleBonds() { var m = new Mock <BondMatcher>(); BondMatcher mock = m.Object; m.Setup(n => n.Matches(It.IsAny <IBond>(), It.IsAny <IBond>())).Returns(false); VFSubState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), 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++) { Assert.IsFalse(state.Feasible(i, j)); } } }
public void Add() { UllmannState state = CreateBenzeneToNaphthalene(AtomMatcher.CreateAnyMatcher(), BondMatcher.CreateAnyMatcher()); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, new[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, state.matrix.Fix() )); Assert.IsTrue(state.Add(0, 0)); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, 1 }, new[] { 1, -1, 1, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, 1, -1, 1, -1, -1, -1, 1, -1, 1 }, new[] { 1, -1, 1, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, 1 } }, state.matrix.Fix())); Assert.IsTrue(state.Add(1, 9)); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, new[] { -1, -2, -1, -1, -1, -1, -1, -1, -1, 1 }, new[] { 1, -1, -2, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, 1, -1, -2, -1, -1, -1, 1, -1, 1 }, new[] { 1, -1, 1, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, 1 } }, state.matrix.Fix())); Assert.IsTrue(state.Add(2, 8)); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, new[] { -1, -2, -1, -1, -1, -1, -1, -1, -1, 1 }, new[] { -3, -1, -2, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, -3, -1, -2, -1, -1, -1, 1, -1, 1 }, new[] { 1, -1, 1, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, 1 } }, state.matrix.Fix())); Assert.IsTrue(state.Add(3, 7)); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, new[] { -1, -2, -1, -1, -1, -1, -1, -1, -1, 1 }, new[] { -3, -1, -2, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, -3, -1, -2, -1, -1, -1, 1, -1, -4 }, new[] { -4, -1, 1, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, 1 } }, state.matrix.Fix())); Assert.IsTrue(state.Add(4, 2)); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, new[] { -1, -2, -1, -1, -1, -1, -1, -1, -1, 1 }, new[] { -3, -1, -2, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, -3, -1, -2, -1, -1, -1, 1, -1, -4 }, new[] { -4, -1, 1, -1, -1, -1, -1, -1, -5, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, -5 } }, state.matrix.Fix())); Assert.IsTrue(state.Add(5, 1)); Assert.IsTrue(Compares.AreDeepEqual( new int[][] { new[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, new[] { -1, -2, -1, -1, -1, -1, -1, -1, -1, 1 }, new[] { -3, -1, -2, -1, -1, -1, -1, -1, 1, -1 }, new[] { -1, -3, -1, -2, -1, -1, -1, 1, -1, -4 }, new[] { -4, -1, 1, -1, -1, -1, -1, -1, -5, -1 }, new[] { -1, 1, -1, -1, -1, -1, -1, -1, -1, -5 } }, state.matrix.Fix())); }
/// <summary> /// Create a pattern which can be used to find molecules which contain the /// <paramref name="query"/> structure. /// </summary> /// <param name="query">the substructure to find</param> /// <param name="atomMatcher">how atoms are matched</param> /// <param name="bondMatcher">how bonds are matched</param> /// <returns>a pattern for finding the <paramref name="query"/></returns> public static Pattern CreateSubstructureFinder(IAtomContainer query, AtomMatcher atomMatcher, BondMatcher bondMatcher) { return(new VentoFoggia(query, atomMatcher, bondMatcher, true)); }
/// <summary> /// Create a pattern which can be used to find molecules which are the same /// as the <paramref name="query"/> structure. /// </summary> /// <param name="query">the substructure to find</param> /// <param name="atomMatcher">how atoms are matched</param> /// <param name="bondMatcher">how bonds are matched</param> /// <returns>a pattern for finding the <paramref name="query"/></returns> public static Pattern CreateIdenticalFinder(IAtomContainer query, AtomMatcher atomMatcher, BondMatcher bondMatcher) { return(new VentoFoggia(query, atomMatcher, bondMatcher, false)); }