Esempio n. 1
0
 public void Issue602()
 {
     using (var reader = new MDLV3000Reader(ResourceLoader.GetAsStream(GetType(), "issue602.mol")))
     {
         var mol = reader.Read(builder.NewAtomContainer());
         Assert.AreEqual(31, mol.Atoms.Count);
     }
 }
Esempio n. 2
0
 public void PositionalVariationRoundTrip()
 {
     using (var mdlr = new MDLV3000Reader(GetType().Assembly.GetManifestResourceStream(GetType(), "multicenterBond.mol")))
     {
         var mol = mdlr.Read(builder.NewAtomContainer());
         var res = WriteToStr(mol);
         Assert.IsTrue(res.Contains("M  V30 8 1 8 9 ATTACH=Any ENDPTS=(5 2 3 4 5 6)\n"));
     }
 }
Esempio n. 3
0
 public void RadicalsInCH3()
 {
     using (MDLV3000Reader reader = new MDLV3000Reader(GetType().Assembly.GetManifestResourceStream(GetType(), "CH3.mol")))
     {
         IAtomContainer container = reader.Read(builder.NewAtomContainer());
         Assert.AreEqual(1, container.SingleElectrons.Count);
         Assert.AreEqual(3, container.Atoms[0].ImplicitHydrogenCount);
     }
 }
Esempio n. 4
0
 public void PseuDoAtomReplacement()
 {
     using (MDLV3000Reader reader = new MDLV3000Reader(GetType().Assembly.GetManifestResourceStream(GetType(), "pseudoAtomReplacement.mol")))
     {
         IAtomContainer container = reader.Read(builder.NewAtomContainer());
         foreach (var atom in container.Bonds[9].Atoms)
         {
             Assert.IsTrue(container.Contains(atom));
         }
     }
 }
Esempio n. 5
0
 public void PositionalVariation()
 {
     using (MDLV3000Reader reader = new MDLV3000Reader(GetType().Assembly.GetManifestResourceStream(GetType(), "multicenterBond.mol")))
     {
         IAtomContainer container = reader.Read(builder.NewAtomContainer());
         Assert.AreEqual(8, container.Bonds.Count);
         var sgroups = container.GetCtabSgroups();
         Assert.IsNotNull(sgroups);
         Assert.AreEqual(1, sgroups.Count);
         Assert.AreEqual(SgroupType.ExtMulticenter, sgroups[0].Type);
     }
 }
Esempio n. 6
0
 public void TestPseudoAtomLabels()
 {
     using (var ins = ResourceLoader.GetAsStream("NCDK.Data.MDL.pseudoatomsv3000.mol"))
         using (MDLV3000Reader reader = new MDLV3000Reader(ins))
         {
             IAtomContainer molecule = builder.NewAtomContainer();
             molecule = reader.Read(molecule);
             reader.Close();
             Assert.IsTrue(molecule.Atoms[9] is IPseudoAtom);
             Assert.AreEqual("R", molecule.Atoms[9].Symbol);
             IPseudoAtom pa = (IPseudoAtom)molecule.Atoms[9];
             Assert.AreEqual("Leu", pa.Label);
         }
 }
Esempio n. 7
0
        public void TestEmptyString()
        {
            string emptyString = "";

            try
            {
                using (MDLV3000Reader reader = new MDLV3000Reader(new StringReader(emptyString)))
                {
                    reader.Read(builder.NewAtomContainer());
                    reader.Close();
                    Assert.Fail("Should have received a CDK Exception");
                }
            }
            catch (CDKException cdkEx)
            {
                Assert.AreEqual("Expected a header line, but found nothing.", cdkEx.Message);
            }
        }
Esempio n. 8
0
        public void TestBug1571207()
        {
            var filename = "NCDK.Data.MDL.molV3000.mol";

            Trace.TraceInformation("Testing: " + filename);
            using (var ins = ResourceLoader.GetAsStream(filename))
            {
                MDLV3000Reader reader = new MDLV3000Reader(ins);
                IAtomContainer m      = reader.Read(builder.NewAtomContainer());
                reader.Close();
                Assert.IsNotNull(m);
                Assert.AreEqual(31, m.Atoms.Count);
                Assert.AreEqual(34, m.Bonds.Count);

                IAtom atom = m.Atoms[0];
                Assert.IsNotNull(atom);
                Assert.IsNotNull(atom.Point2D);
                Assert.AreEqual(10.4341, atom.Point2D.Value.X, 0.0001);
                Assert.AreEqual(5.1053, atom.Point2D.Value.Y, 0.0001);
            }
        }
