Ejemplo n.º 1
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 (Ready && !foundCOUNTS)
            {
                System.String command = readCommand();
                if (command.StartsWith("COUNTS"))
                {
                    SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command);
                    try
                    {
                        tokenizer.NextToken();
                        reactantCount = System.Int32.Parse(tokenizer.NextToken());
                        //logger.info("Expecting " + reactantCount + " reactants in file");
                        productCount = System.Int32.Parse(tokenizer.NextToken());
                        //logger.info("Expecting " + productCount + " products in file");
                    }
                    catch (System.Exception exception)
                    {
                        //logger.debug(exception);
                        throw new CDKException("Error while counts line of RXN file", exception);
                    }
                    foundCOUNTS = true;
                }
                else
                {
                    //logger.warn("Waiting for COUNTS line, but found: " + command);
                }
            }

            // now read the reactants
            for (int i = 1; i <= reactantCount; i++)
            {
                System.Text.StringBuilder molFile             = new System.Text.StringBuilder();
                System.String             announceMDLFileLine = readCommand();
                if (!announceMDLFileLine.Equals("BEGIN REACTANT"))
                {
                    System.String error = "Excepted start of reactant, but found: " + announceMDLFileLine;
                    //logger.error(error);
                    throw new CDKException(error);
                }
                System.String molFileLine = "";
                while (!molFileLine.EndsWith("END REACTANT"))
                {
                    molFileLine = readLine();
                    molFile.Append(molFileLine);
                    molFile.Append("\n");
                }
                ;

                try
                {
                    // read MDL molfile content
                    MDLV3000Reader reader   = new MDLV3000Reader(new StreamReader(molFile.ToString()));
                    IMolecule      reactant = (IMolecule)reader.read(builder.newMolecule());

                    // add reactant
                    reaction.addReactant(reactant);
                }
                catch (System.Exception exception)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    System.String error = "Error while reading reactant: " + exception.Message;
                    //logger.error(error);
                    //logger.debug(exception);
                    throw new CDKException(error, exception);
                }
            }

            // now read the products
            for (int i = 1; i <= productCount; i++)
            {
                System.Text.StringBuilder molFile             = new System.Text.StringBuilder();
                System.String             announceMDLFileLine = readCommand();
                if (!announceMDLFileLine.Equals("BEGIN PRODUCT"))
                {
                    System.String error = "Excepted start of product, but found: " + announceMDLFileLine;
                    //logger.error(error);
                    throw new CDKException(error);
                }
                System.String molFileLine = "";
                while (!molFileLine.EndsWith("END PRODUCT"))
                {
                    molFileLine = readLine();
                    molFile.Append(molFileLine);
                    molFile.Append("\n");
                }
                ;

                try
                {
                    // read MDL molfile content
                    MDLV3000Reader reader  = new MDLV3000Reader(new StreamReader(molFile.ToString()));
                    IMolecule      product = (IMolecule)reader.read(builder.newMolecule());

                    // add product
                    reaction.addProduct(product);
                }
                catch (System.Exception exception)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    System.String error = "Error while reading product: " + exception.Message;
                    //logger.error(error);
                    //logger.debug(exception);
                    throw new CDKException(error, exception);
                }
            }

            return(reaction);
        }
Ejemplo n.º 2
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 (Ready && !foundCOUNTS)
            {
                System.String command = readCommand();
                if (command.StartsWith("COUNTS"))
                {
                    SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(command);
                    try
                    {
                        tokenizer.NextToken();
                        reactantCount = System.Int32.Parse(tokenizer.NextToken());
                        //logger.info("Expecting " + reactantCount + " reactants in file");
                        productCount = System.Int32.Parse(tokenizer.NextToken());
                        //logger.info("Expecting " + productCount + " products in file");
                    }
                    catch (System.Exception exception)
                    {
                        //logger.debug(exception);
                        throw new CDKException("Error while counts line of RXN file", exception);
                    }
                    foundCOUNTS = true;
                }
                else
                {
                    //logger.warn("Waiting for COUNTS line, but found: " + command);
                }
            }

            // now read the reactants
            for (int i = 1; i <= reactantCount; i++)
            {
                System.Text.StringBuilder molFile = new System.Text.StringBuilder();
                System.String announceMDLFileLine = readCommand();
                if (!announceMDLFileLine.Equals("BEGIN REACTANT"))
                {
                    System.String error = "Excepted start of reactant, but found: " + announceMDLFileLine;
                    //logger.error(error);
                    throw new CDKException(error);
                }
                System.String molFileLine = "";
                while (!molFileLine.EndsWith("END REACTANT"))
                {
                    molFileLine = readLine();
                    molFile.Append(molFileLine);
                    molFile.Append("\n");
                };

                try
                {
                    // read MDL molfile content
                    MDLV3000Reader reader = new MDLV3000Reader(new StreamReader(molFile.ToString()));
                    IMolecule reactant = (IMolecule)reader.read(builder.newMolecule());

                    // add reactant
                    reaction.addReactant(reactant);
                }
                catch (System.Exception exception)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    System.String error = "Error while reading reactant: " + exception.Message;
                    //logger.error(error);
                    //logger.debug(exception);
                    throw new CDKException(error, exception);
                }
            }

            // now read the products
            for (int i = 1; i <= productCount; i++)
            {
                System.Text.StringBuilder molFile = new System.Text.StringBuilder();
                System.String announceMDLFileLine = readCommand();
                if (!announceMDLFileLine.Equals("BEGIN PRODUCT"))
                {
                    System.String error = "Excepted start of product, but found: " + announceMDLFileLine;
                    //logger.error(error);
                    throw new CDKException(error);
                }
                System.String molFileLine = "";
                while (!molFileLine.EndsWith("END PRODUCT"))
                {
                    molFileLine = readLine();
                    molFile.Append(molFileLine);
                    molFile.Append("\n");
                };

                try
                {
                    // read MDL molfile content
                    MDLV3000Reader reader = new MDLV3000Reader(new StreamReader(molFile.ToString()));
                    IMolecule product = (IMolecule)reader.read(builder.newMolecule());

                    // add product
                    reaction.addProduct(product);
                }
                catch (System.Exception exception)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    System.String error = "Error while reading product: " + exception.Message;
                    //logger.error(error);
                    //logger.debug(exception);
                    throw new CDKException(error, exception);
                }
            }

            return reaction;
        }