From: <ha...@us...> - 2009-07-08 16:41:32
|
Revision: 11195 http://jmol.svn.sourceforge.net/jmol/?rev=11195&view=rev Author: hansonr Date: 2009-07-08 16:41:28 +0000 (Wed, 08 Jul 2009) Log Message: ----------- version=11.7.47 # new feature: GROMACS reader Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/molxyz/XyzReader.java trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/JmolConstants.java Added Paths: ----------- trunk/Jmol/src/org/jmol/adapter/readers/more/GromacsReader.java Modified: trunk/Jmol/src/org/jmol/adapter/readers/molxyz/XyzReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/molxyz/XyzReader.java 2009-07-08 14:22:57 UTC (rev 11194) +++ trunk/Jmol/src/org/jmol/adapter/readers/molxyz/XyzReader.java 2009-07-08 16:41:28 UTC (rev 11195) @@ -75,13 +75,13 @@ } } - void skipAtomSet(int modelAtomCount) throws Exception { + private void skipAtomSet(int modelAtomCount) throws Exception { readLine(); //comment for (int i = modelAtomCount; --i >= 0;) readLine(); //atoms } - int readAtomCount() throws Exception { + private int readAtomCount() throws Exception { readLine(); if (line != null) { int atomCount = parseInt(line); @@ -91,7 +91,7 @@ return 0; } - void readAtomSetName() throws Exception { + private void readAtomSetName() throws Exception { readLineTrimmed(); checkLineForScript(); // newAtomSet(line); // makes that the titles of multi-xyz file gets messed up @@ -99,7 +99,7 @@ atomSetCollection.setAtomSetName(line); } - void readAtoms(int modelAtomCount) throws Exception { + private void readAtoms(int modelAtomCount) throws Exception { for (int i = 0; i < modelAtomCount; ++i) { readLine(); String[] tokens = getTokens(); Added: trunk/Jmol/src/org/jmol/adapter/readers/more/GromacsReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/more/GromacsReader.java (rev 0) +++ trunk/Jmol/src/org/jmol/adapter/readers/more/GromacsReader.java 2009-07-08 16:41:28 UTC (rev 11195) @@ -0,0 +1,156 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2006-10-15 17:34:01 -0500 (Sun, 15 Oct 2006) $ + * $Revision: 5957 $ + * + * Copyright (C) 2003-2005 Miguel, Jmol Development, www.jmol.org + * + * Contact: jmo...@li... + * + * 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.jmol.adapter.readers.more; + +import org.jmol.adapter.smarter.*; + + +import org.jmol.util.Logger; +import org.jmol.viewer.JmolConstants; + +import java.io.BufferedReader; + +/** + * PDB file reader. + * + *<p> + * <a href='http://www.rcsb.org'> + * http://www.rcsb.org + * </a> + * + * @author Miguel, Egon, and Bob (ha...@st...) + * + * symmetry added by Bob Hanson: + * + * setFractionalCoordinates() + * setSpaceGroupName() + * setUnitCell() + * initializeCartesianToFractional(); + * setUnitCellItem() + * setAtomCoord() + * applySymmetryAndSetTrajectory() + * + */ + +public class GromacsReader extends AtomSetCollectionReader { + protected String fileType = "gromacs"; + + public void readAtomSetCollection(BufferedReader reader) { + this.reader = reader; + atomSetCollection = new AtomSetCollection("xyz"); + try { + readAtomSetName(); + int modelAtomCount = readAtomCount(); + readAtoms(modelAtomCount); + applySymmetryAndSetTrajectory(); + } catch (Exception e) { + setError(e); + } + } + + private int readAtomCount() throws Exception { + readLine(); + if (line != null) { + int atomCount = parseInt(line); + if (atomCount > 0) + return atomCount; + } + return 0; + } + + private void readAtomSetName() throws Exception { + readLineTrimmed(); + checkLineForScript(); + atomSetCollection.newAtomSet(); + atomSetCollection.setAtomSetName(line); + } + + /* + +"Check Your Input" (D. van der Spoel) + 59 + 1TYR N 1 1.521 1.583 2.009 0.0000 0.0000 0.0000 + 1TYR H1 2 1.421 1.595 2.009 0.0000 0.0000 0.0000 + 1TYR H2 3 1.548 1.533 1.927 0.0000 0.0000 0.0000 + 1TYR CA 4 1.585 1.713 2.009 0.0000 0.0000 0.0000 + 1TYR HA 5 1.555 1.760 1.926 0.0000 0.0000 0.0000 + 1TYR CB 6 1.541 1.791 2.133 0.0000 0.0000 0.0000 + + */ + private void readAtoms(int modelAtomCount) throws Exception { + for (int i = 0; i < modelAtomCount; ++i) { + readLine(); + if (line.length() < 68) { + Logger.warn("line cannot be read for GROMACS atom data: " + line); + continue; + } + Atom atom = new Atom(); + atom.atomSerial = parseInt(line, 0, 5); + atom.group3 = parseToken(line, 5, 9).trim(); //allowing for 4 characters + atom.atomName = line.substring(11, 15).trim(); + atom.sequenceNumber = parseInt(line, 15, 20); + atom.x = parseFloat(line, 20, 28) * 10; + atom.y = parseFloat(line, 28, 36) * 10; + atom.z = parseFloat(line, 36, 44) * 10; + if (Float.isNaN(atom.x) || Float.isNaN(atom.y) || Float.isNaN(atom.z)) { + Logger.warn("line cannot be read for GROMACS atom data: " + line); + atom.set(0, 0, 0); + } + setAtomCoord(atom); + atom.elementSymbol = deduceElementSymbol(atom.group3, atom.atomName); + if (filter != null) + if (!filterAtom(atom)) + continue; + atom.isHetero = false; + atomSetCollection.addAtom(atom); + float vx = parseFloat(line, 44, 52) * 10; + float vy = parseFloat(line, 52, 60) * 10; + float vz = parseFloat(line, 60, 68) * 10; + if (Float.isNaN(vx) || Float.isNaN(vy) || Float.isNaN(vz)) + continue; + atom.vectorX = vx; + atom.vectorY = vy; + atom.vectorZ = vz; + } + } + + String deduceElementSymbol(String group3, String atomName) { + // best we can do + if (atomName.length() <= 2 && group3.equals(atomName)) + return atomName; + char ch1 = (atomName.length() == 4 ? atomName.charAt(0) : '\0'); + char ch2 = atomName.charAt(atomName.length() == 4 ? 1 : 0); + boolean isHetero = JmolConstants.isHetero(group3); + if (Atom.isValidElementSymbolNoCaseSecondChar(ch1, ch2)) + return (isHetero || ch1 != 'H' ? "" + ch1 + ch2 : "H"); + if (Atom.isValidElementSymbol(ch2)) + return "" + ch2; + if (Atom.isValidElementSymbol(ch1)) + return "" + ch1; + return "Xx"; + } + +} + Property changes on: trunk/Jmol/src/org/jmol/adapter/readers/more/GromacsReader.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2009-07-08 14:22:57 UTC (rev 11194) +++ trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2009-07-08 16:41:28 UTC (rev 11195) @@ -34,6 +34,7 @@ import org.jmol.util.Escape; import org.jmol.util.Logger; +import org.jmol.util.Parser; import org.jmol.util.TextFormat; import org.jmol.util.ZipUtil; @@ -426,7 +427,7 @@ nLines++; } - String readerName = checkSpecial(nLines, lines); + String readerName = checkSpecial(nLines, lines, false); if (readerName != null) return readerName; @@ -479,6 +480,12 @@ } } } + + readerName = checkSpecial(nLines, lines, true); + + if (readerName != null) + return readerName; + return (returnLines ? "\n" + lines[0] + "\n" + lines[1] + "\n" + lines[2] + "\n" : null); } @@ -561,8 +568,12 @@ }; - private final static String checkSpecial(int nLines, String[] lines) { + private final static String checkSpecial(int nLines, String[] lines, boolean isEnd) { // the order here is CRITICAL + if (isEnd) { + if (checkGromacs(lines)) + return "Gromacs"; + } if (nLines == 1 && lines[0].length() > 0 && Character.isDigit(lines[0].charAt(0))) return specialTags[SPECIAL_JME][0]; //only one line, and that line starts with a number @@ -587,6 +598,16 @@ return null; } + private static boolean checkGromacs(String[] lines) { + if (Parser.parseInt(lines[1]) == Integer.MIN_VALUE) + return false; + int len = -1; + for (int i = 2; i < 16 && len != 0; i++) + if ((len = lines[i].length()) != 69 && len != 0) + return false; + return true; + } + private static boolean checkWien2k(String[] lines) { return (lines[2].startsWith("MODE OF CALC=") || lines[2].startsWith(" RELA") Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-07-08 14:22:57 UTC (rev 11194) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-07-08 16:41:28 UTC (rev 11195) @@ -3,6 +3,7 @@ version=11.7.47 +# new feature: GROMACS reader # bug fix: arrays passed to functions by reference do not update if size is increased # new feature: by passing an array to a function, you can make that variable # return a value -- any value, not just an array: Modified: trunk/Jmol/src/org/jmol/viewer/JmolConstants.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/JmolConstants.java 2009-07-08 14:22:57 UTC (rev 11194) +++ trunk/Jmol/src/org/jmol/viewer/JmolConstants.java 2009-07-08 16:41:28 UTC (rev 11195) @@ -2386,7 +2386,7 @@ public final static int GROUPID_AMINO_MAX = 24; private final static int GROUPID_WATER = 42; - private final static int GROUPID_SULPHATE = 46; + private final static int GROUPID_SULPHATE = 48; public final static String[] predefinedGroup3Names = { // taken from PDB spec @@ -2443,12 +2443,15 @@ "+U", "+I", + // solvent types: + "HOH", // 42 water "DOD", // 43 "WAT", // 44 - - "PO4", // 45 phosphate ions - "SO4", // 46 sulphate ions + "SOL", // 45 gromacs solvent + "UREA", // 46 urea + "PO4", // 47 phosphate ions + "SO4", // 48 sulphate ions }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |