public void TestGetSubgraphMapIAtomContainerIAtomContainer()
        {
            var molfile               = "NCDK.Data.MDL.decalin.mol";
            var queryfile             = "NCDK.Data.MDL.decalin.mol";
            var mol                   = builder.NewAtomContainer();
            var temp                  = builder.NewAtomContainer();
            QueryAtomContainer query1 = null;
            QueryAtomContainer query2 = null;

            var ins    = ResourceLoader.GetAsStream(molfile);
            var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);

            reader.Read(mol);
            ins    = ResourceLoader.GetAsStream(queryfile);
            reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            reader.Read(temp);
            query1 = QueryAtomContainerCreator.CreateBasicQueryContainer(temp);

            var sp            = CDK.SmilesParser;
            var atomContainer = sp.ParseSmiles("C1CCCCC1");

            query2 = QueryAtomContainerCreator.CreateBasicQueryContainer(atomContainer);

            var list = uiTester.GetSubgraphMap(mol, query1);

            Assert.AreEqual(11, list.Count);

            list = uiTester.GetSubgraphMap(mol, query2);
            Assert.AreEqual(6, list.Count);
        }
Пример #2
0
        public void TestManuallyCentreActive()
        {
            var 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);

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

            var molecule2 = GetExpectedProducts()[0];

            var queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(uiTester.IsIsomorph(molecule2, queryAtom));
        }
Пример #3
0
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            var type = new SharingChargeSBReaction();

            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(2, setOfReactions[0].Products.Count);

            var product1 = setOfReactions[1].Products[0];

            var molecule1 = GetExpectedProducts()[0];
            var queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product1);

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

            var product2  = setOfReactions[0].Products[1];
            var expected2 = GetExpectedProducts()[0];

            queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(expected2);
            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(product2, queryAtom));
        }
Пример #4
0
        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));
        }
        public void TestSingleAtomMatching2()
        {
            var sp      = CDK.SmilesParser;
            var target  = sp.ParseSmiles("CNC");
            var queryac = sp.ParseSmiles("C");
            var query   = QueryAtomContainerCreator.CreateSymbolAndBondOrderQueryContainer(queryac);

            var matches = uiTester.GetIsomorphMaps(target, query).ToReadOnlyList();

            Assert.AreEqual(2, matches.Count);
            Assert.AreEqual(1, matches[0].Count);
            Assert.AreEqual(1, matches[1].Count);
            var map1 = matches[0][0];
            var map2 = matches[1][0];

            Assert.AreEqual(0, map1.Id1);
            Assert.AreEqual(0, map1.Id2);

            Assert.AreEqual(2, map2.Id1);
            Assert.AreEqual(0, map2.Id2);

            var atomMappings = UniversalIsomorphismTester.MakeAtomsMapsOfBondsMaps(matches, target, query);

            Assert.IsTrue(Compares.AreDeepEqual(matches, atomMappings));
        }
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            var type = new RadicalSiteRrGammaReaction();

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

            /* initiate */

            molecule.Atoms[0].IsReactiveCenter = true;
            molecule.Atoms[1].IsReactiveCenter = true;
            molecule.Atoms[5].IsReactiveCenter = true;
            molecule.Bonds[0].IsReactiveCenter = true;

            var paramList = new List <IParameterReaction>();
            var param     = new SetReactionCenter
            {
                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);

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

            var queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Пример #7
0
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            var type = new RearrangementLonePairReaction();

            var setOfReactants = GetExampleReactants();
            var 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);

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

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

            var molecule2 = GetExpectedProducts()[0];

            var queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Пример #8
