Esempio n. 1
0
        private void MCSBuilder(IQueryAtomContainer mol1, IAtomContainer mol2)
        {
            int rBondCount = mol1.Bonds.Count;
            int pBondCount = mol2.Bonds.Count;

            int rAtomCount = mol1.Atoms.Count;
            int pAtomCount = mol2.Atoms.Count;

            if ((rBondCount == 0 && rAtomCount > 0) || (pBondCount == 0 && pAtomCount > 0))
            {
                SingleMapping();
            }
            else
            {
                ChooseAlgorithm(rBondCount, pBondCount);
            }

            if (allAtomMCS.Count != 0 && firstAtomMCS.Count != 0 && firstAtomMCS.Count > 1)
            {
                AllBondMaps = MakeBondMapsOfAtomMaps(mol1, mol2, allAtomMCS);
                if (AllBondMaps.Count != 0)
                {
                    SetFirstBondMap(AllBondMaps[0]);
                }
            }
        }
Esempio n. 2
0
        private static bool CheckQuery(IQueryAtomContainer query)
        {
            if (!(query is PharmacophoreQuery))
            {
                return(false);
            }
            var map = new Dictionary <string, string>();

            for (int i = 0; i < query.Atoms.Count; i++)
            {
                var atom = (IQueryAtom)query.Atoms[i];
                if (!(atom is PharmacophoreQueryAtom))
                {
                    return(false);
                }

                var    pqatom = (PharmacophoreQueryAtom)atom;
                string label  = pqatom.Symbol;
                string smarts = pqatom.Smarts;

                if (!map.ContainsKey(label))
                {
                    map[label] = smarts;
                }
                else
                {
                    if (!map[label].Equals(smarts, StringComparison.Ordinal))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            IReactionProcess type = new RadicalSiteHrBetaReaction();

            var setOfReactants = GetExampleReactants();

            /* initiate */

            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = false;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(3, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product   = setOfReactions[0].Products[0];
            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Esempio n. 4
0
        public void TestManuallyCentreActive()
        {
            IReactionProcess type = new AdductionProtonLPReaction();
            var setOfReactants    = GetExampleReactants();

            /* manually putting the active center */
            setOfReactants[0].Atoms[0].IsReactiveCenter = true;

            /* initiate */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = true;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];

            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(uiTester.IsIsomorph(molecule2, queryAtom));
        }
        public void TestManuallyCentreActive()
        {
            IReactionProcess type = new SharingAnionReaction();

            var            setOfReactants = GetExampleReactants();
            IAtomContainer molecule       = setOfReactants[0];

            /* manually put the center active */
            molecule.Atoms[0].IsReactiveCenter = true;
            molecule.Atoms[1].IsReactiveCenter = true;
            molecule.Bonds[0].IsReactiveCenter = true;

            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = true;
            paramList.Add(param);
            type.ParameterList = paramList;

            /* initiate */

            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];

            /* C=[O+] */
            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Esempio n. 6
0
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            IReactionProcess type = new SharingChargeDBReaction();

            var            setOfReactants = GetExampleReactants();
            IAtomContainer molecule       = setOfReactants[0];

            /* initiate */

            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter
            {
                IsSetParameter = false
            };

            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];

            Assert.AreEqual(1, product.Atoms[1].FormalCharge.Value);
            Assert.AreEqual(0, product.GetConnectedLonePairs(product.Atoms[1]).Count());

            /* C[C+]O| */
            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
        public void TestManuallyCentreActive()
        {
            IReactionProcess type = new TautomerizationReaction();

            var            setOfReactants = GetExampleReactants();
            IAtomContainer molecule       = setOfReactants[0];

            /* manually putting the active center */
            molecule.Atoms[0].IsReactiveCenter = true;
            molecule.Atoms[1].IsReactiveCenter = true;
            molecule.Atoms[2].IsReactiveCenter = true;
            molecule.Atoms[4].IsReactiveCenter = true;
            molecule.Bonds[0].IsReactiveCenter = true;
            molecule.Bonds[1].IsReactiveCenter = true;
            molecule.Bonds[3].IsReactiveCenter = true;

            /* initiate */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = true;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];

            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));

            // reverse process
            /* manually putting the active center */
            molecule2.Atoms[0].IsReactiveCenter = true;
            molecule2.Atoms[1].IsReactiveCenter = true;
            molecule2.Atoms[2].IsReactiveCenter = true;
            molecule2.Atoms[6].IsReactiveCenter = true;
            molecule2.Bonds[0].IsReactiveCenter = true;
            molecule2.Bonds[1].IsReactiveCenter = true;
            molecule2.Bonds[5].IsReactiveCenter = true;
            var setOfReactants2 = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants2.Add(molecule2);

            var setOfReactions2 = type.Initiate(setOfReactants2, null);

            Assert.AreEqual(1, setOfReactions2.Count);
            Assert.AreEqual(1, setOfReactions2[0].Products.Count);

            IAtomContainer product2 = setOfReactions2[0].Products[0];

            queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product2);
            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule, queryAtom));
        }
Esempio n. 8
0
 static void Main()
 {
     #region
     SmilesParser        sp            = new SmilesParser();
     IAtomContainer      atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); // acetic acid anhydride
     IAtomContainer      SMILESquery   = sp.ParseSmiles("CC");            // acetic acid anhydride
     IQueryAtomContainer query         = QueryAtomContainerCreator.CreateBasicQueryContainer(SMILESquery);
     bool isSubstructure = CDKMCS.IsSubgraph(atomContainer, query, true);
     #endregion
 }
Esempio n. 9
0
 private static bool HasAngleConstraints(IQueryAtomContainer query)
 {
     foreach (var bond in query.Bonds)
     {
         if (bond is PharmacophoreQueryAngleBond)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 10
0
        static void Main()
        {
            UniversalIsomorphismTester universalIsomorphismTester = new UniversalIsomorphismTester();

            #region
            SmilesParser        sp            = new SmilesParser();
            IAtomContainer      atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); // acetic acid anhydride
            IAtomContainer      SMILESquery   = sp.ParseSmiles("CC");            // ethylene
            IQueryAtomContainer query         = QueryAtomContainerCreator.CreateBasicQueryContainer(SMILESquery);
            bool isSubstructure = universalIsomorphismTester.IsSubgraph(atomContainer, query);
            #endregion
        }
Esempio n. 11
0
        public void TestCarbons()
        {
            IReactionProcess type     = new SharingAnionReaction();
            IAtomContainer   molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[0].FormalCharge = 1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[1].FormalCharge = -1;
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);

            AddExplicitHydrogens(molecule);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);

            CDK.LonePairElectronChecker.Saturate(molecule);

            var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants.Add(molecule);

            /* initiate */

            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = false;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product   = setOfReactions[0].Products[0];
            IAtomContainer molecule2 = builder.NewAtomContainer();

            molecule2.Atoms.Add(builder.NewAtom("C"));
            molecule2.Atoms.Add(builder.NewAtom("C"));
            molecule2.AddBond(molecule2.Atoms[0], molecule2.Atoms[1], BondOrder.Double);

            AddExplicitHydrogens(molecule2);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule2);
            CDK.LonePairElectronChecker.Saturate(molecule2);

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Esempio n. 12
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
        }
Esempio n. 13
0
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            IReactionProcess type = new PiBondingMovementReaction();
            // C1=C(C)-C(C)=C-C=C1
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[3], molecule.Atoms[4], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[4], molecule.Atoms[5], BondOrder.Double);
            molecule.AddBond(molecule.Atoms[5], molecule.Atoms[0], BondOrder.Single);

            AddExplicitHydrogens(molecule);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            MakeSureAtomTypesAreRecognized(molecule);

            var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants.Add(molecule);

            /* initiate */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = false;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product2 = setOfReactions[0].Products[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product2);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule, queryAtom));
        }
Esempio n. 14
0
        internal DfState(IQueryAtomContainer query)
        {
            var builder = query.Builder;

            if (builder == null)
            {
                builder = FindBuilder();
                if (builder == null)
                {
                    throw new ArgumentException("Please ensure query molecule has a IChemObjectBuilder set!");
                }
            }

            var tmp = builder.NewAtomContainer();

            tmp.Add(query);
            this.qbonds = new IQueryBond[tmp.Bonds.Count];
            this.amap   = new int[query.Atoms.Count];

            int stackSize = 0;

            foreach (var atom in tmp.Atoms)
            {
                if (atom is IQueryAtom)
                {
                    if (amap[atom.Index] == 0)
                    {
                        stackSize += Prepare(atom, null) + 1;
                    }
                }
                else
                {
                    throw new ArgumentException("All atoms must be IQueryAtoms!");
                }
            }

            this.stack = new StackFrame[stackSize + 2];
            for (int i = 0; i < stack.Length; i++)
            {
                this.stack[i] = new StackFrame();
            }

            this.numAtoms = amap.Length;
            this.query    = tmp;
        }
