Revision: 18669
          http://sourceforge.net/p/jmol/code/18669
Author:   hansonr
Date:     2013-09-18 23:09:05 +0000 (Wed, 18 Sep 2013)
Log Message:
-----------


Modified Paths:
--------------
    branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/JcampdxReader.java
    branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/MdTopReader.java

Removed Paths:
-------------
    branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/P2nReader.java
    branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java

Modified: 
branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/JcampdxReader.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/JcampdxReader.java    
2013-09-18 23:07:12 UTC (rev 18668)
+++ branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/JcampdxReader.java    
2013-09-18 23:09:05 UTC (rev 18669)
@@ -26,10 +26,12 @@
 
 import java.io.BufferedReader;
 import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
 import org.jmol.util.JmolList;
-
-
-
 import org.jmol.util.TextFormat;
 
 import org.jmol.adapter.readers.molxyz.MolReader;
@@ -96,7 +98,7 @@
 
 public class JcampdxReader extends MolReader {
 
-  private String modelID;
+  private String thisModelID;
   private AtomSetCollection models;
   private String modelIdList = "";
   private  JmolList<String> peakData = new  JmolList<String>();
@@ -152,7 +154,9 @@
     if (label.equals("##$MODELS"))
       return readModels();
     if (label.equals("##$PEAKS"))
-      return readPeaks();
+      return (readPeaks(false) > 0);
+    if (label.equals("##$SIGNALS"))
+      return (readPeaks(true) > 0);
     return true;
   }
 
@@ -180,7 +184,7 @@
     // load xxx.jdx 0  will mean "load only the base model(s)"
     models = null;
     line = "";
-    modelID = "";
+    thisModelID = "";
     boolean isFirst = true;
     while (true) {
       int model0 = atomSetCollection.getCurrentAtomSetIndex();
@@ -208,11 +212,11 @@
   private void updateModelIDs(int model0, boolean isFirst) {
     int n = atomSetCollection.getAtomSetCount();
     if (isFirst && n == model0 + 2) {
-      atomSetCollection.setAtomSetAuxiliaryInfo("modelID", modelID);
+      atomSetCollection.setAtomSetAuxiliaryInfo("modelID", thisModelID);
       return;
     }
     for (int pt = 0, i = model0; ++i < n;) {
-      atomSetCollection.setAtomSetAuxiliaryInfoForSet("modelID", modelID + "."
+      atomSetCollection.setAtomSetAuxiliaryInfoForSet("modelID", thisModelID + 
"."
           + (++pt), i);
     }
   }
@@ -223,10 +227,10 @@
   }
 
   private AtomSetCollection getModelAtomSetCollection() throws Exception {
-    lastModel = modelID;
-    modelID = getAttribute(line, "id");
+    lastModel = thisModelID;
+    thisModelID = getAttribute(line, "id");
     // read model only once for a given ID
-    String key = ";" + modelID + ";";
+    String key = ";" + thisModelID + ";";
     if (modelIdList.indexOf(key) >= 0) {
       discardLinesUntilContains("</ModelData>");
       return null;
@@ -276,7 +280,7 @@
       for (int i = a.getAtomCount(); --i >= 0;)
         atoms[i].scaleVector(vibScale);
     }
-    Logger.info("jdx model=" + modelID + " type=" + a.getFileTypeName());
+    Logger.info("jdx model=" + thisModelID + " type=" + a.getFileTypeName());
     return a;
   }
 
@@ -312,23 +316,171 @@
     }
   }
 