0
        public void TestSingleAtomMatching2()
        {
            var sp      = CDK.SmilesParser;
            var target  = sp.ParseSmiles("CNC");
            var queryac = sp.ParseSmiles("C");
            var query   = QueryAtomContainerCreator.CreateSymbolAndBondOrderQueryContainer(queryac);

            var matches = CDKMCS.GetIsomorphMaps(target, query, true);

            Assert.AreEqual(2, matches.Count);
            Assert.AreEqual(1, matches[0].Count);
            Assert.AreEqual(1, matches[1].Count);
            var map1 = matches[0][0];
            var map2 = matches[1][0];

            Assert.AreEqual(0, map1.Id1);
            Assert.AreEqual(0, map1.Id2);

            Assert.AreEqual(2, map2.Id1);
            Assert.AreEqual(0, map2.Id2);

            var atomMappings = CDKMCS.MakeAtomsMapsOfBondsMaps(matches, target, query);

            Assert.AreEqual(matches, atomMappings);
        }
        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));
        }
Пример #10
0
        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));
        }
Пример #11
0
        public void TestOspDoubleB()
        {
            //CreateFromSmiles("O=C")
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.Atoms.Add(builder.NewAtom("H"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[3], BondOrder.Single);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            CDK.LonePairElectronChecker.Saturate(molecule);

            molecule.Atoms[0].IsReactiveCenter = true;
            molecule.Atoms[1].IsReactiveCenter = true;
            molecule.Bonds[0].IsReactiveCenter = true;

            var setOfReactants = ChemObjectBuilder.Instance.NewAtomContainerSet();

            setOfReactants.Add(molecule);

            IReactionProcess type = new HeterolyticCleavagePBReaction();
            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);

            // expected products

            //CreateFromSmiles("[O-][C+]")
            IAtomContainer expected1 = builder.NewAtomContainer();

            expected1.Atoms.Add(builder.NewAtom("O"));
            expected1.Atoms[0].FormalCharge = -1;
            expected1.Atoms.Add(builder.NewAtom("C"));
            expected1.Atoms[1].FormalCharge = +1;
            expected1.AddBond(expected1.Atoms[0], expected1.Atoms[1], BondOrder.Single);
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.Atoms.Add(builder.NewAtom("H"));
            expected1.AddBond(expected1.Atoms[1], expected1.Atoms[2], BondOrder.Single);
            expected1.AddBond(expected1.Atoms[1], expected1.Atoms[3], BondOrder.Single);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(expected1);
            CDK.LonePairElectronChecker.Saturate(expected1);
            IAtomContainer     product1  = setOfReactions[0].Products[0];
            QueryAtomContainer queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(expected1);

            Assert.IsTrue(uiTester.IsIsomorph(product1, queryAtom));
        }
        public void TestBasicQueryAtomContainer()
        {
            var sp            = CDK.SmilesParser;
            var atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C"); // acetic acid anhydride
            var SMILESquery   = sp.ParseSmiles("CC");            // acetic acid anhydride
            var query         = QueryAtomContainerCreator.CreateBasicQueryContainer(SMILESquery);

            Assert.IsTrue(uiTester.IsSubgraph(atomContainer, query));
        }
Пример #13
0
        private static void Test(string smaexp, string smainp)
        {
            var qry = new QueryAtomContainer();

            Assert.IsTrue(Smarts.Parse(qry, smainp));
            var sup    = QueryAtomContainerCreator.SuppressQueryHydrogens(qry);
            var smaact = Smarts.Generate(sup);

            Assert.AreEqual(smaexp, smaact);
        }
        public void TestAnyAtomAnyBondCase()
        {
            var sp      = CDK.SmilesParser;
            var target  = sp.ParseSmiles("O1C=CC=C1");
            var queryac = sp.ParseSmiles("C1CCCC1");
            var query   = QueryAtomContainerCreator.CreateAnyAtomAnyBondContainer(queryac, false);

            Assert.IsTrue(uiTester.IsSubgraph(target, query), "C1CCCC1 should be a subgraph of O1C=CC=C1");
            Assert.IsTrue(uiTester.IsIsomorph(target, query), "C1CCCC1 should be a isomorph of O1C=CC=C1");
        }
Пример #15
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
 }
Пример #16
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
        }
Пример #17
0
        private void AddTemplateMol(IAtomContainer mol)
        {
            templates.Add(mol);
            var query = QueryAtomContainerCreator.CreateAnyAtomAnyBondContainer(mol, false);

            queries.Add(query);
            for (int i = 0; i < mol.Atoms.Count; i++)
            {
                query.Atoms[i].Point3D = mol.Atoms[i].Point3D;
            }
            patterns.Add(Pattern.CreateSubstructureFinder(query));
        }
