📄 mm2basedparametersetreader.java
字号:
/* $RCSfile$ * $Author: egonw $ * $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $ * $Revision: 7636 $ * * Copyright (C) 2005-2007 Christian Hoppe <chhoppe@users.sf.net> * * Contact: cdk-devel@lists.sourceforge.net * * This program 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. * All we ask is that proper credit is given for our work, which includes * - but is not limited to - adding the above copyright notice to the beginning * of your source code files, and to any copyright notice that you may distribute * with programs based on this work. * * This program 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 program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * */package org.openscience.cdk.modeling.builder3d;import java.awt.Color;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.Hashtable;import java.util.StringTokenizer;import java.util.Vector;import org.openscience.cdk.AtomType;import org.openscience.cdk.tools.LoggingTool;/** * AtomType list configurator that uses the ParameterSet originally * defined in mm2.prm from tinker. This class was added to be able to port * mm2 to CDK. * * @author chhoppe * @cdk.created 2004-09-07 * @cdk.module forcefield * @cdk.keyword atom type, MM2 */public class MM2BasedParameterSetReader {// private final LoggingTool logger = new LoggingTool(MM2BasedParameterSetReader.class); private String configFile = "org/openscience/cdk/modeling/forcefield/data/mm2.prm"; private InputStream ins = null; private Hashtable parameterSet; private Vector atomTypes; private StringTokenizer st; private String key = ""; /** *Constructor for the MM2BasedParameterSetReader object */ public MM2BasedParameterSetReader() { parameterSet = new Hashtable(); atomTypes = new Vector(); } public Hashtable getParamterSet(){ return parameterSet; } public Vector getAtomTypes(){ return atomTypes; } /** * Sets the file containing the config data * * @param ins The new inputStream type InputStream */ public void setInputStream(InputStream ins) { this.ins = ins; } /** * Read a text based configuration file out of the force field mm2 file * * @exception Exception Description of the Exception */ private void setForceFieldDefinitions() throws Exception { String sid = st.nextToken(); String svalue = st.nextToken(); if (sid.equals(">bontunit")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">bond-cubic")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">bond-quartic")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">angleunit")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">angle-sextic")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">strbndunit")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">opbendunit")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">torsionunit")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">vdwtype")) { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } else if (sid.equals(">radiusrule")) { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } else if (sid.equals(">radiustype")) { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } else if (sid.equals(">radiussize")) { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } else if (sid.equals(">epsilonrule")) { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } else if (sid.equals(">a-expterm")) { try { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals("b-expterm")) { try { key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, svalue); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">c-expterm")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">vdw-14-scale")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">chg-14-scale")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else if (sid.equals(">dielectric")) { try { double value1 = new Double(svalue).doubleValue(); key = sid.substring(1); //if (parameterSet.containsKey(key)){logger.debug("KeyError: hasKey "+key);} parameterSet.put(key, new Double(value1)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } } else { } } /** * Read and stores the atom types in a vector * * @exception Exception Description of the Exception */ private void setAtomTypes() throws Exception { String name = ""; String rootType = ""; int an = 0; int rl = 255; int gl = 20; int bl = 147; int maxbond = 0; double mass = 0.0; st.nextToken(); String sid = st.nextToken(); rootType = st.nextToken(); name = st.nextToken(); String san = st.nextToken(); String sam = st.nextToken(); String smaxbond = st.nextToken(); try { mass = new Double(sam).doubleValue(); an = Integer.parseInt(san); maxbond = Integer.parseInt(smaxbond); } catch (NumberFormatException nfe) { throw new IOException("AtomTypeTable.ReadAtypes: " + "Malformed Number"); } AtomType atomType = new AtomType(name, rootType); atomType.setAtomicNumber(an); atomType.setExactMass(mass); atomType.setFormalNeighbourCount(maxbond); atomType.setSymbol(rootType); Color co = new Color(rl, gl, bl); atomType.setProperty("org.openscience.cdk.renderer.color", co); atomType.setAtomTypeName(sid); atomTypes.addElement(atomType); } /** * Read vdw radius, stored into the parameter set * * @exception Exception Description of the Exception */ private void setvdWaals() throws Exception { Vector data = new Vector(); st.nextToken(); String sid = st.nextToken(); String sradius = st.nextToken(); String sepsi = st.nextToken(); try { double epsi = new Double(sepsi).doubleValue(); double radius = new Double(sradius).doubleValue(); data.add(new Double(radius)); data.add(new Double(epsi)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaals: " + "Malformed Number"); } key = "vdw" + sid; //if (parameterSet.containsKey(key)){System.out.println("KeyError: hasKey "+key);} parameterSet.put(key, data); } /** * Read vdW pair radius,stored into the parameter set * * @exception Exception Description of the Exception */ private void setvdWaalpr() throws Exception { Vector data = new Vector(); st.nextToken(); String sid1 = st.nextToken(); String sid2 = st.nextToken(); String value1 = st.nextToken(); String value2 = st.nextToken(); try { double va1 = new Double(value1).doubleValue(); double va2 = new Double(value2).doubleValue(); data.add(new Double(va1)); data.add(new Double(va2)); } catch (NumberFormatException nfe) { throw new IOException("VdWaalsTable.ReadvdWaalsPR:Malformed Number due to"+nfe.toString()); } key = "vdwpr" + sid1 + ";" + sid2; parameterSet.put(key, data); } /** * Sets the bond attribute stored into the parameter set * * @exception Exception Description of the Exception */ private void setBond() throws Exception { Vector data = new Vector(); st.nextToken(); String sid1 = st.nextToken(); String sid2 = st.nextToken(); String value1 = st.nextToken(); String value2 = st.nextToken(); try { double va1 = new Double(value1).doubleValue(); double va2 = new Double(value2).doubleValue(); data.add(new Double(va1)); data.add(new Double(va2)); } catch (NumberFormatException nfe) { throw new IOException("setBond: Malformed Number"); } key = "bond" + sid1 + ";" + sid2; parameterSet.put(key, data); } /** * Sets the bond3 attribute stored into the parameter set * * @exception Exception Description of the Exception */ private void setBond3() throws Exception { Vector data = new Vector(); st.nextToken(); String sid1 = st.nextToken(); String sid2 = st.nextToken(); String value1 = st.nextToken(); String value2 = st.nextToken(); try { double va1 = new Double(value1).doubleValue(); double va2 = new Double(value2).doubleValue(); data.add(new Double(va1)); data.add(new Double(va2)); } catch (NumberFormatException nfe) { throw new IOException("setBond3: Malformed Number"); } key = "bond3_" + sid1 + ";" + sid2; parameterSet.put(key, data); } /** * Sets the bond4 attribute stored into the parameter set * * @exception Exception Description of the Exception */ private void setBond4() throws Exception { Vector data = new Vector(); st.nextToken(); String sid1 = st.nextToken(); String sid2 = st.nextToken(); String value1 = st.nextToken(); String value2 = st.nextToken(); try { double va1 = new Double(value1).doubleValue(); double va2 = new Double(value2).doubleValue(); data.add(new Double(va1)); data.add(new Double(va2)); } catch (NumberFormatException nfe) { throw new IOException("setBond4: Malformed Number"); } key = "bond4_" + sid1 + ";" + sid2; parameterSet.put(key, data); } /** * Sets the angle attribute stored into the parameter set * * @exception Exception Description of the Exception */ private void setAngle() throws Exception { Vector data = new Vector(); st.nextToken(); String sid1 = st.nextToken(); String sid2 = st.nextToken(); String sid3 = st.nextToken(); String value1 = st.nextToken(); String value2 = st.nextToken(); String value3 = st.nextToken(); String value4 = st.nextToken(); try { double va1 = new Double(value1).doubleValue(); double va2 = new Double(value2).doubleValue(); double va3 = new Double(value3).doubleValue();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -