Пример #1
0
        public void TestBug795480()
        {
            IAtomContainer    molecule = null;
            HOSECodeGenerator hcg      = null;

            string[] result = { "C-4-;C(=C/Y'+4'/)", "C-3;=CC-(Y'+4',//)", "C-3;=CY'+4'(C-,//)", "Br-1'+4';C(=C/C-/)" };

            molecule = CDK.SmilesParser.ParseSmiles("CC=CBr");
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            bool isAromatic = Aromaticity.CDKLegacy.Apply(molecule);

            Assert.IsFalse(isAromatic);
            molecule.Atoms[0].FormalCharge = -1;
            molecule.Atoms[3].FormalCharge = +4;
            hcg = new HOSECodeGenerator();
            string s = null;

            for (int f = 0; f < molecule.Atoms.Count; f++)
            {
                s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 4);
                if (standAlone)
                {
                    Console.Out.Write("|" + s + "| -> " + result[f]);
                }
                Assert.AreEqual(result[f], s);
                if (standAlone)
                {
                    Console.Out.WriteLine("  OK");
                }
            }
        }
Пример #2
0
        public void TestBug655169()
        {
            IAtomContainer    molecule = null;
            HOSECodeGenerator hcg      = null;

            string[] result = { "C-4;C(=C/Y/)", "C-3;=CC(Y,//)", "C-3;=CY(C,//)", "Br-1;C(=C/C/)" };

            molecule = CDK.SmilesParser.ParseSmiles("CC=CBr");
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            Aromaticity.CDKLegacy.Apply(molecule);
            hcg = new HOSECodeGenerator();
            string s = null;

            for (int f = 0; f < molecule.Atoms.Count; f++)
            {
                s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 4);
                if (standAlone)
                {
                    Console.Out.Write("|" + s + "| -> " + result[f]);
                }
                Assert.AreEqual(result[f], s);
                if (standAlone)
                {
                    Console.Out.WriteLine("  OK");
                }
            }
        }
Пример #3
0
        public void Test4()
        {
            string[] result = { "C-3;*C*C*C(*C*N,*C,*C/*C,*&,*&,*&/*&)", "C-3;*C*C(*C*C,*N/*C*&,*C,*&/*C,*&)",
                                "C-3;*C*N(*C,*C/*&*C,*&*C/,*C,*C)",      "N-3;*C*C(*C*C,*C/*C*&,*C,*&/*C,*&)",
                                "C-3;*C*C*N(*C*C,*C,*C/*C,*&,*&,*&/*&)", "C-3;*C*C(*C*N,*C/*C*C,*C,*&/*&,*&,*&)",
                                "C-3;*C*C(*C,*C/*C*N,*&/*&*C,*C)",       "C-3;*C*C(*C,*C/*C*C,*&/*&*N,*C)",
                                "C-3;*C*C(*C*C,*C/*C*N,*C,*&/*&,*&,*&)" };

            IAtomContainer molecule = CDK.SmilesParser
                                      .ParseSmiles("C1(C=CN2)=C2C=CC=C1");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            Aromaticity.CDKLegacy.Apply(molecule);
            //Display(molecule);
            HOSECodeGenerator hcg = new HOSECodeGenerator();
            string            s   = null;

            for (int f = 0; f < molecule.Atoms.Count; f++)
            {
                s = hcg.GetHOSECode(molecule, molecule.Atoms[f], 4);
                if (standAlone)
                {
                    Console.Out.WriteLine(f + "|" + s + "| -> " + result[f]);
                }
                Assert.AreEqual(result[f], s);
                if (standAlone)
                {
                    Console.Out.WriteLine("  OK");
                }
            }
        }
Пример #4
0
        public void TestMakeBremserCompliant()
        {
            string[] startData = { "O-1;=C(//)",  "C-3;=OCC(//)", "C-2;CC(//)",  "C-2;CC(//)",  "C-3;CCC(//)", "C-2;CC(//)",
                                   "C-2;CC(//)",  "C-3;CCC(//)",  "C-3;CCC(//)", "C-2;CC(//)",  "C-2;CC(//)",  "C-2;CC(//)","C-2;CC(//)",
                                   "C-3;CCO(//)", "O-2;CC(//)",   "C-3;CCO(//)", "C-3;CCO(//)", "O-2;CC(//)",  "C-1;O(//)", "C-2;CC(//)",
                                   "C-3;CCC(//)", "C-3;CCC(//)",  "C-3;CCC(//)" };

            string[] result = { "=C(//)",  "=OCC(//)", "CC(//)",  "CC(//)",  "CCC(//)", "CC(//)",  "CC(//)", "CCC(//)",
                                "CCC(//)", "CC(//)",   "CC(//)",  "CC(//)",  "CC(//)",  "CCO(//)", "CC(//)", "CCO(//)","CCO(//)","CC(//)",
                                "O(//)",   "CC(//)",   "CCC(//)", "CCC(//)", "CCC(//)" };

            string s = null;

            for (int f = 0; f < startData.Length; f++)
            {
                s = HOSECodeGenerator.MakeBremserCompliant(startData[f]);
                if (standAlone)
                {
                    Console.Out.Write("|" + s + "| -> " + result[f]);
                }
                Assert.AreEqual(result[f], s);
                if (standAlone)
                {
                    Console.Out.WriteLine("  OK");
                }
            }
        }