Esempio n. 9
0
        public void TestAccepts()
        {
            MDLV3000Reader reader = new MDLV3000Reader(new StringReader(""));

            Assert.IsTrue(reader.Accepts(typeOfAtomContainer));
        }
Esempio n. 10
0
        private IReaction ReadReaction(IChemObjectBuilder builder)
        {
            IReaction reaction = builder.NewReaction();

            ReadLine(); // first line should be $RXN
            ReadLine(); // second line
            ReadLine(); // third line
            ReadLine(); // fourth line

            int  reactantCount = 0;
            int  productCount  = 0;
            bool foundCOUNTS   = false;

            while (!foundCOUNTS)
            {
                string command = ReadCommand();
                if (command.StartsWith("COUNTS", StringComparison.Ordinal))
                {
                    var tokenizer = Strings.Tokenize(command);
                    try
                    {
                        reactantCount = int.Parse(tokenizer[1], NumberFormatInfo.InvariantInfo);
                        Trace.TraceInformation($"Expecting {reactantCount} reactants in file");
                        productCount = int.Parse(tokenizer[2], NumberFormatInfo.InvariantInfo);
                        Trace.TraceInformation($"Expecting {productCount } products in file");
                    }
                    catch (Exception exception)
                    {
                        Debug.WriteLine(exception);
                        throw new CDKException("Error while counts line of RXN file", exception);
                    }
                    foundCOUNTS = true;
                }
                else
                {
                    Trace.TraceWarning("Waiting for COUNTS line, but found: " + command);
                }
            }

            // now read the reactants
            for (int i = 1; i <= reactantCount; i++)
            {
                var    molFile             = new StringBuilder();
                string announceMDLFileLine = ReadCommand();
                if (!string.Equals(announceMDLFileLine, "BEGIN REACTANT", StringComparison.Ordinal))
                {
                    string error = "Excepted start of reactant, but found: " + announceMDLFileLine;
                    Trace.TraceError(error);
                    throw new CDKException(error);
                }
                string molFileLine = "";
                while (!molFileLine.EndsWith("END REACTANT", StringComparison.Ordinal))
                {
                    molFileLine = ReadLine();
                    molFile.Append(molFileLine);
                    molFile.Append('\n');
                }
                ;

                try
                {
                    // read MDL molfile content
                    MDLV3000Reader reader   = new MDLV3000Reader(new StringReader(molFile.ToString()), base.ReaderMode);
                    IAtomContainer reactant = (IAtomContainer)reader.Read(builder.NewAtomContainer());
                    reader.Close();

                    // add reactant
                    reaction.Reactants.Add(reactant);
                }
                catch (Exception exception)
                {
                    if (!(exception is ArgumentException ||
                          exception is CDKException ||
                          exception is IOException))
                    {
                        throw;
                    }
                    string error = "Error while reading reactant: " + exception.Message;
                    Trace.TraceError(error);
                    Debug.WriteLine(exception);
                    throw new CDKException(error, exception);
                }
            }

            // now read the products
            for (int i = 1; i <= productCount; i++)
            {
                var    molFile             = new StringBuilder();
                string announceMDLFileLine = ReadCommand();
                if (!string.Equals(announceMDLFileLine, "BEGIN PRODUCT", StringComparison.Ordinal))
                {
                    string error = "Excepted start of product, but found: " + announceMDLFileLine;
                    Trace.TraceError(error);
                    throw new CDKException(error);
                }
                string molFileLine = "";
                while (!molFileLine.EndsWith("END PRODUCT", StringComparison.Ordinal))
                {
                    molFileLine = ReadLine();
                    molFile.Append(molFileLine);
                    molFile.Append('\n');
                }
                ;

                try
                {
                    // read MDL molfile content
                    MDLV3000Reader reader  = new MDLV3000Reader(new StringReader(molFile.ToString()));
                    IAtomContainer product = (IAtomContainer)reader.Read(builder.NewAtomContainer());
                    reader.Close();

                    // add product
                    reaction.Products.Add(product);
                }
                catch (Exception exception)
                {
                    if (!(exception is ArgumentException ||
                          exception is CDKException ||
                          exception is IOException))
                    {
                        throw;
                    }
                    string error = "Error while reading product: " + exception.Message;
                    Trace.TraceError(error);
                    Debug.WriteLine(exception);
                    throw new CDKException(error, exception);
                }
            }

            return(reaction);
        }