debug messages and graceful recovery when structure state is corrupted. apply gpl...
authorjprocter <Jim Procter>
Mon, 8 Jun 2009 11:11:41 +0000 (11:11 +0000)
committerjprocter <Jim Procter>
Mon, 8 Jun 2009 11:11:41 +0000 (11:11 +0000)
src/jalview/gui/Jalview2XML.java

index b3cf1af..03a9ecc 100755 (executable)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
- * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
+ * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -2366,7 +2366,7 @@ public class Jalview2XML
                 }
               }
               Desktop.desktop.getComponentAt(x, y);
-
+              // TODO: NOW: check that this recovers the PDB file correctly.
               String pdbFile = loadPDBFile(jprovider, ids[p].getId());
 
               jalview.datamodel.SequenceI[] seq = new jalview.datamodel.SequenceI[]
@@ -2377,17 +2377,28 @@ public class Jalview2XML
               {
                 // create a new Jmol window
                 String state = ids[p].getStructureState(s).getContent();
-
-                StringBuffer newFileLoc = new StringBuffer(state.substring(
+                StringBuffer newFileLoc=null;
+                if (state.indexOf("load")>-1) {
+                newFileLoc = new StringBuffer(state.substring(
                         0, state.indexOf("\"", state.indexOf("load")) + 1));
 
                 newFileLoc.append(jpdb.getFile());
                 newFileLoc.append(state.substring(state.indexOf("\"", state
                         .indexOf("load \"") + 6)));
-
-                new AppJmol(pdbFile, ids[p].getId(), seq, af.alignPanel,
-                        newFileLoc.toString(), new java.awt.Rectangle(x, y,
+                } else {
+                  System.err.println("Ignoring incomplete Jmol state for PDB "+ids[p].getId());
+                  
+                  newFileLoc = new StringBuffer(state);
+                  newFileLoc.append("; load \"");
+                  newFileLoc.append(jpdb.getFile());
+                  newFileLoc.append("\";");
+                }
+                
+                if (newFileLoc!=null) {
+                  new AppJmol(pdbFile, ids[p].getId(), seq, af.alignPanel,
+                          newFileLoc.toString(), new java.awt.Rectangle(x, y,
                                 width, height), sviewid);
+                }
 
               }
               else
@@ -2796,6 +2807,7 @@ public class Jalview2XML
       SequenceI[] dsseqs = new SequenceI[dseqs.size()];
       dseqs.copyInto(dsseqs);
       ds = new jalview.datamodel.Alignment(dsseqs);
+      debug("Created new dataset "+vamsasSet.getDatasetId()+" for alignment "+System.identityHashCode(al));
       addDatasetRef(vamsasSet.getDatasetId(), ds);
     }
     // set the dataset for the newly imported alignment.
@@ -3149,6 +3161,33 @@ public class Jalview2XML
     }
   }
 
+  private void debug(String string)
+  {
+    debug(string,null);
+  }
+  private void debug(String msg, Exception e)
+  {
+    if (Cache.log != null)
+    {
+      if (e != null)
+      {
+        Cache.log.debug(msg, e);
+      }
+      else
+      {
+        Cache.log.debug(msg);
+      }
+    }
+    else
+    {
+      System.err.println("Warning: " + msg);
+      if (e != null)
+      {
+        e.printStackTrace();
+      }
+    }
+  }
+
   /**
    * set the object to ID mapping tables used to write/recover objects and XML
    * ID strings for the jalview project. If external tables are provided then