Пример #18
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));
        }
        public void TestFirstArgumentMustNotBeAnQueryAtomContainer()
        {
            var sp      = CDK.SmilesParser;
            var target  = sp.ParseSmiles("O1C=CC=C1");
            var queryac = sp.ParseSmiles("C1CCCC1");
            var query   = QueryAtomContainerCreator.CreateAnyAtomAnyBondContainer(queryac, false);

            try
            {
                uiTester.IsSubgraph(query, target);
                Assert.Fail("The UniversalIsomorphism should check when the first arguments is a QueryAtomContainer");
            }
            catch (Exception)
            {
                // OK, it must Assert.fail!
            }
        }
Пример #20
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));
        }
Пример #21
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);
        }
Пример #22
0
        public void TestManuallyCentreActive()
        {
            var type           = new RadicalSiteInitiationHReaction();
            var setOfReactants = GetExampleReactants();
            var 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);

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

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

            var queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product1);

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

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

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

            queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product2);
            Assert.IsTrue(new UniversalIsomorphismTester().IsIsomorph(molecule2, queryAtom));
        }
Пример #23
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);
        }
Пример #24
0
        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));
        }
Пример #25
0
        public override void TestInitiate_IAtomContainerSet_IAtomContainerSet()
        {
            var type = new AdductionProtonLPReaction();

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

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

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

            var product   = setOfReactions[0].Products[0];
            var molecule2 = GetExpectedProducts()[0];
            var queryAtom = QueryAtomContainerCreator.CreateSymbolAndChargeQueryContainer(product);

            Assert.IsTrue(uiTester.IsIsomorph(molecule2, queryAtom));
        }
        public void TestItself()
        {
            var smiles = "C1CCCCCCC1CC";
            var query  = QueryAtomContainerCreator.CreateAnyAtomContainer(CDK.SmilesParser.ParseSmiles(smiles), true);
            var ac     = CDK.SmilesParser.ParseSmiles(smiles);

            if (standAlone)
            {
                Console.Out.WriteLine("AtomCount of query: " + query.Atoms.Count);
                Console.Out.WriteLine("AtomCount of target: " + ac.Atoms.Count);
            }

            bool matched = uiTester.IsSubgraph(ac, query);

            if (standAlone)
            {
                Console.Out.WriteLine("QueryAtomContainer matched: " + matched);
            }
            if (!standAlone)
            {
                Assert.IsTrue(matched);
            }
        }
        public void TestWithNegativeCharge()
        {
            var 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);

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

            var molecule2 = GetExpectedProducts()[0];

            var 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));
        }
Пример #28
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));
        }
        public void TestUITTimeoutFix()
        {
            // Load molecules
            var filename  = "NCDK.Data.MDL.UITTimeout.sdf";
            var ins       = ResourceLoader.GetAsStream(filename);
            var reader    = new MDLV2000Reader(ins);
            var content   = reader.Read(builder.NewChemFile());
            var cList     = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();
            var molecules = new IAtomContainer[2];

            for (int j = 0; j < 2; j++)
            {
                var aAtomContainer = cList[j];
                var tmpMatcher     = CDK.AtomTypeMatcher;
                var tmpAdder       = CDK.HydrogenAdder;
                for (int i = 0; i < aAtomContainer.Atoms.Count; i++)
                {
                    var tmpAtom = aAtomContainer.Atoms[i];
                    var tmpType = tmpMatcher.FindMatchingAtomType(aAtomContainer, tmpAtom);
                    AtomTypeManipulator.Configure(tmpAtom, tmpType);
                    tmpAdder.AddImplicitHydrogens(aAtomContainer, tmpAtom);
                }
                AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(aAtomContainer);
                molecules[j] = aAtomContainer;
            }
            var query = QueryAtomContainerCreator.CreateAnyAtomForPseudoAtomQueryContainer(molecules[1]);
            // test
            var starttime = System.DateTime.Now.Ticks;

            uiTester.Timeout = 200;
            uiTester.GetSubgraphAtomsMaps(molecules[0], query);
            var duration = System.DateTime.Now.Ticks - starttime;

            // The search must last much longer then two seconds if the timeout not works
            Assert.IsTrue(duration < 2000 * 10000);  // 1 msec = 10000 ticks
        }
