From e06ef51ba3dd8cdae7632d71db162ff416b88256 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 9 Apr 2018 10:09:58 +0100 Subject: [PATCH] JAL-1847 JAL-2944 make superposition step a configurable property when opening/adding data to a structure viewer --- .../api/structures/JalviewStructureDisplayI.java | 4 ++ src/jalview/gui/AppJmol.java | 26 +++++++---- src/jalview/gui/ChimeraViewFrame.java | 12 ++--- src/jalview/gui/StructureViewer.java | 17 ++++++- src/jalview/gui/StructureViewerBase.java | 48 ++++++++++---------- 5 files changed, 64 insertions(+), 43 deletions(-) diff --git a/src/jalview/api/structures/JalviewStructureDisplayI.java b/src/jalview/api/structures/JalviewStructureDisplayI.java index c58e3c1..a27cec6 100644 --- a/src/jalview/api/structures/JalviewStructureDisplayI.java +++ b/src/jalview/api/structures/JalviewStructureDisplayI.java @@ -85,4 +85,8 @@ public interface JalviewStructureDisplayI */ void updateTitleAndMenus(); + boolean isAlignAddedStructures(); + + void setAlignAddedStructures(boolean alignAdded); + } diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 29f02d6..7b4af56 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -175,10 +175,13 @@ public class AppJmol extends StructureViewerBase { progressBar = ap.alignFrame; - openNewJmol(ap, new PDBEntry[] { pdbentry }, new SequenceI[][] { seq }); + openNewJmol(ap, alignAddedStructures, new PDBEntry[] { pdbentry }, + new SequenceI[][] + { seq }); } - private void openNewJmol(AlignmentPanel ap, PDBEntry[] pdbentrys, + private void openNewJmol(AlignmentPanel ap, boolean alignAdded, + PDBEntry[] pdbentrys, SequenceI[][] seqs) { progressBar = ap.alignFrame; @@ -187,8 +190,8 @@ public class AppJmol extends StructureViewerBase addAlignmentPanel(ap); useAlignmentPanelForColourbyseq(ap); - alignAddedStructures = true; - useAlignmentPanelForSuperposition(ap); + alignAddedStructures = alignAdded; + useAlignmentPanelForSuperposition(ap); jmb.setColourBySequence(true); setSize(400, 400); // probably should be a configurable/dynamic default here @@ -210,16 +213,19 @@ public class AppJmol extends StructureViewerBase } /** - * create a new Jmol containing several structures superimposed using the - * given alignPanel. + * create a new Jmol containing several structures optionally superimposed + * using the given alignPanel. * * @param ap + * @param alignAdded + * - true to superimpose * @param pe * @param seqs */ - public AppJmol(AlignmentPanel ap, PDBEntry[] pe, SequenceI[][] seqs) + public AppJmol(AlignmentPanel ap, boolean alignAdded, PDBEntry[] pe, + SequenceI[][] seqs) { - openNewJmol(ap, pe, seqs); + openNewJmol(ap, alignAdded, pe, seqs); } @@ -397,7 +403,7 @@ public class AppJmol extends StructureViewerBase jmb.updateColours(ap); } // do superposition if asked to - if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures) + if (alignAddedStructures) { alignAddedStructures(); } @@ -431,7 +437,7 @@ public class AppJmol extends StructureViewerBase } } }); - alignAddedStructures = false; + } /** diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index c595d9d..b4520c4 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -241,7 +241,6 @@ public class ChimeraViewFrame extends StructureViewerBase if (pdbentrys.length > 1) { - alignAddedStructures = true; useAlignmentPanelForSuperposition(ap); } jmb.setColourBySequence(true); @@ -300,17 +299,19 @@ public class ChimeraViewFrame extends StructureViewerBase } /** - * create a new viewer containing several structures superimposed using the - * given alignPanel. + * create a new viewer containing several structures, optionally superimposed + * using the given alignPanel. * * @param pe * @param seqs * @param ap */ - public ChimeraViewFrame(PDBEntry[] pe, SequenceI[][] seqs, + public ChimeraViewFrame(PDBEntry[] pe, boolean alignAdded, + SequenceI[][] seqs, AlignmentPanel ap) { this(); + setAlignAddedStructures(alignAdded); openNewChimera(ap, pe, seqs); } @@ -595,7 +596,7 @@ public class ChimeraViewFrame extends StructureViewerBase jmb.updateColours(ap); } // do superposition if asked to - if (Cache.getDefault("AUTOSUPERIMPOSE", true) && alignAddedStructures) + if (alignAddedStructures) { new Thread(new Runnable() { @@ -605,7 +606,6 @@ public class ChimeraViewFrame extends StructureViewerBase alignStructs_withAllAlignPanels(); } }).start(); - alignAddedStructures = false; } addingStructures = false; } diff --git a/src/jalview/gui/StructureViewer.java b/src/jalview/gui/StructureViewer.java index b7767fa..19e0a22 100644 --- a/src/jalview/gui/StructureViewer.java +++ b/src/jalview/gui/StructureViewer.java @@ -49,6 +49,11 @@ public class StructureViewer StructureSelectionManager ssm; + /** + * decide if new structures are aligned to existing ones + */ + private boolean superposeAdded = true; + public enum ViewerType { JMOL, CHIMERA @@ -127,6 +132,7 @@ public class StructureViewer new SequenceI[seqsForPdbs.size()][]); if (sview != null) { + sview.setAlignAddedStructures(superposeAdded); new Thread(new Runnable() { @Override @@ -152,11 +158,12 @@ public class StructureViewer 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 { @@ -279,6 +286,7 @@ public class StructureViewer { if (sview != null) { + sview.setAlignAddedStructures(superposeAdded); if (!sview.addAlreadyLoadedFile(seqsForPdb, null, ap, pdb.getId())) { sview.addToExistingViewer(pdb, seqsForPdb, null, ap, pdb.getId()); @@ -373,4 +381,9 @@ public class StructureViewer return sview != null && sview.isVisible(); } + public void setSuperpose(boolean alignAddedStructures) + { + superposeAdded = alignAddedStructures; + } + } diff --git a/src/jalview/gui/StructureViewerBase.java b/src/jalview/gui/StructureViewerBase.java index 3b80ff0..20f5c1f 100644 --- a/src/jalview/gui/StructureViewerBase.java +++ b/src/jalview/gui/StructureViewerBase.java @@ -130,6 +130,26 @@ public abstract class StructureViewerBase extends GStructureViewer } /** + * @return true if added structures should be aligned to existing one(s) + */ + @Override + public boolean isAlignAddedStructures() + { + return alignAddedStructures; + } + + /** + * + * @param true + * if added structures should be aligned to existing one(s) + */ + @Override + public void setAlignAddedStructures(boolean alignAdded) + { + alignAddedStructures = alignAdded; + } + + /** * * @param ap2 * @return true if this Jmol instance is linked with the given alignPanel @@ -335,7 +355,7 @@ public abstract class StructureViewerBase extends GStructureViewer */ protected void addStructure(final PDBEntry pdbentry, final SequenceI[] seqs, final String[] chains, - final boolean align, final IProgressIndicator alignFrame) + final IProgressIndicator alignFrame) { if (pdbentry.getFile() == null) { @@ -359,7 +379,7 @@ public abstract class StructureViewerBase extends GStructureViewer } } // and call ourselves again. - addStructure(pdbentry, seqs, chains, align, alignFrame); + addStructure(pdbentry, seqs, chains, alignFrame); } }).start(); return; @@ -371,33 +391,11 @@ public abstract class StructureViewerBase extends GStructureViewer { seqs }, new String[][] { chains }); addingStructures = true; _started = false; - alignAddedStructures = align; worker = new Thread(this); worker.start(); return; } - /** - * Presents a dialog with the option to add an align a structure to an - * existing structure view - * - * @param pdbId - * @param view - * @return YES, NO or CANCEL JvOptionPane code - */ - protected int chooseAlignStructureToViewer(String pdbId, - StructureViewerBase view) - { - int option = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, - MessageManager.formatMessage("label.add_pdbentry_to_view", - new Object[] - { pdbId, view.getTitle() }), - MessageManager - .getString("label.align_to_existing_structure_view"), - JvOptionPane.YES_NO_CANCEL_OPTION); - return option; - } - protected boolean hasPdbId(String pdbId) { return getBinding().hasPdbId(pdbId); @@ -439,7 +437,7 @@ public abstract class StructureViewerBase extends GStructureViewer AlignmentPanel ap = (AlignmentPanel) apanel; // Implementation error if this // cast fails useAlignmentPanelForSuperposition(ap); - addStructure(pdbentry, seq, chains, true, ap.alignFrame); + addStructure(pdbentry, seq, chains, ap.alignFrame); return true; } -- 1.7.10.2