Пример #5
0
        public void TestGetConfidenceLimit()
        {
            var result = new double[]
            {
                28.5, 25.7, 28.5, 34.9, 28.5, 25.7, 25.4, 28.5, 28.5, 14.8, 13.3, 23.0, 34.9, 25.7, 25.7,
                28.5, 25.7, 25.7, 13.3, 14.4, 14.4, 8.9, 14.8, 14.8, 13.3, 13.3, 13.3, 14.4, 14.4, 13.3, 14.4, 14.4,
                8.9, 14.8, 14.8, 13.3, 13.3, 13.3, 14.4, 14.4, 13.3,
            };
            IAtomContainer molecule = null;
            var            filename = "NCDK.Data.MDL.BremserPredictionTest.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);

            molecule = reader.Read(builder.NewAtomContainer());
            double prediction;
            var    bp  = new BremserOneSphereHOSECodePredictor();
            var    hcg = new HOSECodeGenerator();
            string s   = null;

            RemoveHydrogens(molecule);
            for (int f = 0; f < molecule.Atoms.Count; f++)
            {
                s          = hcg.GetHOSECode(molecule, molecule.Atoms[f], 1);
                prediction = bp.GetConfidenceLimit(HOSECodeGenerator.MakeBremserCompliant(s));
                Assert.AreEqual(result[f], prediction, 0.001);
            }
        }
Пример #6
0
        public void TestGetAtomsOfSphere()
        {
            IAtomContainer molecule = CDK.SmilesParser.ParseSmiles("CC=CBr");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            Aromaticity.CDKLegacy.Apply(molecule);
            HOSECodeGenerator hcg = new HOSECodeGenerator();

            hcg.GetSpheres(molecule, molecule.Atoms[0], 4, true);
            var atoms = hcg.GetNodesInSphere(3).ToReadOnlyList();

            Assert.AreEqual(1, atoms.Count);
            Assert.AreEqual("Br", atoms[0].Symbol);
        }
Пример #7
0
            /// <summary>
            /// Constructor for the TreeNode object.
            /// </summary>
            /// <param name="parent"></param>
            /// <param name="symbol">The Element symbol of the node</param>
            /// <param name="source">The preceding node for this node</param>
            /// <param name="atom">The IAtom object belonging to this node</param>
            /// <param name="bondType">The bond type by which this node was connect to its predecessor</param>
            /// <param name="degree">Description of the Parameter</param>
            /// <param name="score">The score used to rank this node within its sphere.</param>
            public TreeNode(HOSECodeGenerator parent, string symbol, TreeNode source, IAtom atom, double bondType, int degree, long score)
            {
                this.parent = parent;

                this.symbol   = symbol;
                this.source   = source;
                this.atom     = atom;
                this.degree   = degree;
                this.score    = score;
                this.bondType = bondType;
                ranking       = 0;
                sortOrder     = 1;
                childs        = new List <TreeNode>();
            }
Пример #8
0
        public void TestSecondSphere()
        {
            var            filename = "NCDK.Data.MDL.isopropylacetate.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            IAtomContainer mol1     = reader.Read(builder.NewAtomContainer());
            string         code1    = new HOSECodeGenerator().GetHOSECode(mol1, mol1.Atoms[0], 6);

            filename = "NCDK.Data.MDL.testisopropylacetate.mol";
            var            ins2    = ResourceLoader.GetAsStream(filename);
            MDLV2000Reader reader2 = new MDLV2000Reader(ins2, ChemObjectReaderMode.Strict);
            IAtomContainer mol2    = reader2.Read(builder.NewAtomContainer());
            string         code2   = new HOSECodeGenerator().GetHOSECode(mol2, mol2.Atoms[2], 6);

            Assert.AreNotSame(code2, code1);
        }
