X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FStructureViewer.java;h=5effa1a9c19ef37feb8d4aaaf719887c66ad8106;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=fb37b7739c892c4774c2ce8c17d3f5a0ad014882;hpb=aa885913f06fc3885c818370544f43474a14f402;p=jalview.git diff --git a/src/jalview/gui/StructureViewer.java b/src/jalview/gui/StructureViewer.java index fb37b77..5effa1a 100644 --- a/src/jalview/gui/StructureViewer.java +++ b/src/jalview/gui/StructureViewer.java @@ -20,14 +20,6 @@ */ package jalview.gui; -import jalview.api.structures.JalviewStructureDisplayI; -import jalview.bin.Cache; -import jalview.datamodel.PDBEntry; -import jalview.datamodel.SequenceI; -import jalview.datamodel.StructureViewerModel; -import jalview.structure.StructureSelectionManager; - -import java.awt.Rectangle; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -35,6 +27,14 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import jalview.api.structures.JalviewStructureDisplayI; +import jalview.bin.Cache; +import jalview.bin.Console; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.datamodel.StructureViewerModel; +import jalview.structure.StructureSelectionManager; + /** * A proxy for handling structure viewers, that orchestrates adding selected * structures, associated with sequences in Jalview, to an existing viewer, or @@ -49,9 +49,14 @@ public class StructureViewer StructureSelectionManager ssm; + /** + * decide if new structures are aligned to existing ones + */ + private boolean superposeAdded = true; + public enum ViewerType { - JMOL, CHIMERA + JMOL, CHIMERA, CHIMERAX, PYMOL }; /** @@ -59,12 +64,39 @@ public class StructureViewer * * @param structureSelectionManager */ - public StructureViewer(StructureSelectionManager structureSelectionManager) + public StructureViewer( + StructureSelectionManager structureSelectionManager) { ssm = structureSelectionManager; } - public ViewerType getViewerType() + /** + * Factory to create a proxy for modifying existing structure viewer + * + */ + public static StructureViewer reconfigure( + JalviewStructureDisplayI display) + { + StructureViewer sv = new StructureViewer(display.getBinding().getSsm()); + sv.sview = display; + return sv; + } + + @Override + public String toString() + { + if (sview != null) + { + return sview.toString(); + } + return "New View"; + } + + /** + * + * @return ViewerType for currently configured structure viewer + */ + public static ViewerType getViewerType() { String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name()); @@ -100,22 +132,57 @@ public class StructureViewer Map seqsForPdbs = getSequencesForPdbs(pdbs, seqs); - PDBEntry[] pdbsForFile = seqsForPdbs.keySet().toArray( - new PDBEntry[seqsForPdbs.size()]); - SequenceI[][] theSeqs = seqsForPdbs.values().toArray( - new SequenceI[seqsForPdbs.size()][]); - JalviewStructureDisplayI sview = null; + PDBEntry[] pdbsForFile = seqsForPdbs.keySet() + .toArray(new PDBEntry[seqsForPdbs.size()]); + SequenceI[][] theSeqs = seqsForPdbs.values() + .toArray(new SequenceI[seqsForPdbs.size()][]); + if (sview != null) + { + sview.setAlignAddedStructures(superposeAdded); + new Thread(new Runnable() + { + @Override + public void run() + { + + for (int pdbep = 0; pdbep < pdbsForFile.length; pdbep++) + { + PDBEntry pdb = pdbsForFile[pdbep]; + if (!sview.addAlreadyLoadedFile(theSeqs[pdbep], null, ap, + pdb.getId())) + { + sview.addToExistingViewer(pdb, theSeqs[pdbep], null, ap, + pdb.getId()); + } + } + + sview.updateTitleAndMenus(); + } + }).start(); + return sview; + } + if (viewerType.equals(ViewerType.JMOL)) { - sview = new AppJmol(ap, pdbsForFile, theSeqs); + sview = new AppJmol(ap, superposeAdded, pdbsForFile, theSeqs); } else if (viewerType.equals(ViewerType.CHIMERA)) { - sview = new ChimeraViewFrame(pdbsForFile, theSeqs, ap); + sview = new ChimeraViewFrame(pdbsForFile, superposeAdded, theSeqs, + ap); + } + else if (viewerType.equals(ViewerType.CHIMERAX)) + { + sview = new ChimeraXViewFrame(pdbsForFile, superposeAdded, theSeqs, + ap); + } + else if (viewerType.equals(ViewerType.PYMOL)) + { + sview = new PymolViewer(pdbsForFile, superposeAdded, theSeqs, ap); } else { - Cache.log.error(UNKNOWN_VIEWER_TYPE + getViewerType().toString()); + Console.error(UNKNOWN_VIEWER_TYPE + getViewerType().toString()); } return sview; } @@ -203,7 +270,7 @@ public class StructureViewer private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs, SequenceI[] seqsForPdbs, AlignmentPanel ap) { - List seqs = new ArrayList(); + List seqs = new ArrayList<>(); if (pdbs == null || pdbs.length == 0) { return null; @@ -227,11 +294,24 @@ public class StructureViewer ap); } + JalviewStructureDisplayI sview = null; + public JalviewStructureDisplayI viewStructures(PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap) { + if (sview != null) + { + sview.setAlignAddedStructures(superposeAdded); + String pdbId = pdb.getId(); + if (!sview.addAlreadyLoadedFile(seqsForPdb, null, ap, pdbId)) + { + sview.addToExistingViewer(pdb, seqsForPdb, null, ap, pdbId); + } + sview.updateTitleAndMenus(); + sview.raiseViewer(); + return sview; + } ViewerType viewerType = getViewerType(); - JalviewStructureDisplayI sview = null; if (viewerType.equals(ViewerType.JMOL)) { sview = new AppJmol(pdb, seqsForPdb, null, ap); @@ -240,51 +320,94 @@ public class StructureViewer { sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap); } + else if (viewerType.equals(ViewerType.CHIMERAX)) + { + sview = new ChimeraXViewFrame(pdb, seqsForPdb, null, ap); + } + else if (viewerType.equals(ViewerType.PYMOL)) + { + sview = new PymolViewer(pdb, seqsForPdb, null, ap); + } else { - Cache.log.error(UNKNOWN_VIEWER_TYPE + getViewerType().toString()); + Console.error(UNKNOWN_VIEWER_TYPE + getViewerType().toString()); } return sview; } /** - * Create a new panel controlling a structure viewer. + * Creates a new panel controlling a structure viewer * * @param type - * @param pdbf - * @param id - * @param sq * @param alignPanel * @param viewerData - * @param fileloc - * @param rect + * @param sessionFile * @param vid * @return */ - public JalviewStructureDisplayI createView(ViewerType type, String[] pdbf, - String[] id, SequenceI[][] sq, AlignmentPanel alignPanel, - StructureViewerModel viewerData, String fileloc, Rectangle rect, - String vid) + public static JalviewStructureDisplayI createView(ViewerType type, + AlignmentPanel alignPanel, StructureViewerModel viewerData, + String sessionFile, String vid) { - final boolean useinViewerSuperpos = viewerData.isAlignWithPanel(); - final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel(); - final boolean viewerColouring = viewerData.isColourByViewer(); - - JalviewStructureDisplayI sview = null; + JalviewStructureDisplayI viewer = null; switch (type) { case JMOL: - sview = new AppJmol(pdbf, id, sq, alignPanel, usetoColourbyseq, - useinViewerSuperpos, viewerColouring, fileloc, rect, vid); + viewer = new AppJmol(viewerData, alignPanel, sessionFile, vid); + // todo or construct and then openSession(sessionFile)? break; case CHIMERA: - Cache.log.error( - "Unsupported structure viewer type " + type.toString()); + viewer = new ChimeraViewFrame(viewerData, alignPanel, sessionFile, + vid); + break; + case CHIMERAX: + viewer = new ChimeraXViewFrame(viewerData, alignPanel, sessionFile, + vid); + break; + case PYMOL: + viewer = new PymolViewer(viewerData, alignPanel, sessionFile, vid); break; default: - Cache.log.error(UNKNOWN_VIEWER_TYPE + type.toString()); + Console.error(UNKNOWN_VIEWER_TYPE + type.toString()); } - return sview; + return viewer; + } + + public boolean isBusy() + { + if (sview != null) + { + if (!sview.hasMapping()) + { + return true; + } + } + return false; + } + + /** + * + * @param pDBid + * @return true if view is already showing PDBid + */ + public boolean hasPdbId(String pDBid) + { + if (sview == null) + { + return false; + } + + return sview.getBinding().hasPdbId(pDBid); + } + + public boolean isVisible() + { + return sview != null && sview.isVisible(); + } + + public void setSuperpose(boolean alignAddedStructures) + { + superposeAdded = alignAddedStructures; } }