Ejemplo n.º 1
0
        /// <summary>
        /// Adapter to current CDK <see cref="Pattern"/> that takes and iterator of an
        /// int[] permutation from the query to the molecule.
        /// </summary>
        /// <returns>the enumerator</returns>
        public IEnumerator <int[]> GetEnumerator()
        {
            var lstate = new DfState(this);

            while (lstate.MatchNext())
            {
                yield return(lstate.amap);
            }
            yield break;
        }
Ejemplo n.º 2
0
        void Main()
        {
            IQueryAtomContainer query = null;
            IAtomContainer      mol   = null;

            #region
            var state = new DfState(query);
            state.SetMol(mol);
            int count = 0;
            foreach (int[] amap in state)
            {
                // amap is permutation of query to molecule
                ++count;
            }
            #endregion
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Match the pattern at the provided root.
        /// </summary>
        /// <param name="root">the root atom of the molecule</param>
        /// <returns>mappings</returns>
        /// <see cref="Mappings"/>
        Mappings MatchRoot(IAtom root)
        {
            CheckCompatibleAPI(root);
            var mol = root.Container;

            if (query.Atoms.Count > 0 && ((IQueryAtom)query.Atoms[0]).Matches(root))
            {
                var local = new DfState(state);
                local.SetRoot(root);
                return(Filter(new Mappings(query, mol, local), query, mol));
            }
            else
            {
                return(new Mappings(query, mol, Array.Empty <int[]>()));
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override Mappings MatchAll(IAtomContainer mol)
        {
            if (mol.Atoms.Count < query.Atoms.Count)
            {
                return(new Mappings(query, mol, Array.Empty <int[]>()));
            }
            if (mol.Atoms.Count > 0)
            {
                CheckCompatibleAPI(mol.Atoms[0]);
            }
            var local = new DfState(state);

            local.SetMol(mol);
            var mappings = new Mappings(query, mol, local);

            return(Filter(mappings, query, mol));
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Copy constructor, if a state has already been prepared the internals
 /// can be copied and the separate instance used in a thread-safe manner.
 /// </summary>
 /// <param name="state">the state</param>
 internal DfState(DfState state)
 {
     // only need shallow copy of the query bonds
     this.qbonds    = (IQueryBond[])state.qbonds.Clone();
     this.query     = state.query;
     this.numBonds  = state.numBonds;
     this.numAtoms  = state.numAtoms;
     this.numMapped = state.numMapped;
     this.amap      = (int[])state.amap.Clone();
     this.avisit    = state.avisit != null ? (bool[])state.avisit.Clone() : null;
     this.mol       = state.mol;
     // deep copy of the stack-frame
     this.stack = new StackFrame[state.stack.Length];
     for (int i = 0; i < stack.Length; i++)
     {
         this.stack[i] = new StackFrame(state.stack[i]);
     }
     this.sptr = state.sptr;
 }
Ejemplo n.º 6
0
 private DfPattern(IQueryAtomContainer query)
 {
     this.query = query;
     DetermineFilters(query);
     state = new DfState(query);
 }