Example #1
0
        public void TestQueryToolReSetSmarts()
        {
            var             sp            = CDK.SmilesParser;
            var             atomContainer = sp.ParseSmiles("C1CCC12CCCC2");
            SMARTSQueryTool querytool     = new SMARTSQueryTool("C", ChemObjectBuilder.Instance);

            bool status = querytool.Matches(atomContainer);

            Assert.IsTrue(status);

            int nmatch = querytool.MatchesCount;

            Assert.AreEqual(8, nmatch);

            querytool.Smarts = "CC";
            status           = querytool.Matches(atomContainer);
            Assert.IsTrue(status);

            nmatch = querytool.MatchesCount;
            Assert.AreEqual(18, nmatch);

            var umatch = querytool.GetUniqueMatchingAtoms();

            Assert.AreEqual(9, umatch.Count());
        }
 static void Main()
 {
     {
         #region
         SmilesParser    sp            = new SmilesParser();
         IAtomContainer  atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C");
         SMARTSQueryTool querytool     = new SMARTSQueryTool("O=CO");
         bool            status        = querytool.Matches(atomContainer);
         if (status)
         {
             int nmatch   = querytool.MatchesCount;
             var mappings = querytool.GetMatchingAtoms();
             foreach (var atomIndices in mappings)
             {
                 // do something
             }
         }
         #endregion
     }
     {
         string someSmartsPattern = null;
         IChemObjectSet <IAtomContainer> molecules = null;
         #region SetAromaticity
         SMARTSQueryTool sqt = new SMARTSQueryTool(someSmartsPattern);
         sqt.SetAromaticity(new Aromaticity(ElectronDonation.CDKModel, Cycles.CDKAromaticSetFinder));
         foreach (var molecule in molecules)
         {
             // CDK Aromatic model needs atom types
             AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
             sqt.Matches(molecule);
         }
         #endregion
     }
 }
Example #3
0
        public void TestMethane()
        {
            IAtomContainer methane = CDK.Builder.NewAtomContainer();
            IAtom          carbon  = methane.Builder.NewAtom(ChemicalElement.C);

            carbon.ImplicitHydrogenCount = 4;
            methane.Atoms.Add(carbon);

            SMARTSQueryTool sqt     = new SMARTSQueryTool("CC", ChemObjectBuilder.Instance);
            bool            matches = sqt.Matches(methane);

            Assert.IsFalse(matches);
        }
Example #4
0
        public void TestQueryToolSingleAtomCase()
        {
            var             sp            = CDK.SmilesParser;
            var             atomContainer = sp.ParseSmiles("C1CCC12CCCC2");
            SMARTSQueryTool querytool     = new SMARTSQueryTool("C", ChemObjectBuilder.Instance);

            bool status = querytool.Matches(atomContainer);

            Assert.IsTrue(status);

            int nmatch = querytool.MatchesCount;

            Assert.AreEqual(8, nmatch);
        }
Example #5
0
        public void SetAromaticity()
        {
            SMARTSQueryTool sqt = new SMARTSQueryTool("[a]", ChemObjectBuilder.Instance);

            IAtomContainer furan = CreateFromSmiles("O1C=CC=C1");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(furan);

            sqt.SetAromaticity(new Aromaticity(ElectronDonation.CDKModel, Cycles.MCBFinder));
            Assert.IsTrue(sqt.Matches(furan, true));

            sqt.SetAromaticity(new Aromaticity(ElectronDonation.PiBondsModel, Cycles.MCBFinder));
            Assert.IsFalse(sqt.Matches(furan, true));
        }
Example #6
0
        public void TestIndoleAgainstItself()
        {
            IAtomContainer indole = TestMoleculeFactory.MakeIndole();

            AddImplicitHydrogens(indole);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(indole);
            Aromaticity.CDKLegacy.Apply(indole);
            SmilesGenerator generator    = new SmilesGenerator().Aromatic();
            string          indoleSmiles = generator.Create(indole);
            var             smilesParser = CDK.SmilesParser;

            indole = smilesParser.ParseSmiles(indoleSmiles);

            SMARTSQueryTool querytool = new SMARTSQueryTool(indoleSmiles, ChemObjectBuilder.Instance);

            Assert.IsTrue(querytool.Matches(indole));
        }
Example #7
0
        public void TestQuery()
        {
            var sp            = CDK.SmilesParser;
            var atomContainer = sp.ParseSmiles("c12cc(CCN)ccc1c(COC)ccc2");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(atomContainer);
            Aromaticity.CDKLegacy.Apply(atomContainer);
            SMARTSQueryTool querytool = new SMARTSQueryTool("c12ccccc1cccc2", ChemObjectBuilder.Instance);

            bool status = querytool.Matches(atomContainer);

            Assert.IsTrue(status);

            int nmatch = querytool.MatchesCount;

            Assert.AreEqual(4, nmatch);

            var umatch = querytool.GetUniqueMatchingAtoms();

            Assert.AreEqual(1, umatch.Count());
        }
Example #8
0
        public void TestUniqueQueries()
        {
            var sp            = CDK.SmilesParser;
            var atomContainer = sp.ParseSmiles("c1ccccc1CCCNCCCc1ccccc1");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(atomContainer);
            Aromaticity.CDKLegacy.Apply(atomContainer);
            SMARTSQueryTool querytool = new SMARTSQueryTool("c1ccccc1");

            bool status = querytool.Matches(atomContainer);

            Assert.IsTrue(status);

            int nmatch = querytool.MatchesCount;

            Assert.AreEqual(24, nmatch);

            var umatch = querytool.GetUniqueMatchingAtoms();

            Assert.AreEqual(2, umatch.Count());
        }
Example #9
0
        public void TestQueryTool()
        {
            var             sp            = CDK.SmilesParser;
            var             atomContainer = sp.ParseSmiles("CC(=O)OC(=O)C");
            SMARTSQueryTool querytool     = new SMARTSQueryTool("O=CO", ChemObjectBuilder.Instance);

            bool status = querytool.Matches(atomContainer);

            Assert.IsTrue(status);

            int nmatch = querytool.MatchesCount;

            Assert.AreEqual(2, nmatch);

            List <int> map1 = new List <int> {
                1, 2, 3,
            };
            List <int> map2 = new List <int> {
                3, 4, 5,
            };

            var mappings = querytool.GetMatchingAtoms().ToReadOnlyList();
            var ret1     = mappings[0].OrderBy(n => n).ToReadOnlyList();

            for (int i = 0; i < 3; i++)
            {
                Assert.IsTrue(Compares.AreDeepEqual(map1[i], ret1[i]));
            }

            var ret2 = mappings[1].OrderBy(n => n).ToReadOnlyList();

            for (int i = 0; i < 3; i++)
            {
                Assert.AreEqual(map2[i], ret2[i]);
            }
        }
Example #10
0
 public void TestLexicalError()
 {
     SMARTSQueryTool sqt = new SMARTSQueryTool("Epoxide", ChemObjectBuilder.Instance);
 }
Example #11
0
        public void NullAromaticity()
        {
            SMARTSQueryTool sqt = new SMARTSQueryTool("CC", ChemObjectBuilder.Instance);

            sqt.SetAromaticity(null);
        }
Example #12
0
 public void TestLexicalError()
 {
     SMARTSQueryTool sqt = new SMARTSQueryTool("Epoxide");
 }
Example #13
0
        public void NullAromaticity()
        {
            SMARTSQueryTool sqt = new SMARTSQueryTool("CC");

            sqt.SetAromaticity(null);
        }