Пример #30
0
        public static IReadOnlyList <IBitFingerprint> MakeFingerprintsFromSdf(bool anyAtom, bool anyAtomAnyBond, Dictionary <string, int> timings, TextReader fin, int limit)
        {
            var fingerPrinter = new HybridizationFingerprinter(HybridizationFingerprinter.DefaultSize, HybridizationFingerprinter.DefaultSearchDepth);

            fingerPrinter.SetHashPseudoAtoms(true);
            IAtomContainer query = null;
            var            data  = new List <IBitFingerprint>();

            try
            {
                Trace.TraceInformation("Read data file in ...");
                using (var imdl = new EnumerableSDFReader(fin, builder))
                {
                    Trace.TraceInformation("ready");

                    int moleculeCounter    = 0;
                    int fingerprintCounter = 0;
                    Trace.TraceInformation($"Generated Fingerprints: {fingerprintCounter}    ");
                    foreach (var m in imdl)
                    {
                        if (!(moleculeCounter < limit || limit == -1))
                        {
                            break;
                        }
                        moleculeCounter++;
                        if (anyAtom && !anyAtomAnyBond)
                        {
                            query = QueryAtomContainerCreator.CreateAnyAtomContainer(m, false);
                        }
                        else
                        {
                            query = AtomContainerManipulator.Anonymise(m);
                        }
                        try
                        {
                            var time = -DateTime.Now.Ticks / 10000;
                            if (anyAtom || anyAtomAnyBond)
                            {
                                data.Add(fingerPrinter.GetBitFingerprint(query));
                                fingerprintCounter = fingerprintCounter + 1;
                            }
                            else
                            {
                                data.Add(fingerPrinter.GetBitFingerprint(query));
                                fingerprintCounter = fingerprintCounter + 1;
                            }
                            time += (DateTime.Now.Ticks / 10000);
                            // store the time
                            var bin = ((int)Math.Floor(time / 10.0)).ToString(NumberFormatInfo.InvariantInfo);
                            if (timings.ContainsKey(bin))
                            {
                                timings[bin] = (timings[bin]) + 1;
                            }
                            else
                            {
                                timings[bin] = 1;
                            }
                        }
                        catch (Exception exc1)
                        {
                            Trace.TraceInformation($"QueryFingerprintError: from molecule:{moleculeCounter} due to:{exc1.Message}");

                            // OK, just adds a fingerprint with all ones, so that any
                            // structure will match this template, and leave it up
                            // to substructure match to figure things out
                            var allOnesFingerprint = new BitSetFingerprint(fingerPrinter.Length);
                            for (int i = 0; i < fingerPrinter.Length; i++)
                            {
                                allOnesFingerprint.Set(i);
                            }
                            data.Add(allOnesFingerprint);
                            fingerprintCounter = fingerprintCounter + 1;
                        }

                        if (fingerprintCounter % 2 == 0)
                        {
                            Trace.TraceInformation("\b" + "/");
                        }
                        else
                        {
                            Trace.TraceInformation("\b" + "\\");
                        }

                        if (fingerprintCounter % 100 == 0)
                        {
                            Trace.TraceInformation("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
                                                   + "Generated Fingerprints: " + fingerprintCounter + "   \n");
                        }
                    }// while
                    Trace.TraceInformation($"...ready with:{moleculeCounter} molecules\nWrite data...of data vector:{data.Count} fingerprintCounter:{fingerprintCounter}");
                }
            }
            catch (Exception exc)
            {
                Console.Out.WriteLine("Could not read Molecules from file" + " due to: " + exc.Message);
            }
            return(data);
        }