コード例 #1
0
        public void TestZeroZCoordinates()
        {
            var filename = "NCDK.Data.MDL.nozcoord.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins  = ResourceLoader.GetAsStream(filename);
            var prop = new NameValueCollection
            {
                ["ForceReadAs3DCoordinates"] = "true"
            };
            PropertiesListener  listener = new PropertiesListener(prop);
            EnumerableSDFReader reader   = new EnumerableSDFReader(ins, CDK.Builder);

            reader.Listeners.Add(listener);
            reader.CustomizeJob();
            int molCount = 0;

            foreach (var obj in reader)
            {
                Assert.IsNotNull(obj);
                Assert.IsTrue(obj is IAtomContainer);
                molCount++;
                bool has3d = GeometryUtil.Has3DCoordinates((IAtomContainer)obj);
                Assert.IsTrue(has3d);
            }
            Assert.AreNotSame(0, molCount);
            reader.Close();
        }
コード例 #2
0
        public void TestEmptyEntryIteratingReader()
        {
            var filename = "NCDK.Data.MDL.emptyStructures.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);
            int molCount = 0;

            foreach (var obj in reader)
            {
                Assert.IsNotNull(obj);
                Assert.IsTrue(obj is IAtomContainer);
                molCount++;

                if (molCount == 2)
                {
                    IAtomContainer mol = (IAtomContainer)obj;
                    string         s   = mol.GetProperty <string>("Species");
                    Assert.AreEqual("rat", s);
                }
            }

            Assert.AreEqual(2, molCount);
            reader.Close();
        }
コード例 #3
0
        public void TestNo3DCoordsButForcedAs()
        {
            // First test unforced 3D coordinates
            var filename = "NCDK.Data.MDL.no3dStructures.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);
            int            molCount    = 0;
            IAtomContainer mol         = null;

            foreach (var obj in reader)
            {
                Assert.IsNotNull(obj);
                Assert.IsTrue(obj is IAtomContainer);
                molCount++;
                mol = (IAtomContainer)obj;
            }

            Assert.AreEqual(2, molCount);
            Assert.IsNotNull(mol.Atoms[0].Point2D);
            Assert.IsNull(mol.Atoms[0].Point3D);
            reader.Close();

            // Now test forced 3D coordinates
            Trace.TraceInformation("Testing: " + filename);
            ins    = ResourceLoader.GetAsStream(filename);
            reader = new EnumerableSDFReader(ins, CDK.Builder);
            reader.Listeners.Add(new MyListener());
            reader.CustomizeJob();
            molCount = 0;
            mol      = null;
            foreach (var obj in reader)
            {
                Assert.IsNotNull(obj);
                Assert.IsTrue(obj is IAtomContainer);
                molCount++;
                mol = (IAtomContainer)obj;
            }

            Assert.AreEqual(2, molCount);
            Assert.IsNull(mol.Atoms[0].Point2D);
            Assert.IsNotNull(mol.Atoms[0].Point3D);
            reader.Close();
        }
コード例 #4
0
        public void TestReadTitle()
        {
            var filename = "NCDK.Data.MDL.test.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);
            var etor = reader.GetEnumerator();

            Assert.IsTrue(etor.MoveNext());
            object obj = etor.Current;

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is IAtomContainer);
            Assert.AreEqual("2-methylbenzo-1,4-quinone", ((IAtomContainer)obj).Title);
            Assert.AreEqual(MDLV2000Format.Instance, reader.Format);
            reader.Close();
        }
コード例 #5
0
        public void TestOnSingleEntrySDFile()
        {
            var filename = "NCDK.Data.MDL.singleMol.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);

            int molCount = 0;

            foreach (var obj in reader)
            {
                Assert.IsNotNull(obj);
                Assert.IsTrue(obj is IAtomContainer);
                molCount++;
            }

            Assert.AreEqual(1, molCount);
            reader.Close();
        }
コード例 #6
0
        public void TestSDF()
        {
            var filename = "NCDK.Data.MDL.test2.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);

            int molCount = 0;

            foreach (var obj in reader)
            {
                Assert.IsNotNull(obj);
                Assert.IsTrue(obj is IAtomContainer);
                molCount++;
                Assert.AreEqual(MDLV2000Format.Instance, reader.Format, "Molecule # was not in MDL V2000 format: " + molCount);
            }

            Assert.AreEqual(6, molCount);
            reader.Close();
        }
コード例 #7
0
        public void TestV3000MolfileFormat()
        {
            string path                = "NCDK.Data.MDL.molV3000.mol";
            var    ins                 = ResourceLoader.GetAsStream(path);
            var    builder             = CDK.Builder;
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, builder)
            {
                Skip = true // skip over null entries and keep reading until EOF
            };

            int count = 0;

            foreach (var m in reader)
            {
                count++;
            }

            reader.Close();

            Assert.AreEqual(1, count);
        }
コード例 #8
0
        public void TestBrokenSDF()
        {
            string path                = "NCDK.Data.MDL.bug3488307.sdf";
            var    ins                 = ResourceLoader.GetAsStream(path);
            var    builder             = CDK.Builder;
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, builder)
            {
                Skip = true // skip over null entries and keep reading until EOF
            };

            int count = 0;

            foreach (var m in reader)
            {
                count++;
            }

            reader.Close();

            Assert.AreEqual(3, count);
        }
コード例 #9
0
        public void TestReadDataItems()
        {
            var filename = "NCDK.Data.MDL.test.sdf";

            Trace.TraceInformation("Testing: " + filename);
            var ins = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);

            var etor = reader.GetEnumerator();

            Assert.IsTrue(etor.MoveNext());
            object obj = etor.Current;

            Assert.IsNotNull(obj);
            Assert.IsTrue(obj is IAtomContainer);
            IAtomContainer m = (IAtomContainer)obj;

            Assert.AreEqual("1", m.GetProperty <string>("E_NSC"));
            Assert.AreEqual("553-97-9", m.GetProperty <string>("E_CAS"));
            reader.Close();
        }