-  private boolean readPeaks() throws Exception {
-    if (line.indexOf("<Peaks") < 0)
-      discardLinesUntilContains2("<Peaks", "##");
-    if (line.indexOf("<Peaks") < 0)
-      return false;
-    String type = getAttribute(line, "type").toUpperCase();
-    if (type.equals("HNMR"))
-      type = "1HNMR";
-    else if (type.equals("CNMR"))
-      type = "13CNMR";
-    while (readLine() != null && !(line = line.trim()).startsWith("</Peaks>"))
-      if (line.startsWith("<PeakData"))
-        peakData.addLast("<PeakData file=" + peakFilePath + " index=\"" + 
(++peakIndex[0]) + "\"" + " type=\"" + type + "\" " + line.substring(9).trim());
-    return true;
+  String piUnitsX, piUnitsY;
+
+  /**
+   * read a <Peaks> or <Signals> block See similar method in
+   * JSpecViewLib/src/jspecview/source/FileReader.java
+   * 
+   * @param isSignals
+   * @return true if successful
+   * @throws Exception
+   */
+  private int readPeaks(boolean isSignals) throws Exception {
+    JcampdxReader reader = this;
+    Object spectrum = null;
+    
+    try {
+      int offset = (isSignals ? 1 : 0);
+      String tag1 = (isSignals ? "Signals" : "Peaks");
+      String tag2 = (isSignals ? "<Signal" : "<PeakData");
+      String line = discardUntil(reader, tag1);
+      if (line.indexOf("<" + tag1) < 0)
+        line = discardUntil(reader, "<" + tag1);
+      if (line.indexOf("<" + tag1) < 0)
+        return 0;
+
+      String file = getPeakFilePath();
+      String model = getQuotedAttribute(line, "model");
+      model = " model=" + escape(model == null ? thisModelID : model);
+      String type = getQuotedAttribute(line, "type");
+      if ("HNMR".equals(type))
+        type = "1HNMR";
+      else if ("CNMR".equals(type))
+        type = "13CNMR";
+      type = (type == null ? "" : " type=" + escape(type));
+      piUnitsX = getQuotedAttribute(line, "xLabel");
+      piUnitsY = getQuotedAttribute(line, "yLabel");
+      Map<String, Object[]> htSets = new Hashtable<String, Object[]>();
+      List<Object[]> list = new ArrayList<Object[]>();
+      while ((line = reader.readLine()) != null
+          && !(line = line.trim()).startsWith("</" + tag1)) {
+        if (line.startsWith(tag2)) {
+          info(line);
+          String title = getQuotedAttribute(line, "title");
+          if (title == null) {
+            title = (type == "1HNMR" ? "atom%S%: %ATOMS%; integration: 
%NATOMS%" : "");
+            title = " title=" + escape(title);
+          } else {
+            title = "";
+          }
+          String stringInfo = "<PeakData "
+              + file
+              + " index=\"%INDEX%\""
+              + title
+              + type
+              + (getQuotedAttribute(line, "model") == null ? model
+                  : "") + " " + line.substring(tag2.length()).trim();
+          String atoms = getQuotedAttribute(stringInfo, "atoms");
+          if (atoms != null)
+            stringInfo = simpleReplace(stringInfo, "atoms=\""
+                + atoms + "\"", "atoms=\"%ATOMS%\"");
+          String key = ((int) (parseFloatStr(getQuotedAttribute(line, "xMin")) 
* 100))
+              + "_"
+              + ((int) (parseFloatStr(getQuotedAttribute(line,
+                  "xMax")) * 100));
+          Object[] o = htSets.get(key);
+          if (o == null) {
+            o = new Object[] { stringInfo,
+                (atoms == null ? null : new BS()) };
+            htSets.put(key, o);
+            list.add(o);
+          }
+          BS bs = (BS) o[1];
+          if (bs != null) {
+            atoms = atoms.replace(',', ' ');
+            bs.or(unescapeBitSet("({" + atoms + "})"));
+          }
+        }
+      }
+      int nH = 0;
+      int n = list.size();
+      for (int i = 0; i < n; i++) {
+        Object[] o = list.get(i);
+        String stringInfo = (String) o[0];
+        stringInfo = simpleReplace(stringInfo, "%INDEX%", ""
+            + getPeakIndex());
+        BS bs = (BS) o[1];
+        if (bs != null) {
+          String s = "";
+          for (int j = bs.nextSetBit(0); j >= 0; j = bs.nextSetBit(j + 1))
+            s += "," + (j + offset);
+          int na = bs.cardinality();
+          nH += na;
+          stringInfo = simpleReplace(stringInfo, "%ATOMS%", s
+              .substring(1));
+          stringInfo = simpleReplace(stringInfo, "%S%",
+              (na == 1 ? "" : "s"));
+          stringInfo = simpleReplace(stringInfo, "%NATOMS%", ""
+              + na);
+        }
+        info("Jmol using " + stringInfo);
+        add(peakData, stringInfo);
+      }
+      setSpectrumPeaks(spectrum, peakData, nH);
+      return n;
+    } catch (Exception e) {
+      return 0;
+    }
   }
 
+  private void info(String s) {
+    Logger.info(s);
+  }
+
+  private BS unescapeBitSet(String s) {
+    return Escape.uB(s);
+  }
+
+  private String simpleReplace(String s, String sfrom, String sto) {
+    return TextFormat.simpleReplace(s, sfrom, sto);
+  }
+
+  private String escape(String s) {
+    return Escape.eS(s);
+  }
+
+  private String getQuotedAttribute(String s, String attr) {
+    return Parser.getQuotedAttribute(s, attr);
+  }
+
   /**
+   * @param o1 
+   * @param o2 
+   * @param nH  
+   */
+  private void setSpectrumPeaks(Object o1, Object o2,
+                                int nH) {
+    // only in JSpecView
+  }
+
+  private void add(JmolList<String> peakData, String info) {
+    peakData.addLast(info);
+  }
+
+  private String getPeakFilePath() {
+    return " file=" + Escape.eS(peakFilePath);
+  }
+
+  
+  /**
+   * @param ignored  
+   * @param tag 
+   * @return line 
+   * @throws Exception 
+   */
+  private String discardUntil(Object ignored, String tag) throws Exception {
+    return discardLinesUntilContains2("<" + tag, "##");
+  }
+
+  /**
+   * @return index
+   */
+  private int getPeakIndex() {
+    return ++peakIndex[0];
+  }
+
+  /**
    * integrate the <PeakAssignment> records into the associated models, and 
delete unreferenced n.m models
    */
   @SuppressWarnings("unchecked")
@@ -341,10 +493,10 @@
     for (int p = 0; p < n; p++) {
       line = peakData.get(p);
       String type = getAttribute(line, "type");
-      modelID = getAttribute(line, "model");
-      int i = findModelById(modelID);
+      thisModelID = getAttribute(line, "model");
+      int i = findModelById(thisModelID);
       if (i < 0) {
-        Logger.warn("cannot find model " + modelID + " required for " + line);
+        Logger.warn("cannot find model " + thisModelID + " required for " + 
line);
         continue;
       }
       addType(i, type);
@@ -372,9 +524,9 @@
     }
     n = atomSetCollection.getAtomSetCount();
     for (int i = n; --i >= 0;) {
-      modelID = (String) atomSetCollection
+      thisModelID = (String) atomSetCollection
           .getAtomSetAuxiliaryInfoValue(i, "modelID");
-      if (havePeaks && !bsModels.get(i) && modelID.indexOf(".") >= 0) {
+      if (havePeaks && !bsModels.get(i) && thisModelID.indexOf(".") >= 0) {
         atomSetCollection.removeAtomSet(i); 
         n--;
       }

Modified: branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/MdTopReader.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/MdTopReader.java      
2013-09-18 23:07:12 UTC (rev 18668)
+++ branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/MdTopReader.java      
2013-09-18 23:09:05 UTC (rev 18669)
@@ -209,7 +209,7 @@
         atomSetCollection.addAtom(new Atom());
     }
 
-  String[] atomTypes;
+  private String[] atomTypes;
   private void getAtomTypes() throws Exception {
     atomTypes = getDataBlock();
   }

Deleted: branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/P2nReader.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/P2nReader.java        
2013-09-18 23:07:12 UTC (rev 18668)
+++ branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/P2nReader.java        
2013-09-18 23:09:05 UTC (rev 18669)
@@ -1,65 +0,0 @@
-/* $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: jmol-develop...@lists.sf.net
- *
- *  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.util.JmolList;
-
-
-import org.jmol.adapter.readers.cifpdb.PdbReader;
-import org.jmol.adapter.smarter.Atom;
-
-/**
- * P2N file reader.
- *
- * This format is the input for Resp ESP Charge Derive server
- * http://q4md-forcefieldtools.org/
- *  
- */
-
-public class P2nReader extends PdbReader {
-
-  private JmolList<String> altNames = new  JmolList<String>();
-  
-  @Override
-  protected void setAdditionalAtomParameters(Atom atom) {
-    String altName = line.substring(69, 72).trim();
-    if (altName.length() == 0)
-      altName = atom.atomName;
-    if (useAltNames)
-      atom.atomName = altName;
-    else
-      altNames.addLast(altName);
-  }
-  
-  @Override
-  protected void finalizeReader() throws Exception {
-    finalizeReaderPDB();
-    if (!useAltNames)
-      atomSetCollection.setAtomSetAuxiliaryInfo("altName", altNames
-          .toArray(new String[altNames.size()]));
-  }
-
-}
-

Deleted: branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java
===================================================================
--- branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java        
2013-09-18 23:07:12 UTC (rev 18668)
+++ branches/v13_2/Jmol/src/org/jmol/adapter/readers/more/PqrReader.java        
2013-09-18 23:09:05 UTC (rev 18669)
@@ -1,72 +0,0 @@
-/* $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: jmol-develop...@lists.sf.net
- *
- *  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.readers.cifpdb.PdbReader;
-
-/**
- * PQR file reader.
- *
-Angel Herraez, 2009 04 19
-
-free form added Bob Hanson hans...@stolaf.edu 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 
-the acronym: P for pdb, Q for charge, R for radius. Jmol interprets the charge 
values 
-(property partialcharge) and the radii (property vanderwaals), and can hence 
use them 
-e.g. in color atoms partialCharge and spacefill.
-
-The PQR format has somewhat uncertain origins, but is used by several 
computational biology packages, including MEAD, AutoDock and APBS[1], for which 
it is the primary input format.
-
-PQR format description[2] within APBS documentation. Note that APBS reads PQR 
loosely, based only on white space delimiters, but Jmol may be more strict 
about column positions.
-
-PDB files can be converted to PQR by the PDB2PQR software[3], which adds 
missing hydrogen atoms and calculates the charge and radius parameters from a 
variety of force fields. 
-
-
-1.- http://apbs.sourceforge.net/
-2.- http://apbs.sourceforge.net/doc/user-guide/index.html#pqr-format
-3.- http://pdb2pqr.sourceforge.net/
-4.- http://cardon.wustl.edu/MediaWiki/index.php/PQR_format
-
- *  
- */
-
-public class PqrReader extends PdbReader {
-
-  
-  protected boolean gromacsWideFormat;
-
-  @Override
-  protected void initializeReader() throws Exception {
-    isPQR = true;
-    super.initializeReader();
-  }
-      
-}
-

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
LIMITED TIME SALE - Full Year of Microsoft Training For Just $49.99!
1,500+ hours of tutorials including VisualStudio 2012, Windows 8, SharePoint
2013, SQL 2012, MVC 4, more. BEST VALUE: New Multi-Library Power Pack includes
Mobile, Cloud, Java, and UX Design. Lowest price ever! Ends 9/20/13. 
http://pubads.g.doubleclick.net/gampad/clk?id=58041151&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to