⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gaussian03reader.java

📁 化学图形处理软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $Revision: 7001 $ $Author: kaihartmann $ $Date: 2006-09-20 21:12:37 +0200 (Wed, 20 Sep 2006) $ * * Copyright (C) 2002-2003  Bradley A. Smith <yeldar@home.com> * * Contact: cdk-devel@lists.sourceforge.net * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * *  This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. */package org.openscience.cdk.io;import org.openscience.cdk.config.IsotopeFactory;import org.openscience.cdk.exception.CDKException;import org.openscience.cdk.interfaces.*;import org.openscience.cdk.io.formats.Gaussian03Format;import org.openscience.cdk.io.formats.IResourceFormat;import org.openscience.cdk.tools.LoggingTool;import javax.vecmath.Point3d;import java.io.*;/** * A reader for Gaussian03 output. * Gaussian 03 is a quantum chemistry program * by Gaussian, Inc. (<a href="http://www.gaussian.com/">http://www.gaussian.com/</a>). *  * <p>Molecular coordinates, energies, and normal coordinates of * vibrations are read. Each set of coordinates is added to the * ChemFile in the order they are found. Energies and vibrations * are associated with the previously read set of coordinates. *  * <p>This reader was developed from a small set of * example output files, and therefore, is not guaranteed to * properly read all Gaussian03 output. If you have problems, * please contact the author of this code, not the developers * of Gaussian03. *  * <p>This code was adaptated by Jonathan from Gaussian98Reader written by * Bradley, and ported to CDK by Egon. * * @author Jonathan C. Rienstra-Kiracofe <jrienst@emory.edu> * @author Bradley A. Smith <yeldar@home.com> * @author Egon Willighagen * @cdk.module io */public class Gaussian03Reader extends DefaultChemObjectReader {    private BufferedReader input;    private LoggingTool logger;    public Gaussian03Reader(Reader reader) {        input = new BufferedReader(reader);        logger = new LoggingTool(this);    }    public Gaussian03Reader(InputStream input) {        this(new InputStreamReader(input));    }    public Gaussian03Reader() {        this(new StringReader(""));    }    public IResourceFormat getFormat() {        return Gaussian03Format.getInstance();    }    public void setReader(Reader reader) throws CDKException {        this.input = new BufferedReader(input);    }    public void setReader(InputStream input) throws CDKException {        setReader(new InputStreamReader(input));    }    public boolean accepts(Class classObject) {        Class[] interfaces = classObject.getInterfaces();        for (int i = 0; i < interfaces.length; i++) {            if (IChemFile.class.equals(interfaces[i])) return true;            if (IChemSequence.class.equals(interfaces[i])) return true;        }        return false;    }    public IChemObject read(IChemObject object) throws CDKException {        if (object instanceof IChemSequence) {            return readChemSequence((IChemSequence) object);        } else if (object instanceof IChemFile) {            return readChemFile((IChemFile) object);        } else {            throw new CDKException("Object " + object.getClass().getName() + " is not supported");        }    }    public void close() throws IOException {        input.close();    }    private IChemFile readChemFile(IChemFile chemFile) throws CDKException {        IChemSequence sequence = readChemSequence(chemFile.getBuilder().newChemSequence());        chemFile.addChemSequence(sequence);        return chemFile;    }    private IChemSequence readChemSequence(IChemSequence sequence) throws CDKException {        IChemModel model = null;        try {            String line = input.readLine();            //String levelOfTheory = null;            // Find first set of coordinates            while (input.ready() && (line != null)) {                if (line.indexOf("Standard orientation:") >= 0) {                    // Found a set of coordinates                    model = sequence.getBuilder().newChemModel();                    try {                        readCoordinates(model);                    } catch (IOException exception) {                        throw new CDKException("Error while reading coordinates: " + exception.toString(), exception);                    }                    break;                }                line = input.readLine();            }            if (model != null) {                // Read all other data                line = input.readLine();                while (input.ready() && (line != null)) {                    if (line.indexOf("Standard orientation:") >= 0) {                        // Found a set of coordinates                        // Add current frame to file and create a new one.                        sequence.addChemModel(model);                        fireFrameRead();                        model = sequence.getBuilder().newChemModel();                        readCoordinates(model);                    } else if (line.indexOf("SCF Done:") >= 0) {                        // Found an energy                        model.setProperty("org.openscience.cdk.io.Gaussian03Reaer:SCF Done", line.trim());                    } else if (line.indexOf("Harmonic frequencies") >= 0) {                        // Found a set of vibrations//                        try {//                            readFrequencies(model);//                        } catch (IOException exception) {//                            throw new CDKException("Error while reading frequencies: " + exception.toString(), exception);//                        }                    } else if (line.indexOf("Mulliken atomic charges") >= 0) {                        readPartialCharges(model);                    } else if (line.indexOf("Magnetic shielding") >= 0) {                        // Found NMR data//                        try {//                            readNMRData(model, line);//                        } catch (IOException exception) {//                            throw new CDKException("Error while reading NMR data: " + exception.toString(), exception);//                        }                    } else if (line.indexOf("GINC") >= 0) {                        // Found calculation level of theory                        //levelOfTheory = parseLevelOfTheory(line);                        // FIXME: is doing anything with it?                    }                    line = input.readLine();                }                // Add current frame to file                sequence.addChemModel(model);                fireFrameRead();            }        } catch (IOException exception) {            throw new CDKException("Error while reading general structure: " + exception.toString(), exception);        }        return sequence;    }    /**     * Reads a set of coordinates into ChemModel.     *     * @param model the destination ChemModel     * @throws IOException if an I/O error occurs     */    private void readCoordinates(IChemModel model) throws CDKException, IOException {        IAtomContainer container = model.getBuilder().newAtomContainer();        String line = input.readLine();        line = input.readLine();        line = input.readLine();        line = input.readLine();        while (input.ready()) {            line = input.readLine();            if ((line == null) || (line.indexOf("-----") >= 0)) {                break;            }            int atomicNumber = 0;            StringReader sr = new StringReader(line);            StreamTokenizer token = new StreamTokenizer(sr);            token.nextToken();            // ignore first token            if (token.nextToken() == StreamTokenizer.TT_NUMBER) {                atomicNumber = (int) token.nval;                if (atomicNumber == 0) {                    // Skip dummy atoms. Dummy atoms must be skipped

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -