public void TestRemoveMolecule()
        {
            Debug.WriteLine("***TestRemoveMolecule***");
            bool            itIsInThere = false;
            TemplateHandler th          = new TemplateHandler();
            IAtomContainer  mol         = TestMoleculeFactory.MakeAlphaPinene();

            sdg.Molecule = mol;
            sdg.GenerateCoordinates();
            mol = sdg.Molecule;

            var smiles    = "C1=C(C)C2CC(C1)C2(C)(C)";
            var smilesMol = sp.ParseSmiles(smiles);

            itIsInThere = th.MapTemplates(smilesMol);
            Debug.WriteLine($"Alpha-Pinene found by templateMapper: {itIsInThere}");
            Assert.IsFalse(itIsInThere);
            th.AddMolecule(mol);
            Debug.WriteLine("now adding template for alpha-Pinen and trying again.");
            itIsInThere = th.MapTemplates(smilesMol);
            Debug.WriteLine($"Alpha-Pinene found by templateMapper: {itIsInThere}");
            Assert.IsTrue(itIsInThere);
            Debug.WriteLine("now removing template for alpha-Pinen again and trying again.");
            th.RemoveMolecule(mol);
            itIsInThere = th.MapTemplates(smilesMol);
            Debug.WriteLine($"Alpha-Pinene found by templateMapper: {itIsInThere}");
            Assert.IsFalse(itIsInThere);
        }
Exemple #2
0
        /// <summary>
        /// Singleton template instance, mainly useful for aligning molecules.
        /// </summary>
        /// <remarks>
        /// If the template does not have coordinates an error is thrown.
        /// For safety we clone the molecule.
        /// </remarks>
        /// <param name="template">the molecule</param>
        /// <returns>new template handler</returns>
        public static TemplateHandler CreateSingleton(IAtomContainer template)
        {
            var handler = new TemplateHandler();
            var copy    = (IAtomContainer)template.Clone();

            handler.AddMolecule(copy);
            return(handler);
        }
        public void TestDetection()
        {
            TemplateHandler th     = new TemplateHandler();
            var             smiles = "CC12C3(C6CC6)C4(C)C1C5(C(CC)C)C(C(CC)C)2C(C)3C45CC(C)C";
            var             mol    = sp.ParseSmiles(smiles);

            Assert.IsTrue(th.MapTemplates(mol));
        }
        public void TestOtherBondOrder()
        {
            bool            itIsInThere = false;
            TemplateHandler th          = new TemplateHandler();
            IAtomContainer  mol         = TestMoleculeFactory.MakeSteran();

            itIsInThere = th.MapTemplates(mol);
            Assert.IsTrue(itIsInThere);
            mol.Bonds[0].Order = BondOrder.Double;
            itIsInThere        = th.MapTemplates(mol);
            Assert.IsTrue(itIsInThere);
        }
        public void TestOtherElements()
        {
            bool            itIsInThere = false;
            TemplateHandler th          = new TemplateHandler();
            IAtomContainer  mol         = TestMoleculeFactory.MakeSteran();

            itIsInThere = th.MapTemplates(mol);
            Assert.IsTrue(itIsInThere);
            mol.Atoms[0].Symbol = "N";
            itIsInThere         = th.MapTemplates(mol);
            Assert.IsTrue(itIsInThere);
        }
        public void Convert()
        {
            var templateHandler = new TemplateHandler();

            using (var bout = new MemoryStream())
            {
                templateHandler.ToIdentityTemplateLibrary().Store(bout);
                Assert.AreEqual(
                    "C1C2CC3CC1CC(C2)C3 |(-1.07,-1.59,;.38,-1.21,;1.82,-1.59,;1.07,-.29,;-.38,-.67,;-1.82,-.29,;-1.82,1.21,;-.37,1.59,;.38,.29,;1.07,1.21,)|\n"
                    + "C12C3C4C1C5C2C3C45 |(.62,-.99,;-.88,-1.12,;-1.23,.43,;.26,.57,;.88,1.12,;1.23,-.43,;-.26,-.57,;-.62,.98,)|\n"
                    + "C1C2CC3C4CC5CC(C14)C(C2)C3C5 |(-1.82,2.15,;-.37,2.53,;1.07,2.15,;1.07,.65,;-.38,.27,;-.38,-1.23,;.37,-2.53,;-1.07,-2.15,;-1.07,-.65,;-1.82,.65,;.38,-.27,;.38,1.23,;1.82,-.65,;1.82,-2.15,)|\n"
                    + "C1CCC2C(C1)CCC3C4CCCC4CCC23 |(-6.51,.72,;-6.51,-.78,;-5.22,-1.53,;-3.92,-.78,;-3.92,.72,;-5.22,1.47,;-2.62,1.47,;-1.32,.72,;-1.32,-.78,;-.02,-1.53,;1.41,-1.07,;2.29,-2.28,;1.41,-3.49,;-.02,-3.03,;-1.32,-3.78,;-2.62,-3.03,;-2.62,-1.53,)|\n"
                    + "C1CCCCCCCCCCCCC1 |(-.04,1.51,;1.26,.76,;1.26,-.74,;2.56,-1.49,;2.56,-2.99,;1.29,-3.72,;1.31,-5.29,;-.09,-5.89,;-1.34,-5.24,;-1.34,-3.74,;-2.63,-2.99,;-2.63,-1.49,;-1.34,-.74,;-1.34,.76,)|\n",
                    System.Text.Encoding.UTF8.GetString(bout.ToArray()));
            }
        }
        /// <summary>
        /// Loads a molecule with two adamantanes and one cubane
        /// substructure and tests whether all are found.
        /// </summary>
        public void GetMappedSubstructures_IAtomContainer()
        {
            // Set up molecule reader
            var filename  = "NCDK.Data.MDL.diadamantane-cubane.mol";
            var ins       = ResourceLoader.GetAsStream(filename);
            var molReader = new MDLReader(ins, ChemObjectReaderMode.Strict);

            // Read molecule
            var molecule = molReader.Read(builder.NewAtomContainer());

            // Map templates
            var th = new TemplateHandler();
            var mappedStructures = th.GetMappedSubstructures(molecule);

            // Do the Assert.assertion
            Assert.AreEqual(3, mappedStructures.Count, "3 mapped templates");
        }
        public void TestInit()
        {
            TemplateHandler th = new TemplateHandler();

            Assert.AreEqual(5, th.TemplateCount);
        }