Exemple #1
0
        private void loadReaders()
        {
            if (formats == null)
            {
                formats = new List <IChemFormatMatcher>();
                //System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                try
                {
                    //logger.debug("Starting loading Readers...");
                    Stream stm = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + IO_FORMATS_LIST);
                    System.IO.StreamReader reader = new System.IO.StreamReader(stm);

                    int formatCount = 0;
                    while (reader.Peek() != -1)
                    {
                        // load them one by one
                        System.String formatName = reader.ReadLine();
                        formatCount++;
                        try
                        {
                            ObjectHandle       handle = System.Activator.CreateInstance("NuGenCDKSharp", formatName);
                            IChemFormatMatcher format = (IChemFormatMatcher)handle.Unwrap();
                            formats.Add(format);
                            //logger.info("Loaded IO format: " + format.GetType().FullName);
                        }
                        catch (System.Exception exception)
                        {
                            //logger.error("Could not find this ChemObjectReader: ", formatName);
                            //logger.debug(exception);
                        }
                    }
                    //logger.info("Number of loaded formats used in detection: ", formatCount);
                }
                catch (System.Exception exception)
                {
                    //logger.error("Could not load this io format list: ", IO_FORMATS_LIST);
                    //logger.debug(exception);
                }
            }
        }
        public void TestBug2153298()
        {
            var filename = "NCDK.Data.ASN.PubChem.cid1145.xml";
            var ins      = ResourceLoader.GetAsStream(filename);

            Assert.IsNotNull(ins, "Cannot find file: " + filename);
            IChemFormatMatcher realFormat = (IChemFormatMatcher)PubChemCompoundXMLFormat.Instance;

            factory.RegisterFormat(realFormat);
            // ok, if format ok, try instantiating a reader
            ins = ResourceLoader.GetAsStream(filename);
            ISimpleChemObjectReader reader = factory.CreateReader(ins);

            Assert.IsNotNull(reader);
            Assert.AreEqual(((IChemFormat)PubChemCompoundXMLFormat.Instance).ReaderClassName, reader.GetType().FullName);
            // now try reading something from it
            IAtomContainer molecule = (IAtomContainer)reader.Read(builder.NewAtomContainer());

            Assert.IsNotNull(molecule);
            Assert.AreNotSame(0, molecule.Atoms.Count);
            Assert.AreNotSame(0, molecule.Bonds.Count);
        }
 public virtual void SetChemFormatMatcher(IChemFormatMatcher matcher)
 {
     base.SetChemFormat(matcher);
     this.matcher = matcher;
 }
Exemple #4
0
 /// <summary>
 /// Registers a format for detection.
 /// </summary>
 public void RegisterFormat(IChemFormatMatcher format)
 {
     formats.Add(format);
 }
 /// <summary> Registers a format for detection.</summary>
 public virtual void registerFormat(IChemFormatMatcher format)
 {
     formats.Add(format);
 }
Exemple #6
0
 /// <summary> Registers a format for detection.</summary>
 public virtual void registerFormat(IChemFormatMatcher format)
 {
     formats.Add(format);
 }
Exemple #7
0
        /// <summary> Creates a String of the Class name of the <code>IChemObject</code> reader
        /// for this file format. The input is read line-by-line
        /// until a line containing an identifying string is
        /// found.
        ///
        /// <p>The ReaderFactory detects more formats than the CDK
        /// has Readers for.
        ///
        /// <p>This method is not able to detect the format of gziped files.
        /// Use <code>guessFormat(InputStream)</code> instead for such files.
        ///
        /// </summary>
        /// <throws>  IOException  if an I/O error occurs </throws>
        /// <throws>  IllegalArgumentException if the input is null </throws>
        /// <summary>
        /// </summary>
        /// <seealso cref="guessFormat(InputStream)">
        /// </seealso>
        public virtual IChemFormat guessFormat(StreamReader input)
        {
            if (input == null)
            {
                throw new System.ArgumentException("input cannot be null");
            }

            // make a copy of the header
            char[] header = new char[this.headerLength];
            //UPGRADE_ISSUE: Method 'java.io.BufferedReader.markSupported' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000'"
            //if (!input.markSupported())
            //{
            //    //logger.error("Mark not supported");
            //    throw new System.ArgumentException("input must support mark");
            //}
            //int pos = this.headerLength;//input.mark(this.headerLength);
            input.Read(header, 0, this.headerLength);
            input.BaseStream.Seek(0, SeekOrigin.Begin);

            //UPGRADE_ISSUE: Constructor 'java.io.BufferedReader.BufferedReader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderBufferedReader_javaioReader'"
            System.IO.StringReader buffer = new StringReader(new System.String(header));

            /* Search file for a line containing an identifying keyword */
            System.String line       = null;
            int           lineNumber = 1;

            while ((line = buffer.ReadLine()) != null)
            {
                //logger.debug(lineNumber + ": ", line);
                for (int i = 0; i < formats.Count; i++)
                {
                    IChemFormatMatcher cfMatcher = (IChemFormatMatcher)formats[i];
                    if (cfMatcher.matches(lineNumber, line))
                    {
                        //logger.info("Detected format: ", cfMatcher.FormatName);
                        return(cfMatcher);
                    }
                }
                lineNumber++;
            }

            //logger.warn("Now comes the tricky and more difficult ones....");
            //UPGRADE_ISSUE: Constructor 'java.io.BufferedReader.BufferedReader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioBufferedReaderBufferedReader_javaioReader'"
            buffer = new StringReader(new System.String(header));

            line = buffer.ReadLine();
            // is it a XYZ file?
            SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line.Trim());
            try
            {
                int tokenCount = tokenizer.Count;
                if (tokenCount == 1)
                {
                    System.Int32.Parse(tokenizer.NextToken());
                    // if not failed, then it is a XYZ file
                    return(null);// new org.openscience.cdk.io.formats.XYZFormat();
                }
                else if (tokenCount == 2)
                {
                    System.Int32.Parse(tokenizer.NextToken());
                    if ("Bohr".ToUpper().Equals(tokenizer.NextToken().ToUpper()))
                    {
                        return(null);// new org.openscience.cdk.io.formats.XYZFormat();
                    }
                }
            }
            catch (System.FormatException exception)
            {
                //logger.info("No, it's not a XYZ file");
            }

            //logger.warn("File format undetermined");
            return(null);
        }
Exemple #8
0
 /// <summary>
 /// Registers a format for detection.
 /// </summary>
 public void RegisterFormat(IChemFormatMatcher format)
 {
     formatFactory.RegisterFormat(format);
 }