Esempio n. 15
0
        protected void Process(IQueryAtomContainer query, IAtomContainer target, IList <int> unmappedAtomsMolA,
                               IList <int> mappedAtoms, int counter)
        {
            int  unmappedNumA   = unmappedAtomsMolA.Count;
            bool bondConsidered = false;
            bool normalBond     = true;

            //        Console.Out.WriteLine("\n" + cTab1Copy + "\n");

            for (int atomIndex = 0; atomIndex < query.Bonds.Count; atomIndex++)
            {
                int indexI = query.Atoms.IndexOf(query.Bonds[atomIndex].Begin);
                int indexJ = query.Atoms.IndexOf(query.Bonds[atomIndex].End);
                int order  = 0;
                if (!query.Bonds[atomIndex].Order.IsUnset())
                {
                    order = query.Bonds[atomIndex].Order.Numeric();
                }

                //            Console.Out.WriteLine(AtomI + "= , =" + AtomJ );
                for (int unMappedAtomIndex = 0; unMappedAtomIndex < unmappedNumA; unMappedAtomIndex++)
                {
                    if (unmappedAtomsMolA[unMappedAtomIndex].Equals(indexI))
                    {
                        normalBond = UnMappedAtomsEqualsIndexJ(query, target, atomIndex, counter, mappedAtoms, indexI,
                                                               indexJ, order);
                        bondConsidered = true;
                    }
                    else //Does a ungemaptes atom at second position in the connection occur?
                    if (unmappedAtomsMolA[unMappedAtomIndex].Equals(indexJ))
                    {
                        normalBond = UnMappedAtomsEqualsIndexI(query, target, atomIndex, counter, mappedAtoms, indexI,
                                                               indexJ, order);
                        bondConsidered = true;
                    }
                    if (normalBond && bondConsidered)
                    {
                        MarkNormalBonds(atomIndex, indexI, indexJ, order);
                        normalBond = true;
                        break;
                    }
                }
                bondConsidered = false;
            }
        }
Esempio n. 16
0
        public void TestQueryAtomContainerMCSPLUS()
        {
            Isomorphism smsd   = new Isomorphism(Algorithm.MCSPlus, true);
            var         sp     = CDK.SmilesParser;
            var         query  = sp.ParseSmiles("CC");
            var         target = sp.ParseSmiles("C1CCC12CCCC2");

            smsd.Init(query, target, false, true);
            bool foundMatches = smsd.IsSubgraph();

            Assert.IsTrue(foundMatches);

            IQueryAtomContainer queryContainer = QueryAtomContainerCreator.CreateSymbolAndBondOrderQueryContainer(query);

            smsd.Init(queryContainer, target);
            foundMatches = smsd.IsSubgraph();
            Assert.IsTrue(foundMatches);
        }
Esempio n. 17
0
        public void TestManuallyCentreActive()
        {
            IReactionProcess type         = new RadicalSiteInitiationHReaction();
            var            setOfReactants = GetExampleReactants();
            IAtomContainer molecule       = setOfReactants[0];

            /* initiate */
            MakeSureAtomTypesAreRecognized(molecule);

            /* manually put the reactive center */
            molecule.Atoms[0].IsReactiveCenter = true;
            molecule.Atoms[3].IsReactiveCenter = true;
            molecule.Atoms[4].IsReactiveCenter = true;
            molecule.Bonds[2].IsReactiveCenter = true;
            molecule.Bonds[3].IsReactiveCenter = true;

            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = true;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(2, setOfReactions[0].Products.Count);

            IAtomContainer product1 = setOfReactions[0].Products[0];

            /* C=C */
            IAtomContainer molecule1 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product1);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule1, queryAtom));

            IAtomContainer product2 = setOfReactions[0].Products[1];

            /* [H*] */
            IAtomContainer molecule2 = GetExpectedProducts()[1];

            queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product2);
            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Esempio n. 18
