1 /* $RCSfile$ 2 * $Author: hansonr $ 3 * $Date: 2006-07-14 18:41:50 -0500 (Fri, 14 Jul 2006) $ 4 * $Revision: 5311 $ 5 * 6 * Copyright (C) 2003-2005 Miguel, Jmol Development, www.jmol.org 7 * 8 * Contact: jmol-developers@lists.sf.net 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; either 13 * version 2.1 of the License, or (at your option) any later version. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 23 */ 24 25 package org.jmol.adapter.readers.spartan; 26 27 import javajs.util.PT; 28 29 import org.jmol.adapter.readers.quantum.BasisFunctionReader; 30 import org.jmol.adapter.smarter.Bond; 31 import org.jmol.adapter.smarter.SmarterJmolAdapter; 32 import org.jmol.api.JmolAdapter; 33 34 import org.jmol.util.Logger; 35 36 /* 37 * Wavefunction INPUT section reader 38 * 39 */ 40 41 public abstract class SpartanInputReader extends BasisFunctionReader { 42 43 protected int modelAtomCount; 44 protected String bondData = ""; 45 protected String constraints = ""; 46 readInputRecords()47 protected String readInputRecords() throws Exception { 48 int ac0 = asc.ac; 49 String modelName = readInputHeader(); 50 while (rd() != null) { 51 String[] tokens = getTokens(); 52 //charge and spin 53 if (tokens.length == 2 && parseIntStr(tokens[0]) != Integer.MIN_VALUE 54 && parseIntStr(tokens[1]) >= 0) 55 break; 56 } 57 if (line == null) 58 return null; 59 readInputAtoms(); 60 discardLinesUntilContains("ATOMLABELS"); 61 if (line != null) 62 readAtomNames(); 63 if (modelAtomCount > 1) { 64 discardLinesUntilContains("HESSIAN"); 65 if (line != null) 66 readBonds(ac0); 67 if (line != null && line.indexOf("BEGINCONSTRAINTS") >= 0) 68 readConstraints(); 69 } 70 return modelName; 71 } 72 readConstraints()73 private void readConstraints() throws Exception { 74 constraints = ""; 75 while (rd() != null && line.indexOf("END") < 0) 76 constraints += (constraints == "" ? "" : "\n") + line; 77 rd(); 78 if (constraints.length() == 0) 79 return; 80 asc.setCurrentModelInfo("constraints", constraints); 81 asc.setAtomSetModelProperty(SmarterJmolAdapter.PATH_KEY, "EnergyProfile"); 82 asc.setAtomSetModelProperty("Constraint", constraints); 83 } 84 readTransform()85 void readTransform() throws Exception { 86 rd(); 87 String[] tokens = PT.getTokens(rd() + " " + rd()); 88 //BEGINMOLSTATE 89 //MODEL=3~HYDROGEN=1~LABELS=0 90 //0.70925283 0.69996750 -0.08369886 0.00000000 -0.70480913 0.70649898 -0.06405880 0.00000000 91 //0.01429412 0.10442561 0.99443018 0.00000000 0.00000000 0.00000000 0.00000000 1.00000000 92 //ENDMOLSTATE 93 setTransform( 94 parseFloatStr(tokens[0]), parseFloatStr(tokens[1]), parseFloatStr(tokens[2]), 95 parseFloatStr(tokens[4]), parseFloatStr(tokens[5]), parseFloatStr(tokens[6]), 96 parseFloatStr(tokens[8]), parseFloatStr(tokens[9]), parseFloatStr(tokens[10]) 97 ); 98 } 99 readInputHeader()100 private String readInputHeader() throws Exception { 101 while (rd() != null 102 && !line.startsWith(" ")) {} 103 rd(); 104 return line.substring(0, (line + ";").indexOf(";")).trim(); 105 } 106 readInputAtoms()107 private void readInputAtoms() throws Exception { 108 modelAtomCount = 0; 109 while (rd() != null 110 && !line.startsWith("ENDCART")) { 111 String[] tokens = getTokens(); 112 addAtomXYZSymName(tokens, 1, getElementSymbol(parseIntStr(tokens[0])), null); 113 modelAtomCount++; 114 } 115 if (debugging) 116 Logger.debug(asc.ac + " atoms read"); 117 } 118 readAtomNames()119 private void readAtomNames() throws Exception { 120 int atom0 = asc.ac - modelAtomCount; 121 // note that asc.isTrajectory() gets set onlyAFTER an input is 122 // read. 123 for (int i = 0; i < modelAtomCount; i++) { 124 line = rd().trim(); 125 String name = line.substring(1, line.length() - 1); 126 asc.atoms[atom0 + i].atomName = name; 127 } 128 } 129 readBonds(int ac0)130 private void readBonds(int ac0) throws Exception { 131 int nAtoms = modelAtomCount; 132 /* 133 <one number per atom> 134 1 2 1 135 1 3 1 136 1 4 1 137 1 5 1 138 1 6 1 139 1 7 1 140 */ 141 bondData = ""; //used for frequency business 142 while (rd() != null && !line.startsWith("ENDHESS")) { 143 String[] tokens = getTokens(); 144 bondData += line + " "; 145 if (nAtoms == 0) { 146 int sourceIndex = parseIntStr(tokens[0]) - 1 + ac0; 147 int targetIndex = parseIntStr(tokens[1]) - 1 + ac0; 148 int bondOrder = parseIntStr(tokens[2]); 149 if (bondOrder > 0) { 150 asc.addBond(new Bond(sourceIndex, targetIndex, 151 bondOrder < 4 ? bondOrder : bondOrder == 5 ? JmolAdapter.ORDER_AROMATIC : 1)); 152 } 153 } else { 154 nAtoms -= tokens.length; 155 } 156 } 157 rd(); 158 if (debugging) 159 Logger.debug(asc.bondCount + " bonds read"); 160 } 161 } 162