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();
        }
        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();
        }
Beispiel #3
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    imdlr.Dispose();
                }

                imdlr = null;

                disposedValue = true;
            }
        }
Beispiel #4
0
 static void Main()
 {
     {
         #region
         using (var srm = new FileStream("../zinc-structures/ZINC_subset3_3D_charged_wH_maxmin1000.sdf", FileMode.Open))
         {
             EnumerableSDFReader reader = new EnumerableSDFReader(srm, ChemObjectBuilder.Instance);
             foreach (var molecule in reader)
             {
                 // do something
             }
         }
         #endregion
     }
 }
        public void TestMultipleEntryFields()
        {
            var filename = "NCDK.Data.MDL.test.sdf";
            var ins      = ResourceLoader.GetAsStream(filename);

            using (var reader = new EnumerableSDFReader(ins, CDK.Builder))
            {
                var tor = reader.GetEnumerator();
                tor.MoveNext();
                IAtomContainer m = (IAtomContainer)tor.Current;
                Assert.AreEqual("553-97-9", m.GetProperty <string>("E_CAS"));
                tor.MoveNext();
                m = tor.Current;
                Assert.AreEqual("120-78-5", m.GetProperty <string>("E_CAS"));
            }
        }
        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();
        }
        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();
        }
        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();
        }
        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();
        }
        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);
        }
        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);
        }
        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();
        }
Beispiel #13
0
 public EnumerableMDLConformerReader(Stream ins, IChemObjectBuilder builder)
 {
     imdlr = new EnumerableSDFReader(ins, builder);
 }
Beispiel #14
0
 public IEnumerableMDLConformerReader(TextReader ins, IChemObjectBuilder builder)
 {
     imdlr = new EnumerableSDFReader(ins, builder);
 }