Пример #9
0
        public void Test1Sphere()
        {
            string[] result = { "O-1;=C(//)",   "C-3;=OCC(//)",  "C-3;=CC(//)",   "C-3;=CC(//)",    "C-3;*C*CC(//)", "C-3;*C*C(//)",
                                "C-3;*C*C(//)", "C-3;*C*CC(//)", "C-3;*C*CC(//)", "C-3;*C*C(//)",   "C-3;*C*C(//)",  "C-3;*C*C(//)",
                                "C-3;*C*C(//)", "C-3;*C*CO(//)", "O-2;CC(//)",    "C-3;*C*CO(//)",  "C-3;*C*CO(//)", "O-2;CC(//)",
                                "C-4;O(//)",    "C-3;*C*C(//)",  "C-3;*C*CC(//)", "C-3;*C*C*C(//)", "C-3;*C*C*C(//)" };

            var   mol = builder.NewAtomContainer();
            IAtom a1  = mol.Builder.NewAtom("O");

            a1.Point2D = new Vector2(502.88457268119913, 730.4999999999999);
            mol.Atoms.Add(a1);
            IAtom a2 = mol.Builder.NewAtom("C");

            a2.Point2D = new Vector2(502.8845726811991, 694.4999999999999);
            mol.Atoms.Add(a2);
            IAtom a3 = mol.Builder.NewAtom("C");

            a3.Point2D = new Vector2(534.0614872174388, 676.4999999999999);
            mol.Atoms.Add(a3);
            IAtom a4 = mol.Builder.NewAtom("C");

            a4.Point2D = new Vector2(534.0614872174388, 640.4999999999999);
            mol.Atoms.Add(a4);
            IAtom a5 = mol.Builder.NewAtom("C");

            a5.Point2D = new Vector2(502.8845726811991, 622.4999999999999);
            mol.Atoms.Add(a5);
            IAtom a6 = mol.Builder.NewAtom("C");

            a6.Point2D = new Vector2(502.8845726811991, 586.4999999999999);
            mol.Atoms.Add(a6);
            IAtom a7 = mol.Builder.NewAtom("C");

            a7.Point2D = new Vector2(471.7076581449593, 568.4999999999999);
            mol.Atoms.Add(a7);
            IAtom a8 = mol.Builder.NewAtom("C");

            a8.Point2D = new Vector2(440.5307436087194, 586.5);
            mol.Atoms.Add(a8);
            IAtom a9 = mol.Builder.NewAtom("C");

            a9.Point2D = new Vector2(409.35382907247964, 568.5);
            mol.Atoms.Add(a9);
            IAtom a10 = mol.Builder.NewAtom("C");

            a10.Point2D = new Vector2(409.3538290724796, 532.5);
            mol.Atoms.Add(a10);
            IAtom a11 = mol.Builder.NewAtom("C");

            a11.Point2D = new Vector2(378.1769145362398, 514.5);
            mol.Atoms.Add(a11);
            IAtom a12 = mol.Builder.NewAtom("C");

            a12.Point2D = new Vector2(347.0, 532.5);
            mol.Atoms.Add(a12);
            IAtom a13 = mol.Builder.NewAtom("C");

            a13.Point2D = new Vector2(347.0, 568.5);
            mol.Atoms.Add(a13);
            IAtom a14 = mol.Builder.NewAtom("C");

            a14.Point2D = new Vector2(378.17691453623985, 586.5);
            mol.Atoms.Add(a14);
            IAtom a15 = mol.Builder.NewAtom("O");

            a15.Point2D = new Vector2(378.17691453623985, 622.5);
            mol.Atoms.Add(a15);
            IAtom a16 = mol.Builder.NewAtom("C");

            a16.Point2D = new Vector2(409.3538290724797, 640.5);
            mol.Atoms.Add(a16);
            IAtom a17 = mol.Builder.NewAtom("C");

            a17.Point2D = new Vector2(409.3538290724797, 676.5);
            mol.Atoms.Add(a17);
            IAtom a18 = mol.Builder.NewAtom("O");

            a18.Point2D = new Vector2(378.17691453623996, 694.5);
            mol.Atoms.Add(a18);
            IAtom a19 = mol.Builder.NewAtom("C");

            a19.Point2D = new Vector2(378.17691453624, 730.5);
            mol.Atoms.Add(a19);
            IAtom a20 = mol.Builder.NewAtom("C");

            a20.Point2D = new Vector2(440.5307436087195, 694.4999999999999);
            mol.Atoms.Add(a20);
            IAtom a21 = mol.Builder.NewAtom("C");

            a21.Point2D = new Vector2(471.7076581449593, 676.4999999999999);
            mol.Atoms.Add(a21);
            IAtom a22 = mol.Builder.NewAtom("C");

            a22.Point2D = new Vector2(471.7076581449593, 640.4999999999999);
            mol.Atoms.Add(a22);
            IAtom a23 = mol.Builder.NewAtom("C");

            a23.Point2D = new Vector2(440.53074360871943, 622.4999999999999);
            mol.Atoms.Add(a23);
            IBond b1 = mol.Builder.NewBond(a2, a1, BondOrder.Double);

            mol.Bonds.Add(b1);
            IBond b2 = mol.Builder.NewBond(a3, a2, BondOrder.Single);

            mol.Bonds.Add(b2);
            IBond b3 = mol.Builder.NewBond(a4, a3, BondOrder.Double);

            mol.Bonds.Add(b3);
            IBond b4 = mol.Builder.NewBond(a5, a4, BondOrder.Single);

            mol.Bonds.Add(b4);
            IBond b5 = mol.Builder.NewBond(a6, a5, BondOrder.Single);

            mol.Bonds.Add(b5);
            IBond b6 = mol.Builder.NewBond(a7, a6, BondOrder.Double);

            mol.Bonds.Add(b6);
            IBond b7 = mol.Builder.NewBond(a8, a7, BondOrder.Single);

            mol.Bonds.Add(b7);
            IBond b8 = mol.Builder.NewBond(a9, a8, BondOrder.Single);

            mol.Bonds.Add(b8);
            IBond b9 = mol.Builder.NewBond(a10, a9, BondOrder.Single);

            mol.Bonds.Add(b9);
            IBond b10 = mol.Builder.NewBond(a11, a10, BondOrder.Double);

            mol.Bonds.Add(b10);
            IBond b11 = mol.Builder.NewBond(a12, a11, BondOrder.Single);

            mol.Bonds.Add(b11);
            IBond b12 = mol.Builder.NewBond(a13, a12, BondOrder.Double);

            mol.Bonds.Add(b12);
            IBond b13 = mol.Builder.NewBond(a14, a13, BondOrder.Single);

            mol.Bonds.Add(b13);
            IBond b14 = mol.Builder.NewBond(a14, a9, BondOrder.Double);

            mol.Bonds.Add(b14);
            IBond b15 = mol.Builder.NewBond(a15, a14, BondOrder.Single);

            mol.Bonds.Add(b15);
            IBond b16 = mol.Builder.NewBond(a16, a15, BondOrder.Single);

            mol.Bonds.Add(b16);
            IBond b17 = mol.Builder.NewBond(a17, a16, BondOrder.Double);

            mol.Bonds.Add(b17);
            IBond b18 = mol.Builder.NewBond(a18, a17, BondOrder.Single);

            mol.Bonds.Add(b18);
            IBond b19 = mol.Builder.NewBond(a19, a18, BondOrder.Single);

            mol.Bonds.Add(b19);
            IBond b20 = mol.Builder.NewBond(a20, a17, BondOrder.Single);

            mol.Bonds.Add(b20);
            IBond b21 = mol.Builder.NewBond(a21, a20, BondOrder.Double);

            mol.Bonds.Add(b21);
            IBond b22 = mol.Builder.NewBond(a21, a2, BondOrder.Single);

            mol.Bonds.Add(b22);
            IBond b23 = mol.Builder.NewBond(a22, a21, BondOrder.Single);

            mol.Bonds.Add(b23);
            IBond b24 = mol.Builder.NewBond(a22, a5, BondOrder.Double);

            mol.Bonds.Add(b24);
            IBond b25 = mol.Builder.NewBond(a23, a22, BondOrder.Single);

            mol.Bonds.Add(b25);
            IBond b26 = mol.Builder.NewBond(a23, a16, BondOrder.Single);

            mol.Bonds.Add(b26);
            IBond b27 = mol.Builder.NewBond(a23, a8, BondOrder.Double);

            mol.Bonds.Add(b27);

            AddImplicitHydrogens(mol);

            //MoleculeViewer2D.Display(molecule, true);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);
            Aromaticity.CDKLegacy.Apply(mol);
            HOSECodeGenerator hcg = new HOSECodeGenerator();
            string            s   = null;

            for (int f = 0; f < 23; f++)
            {
                s = hcg.GetHOSECode(mol, mol.Atoms[f], 1);
                if (standAlone)
                {
                    Console.Out.Write("|" + s + "| -> " + result[f]);
                }
                Assert.AreEqual(result[f], s);
                if (standAlone)
                {
                    Console.Out.WriteLine("  OK");
                }
            }
        }