From: hansonr Date: Sun, 24 Mar 2019 03:46:57 +0000 (-0500) Subject: Allows Jmol to share cached files X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c8fa8a8916f70196f3a687e6403ac4889771da77;p=jalview.git Allows Jmol to share cached files --- diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java index c1dc77c..407f87d 100755 --- a/src/jalview/datamodel/PDBEntry.java +++ b/src/jalview/datamodel/PDBEntry.java @@ -22,6 +22,7 @@ package jalview.datamodel; import jalview.util.CaseInsensitiveString; +import java.io.File; import java.util.Collections; import java.util.Enumeration; import java.util.Hashtable; @@ -38,7 +39,9 @@ public class PDBEntry private static final int PDB_ID_LENGTH = 4; - private String file; + private String fileName; + + private File file; private String type; @@ -133,8 +136,8 @@ public class PDBEntry */ boolean idMatches = id == o.id || (id != null && id.equalsIgnoreCase(o.id)); - boolean fileMatches = file == o.file - || (file != null && file.equals(o.file)); + boolean fileMatches = fileName == o.fileName + || (fileName != null && fileName.equals(o.fileName)); boolean typeMatches = type == o.type || (type != null && type.equals(o.type)); if (idMatches && fileMatches && typeMatches) @@ -164,12 +167,12 @@ public class PDBEntry * @param entryType * @param filePath */ - void init(String pdbId, String chain, PDBEntry.Type entryType, + private void init(String pdbId, String chain, PDBEntry.Type entryType, String filePath) { this.id = pdbId; this.type = entryType == null ? null : entryType.toString(); - this.file = filePath; + this.fileName = filePath; setChainCode(chain); } @@ -180,7 +183,7 @@ public class PDBEntry */ public PDBEntry(PDBEntry entry) { - file = entry.file; + fileName = entry.fileName; type = entry.type; id = entry.id; if (entry.properties != null) @@ -220,12 +223,22 @@ public class PDBEntry public void setFile(String f) { + this.fileName = f; + } + + public void setFile(File f) + { this.file = f; } public String getFile() { - return file; + return (file != null ? file.getAbsolutePath() : fileName); + } + + public File getFileF() + { + return (file == null ? new File(fileName) : file); } public void setType(String t) @@ -420,6 +433,7 @@ public class PDBEntry { setFile(newFile); setType(newType); + setFile(newEntry.getFileF()); } /* diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 7179a18..f937f22 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -140,7 +140,7 @@ public class AppJmol extends StructureViewerBase closeViewer(false); } }); - initJmol(loadStatus); // pdbentry, seq, JBPCHECK! + initJmol(loadStatus, null); // pdbentry, seq, JBPCHECK! } @Override @@ -199,8 +199,6 @@ public class AppJmol extends StructureViewerBase setSize(400, 400); // probably should be a configurable/dynamic default here initMenus(); addingStructures = false; - worker = new Thread(this); - worker.start(); this.addInternalFrameListener(new InternalFrameAdapter() { @@ -212,6 +210,8 @@ public class AppJmol extends StructureViewerBase } }); + worker = new Thread(this); + worker.start(); } /** @@ -231,7 +231,7 @@ public class AppJmol extends StructureViewerBase } - void initJmol(String command) + private void initJmol(String command, List files) { jmb.setFinishedInit(false); renderPanel = new RenderPanel(); @@ -255,6 +255,8 @@ public class AppJmol extends StructureViewerBase if (command == null) { command = ""; + } else if (files != null) { + jmb.cacheFiles(files); } jmb.evalStateCommand(command); jmb.evalStateCommand("set hoverDelay=0.1"); @@ -302,7 +304,7 @@ public class AppJmol extends StructureViewerBase _started = true; try { - List files = fetchPdbFiles(); + List files = fetchPdbFiles(); if (files.size() > 0) { showFilesInViewer(files); @@ -321,12 +323,13 @@ public class AppJmol extends StructureViewerBase * @param files * list of absolute paths to structure files */ - void showFilesInViewer(List files) + void showFilesInViewer(List files) { long lastnotify = jmb.getLoadNotifiesHandled(); StringBuilder fileList = new StringBuilder(); - for (String s : files) + for (File f : files) { + String s = f.getAbsolutePath(); fileList.append(SPACE).append(QUOTE) .append(Platform.escapeString(s)).append(QUOTE); } @@ -336,7 +339,7 @@ public class AppJmol extends StructureViewerBase { try { - initJmol("load FILES " + filesString); + initJmol("load FILES " + filesString, files); } catch (OutOfMemoryError oomerror) { new OOMWarning("When trying to open the Jmol viewer!", oomerror); @@ -359,6 +362,7 @@ public class AppJmol extends StructureViewerBase try { + jmb.cacheFiles(files); jmb.evalStateCommand(command); } catch (OutOfMemoryError oomerror) { @@ -453,12 +457,12 @@ public class AppJmol extends StructureViewerBase * * @return */ - List fetchPdbFiles() + List fetchPdbFiles() { // todo - record which pdbids were successfully imported. StringBuilder errormsgs = new StringBuilder(); - List files = new ArrayList<>(); + List files = new ArrayList<>(); String pdbid = ""; try { @@ -468,7 +472,7 @@ public class AppJmol extends StructureViewerBase Pdb pdbclient = new Pdb(); for (int pi = 0; pi < jmb.getPdbCount(); pi++) { - String file = jmb.getPdbEntry(pi).getFile(); + File file = jmb.getPdbEntry(pi).getFileF(); if (file == null) { // todo: extract block as method and pull up (also ChimeraViewFrame) @@ -506,7 +510,7 @@ public class AppJmol extends StructureViewerBase // just transfer the file name from the first sequence's first // PDBEntry file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries() - .elementAt(0).getFile()).getAbsolutePath(); + .elementAt(0).getFile()); jmb.getPdbEntry(pi).setFile(file); files.add(file); } @@ -520,9 +524,10 @@ public class AppJmol extends StructureViewerBase if (filesInViewer != null && filesInViewer.length > 0) { addingStructures = true; // already files loaded. + String filename = file.getAbsolutePath(); for (int c = 0; c < filesInViewer.length; c++) { - if (filesInViewer[c].equals(file)) + if (filesInViewer[c].equals(filename)) { file = null; break; diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index eeb4888..5c2addc 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -28,12 +28,16 @@ import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; import jalview.io.DataSourceType; import jalview.structure.StructureSelectionManager; +import jalview.util.Platform; import java.awt.Container; +import java.io.File; +import java.util.List; import java.util.Map; import org.jmol.api.JmolAppConsoleInterface; import javajs.util.BS; + import org.openscience.jmol.app.jmolpanel.console.AppConsole; public class AppJmolBinding extends JalviewJmolBinding @@ -215,4 +219,17 @@ public class AppJmolBinding extends JalviewJmolBinding return null; } + + @SuppressWarnings("unused") +public void cacheFiles(List files) { + if (files == null) + return; + for (File f : files) { + String path = f.getAbsolutePath(); + byte[] data = Platform.getFileBytes(f); + if (data != null) { + Platform.cacheFileData(path, data); + } + } + } } diff --git a/src/jalview/io/StructureFile.java b/src/jalview/io/StructureFile.java index 084f886..5c8360c 100644 --- a/src/jalview/io/StructureFile.java +++ b/src/jalview/io/StructureFile.java @@ -120,6 +120,7 @@ public abstract class StructureFile extends AlignFile PDBEntry entry = new PDBEntry(); entry.setId(getId()); entry.setType(getStructureFileType()); + entry.setFile(inFile); if (chain.id != null) { entry.setChainCode(chain.id);