/// <summary> Reads a text based configuration file.
        ///
        /// </summary>
        /// <param name="builder">IChemObjectBuilder used to construct the IAtomType's.
        /// </param>
        /// <throws>         IOException when a problem occured with reading from the InputStream </throws>
        /// <returns>        A Vector with read IAtomType's.
        /// </returns>
        public virtual System.Collections.ArrayList readAtomTypes(IChemObjectBuilder builder)
        {
            System.Collections.ArrayList atomTypes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));

            if (ins == null)
            {
                // trying the default
                //System.out.println("readAtomTypes getResourceAsStream:"
                //                   + configFile);
                //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'"
                //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'"
                ins = Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + configFile);
            }
            if (ins == null)
            {
                throw new System.IO.IOException("There was a problem getting the default stream: " + configFile);
            }

            // read the contents from file
            //UPGRADE_TODO: The differences in the expected value  of parameters for constructor 'java.io.BufferedReader.BufferedReader'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
            //UPGRADE_WARNING: At least one expression was used more than once in the target code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1181'"
            System.IO.StreamReader reader = new System.IO.StreamReader(new System.IO.StreamReader(ins, System.Text.Encoding.Default).BaseStream, new System.IO.StreamReader(ins, System.Text.Encoding.Default).CurrentEncoding, false, 1024);
            SupportClass.Tokenizer tokenizer;
            System.String          string_Renamed;

            while (true)
            {
                string_Renamed = reader.ReadLine();
                if (string_Renamed == null)
                {
                    break;
                }
                if (!string_Renamed.StartsWith("#"))
                {
                    System.String name = "";
                    System.String rootType = "";
                    int           atomicNumber = 0, colorR = 0, colorG = 0, colorB = 0;
                    double        mass = 0.0, vdwaals = 0.0, covalent = 0.0;
                    tokenizer = new SupportClass.Tokenizer(string_Renamed, "\t ,;");
                    int tokenCount = tokenizer.Count;

                    if (tokenCount == 9)
                    {
                        name     = tokenizer.NextToken();
                        rootType = tokenizer.NextToken();
                        System.String san       = tokenizer.NextToken();
                        System.String sam       = tokenizer.NextToken();
                        System.String svdwaals  = tokenizer.NextToken();
                        System.String scovalent = tokenizer.NextToken();
                        System.String sColorR   = tokenizer.NextToken();
                        System.String sColorG   = tokenizer.NextToken();
                        System.String sColorB   = tokenizer.NextToken();

                        try
                        {
                            //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                            mass = System.Double.Parse(sam);
                            //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                            vdwaals = System.Double.Parse(svdwaals);
                            //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                            covalent     = System.Double.Parse(scovalent);
                            atomicNumber = System.Int32.Parse(san);
                            colorR       = System.Int32.Parse(sColorR);
                            colorG       = System.Int32.Parse(sColorG);
                            colorB       = System.Int32.Parse(sColorB);
                        }
                        catch (System.FormatException nfe)
                        {
                            throw new System.IO.IOException("AtomTypeTable.ReadAtypes: " + "Malformed Number");
                        }

                        IAtomType atomType = builder.newAtomType(name, rootType);
                        atomType.AtomicNumber = atomicNumber;
                        atomType.setExactMass(mass);
                        atomType.VanderwaalsRadius = vdwaals;
                        atomType.CovalentRadius    = covalent;
                        System.Drawing.Color color = System.Drawing.Color.FromArgb(colorR, colorG, colorB);
                        atomType.setProperty("org.openscience.cdk.renderer.color", color);
                        atomTypes.Add(atomType);
                    }
                    else
                    {
                        throw new System.IO.IOException("AtomTypeTable.ReadAtypes: " + "Wrong Number of fields");
                    }
                }
            } // end while
            ins.Close();

            return(atomTypes);
        }
예제 #2
0
 public override void endElement(System.String uri, System.String local, System.String raw)
 {
     //NOPMD
     //logger.debug("END Element: ", raw);
     //logger.debug("  uri: ", uri);
     //logger.debug("  local: ", local);
     //logger.debug("  raw: ", raw);
     //logger.debug("  chars: ", currentChars.Trim());
     if ("atomType".Equals(local))
     {
         atomTypes.Add(atomType);
     }
     else if ("scalar".Equals(local))
     {
         currentChars.Trim();
         try
         {
             if (scalarType == SCALAR_BONDORDERSUM)
             {
                 atomType.BondOrderSum = System.Double.Parse(currentChars);
             }
             else if (scalarType == SCALAR_MAXBONDORDER)
             {
                 atomType.MaxBondOrder = System.Double.Parse(currentChars);
             }
             else if (scalarType == SCALAR_FORMALNEIGHBOURCOUNT)
             {
                 atomType.FormalNeighbourCount = System.Int32.Parse(currentChars);
             }
             else if (scalarType == SCALAR_VALENCY)
             {
                 atomType.Valency = System.Int32.Parse(currentChars);
             }
             else if (scalarType == SCALAR_FORMALCHARGE)
             {
                 atomType.setFormalCharge(System.Int32.Parse(currentChars));
             }
             else if (scalarType == SCALAR_HYBRIDIZATION)
             {
                 if ("sp1".Equals(currentChars))
                 {
                     atomType.Hybridization = CDKConstants.HYBRIDIZATION_SP1;
                 }
                 else if ("sp2".Equals(currentChars))
                 {
                     atomType.Hybridization = CDKConstants.HYBRIDIZATION_SP2;
                 }
                 else if ("sp3".Equals(currentChars))
                 {
                     atomType.Hybridization = CDKConstants.HYBRIDIZATION_SP3;
                 }
                 else
                 {
                     //logger.warn("Unrecognized hybridization in config file: ", currentChars);
                 }
             }
             else if (scalarType == SCALAR_DA)
             {
                 if ("A".Equals(currentChars))
                 {
                     atomType.setFlag(CDKConstants.IS_HYDROGENBOND_ACCEPTOR, true);
                 }
                 else if ("D".Equals(currentChars))
                 {
                     atomType.setFlag(CDKConstants.IS_HYDROGENBOND_DONOR, true);
                 }
                 else
                 {
                     //logger.warn("Unrecognized H-bond donor/acceptor pattern in config file: ", currentChars);
                 }
             }
             else if (scalarType == SCALAR_SPHERICALMATCHER)
             {
                 atomType.setProperty(CDKConstants.SPHERICAL_MATCHER, currentChars);
             }
             else if (scalarType == SCALAR_RINGSIZE)
             {
                 atomType.setProperty(CDKConstants.PART_OF_RING_OF_SIZE, (System.Object)System.Int32.Parse(currentChars));
             }
             else if (scalarType == SCALAR_CHEMICALGROUPCONSTANT)
             {
                 atomType.setProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT, (System.Object)System.Int32.Parse(currentChars));
             }
             else if (scalarType == SCALAR_ISAROMATIC)
             {
                 atomType.setFlag(CDKConstants.ISAROMATIC, true);
             }
             else if (scalarType == SCALAR_VANDERWAALSRADIUS)
             {
                 atomType.VanderwaalsRadius = System.Double.Parse(currentChars);
             }
         }
         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'"
             //logger.error("Value (", currentChars, ") is not off the expected type: ", exception.Message);
             //logger.debug(exception);
         }
         scalarType = SCALAR_UNSET;
     }
     currentChars = "";
 }