0
        public void TestMatchCountCDKMCS()
        {
            Isomorphism smsd   = new Isomorphism(Algorithm.CDKMCS, true);
            var         sp     = CDK.SmilesParser;
            var         query  = sp.ParseSmiles("CC");
            var         target = sp.ParseSmiles("C1CCC12CCCC2");

            smsd.Init(query, target, false, true);
            bool foundMatches = smsd.IsSubgraph();

            Assert.AreEqual(18, smsd.GetAllAtomMapping().Count);
            Assert.IsTrue(foundMatches);

            IQueryAtomContainer queryContainer = QueryAtomContainerCreator.CreateSymbolAndBondOrderQueryContainer(query);

            smsd.Init(queryContainer, target);
            foundMatches = smsd.IsSubgraph();
            Assert.IsTrue(foundMatches);
        }
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            IReactionProcess type = new TautomerizationReaction();

            var            setOfReactants = GetExampleReactants();
            IAtomContainer molecule       = setOfReactants[0];

            /* initiate */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = false;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];

            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));

            // reverse process
            var setOfReactants2 = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants2.Add(molecule2);

            IReactionSet setOfReactions2 = type.Initiate(setOfReactants2, null);

            Assert.AreEqual(1, setOfReactions2.Count);
            Assert.AreEqual(1, setOfReactions2[0].Products.Count);

            IAtomContainer product2 = setOfReactions2[0].Products[0];

            queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product2);
            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule, queryAtom));
        }
Esempio n. 20
0
        void Main()
        {
            IQueryAtomContainer query = null;
            IAtomContainer      mol   = null;

            #region
            var pattern = DfPattern.CreateSubstructureFinder(query);
            // has match?
            if (pattern.Matches(mol))
            {
            }
            // get lazy mapping iterator
            foreach (var atom in mol.Atoms)
            {
                if (pattern.MatchesRoot(atom))
                {
                }
            }
            #endregion
        }
Esempio n. 21
0
        /// <summary>
        /// Constructor for the McGregor algorithm.
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="mappings"></param>
        /// </summary>
        public McGregor(IQueryAtomContainer source, IAtomContainer target, IEnumerable <IReadOnlyList <int> > mappings)
        {
            IsBondMatch       = true;
            this.source       = source;
            this.target       = target;
            this.mappings     = mappings.ToList();
            this.bestarcsleft = 0;

            if (this.mappings.Count != 0)
            {
                this.globalMCSSize = this.mappings[0].Count;
            }
            else
            {
                this.globalMCSSize = 0;
            }
            this.modifiedARCS = new List <int>();
            this.bestArcs     = new Stack <IReadOnlyList <int> >();
            this.newMatrix    = false;
        }
Esempio n. 22
0
        private static IQuery Build(IQueryAtomContainer queryMolecule)
        {
            VFQueryBuilder result = new VFQueryBuilder();

            foreach (var atoms in queryMolecule.Atoms)
            {
                IQueryAtom     atom    = (IQueryAtom)atoms;
                IVFAtomMatcher matcher = CreateAtomMatcher(atom, queryMolecule);
                if (matcher != null)
                {
                    result.AddNode(matcher, atom);
                }
            }
            for (int i = 0; i < queryMolecule.Bonds.Count; i++)
            {
                IBond      bond  = queryMolecule.Bonds[i];
                IQueryAtom atomI = (IQueryAtom)bond.Begin;
                IQueryAtom atomJ = (IQueryAtom)bond.End;
                result.Connect(result.GetNode(atomI), result.GetNode(atomJ), CreateBondMatcher((IQueryBond)bond));
            }
            return(result);
        }
