Exemplo n.º 1
0
        /// <summary>
        /// Sets up the fixture.
        /// <para>This method is called before a test is executed and performs the
        /// following actions:
        /// <ul>
        ///     <item>Constructs a new FileReader.</item>
        ///     <item>Constructs a new TextReader.</item>
        ///     <item>Constructs a new GamessReader.</item>
        /// </ul>
        /// </para>
        /// </summary>
        public GamessReaderTest()
        {
            var ins = ResourceLoader.GetAsStream(TestFile);

            this.inputReader           = new StreamReader(ins);
            this.gamessReaderUnderTest = new GamessReader(this.inputReader);
        }
Exemplo n.º 2
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.
        /// </summary>
        /// <remarks>
        /// <para><b>Implementation</b>:
        /// Dummy atoms are ignored.</para>
        /// </remarks>
        /// <param name="molecule"></param>
        /// <param name="coordinatesUnits">The unit in which coordinates are given.</param>
        /// <exception cref="IOException">may be thrown by the "input" object.</exception>
        /// <seealso cref="GamessReader.input"/>
        //TODO Update method comments with appropriate information.
        private IAtomContainer ReadCoordinates(IAtomContainer molecule, bool coordinatesUnits)
        {
            // Coordinates must all be given in angstr???ms.
            double unitScaling = GamessReader.ScalesCoordinatesUnits(coordinatesUnits);

            string retrievedLineFromFile;

            while (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;
                string atomicSymbol;

                //StringReader sr = new StringReader(retrievedLineFromFile);
                StreamTokenizer token = new StreamTokenizer(new StringReader(retrievedLineFromFile));

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

                if (token.NextToken() == StreamTokenizer.TTypeNumber)
                {
                    atomicNumber = (int)token.NumberValue;
                    atomicSymbol = 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 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() == StreamTokenizer.TTypeNumber)
                    {
                        coordinates[i] = token.NumberValue * unitScaling;
                    }
                    else
                    {
                        throw new IOException("Error reading coordinates");
                    }
                }
                IAtom atom = molecule.Builder.NewAtom(atomicSymbol,
                                                      new Vector3(coordinates[0], coordinates[1], coordinates[2]));
                molecule.Atoms.Add(atom);
            }
            return(molecule);
        }