1 /* $RCSfile$ 2 * $Author: hansonr $ 3 * $Date: 2006-07-14 15:35:47 -0500 (Fri, 14 Jul 2006) $ 4 * $Revision: 5303 $ 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 package org.jmol.adapter.readers.simple; 25 26 import javajs.util.PT; 27 28 import org.jmol.adapter.smarter.AtomSetCollectionReader; 29 import org.jmol.adapter.smarter.Atom; 30 31 import org.jmol.api.JmolAdapter; 32 33 /** 34 * Reads Ghemical (<a href="http://www.uku.fi/~thassine/ghemical/"> 35 * http://www.uku.fi/~thassine/ghemical</a>) 36 * molecular mechanics (*.mm1gp) files. 37 * <code> 38 * !Header mm1gp 100 39 * !Info 1 40 * !Atoms 6 41 * 0 6 42 * 1 6 43 * 2 1 44 * 3 1 45 * 4 1 46 * 5 1 47 * !Bonds 5 48 * 1 0 D 49 * 2 0 S 50 * 3 0 S 51 * 4 1 S 52 * 5 1 S 53 * !Coord 54 * 0 0.06677 -0.00197151 4.968e-07 55 * 1 -0.0667699 0.00197154 -5.19252e-07 56 * 2 0.118917 -0.097636 2.03406e-06 57 * 3 0.124471 0.0904495 -4.84021e-07 58 * 4 -0.118917 0.0976359 -2.04017e-06 59 * 5 -0.124471 -0.0904493 5.12591e-07 60 * !Charges 61 * 0 -0.2 62 * 1 -0.2 63 * 2 0.1 64 * 3 0.1 65 * 4 0.1 66 * 5 0.1 67 * !End 68 * </code> 69 * 70 * @author Egon Willighagen <egonw@sci.kun.nl> 71 */ 72 public class GhemicalMMReader extends AtomSetCollectionReader { 73 74 @Override checkLine()75 protected boolean checkLine() throws Exception { 76 if (line.startsWith("!Header")) { 77 processHeader(); 78 return true; 79 } 80 if (line.startsWith("!Info")) { 81 processInfo(); 82 return true; 83 } 84 if (line.startsWith("!Atoms")) { 85 processAtoms(); 86 return true; 87 } 88 if (line.startsWith("!Bonds")) { 89 processBonds(); 90 return true; 91 } 92 if (line.startsWith("!Coord")) { 93 processCoord(); 94 return true; 95 } 96 if (line.startsWith("!Charges")) { 97 processCharges(); 98 return true; 99 } 100 return true; 101 } 102 processHeader()103 void processHeader() { 104 } 105 processInfo()106 void processInfo() { 107 } 108 processAtoms()109 void processAtoms() throws Exception { 110 int ac = parseIntAt(line, 6); 111 //Logger.debug("ac=" + ac); 112 for (int i = 0; i < ac; ++i) { 113 if (asc.ac != i) 114 throw new Exception("GhemicalMMReader error #1"); 115 rd(); 116 int atomIndex = parseIntStr(line); 117 if (atomIndex != i) 118 throw new Exception("bad atom index in !Atoms" + 119 "expected: " + i + " saw:" + atomIndex); 120 int elementNumber = parseInt(); 121 Atom atom = asc.addNewAtom(); 122 atom.elementNumber = (short)elementNumber; 123 } 124 } 125 processBonds()126 void processBonds() throws Exception { 127 int bondCount = parseIntAt(line, 6); 128 for (int i = 0; i < bondCount; ++i) { 129 rd(); 130 int atomIndex1 = parseIntStr(line); 131 int atomIndex2 = parseInt(); 132 String orderCode = parseToken(); 133 int order = 0; 134 //bug found using FindBugs -- was not considering changes in bond order numbers 135 switch(orderCode.charAt(0)) { 136 case 'C': // Conjugated (aromatic) 137 order = JmolAdapter.ORDER_AROMATIC; 138 break; 139 case 'T': 140 order = JmolAdapter.ORDER_COVALENT_TRIPLE; 141 break; 142 case 'D': 143 order = JmolAdapter.ORDER_COVALENT_DOUBLE; 144 break; 145 case 'S': 146 default: 147 order = JmolAdapter.ORDER_COVALENT_SINGLE; 148 } 149 asc.addNewBondWithOrder(atomIndex1, atomIndex2, order); 150 } 151 } 152 processCoord()153 void processCoord() throws Exception { 154 Atom[] atoms = asc.atoms; 155 int ac = asc.ac; 156 for (int i = 0; i < ac; ++i) 157 setAtomCoordScaled(atoms[i], PT.getTokens(rd()), 1, 10); 158 } 159 processCharges()160 void processCharges() throws Exception { 161 Atom[] atoms = asc.atoms; 162 int ac = asc.ac; 163 for (int i = 0; i < ac; ++i) { 164 rd(); 165 int atomIndex = parseIntStr(line); 166 if (atomIndex != i) 167 throw new Exception("bad atom index in !Charges" + 168 "expected: " + i + " saw:" + atomIndex); 169 atoms[i].partialCharge = parseFloat(); 170 } 171 } 172 } 173