Esempio n. 23
0
        private void SetSourceSingleAtomMap(IQueryAtomContainer source, bool removeHydrogen)
        {
            int          counter = 0;
            BondEnergies be      = BondEnergies.Instance;

            foreach (var sourceAtom in source.Atoms)
            {
                var smartAtom = (IQueryAtom)sourceAtom;
                if ((removeHydrogen && !smartAtom.AtomicNumber.Equals(AtomicNumbers.H)) || (!removeHydrogen))
                {
                    foreach (var targetAtom in target.Atoms)
                    {
                        var mapAtoms = new Dictionary <IAtom, IAtom>();
                        if (smartAtom.Matches(targetAtom))
                        {
                            mapAtoms[sourceAtom] = targetAtom;
                            var bonds = target.GetConnectedBonds(targetAtom);

                            double totalOrder = 0;
                            foreach (var bond in bonds)
                            {
                                BondOrder order = bond.Order;
                                totalOrder += order.Numeric() + BondEnergies.GetEnergies(bond);
                            }
                            if (targetAtom.FormalCharge != sourceAtom.FormalCharge)
                            {
                                totalOrder += 0.5;
                            }
                            connectedBondOrder[counter] = totalOrder;
                            mappings.Insert(counter++, mapAtoms);
                        }
                    }
                }
                else
                {
                    Console.Error.WriteLine("Skipping Hydrogen mapping or This is not a single mapping case!");
                }
            }
        }
        public void TestWithNegativeCharge()
        {
            IReactionProcess type = new HyperconjugationReaction();

            var setOfReactants = GetExampleReactants();

            /* automatic search of the center active */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = false;
            paramList.Add(param);
            type.ParameterList = paramList;

            /* initiate */
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(3, setOfReactions.Count);
            Assert.AreEqual(2, setOfReactions[0].Products.Count);

            IAtomContainer product = setOfReactions[0].Products[0];

            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(molecule2);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(product, queryAtom));

            product = setOfReactions[0].Products[1];

            molecule2 = builder.NewAtomContainer();
            molecule2.Atoms.Add(builder.NewAtom("H"));
            molecule2.Atoms[0].FormalCharge = 1;

            queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);
            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Esempio n. 25
0
        public void TestDoubleRingConjugated2()
        {
            IReactionProcess type = new PiBondingMovementReaction();
            // C1=CC(=CC2=C1C=CC=C2)C

            var            setOfReactants = GetExampleReactants();
            IAtomContainer molecule       = setOfReactants[0];

            /* manually putting the reaction center */
            molecule.Bonds[1].IsReactiveCenter  = true;
            molecule.Bonds[2].IsReactiveCenter  = true;
            molecule.Bonds[3].IsReactiveCenter  = true;
            molecule.Bonds[9].IsReactiveCenter  = true;
            molecule.Bonds[10].IsReactiveCenter = true;
            molecule.Bonds[11].IsReactiveCenter = true;

            /* initiate */
            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter();

            param.IsSetParameter = true;
            paramList.Add(param);
            type.ParameterList = paramList;
            var setOfReactions = type.Initiate(setOfReactants, null);

            Assert.AreEqual(1, setOfReactions.Count);
            Assert.AreEqual(1, setOfReactions[0].Products.Count);

            IAtomContainer product2 = setOfReactions[0].Products[0];

            IAtomContainer molecule2 = GetExpectedProducts()[0];

            IQueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product2);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Esempio n. 26
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="smartQueryAtom">query atom</param>
 /// <param name="container"></param>
 public DefaultVFAtomMatcher(IQueryAtom smartQueryAtom, IQueryAtomContainer container)
     : base()
 {
     this.smartQueryAtom = smartQueryAtom;
     this.symbol         = smartQueryAtom.Symbol;
 }
Esempio n. 27
0
 public void Set(IQueryAtomContainer source, IAtomContainer target)
 {
     this.smartSource = source;
     this.source      = source;
     this.target      = target;
 }
Esempio n. 28
0
 /// <summary>
 /// Creates a new instance
 /// </summary>
 /// <param name="query"></param>
 public RecursiveSmartsAtom(IQueryAtomContainer query)
     : base()
 {
     this.query = query;
     this.cache = new Dictionary <IAtomContainer, BitArray>();
 }
Esempio n. 29
0
 private DfPattern(IQueryAtomContainer query)
 {
     this.query = query;
     DetermineFilters(query);
     state = new DfState(query);
 }
Esempio n. 30
0
        /// <summary>
        /// Returns single mapping solutions.
        /// </summary>
        /// <exception cref="CDKException"></exception>
        protected internal IReadOnlyList <IReadOnlyDictionary <IAtom, IAtom> > GetOverLaps(IQueryAtomContainer source, IAtomContainer target, bool removeHydrogen)
        {
            mappings           = new List <IReadOnlyDictionary <IAtom, IAtom> >();
            connectedBondOrder = new SortedDictionary <int, double>();
            this.source        = source;
            this.target        = target;

            if (source.Atoms.Count == 1 || (source.Atoms.Count > 0 && source.Bonds.Count == 0))
            {
                SetSourceSingleAtomMap(source, removeHydrogen);
            }
            if (target.Atoms.Count == 1 || (target.Atoms.Count > 0 && target.Bonds.Count == 0))
            {
                SetTargetSingleAtomMap(removeHydrogen);
            }

            PostFilter();
            return(mappings);
        }