Пример #1
0
        /// <summary> Reads a set of coordinates into ChemModel.
        /// 
        /// </summary>
        /// <param name="model">the destination ChemModel
        /// </param>
        /// <throws>  IOException if an I/O error occurs </throws>
        private void readCoordinates(IChemModel model)
        {
            IAtomContainer container = model.Builder.newAtomContainer();
            System.String line = input.ReadLine();
            line = input.ReadLine();
            line = input.ReadLine();
            line = input.ReadLine();
            while (input.Peek() != -1)
            {
                line = input.ReadLine();
                if ((line == null) || (line.IndexOf("-----") >= 0))
                {
                    break;
                }
                int atomicNumber = 0;
                System.IO.StringReader sr = new System.IO.StringReader(line);
                SupportClass.StreamTokenizerSupport token = new SupportClass.StreamTokenizerSupport(sr);
                token.NextToken();

                // ignore first token
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    atomicNumber = (int)token.nval;
                    if (atomicNumber == 0)
                    {

                        // Skip dummy atoms. Dummy atoms must be skipped
                        // if frequencies are to be read because Gaussian
                        // does not report dummy atoms in frequencies, and
                        // the number of atoms is used for reading frequencies.
                        continue;
                    }
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                token.NextToken();

                // ignore third token
                double x = 0.0;
                double y = 0.0;
                double z = 0.0;
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    x = token.nval;
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    y = token.nval;
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    z = token.nval;
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }
                System.String symbol = "Du";
                try
                {
                    symbol = IsotopeFactory.getInstance(model.Builder).getElementSymbol(atomicNumber);
                }
                catch (System.Exception exception)
                {
                    throw new CDKException("Could not determine element symbol!", exception);
                }
                IAtom atom = model.Builder.newAtom(symbol);
                atom.setPoint3d(new Point3d(x, y, z));
                container.addAtom(atom);
            }
            ISetOfMolecules moleculeSet = model.Builder.newSetOfMolecules();
            moleculeSet.addMolecule(model.Builder.newMolecule(container));
            model.SetOfMolecules = moleculeSet;
        }
Пример #2
0
        /// <summary> Reads partial atomic charges and add the to the given ChemModel.</summary>
        private void readPartialCharges(IChemModel model)
        {
            //logger.info("Reading partial atomic charges");
            ISetOfMolecules moleculeSet = model.SetOfMolecules;
            IMolecule molecule = moleculeSet.getMolecule(0);
            System.String line = input.ReadLine(); // skip first line after "Total atomic charges"
            while (input.Peek() != -1)
            {
                line = input.ReadLine();
                //logger.debug("Read charge block line: " + line);
                if ((line == null) || (line.IndexOf("Sum of Mulliken charges") >= 0))
                {
                    //logger.debug("End of charge block found");
                    break;
                }
                System.IO.StringReader sr = new System.IO.StringReader(line);
                SupportClass.StreamTokenizerSupport tokenizer = new SupportClass.StreamTokenizerSupport(sr);
                if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    int atomCounter = (int)tokenizer.nval;

                    tokenizer.NextToken(); // ignore the symbol

                    double charge = 0.0;
                    if (tokenizer.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                    {
                        charge = (double)tokenizer.nval;
                        //logger.debug("Found charge for atom " + atomCounter + ": " + charge);
                    }
                    else
                    {
                        throw new CDKException("Error while reading charge: expected double.");
                    }
                    IAtom atom = molecule.getAtomAt(atomCounter - 1);
                    atom.setCharge(charge);
                }
            }
        }
Пример #3
0
        /// <summary> Reads a set of coordinates from the "file system" file through the use of 
        /// the "input" field, scales coordinate to angstr???m unit, builds each atom with 
        /// the right associated coordinates, builds a new molecule with these atoms
        /// and returns the complete molecule.
        /// 
        /// <p><b>Implementation</b>:
        /// <br>Dummy atoms are ignored.
        /// 
        /// </summary>
        /// <param name="coordinatesUnits	The">unit in which coordinates are given.
        /// 
        /// </param>
        /// <throws	IOException	may>  be thrown by the "input" object. </throws	IOException	may>
        /// <summary> 
        /// </summary>
        /// <seealso cref="org.openscience.cdk.io.GamessReader.input">
        /// </seealso>
        //TODO Update method comments with appropriate information.
        private IMolecule readCoordinates(IMolecule molecule, bool coordinatesUnits)
        {

            /*
            * Coordinates must all be given in angstr???ms.
            */
            double unitScaling = GamessReader.scalesCoordinatesUnits(coordinatesUnits);

            System.String retrievedLineFromFile;

            while (this.input.Peek() != -1 == true)
            {
                retrievedLineFromFile = this.input.ReadLine();
                /* 
                * A coordinate set is followed by an empty line, so when this line 
                * is reached, there are no more coordinates to add to the current set.
                */
                if ((retrievedLineFromFile == null) || (retrievedLineFromFile.Trim().Length == 0))
                {
                    break;
                }

                int atomicNumber;
                System.String atomicSymbol;

                //StringReader sr = new StringReader(retrievedLineFromFile);
                SupportClass.StreamTokenizerSupport token = new SupportClass.StreamTokenizerSupport(new System.IO.StringReader(retrievedLineFromFile));

                /*
                * The first token is ignored. It contains the atomic symbol and may 
                * be concatenated with a number.
                */
                token.NextToken();

                if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    atomicNumber = (int)token.nval;
                    atomicSymbol = this.identifyAtomicSymbol(atomicNumber);
                    /* 
                    * Dummy atoms are assumed to be given with an atomic number set
                    * to zero. We will do not add them to the molecule.
                    */
                    if (atomicNumber == 0)
                    {
                        continue;
                    }
                }
                else
                {
                    throw new System.IO.IOException("Error reading coordinates");
                }

                /*
                * Atom's coordinates are stored in an array.
                */
                double[] coordinates = new double[3];
                for (int i = 0; i < coordinates.Length; i++)
                {
                    if (token.NextToken() == SupportClass.StreamTokenizerSupport.TT_NUMBER)
                    {
                        coordinates[i] = token.nval * unitScaling;
                    }
                    else
                    {
                        throw new System.IO.IOException("Error reading coordinates");
                    }
                }
                IAtom atom = molecule.Builder.newAtom(atomicSymbol, new Point3d(coordinates[0], coordinates[1], coordinates[2]));
                molecule.addAtom(atom);
            }
            return molecule;
        }