From: <ha...@us...> - 2012-06-25 17:55:32
|
Revision: 17330 http://jmol.svn.sourceforge.net/jmol/?rev=17330&view=rev Author: hansonr Date: 2012-06-25 17:55:25 +0000 (Mon, 25 Jun 2012) Log Message: ----------- version=12.3.33_dev # new feature: PDB reader reads gromacs-created "pdb_wide_format" files # and also automatically reads PQR based on gromacs REMARK Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/cifpdb/PdbReader.java trunk/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/adapter/readers/cifpdb/PdbReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/cifpdb/PdbReader.java 2012-06-24 22:12:14 UTC (rev 17329) +++ trunk/Jmol/src/org/jmol/adapter/readers/cifpdb/PdbReader.java 2012-06-25 17:55:25 UTC (rev 17330) @@ -54,6 +54,8 @@ * * @author Miguel, Egon, and Bob (ha...@st...) * + * pqr and gromacs pdb_wide_format added by Bob + * * symmetry added by Bob Hanson: * * setFractionalCoordinates() @@ -80,6 +82,8 @@ private boolean isConnectStateBug; private boolean isLegacyModelType; + private boolean gromacsWideFormat; + protected boolean isPQR; private final Map<String, Map<String, Boolean>> htFormul = new Hashtable<String, Map<String, Boolean>>(); private Map<String, String> htHetero; @@ -254,6 +258,14 @@ formul(); return true; case 17: + if (line.contains("The B-factors in this file hold atomic radii")) { + isPQR = true; + return true; + } + if (line.contains("This file does not adhere to the PDB standard")) { + gromacsWideFormat = true; + return true; + } if (line.startsWith("REMARK 350")) { remark350(); return false; @@ -631,9 +643,14 @@ } } } - } - + } + // Gromacs pdb_wide_format: + //%-6s%5u %-4.4s %3.3s %c%4d%c %10.5f%10.5f%10.5f%8.4f%8.4f %2s\n") + //0 1 2 3 4 5 6 7 + //01234567890123456789012345678901234567890123456789012345678901234567890123456789 + //aaaaaauuuuu ssss sss cnnnnc xxxxxxxxxxyyyyyyyyyyzzzzzzzzzzccccccccrrrrrrrr + private void atom(int serial) { Atom atom = new Atom(); atom.atomName = line.substring(12, 16).trim(); @@ -660,7 +677,8 @@ currentResno = Integer.MIN_VALUE; htElementsInCurrentGroup = null; } - } else if (!atom.group3.equals(currentGroup3) || atom.sequenceNumber != currentResno) { + } else if (!atom.group3.equals(currentGroup3) + || atom.sequenceNumber != currentResno) { currentGroup3 = atom.group3; currentResno = atom.sequenceNumber; htElementsInCurrentGroup = htFormul.get(atom.group3); @@ -668,32 +686,33 @@ if (atom.group3.equals("UNK")) nUNK++; } - //calculate the charge from cols 79 & 80 (1-based): 2+, 3-, etc - int charge = 0; - if (lineLength >= 80) { - char chMagnitude = line.charAt(78); - char chSign = line.charAt(79); - if (chSign >= '0' && chSign <= '7') { - char chT = chSign; - chSign = chMagnitude; - chMagnitude = chT; + + if (gromacsWideFormat) { + setAtomCoord(atom, parseFloat(line, 30, 40), parseFloat(line, 40, 50), + parseFloat(line, 50, 60)); + } else { + //calculate the charge from cols 79 & 80 (1-based): 2+, 3-, etc + int charge = 0; + if (lineLength >= 80) { + char chMagnitude = line.charAt(78); + char chSign = line.charAt(79); + if (chSign >= '0' && chSign <= '7') { + char chT = chSign; + chSign = chMagnitude; + chMagnitude = chT; + } + if ((chSign == '+' || chSign == '-' || chSign == ' ') + && chMagnitude >= '0' && chMagnitude <= '7') { + charge = chMagnitude - '0'; + if (chSign == '-') + charge = -charge; + } } - if ((chSign == '+' || chSign == '-' || chSign == ' ') - && chMagnitude >= '0' && chMagnitude <= '7') { - charge = chMagnitude - '0'; - if (chSign == '-') - charge = -charge; - } + atom.formalCharge = charge; + setAtomCoord(atom, parseFloat(line, 30, 38), parseFloat(line, 38, 46), + parseFloat(line, 46, 54)); } - atom.formalCharge = charge; - - setAtomCoord(atom, parseFloat(line, 30, 38), parseFloat(line, 38, 46), - parseFloat(line, 46, 54)); - setAdditionalAtomParameters(atom); - - lastAtomData = line.substring(6, 26); - lastAtomIndex = atomSetCollection.getAtomCount(); if (haveMappedSerials) atomSetCollection.addAtomWithMappedSerialNumber(atom); else @@ -708,6 +727,8 @@ } } } + + @Override protected boolean filterAtom(Atom atom, int iAtom) { @@ -749,19 +770,41 @@ * @param atom */ protected void setAdditionalAtomParameters(Atom atom) { + if (isPQR) { + if (gromacsWideFormat) { + atom.partialCharge = parseFloat(line.substring(60, 68)); + atom.radius = fixRadius(parseFloat(line.substring(68, 76))); + } else { + String[] tokens = getTokens(); + int pt = tokens.length - 2 - (line.length() > 75 ? 1 : 0); + atom.partialCharge = parseFloat(tokens[pt++]); + atom.radius = fixRadius(parseFloat(tokens[pt])); + } + return; + } + + float floatOccupancy; + + if (gromacsWideFormat) { + floatOccupancy = parseFloat(line.substring(60, 68)); + atom.bfactor = fixRadius(parseFloat(line.substring(68, 76))); + } else { + /**************************************************************** + * read the occupancy from cols 55-60 (1-based) + * --should be in the range 0.00 - 1.00 + ****************************************************************/ + + floatOccupancy = parseFloat(line, 54, 60); - /**************************************************************** - * read the occupancy from cols 55-60 (1-based) - * should be in the range 0.00 - 1.00 - ****************************************************************/ - float floatOccupancy = parseFloat(line, 54, 60); - atom.occupancy = (Float.isNaN(floatOccupancy) ? 100 : (int) (floatOccupancy * 100)); - - /**************************************************************** - * read the bfactor from cols 61-66 (1-based) - ****************************************************************/ - atom.bfactor = parseFloat(line, 60, 66); - + /**************************************************************** + * read the bfactor from cols 61-66 (1-based) + ****************************************************************/ + atom.bfactor = parseFloat(line, 60, 66); + } + + atom.occupancy = (Float.isNaN(floatOccupancy) ? 100 + : (int) (floatOccupancy * 100)); + } /** @@ -786,7 +829,7 @@ * @param isHetero * @return an atom symbol */ - private String deduceElementSymbol(boolean isHetero) { + protected String deduceElementSymbol(boolean isHetero) { if (lineLength >= 78) { char ch76 = line.charAt(76); char ch77 = line.charAt(77); @@ -1625,5 +1668,16 @@ sbTlsErrors.append(fileName).append('\t').append("TLS group ").append( tlsGroupID).append('\t').append(error).append('\n'); } + + protected static float fixRadius(float r) { + return (r < 0.9f ? 1 : r); + // based on parameters in http://pdb2pqr.svn.sourceforge.net/viewvc/pdb2pqr/trunk/pdb2pqr/dat/ + // AMBER forcefield, H atoms may be given 0 (on O) or 0.6 (on N) for radius + // PARSE forcefield, lots of H atoms may be given 0 radius + // CHARMM forcefield, HN atoms may be given 0.2245 radius + // PEOEPB forcefield, no atoms given 0 radius + // SWANSON forcefield, HW (on water) will be given 0 radius, and H on oxygen given 0.9170 + } + } Modified: trunk/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java 2012-06-24 22:12:14 UTC (rev 17329) +++ trunk/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java 2012-06-25 17:55:25 UTC (rev 17330) @@ -25,13 +25,16 @@ package org.jmol.adapter.readers.more; import org.jmol.adapter.readers.cifpdb.PdbReader; -import org.jmol.adapter.smarter.Atom; /** * PQR file reader. * Angel Herraez, 2009 04 19 +free form added Bob Hanson ha...@st... 2012 06 25 + +filter "FREE" + PQR format is a format based on pdb, where the occupancy is replaced with the atomic charge and the temperature (or B factor) is replaced with atomic radius (however, the column positions in many pqr files do not match those of pdb files). This gives @@ -56,24 +59,14 @@ public class PqrReader extends PdbReader { - @Override - protected void setAdditionalAtomParameters(Atom atom) { + + protected boolean gromacsWideFormat; - String[] tokens = getTokens(); - int offset = (line.length() > 75 ? 1 : 0); - atom.radius = parseFloat(tokens[tokens.length - 1 - offset]); - if (atom.radius < 0.9f) - atom.radius = 1; - // based on parameters in http://pdb2pqr.svn.sourceforge.net/viewvc/pdb2pqr/trunk/pdb2pqr/dat/ - // AMBER forcefield, H atoms may be given 0 (on O) or 0.6 (on N) for radius - // PARSE forcefield, lots of H atoms may be given 0 radius - // CHARMM forcefield, HN atoms may be given 0.2245 radius - // PEOEPB forcefield, no atoms given 0 radius - // SWANSON forcefield, HW (on water) will be given 0 radius, and H on oxygen given 0.9170 - - atom.partialCharge = parseFloat(tokens[tokens.length - 2 - offset]); - + @Override + protected void initializeReader() throws Exception { + isPQR = true; + super.initializeReader(); } - + } Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2012-06-24 22:12:14 UTC (rev 17329) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2012-06-25 17:55:25 UTC (rev 17330) @@ -5,6 +5,9 @@ version=12.3.33_dev +# new feature: PDB reader reads gromacs-created "pdb_wide_format" files +# and also automatically reads PQR based on gromacs REMARK + # ============================================================================= #version=12.3.32 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |