From: gmungoc Date: Tue, 6 Jan 2015 11:31:32 +0000 (+0000) Subject: JAL-1588 refactoring prior to 'save Chimera project' X-Git-Tag: Jalview_2_9~106^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=c66902a9536b10a5477b58aaf7c2d75772890a5d;p=jalview.git JAL-1588 refactoring prior to 'save Chimera project' --- diff --git a/schemas/jalview.xsd b/schemas/jalview.xsd index 27f952d..137f7fb 100755 --- a/schemas/jalview.xsd +++ b/schemas/jalview.xsd @@ -203,7 +203,14 @@ - + + + +Full path name to a saved Chimera session file (usually a .py file). + + + diff --git a/src/jalview/api/SequenceStructureBinding.java b/src/jalview/api/SequenceStructureBinding.java index 32c5bca..d620401 100644 --- a/src/jalview/api/SequenceStructureBinding.java +++ b/src/jalview/api/SequenceStructureBinding.java @@ -32,7 +32,7 @@ public interface SequenceStructureBinding /** * * @return true if Jalview or the Viewer is still restoring state or loading - * is still going on (see setFinsihedLoadingFromArchive) + * is still going on (see setFinishedLoadingFromArchive) */ void setLoadingFromArchive(boolean loadingFromArchive); diff --git a/src/jalview/api/structures/JalviewStructureDisplayI.java b/src/jalview/api/structures/JalviewStructureDisplayI.java index efb60dd..45b074b 100644 --- a/src/jalview/api/structures/JalviewStructureDisplayI.java +++ b/src/jalview/api/structures/JalviewStructureDisplayI.java @@ -20,21 +20,13 @@ */ package jalview.api.structures; -import jalview.api.FeatureRenderer; -import jalview.api.SequenceRenderer; -import jalview.api.SequenceStructureBinding; -import jalview.datamodel.AlignmentI; -import jalview.datamodel.SequenceI; -import jalview.ext.jmol.JalviewJmolBinding; import jalview.schemes.ColourSchemeI; -import jalview.schemes.UserColourScheme; -import jalview.structure.StructureMappingcommandSet; -import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; public interface JalviewStructureDisplayI { - SequenceStructureBinding getBinding(); + AAStructureBindingModel getBinding(); /** * @return true if there is an active GUI handling a structure display diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index ed64215..9f65786 100644 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -62,6 +62,7 @@ import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; import jalview.schemes.ZappoColourScheme; import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; import java.awt.BorderLayout; @@ -3615,7 +3616,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener, return null; } } - ExtJmol jmv = null; + AAStructureBindingModel jmv = null; // TODO: search for a jmv that involves viewer if (jmv == null) { // create a new viewer/jalview binding. diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 42fbd70..0db3e30 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -20,18 +20,49 @@ */ package jalview.appletgui; -import java.util.*; -import java.awt.*; -import java.awt.event.*; - -import jalview.api.SequenceStructureBinding; -import jalview.datamodel.*; -import jalview.structure.*; -import jalview.io.*; - -import jalview.schemes.*; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.io.AppletFormatAdapter; +import jalview.io.FileParse; +import jalview.schemes.BuriedColourScheme; +import jalview.schemes.HelixColourScheme; +import jalview.schemes.HydrophobicColourScheme; +import jalview.schemes.PurinePyrimidineColourScheme; +import jalview.schemes.StrandColourScheme; +import jalview.schemes.TaylorColourScheme; +import jalview.schemes.TurnColourScheme; +import jalview.schemes.UserColourScheme; +import jalview.schemes.ZappoColourScheme; +import jalview.structure.StructureSelectionManager; import jalview.util.MessageManager; +import java.awt.BorderLayout; +import java.awt.CheckboxMenuItem; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Menu; +import java.awt.MenuBar; +import java.awt.MenuItem; +import java.awt.Panel; +import java.awt.Rectangle; +import java.awt.TextArea; +import java.awt.TextField; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Vector; + public class AppletJmol extends EmbmenuFrame implements // StructureListener, KeyListener, ActionListener, ItemListener @@ -398,9 +429,9 @@ public class AppletJmol extends EmbmenuFrame implements StringBuffer sb = new StringBuffer(); try { - for (int s = 0; s < jmb.pdbentry.length; s++) + for (int s = 0; s < jmb.getPdbCount(); s++) { - sb.append(jmb.printMapping(jmb.pdbentry[s].getFile())); + sb.append(jmb.printMapping(jmb.getPdbEntry(s).getFile())); sb.append("\n"); } cap.setText(sb.toString()); @@ -488,7 +519,9 @@ public class AppletJmol extends EmbmenuFrame implements for (int i = 0; i < chainMenu.getItemCount(); i++) { if (chainMenu.getItem(i) instanceof CheckboxMenuItem) + { ((CheckboxMenuItem) chainMenu.getItem(i)).setState(true); + } } centerViewer(); @@ -522,7 +555,9 @@ public class AppletJmol extends EmbmenuFrame implements jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } else if (!allChainsSelected) + { centerViewer(); + } } public void keyPressed(KeyEvent evt) diff --git a/src/jalview/appletgui/AppletJmolBinding.java b/src/jalview/appletgui/AppletJmolBinding.java index 650693d..e22e20a 100644 --- a/src/jalview/appletgui/AppletJmolBinding.java +++ b/src/jalview/appletgui/AppletJmolBinding.java @@ -77,7 +77,9 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding public void sendConsoleEcho(String strEcho) { if (appletJmolBinding.scriptWindow == null) + { appletJmolBinding.showConsole(true); + } appletJmolBinding.history.append("\n" + strEcho); } @@ -138,10 +140,10 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding } + @Override public void refreshPdbEntries() { - // TODO Auto-generated method stub - + // noop } @Override @@ -164,20 +166,7 @@ class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding protected void releaseUIResources() { appletJmolBinding = null; - if (console != null) - { - try - { - console.setVisible(false); - } catch (Error e) - { - } catch (Exception x) - { - } - ; - console = null; - } - + closeConsole(); } @Override diff --git a/src/jalview/appletgui/ExtJmol.java b/src/jalview/appletgui/ExtJmol.java index 6389250..58bd5a6 100644 --- a/src/jalview/appletgui/ExtJmol.java +++ b/src/jalview/appletgui/ExtJmol.java @@ -20,14 +20,6 @@ */ package jalview.appletgui; -import java.awt.Container; -import java.util.BitSet; -import java.util.Hashtable; -import java.util.Vector; - -import org.jmol.api.JmolAppConsoleInterface; -import org.jmol.api.JmolViewer; - import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; @@ -35,6 +27,15 @@ import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; import jalview.ext.jmol.JalviewJmolBinding; +import java.awt.Container; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.List; +import java.util.Vector; + +import org.jmol.api.JmolAppConsoleInterface; +import org.jmol.api.JmolViewer; + /** * bind an alignment view to an external Jmol instance. * @@ -57,9 +58,8 @@ public class ExtJmol extends JalviewJmolBinding public ExtJmol(JmolViewer viewer, AlignmentPanel alignPanel, SequenceI[][] seqs) { - super(alignPanel.getStructureSelectionManager(), viewer); + super(alignPanel.getStructureSelectionManager(), seqs, viewer); ap = alignPanel; - this.sequence = seqs; notifyFileLoaded(null, null, null, null, 0); } @@ -125,8 +125,8 @@ public class ExtJmol extends JalviewJmolBinding public void refreshPdbEntries() { - Vector pdbe = new Vector(); - Hashtable fileids = new Hashtable(); + List pdbe = new ArrayList(); + List fileids = new ArrayList(); SequenceI[] sq = ap.av.getAlignment().getSequencesArray(); for (int s = 0; s < sq.length; s++) { @@ -136,18 +136,23 @@ public class ExtJmol extends JalviewJmolBinding for (int pe = 0, peSize = pdbids.size(); pe < peSize; pe++) { PDBEntry pentry = (PDBEntry) pdbids.elementAt(pe); - if (!fileids.containsKey(pentry.getId())) + if (!fileids.contains(pentry.getId())) { - pdbe.addElement(pentry); + pdbe.add(pentry); + } + else + { + fileids.add(pentry.getId()); } } } } - pdbentry = new PDBEntry[pdbe.size()]; + PDBEntry[] newEntries = new PDBEntry[pdbe.size()]; for (int pe = 0; pe < pdbe.size(); pe++) { - pdbentry[pe] = (PDBEntry) pdbe.elementAt(pe); + newEntries[pe] = pdbe.get(pe); } + setPdbentry(newEntries); } @Override @@ -172,19 +177,7 @@ public class ExtJmol extends JalviewJmolBinding protected void releaseUIResources() { ap = null; - if (console != null) - { - try - { - console.setVisible(false); - } catch (Error e) - { - } catch (Exception x) - { - } - ; - console = null; - } + closeConsole(); } diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 9187912..619144e 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -23,8 +23,6 @@ package jalview.ext.jmol; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; -import jalview.api.SequenceStructureBinding; -import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; @@ -32,10 +30,10 @@ import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; -import jalview.structure.StructureListener; import jalview.structure.StructureMapping; +import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; -import jalview.structures.models.SequenceStructureBindingModel; +import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; import java.awt.Color; @@ -58,30 +56,18 @@ import org.jmol.api.JmolViewer; import org.jmol.constant.EnumCallback; import org.jmol.popup.JmolPopup; -public abstract class JalviewJmolBinding extends SequenceStructureBindingModel implements StructureListener, - JmolStatusListener, SequenceStructureBinding, - JmolSelectionListener, ComponentListener, - StructureSelectionManagerProvider - +public abstract class JalviewJmolBinding extends AAStructureBindingModel + implements JmolStatusListener, JmolSelectionListener, + ComponentListener { - /** + /* * state flag used to check if the Jmol viewer's paint method can be called */ private boolean finishedInit = false; - public boolean isFinishedInit() - { - return finishedInit; - } - - public void setFinishedInit(boolean finishedInit) - { - this.finishedInit = finishedInit; - } - boolean allChainsSelected = false; - /** + /* * when true, try to search the associated datamodel for sequences that are * associated with any unknown structures in the Jmol view. */ @@ -93,18 +79,11 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i Hashtable chainFile; - /** - * array of target chains for seuqences - tied to pdbentry and sequence[] - */ - protected String[][] chains; - - boolean colourBySequence = true; - StringBuffer eval = new StringBuffer(); public String fileLoadingError; - /** + /* * the default or current model displayed if the model cannot be identified * from the selection message */ @@ -123,37 +102,15 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i */ String[] modelFileNames = null; - public PDBEntry[] pdbentry; - - /** - * datasource protocol for access to PDBEntrylatest - */ - String protocol = null; - StringBuffer resetLastRes = new StringBuffer(); - /** - * sequences mapped to each pdbentry - */ - public SequenceI[][] sequence; - - public StructureSelectionManager ssm; - public JmolViewer viewer; public JalviewJmolBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, String protocol) { - this.ssm = ssm; - this.sequence = sequenceIs; - this.chains = chains; - this.pdbentry = pdbentry; - this.protocol = protocol; - if (chains == null) - { - this.chains = new String[pdbentry.length][]; - } + super(ssm, pdbentry, sequenceIs, chains, protocol); /* * viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(), * "jalviewJmol", ap.av.applet .getDocumentBase(), @@ -164,10 +121,11 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i } public JalviewJmolBinding(StructureSelectionManager ssm, - JmolViewer viewer2) + SequenceI[][] seqs, JmolViewer theViewer) { - this.ssm = ssm; - viewer = viewer2; + super(ssm, seqs); + + viewer = theViewer; viewer.setJmolStatusListener(this); viewer.addSelectionListener(this); } @@ -180,30 +138,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i */ public String getViewerTitle() { - if (sequence == null || pdbentry == null || sequence.length < 1 - || pdbentry.length < 1 || sequence[0].length < 1) - { - return ("Jalview Jmol Window"); - } - // TODO: give a more informative title when multiple structures are - // displayed. - StringBuffer title = new StringBuffer(sequence[0][0].getName() + ":" - + pdbentry[0].getId()); - - if (pdbentry[0].getProperty() != null) - { - if (pdbentry[0].getProperty().get("method") != null) - { - title.append(" Method: "); - title.append(pdbentry[0].getProperty().get("method")); - } - if (pdbentry[0].getProperty().get("chains") != null) - { - title.append(" Chain:"); - title.append(pdbentry[0].getProperty().get("chains")); - } - } - return title.toString(); + return getViewerTitle("JMol", true); } /** @@ -232,7 +167,9 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i + (1 + getModelNum((String) chainFile.get(lbl))) + " or "); } if (cmd.length() > 0) + { cmd.setLength(cmd.length() - 4); + } evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd); } @@ -240,7 +177,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i { viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE); // remove listeners for all structures in viewer - ssm.removeStructureViewerListener(this, this.getPdbFile()); + getSsm().removeStructureViewerListener(this, this.getPdbFile()); // and shut down jmol viewer.evalStringQuiet("zap"); viewer.setJmolStatusListener(null); @@ -249,12 +186,6 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i releaseUIResources(); } - /** - * called by JalviewJmolbinding after closeViewer is called - release any - * resources and references so they can be garbage collected. - */ - protected abstract void releaseUIResources(); - public void colourByChain() { colourBySequence = false; @@ -330,7 +261,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i { // HACK - in Jalview 2.8 this call may not be threadsafe so we catch // every possible exception - StructureMapping[] sm = ssm.getMapping(file); + StructureMapping[] sm = getSsm().getMapping(file); if (sm == null || sm.length == 0) { waiting = true; @@ -408,7 +339,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i String[] chainNames = new String[files.length]; for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { - StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); + StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]); // RACE CONDITION - getMapping only returns Jmol loaded filenames once // Jmol callback has completed. if (mapping == null || mapping.length < 1) @@ -416,12 +347,13 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i throw new Error(MessageManager.getString("error.implementation_error_jmol_getting_data")); } int lastPos = -1; - for (int s = 0; s < sequence[pdbfnum].length; s++) + final int sequenceCountForPdbFile = getSequence()[pdbfnum].length; + for (int s = 0; s < sequenceCountForPdbFile; s++) { for (int sp, m = 0; m < mapping.length; m++) { - if (mapping[m].getSequence() == sequence[pdbfnum][s] - && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1) + if (mapping[m].getSequence() == getSequence()[pdbfnum][s] + && (sp = alignment.findIndex(getSequence()[pdbfnum][s])) > -1) { if (refStructure == -1) { @@ -473,7 +405,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i chainNames[pdbfnum] = mapping[m].getPdbId() + targetC[pdbfnum]; // move on to next pdb file - s = sequence[pdbfnum].length; + s = getSequence()[pdbfnum].length; break; } } @@ -630,8 +562,10 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i jalview.api.AlignmentViewPanel alignmentv) { if (!colourBySequence || !isLoadingFinished()) + { return; - if (ssm == null) + } + if (getSsm() == null) { return; } @@ -646,23 +580,38 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i } AlignmentI alignment = alignmentv.getAlignment(); - for (jalview.structure.StructureMappingcommandSet cpdbbyseq : JmolCommands - .getColourBySequenceCommand(ssm, files, sequence, sr, fr, - alignment)) + for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(files, sr, fr, alignment)) + { for (String cbyseq : cpdbbyseq.commands) { - evalStateCommand(cbyseq); + executeWhenReady(cbyseq); } + } } - public boolean isColourBySequence() + /** + * @param files + * @param sr + * @param fr + * @param alignment + * @return + */ + protected StructureMappingcommandSet[] getColourBySequenceCommands( + String[] files, SequenceRenderer sr, FeatureRenderer fr, + AlignmentI alignment) { - return colourBySequence; + return JmolCommands + .getColourBySequenceCommand(getSsm(), files, getSequence(), sr, + fr, + alignment); } - public void setColourBySequence(boolean colourBySequence) + /** + * @param command + */ + protected void executeWhenReady(String command) { - this.colourBySequence = colourBySequence; + evalStateCommand(command); } public void createImage(String file, String type, int quality) @@ -702,7 +651,9 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i String pdbfile) { if (getModelNum(pdbfile) < 0) + { return null; + } // TODO: verify atomIndex is selecting correct model. return new Color(viewer.getAtomArgb(atomIndex)); } @@ -735,7 +686,9 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i for (int i = 0; i < mfn.length; i++) { if (mfn[i].equalsIgnoreCase(modelFileName)) + { return i; + } } return -1; } @@ -806,7 +759,8 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i /** * map from string to applet */ - public Map getRegistryInfo() + @Override + public Map getRegistryInfo() { // TODO Auto-generated method stub return null; @@ -944,8 +898,10 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i String chainId; if (strInfo.indexOf(":") > -1) + { chainId = strInfo.substring(strInfo.indexOf(":") + 1, strInfo.indexOf(".")); + } else { chainId = " "; @@ -983,7 +939,9 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i ; } if (lastMessage == null || !lastMessage.equals(strInfo)) - ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename); + { + getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename); + } lastMessage = strInfo; } @@ -1017,13 +975,17 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i int chainSeparator = strInfo.indexOf(":"); int p = 0; if (chainSeparator == -1) + { chainSeparator = strInfo.indexOf("."); + } String picked = strInfo.substring(strInfo.indexOf("]") + 1, chainSeparator); String mdlString = ""; if ((p = strInfo.indexOf(":")) > -1) + { picked += strInfo.substring(p + 1, strInfo.indexOf(".")); + } if ((p = strInfo.indexOf("/")) > -1) { @@ -1195,7 +1157,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i } // deregister the Jmol instance for these structures - we'll add // ourselves again at the end for the current structure set. - ssm.removeStructureViewerListener(this, oldmfn); + getSsm().removeStructureViewerListener(this, oldmfn); } } refreshPdbEntries(); @@ -1215,70 +1177,68 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i + ".0", "PDB"); pdbfhash = "" + pdbfile.hashCode(); } - if (pdbentry != null) - { // search pdbentries and sequences to find correct pdbentry for this // model - for (int pe = 0; pe < pdbentry.length; pe++) + for (int pe = 0; pe < getPdbCount(); pe++) + { + boolean matches = false; + if (fileName == null) { - boolean matches = false; - if (fileName == null) + if (false) + // see JAL-623 - need method of matching pasted data up { - if (false) - // see JAL-623 - need method of matching pasted data up - { - pdb = ssm.setMapping(sequence[pe], chains[pe], pdbfile, - AppletFormatAdapter.PASTE); - pdbentry[modelnum].setFile("INLINE" + pdb.id); - matches = true; - foundEntry = true; - } + pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], + pdbfile, AppletFormatAdapter.PASTE); + getPdbEntry(modelnum).setFile("INLINE" + pdb.id); + matches = true; + foundEntry = true; } - else + } + else + { + File fl; + if (matches = (fl = new File(getPdbEntry(pe).getFile())) + .equals(new File(fileName))) { - File fl; - if (matches = (fl = new File(pdbentry[pe].getFile())) - .equals(new File(fileName))) + foundEntry = true; + // TODO: Jmol can in principle retrieve from CLASSLOADER but + // this + // needs + // to be tested. See mantis bug + // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605 + String protocol = AppletFormatAdapter.URL; + try { - foundEntry = true; - // TODO: Jmol can in principle retrieve from CLASSLOADER but - // this - // needs - // to be tested. See mantis bug - // https://mantis.lifesci.dundee.ac.uk/view.php?id=36605 - String protocol = AppletFormatAdapter.URL; - try - { - if (fl.exists()) - { - protocol = AppletFormatAdapter.FILE; - } - } catch (Exception e) - { - } catch (Error e) + if (fl.exists()) { + protocol = AppletFormatAdapter.FILE; } - // Explicitly map to the filename used by Jmol ; - pdb = ssm.setMapping(sequence[pe], chains[pe], fileName, - protocol); - // pdbentry[pe].getFile(), protocol); - + } catch (Exception e) + { + } catch (Error e) + { } + // Explicitly map to the filename used by Jmol ; + pdb = getSsm().setMapping(getSequence()[pe], getChains()[pe], + fileName, protocol); + // pdbentry[pe].getFile(), protocol); + } - if (matches) + } + if (matches) + { + // add an entry for every chain in the model + for (int i = 0; i < pdb.chains.size(); i++) { - // add an entry for every chain in the model - for (int i = 0; i < pdb.chains.size(); i++) - { - String chid = new String(pdb.id + ":" - + ((MCview.PDBChain) pdb.chains.elementAt(i)).id); - chainFile.put(chid, fileName); - chainNames.addElement(chid); - } - notifyLoaded = true; + String chid = new String(pdb.id + ":" + + pdb.chains.elementAt(i).id); + chainFile.put(chid, fileName); + chainNames.addElement(chid); } + notifyLoaded = true; } } + if (!foundEntry && associateNewStructs) { // this is a foreign pdb file that jalview doesn't know about - add @@ -1307,7 +1267,7 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i } // register ourselves as a listener and notify the gui that it needs to // update itself. - ssm.addStructureViewerListener(this); + getSsm().addStructureViewerListener(this); if (notifyLoaded) { FeatureRenderer fr = getFeatureRenderer(null); @@ -1364,7 +1324,9 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i colourBySequence = false; if (cs == null) + { return; + } String res; int index; @@ -1378,7 +1340,9 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i res = en.nextElement().toString(); index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue(); if (index > 20) + { continue; + } col = cs.findColour(ResidueProperties.aa[index].charAt(0)); @@ -1477,185 +1441,93 @@ public abstract class JalviewJmolBinding extends SequenceStructureBindingModel i protected org.jmol.api.JmolAppConsoleInterface console = null; - public void componentResized(ComponentEvent e) + public void setBackgroundColour(java.awt.Color col) { - + jmolHistory(false); + viewer.evalStringQuiet("background [" + col.getRed() + "," + + col.getGreen() + "," + col.getBlue() + "];"); + jmolHistory(true); } - public void componentMoved(ComponentEvent e) + /** + * + * @param pdbfile + * @return text report of alignment between pdbfile and any associated + * alignment sequences + */ + public String printMapping(String pdbfile) { - + return getSsm().printMapping(pdbfile); } - public void componentShown(ComponentEvent e) + @Override + public void resizeInnerPanel(String data) { - showConsole(true); + // Jalview doesn't honour resize panel requests + } - public void componentHidden(ComponentEvent e) + public boolean isFinishedInit() { - showConsole(false); + return finishedInit; } - public void setBackgroundColour(java.awt.Color col) + public void setFinishedInit(boolean finishedInit) { - jmolHistory(false); - viewer.evalStringQuiet("background [" + col.getRed() + "," - + col.getGreen() + "," + col.getBlue() + "];"); - jmolHistory(true); + this.finishedInit = finishedInit; } /** - * add structures and any known sequence associations * - * @returns the pdb entries added to the current set. */ - public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe, - SequenceI[][] seq, String[][] chns) + protected void closeConsole() { - int pe = -1; - Vector v = new Vector(); - Vector rtn = new Vector(); - for (int i = 0; i < pdbentry.length; i++) - { - v.addElement(pdbentry[i]); - } - for (int i = 0; i < pdbe.length; i++) + if (console != null) { - int r = v.indexOf(pdbe[i]); - if (r == -1 || r >= pdbentry.length) + try { - rtn.addElement(new int[] - { v.size(), i }); - v.addElement(pdbe[i]); - } - else + console.setVisible(false); + } catch (Error e) { - // just make sure the sequence/chain entries are all up to date - addSequenceAndChain(r, seq[i], chns[i]); - } - } - pdbe = new PDBEntry[v.size()]; - v.copyInto(pdbe); - pdbentry = pdbe; - if (rtn.size() > 0) - { - // expand the tied seuqence[] and string[] arrays - SequenceI[][] sqs = new SequenceI[pdbentry.length][]; - String[][] sch = new String[pdbentry.length][]; - System.arraycopy(sequence, 0, sqs, 0, sequence.length); - System.arraycopy(chains, 0, sch, 0, this.chains.length); - sequence = sqs; - chains = sch; - pdbe = new PDBEntry[rtn.size()]; - for (int r = 0; r < pdbe.length; r++) + } catch (Exception x) { - int[] stri = ((int[]) rtn.elementAt(r)); - // record the pdb file as a new addition - pdbe[r] = pdbentry[stri[0]]; - // and add the new sequence/chain entries - addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]); } + ; + console = null; } - else - { - pdbe = null; - } - return pdbe; } - public void addSequence(int pe, SequenceI[] seq) + /** + * ComponentListener method + */ + @Override + public void componentMoved(ComponentEvent e) { - // add sequences to the pe'th pdbentry's seuqence set. - addSequenceAndChain(pe, seq, null); } - private void addSequenceAndChain(int pe, SequenceI[] seq, String[] tchain) + /** + * ComponentListener method + */ + @Override + public void componentResized(ComponentEvent e) { - if (pe < 0 || pe >= pdbentry.length) - { - throw new Error(MessageManager.formatMessage("error.implementation_error_no_pdbentry_from_index", new String[]{Integer.valueOf(pe).toString()})); - } - final String nullChain = "TheNullChain"; - Vector s = new Vector(); - Vector c = new Vector(); - if (chains == null) - { - chains = new String[pdbentry.length][]; - } - if (sequence[pe] != null) - { - for (int i = 0; i < sequence[pe].length; i++) - { - s.addElement(sequence[pe][i]); - if (chains[pe] != null) - { - if (i < chains[pe].length) - { - c.addElement(chains[pe][i]); - } - else - { - c.addElement(nullChain); - } - } - else - { - if (tchain != null && tchain.length > 0) - { - c.addElement(nullChain); - } - } - } - } - for (int i = 0; i < seq.length; i++) - { - if (!s.contains(seq[i])) - { - s.addElement(seq[i]); - if (tchain != null && i < tchain.length) - { - c.addElement(tchain[i] == null ? nullChain : tchain[i]); - } - } - } - SequenceI[] tmp = new SequenceI[s.size()]; - s.copyInto(tmp); - sequence[pe] = tmp; - if (c.size() > 0) - { - String[] tch = new String[c.size()]; - c.copyInto(tch); - for (int i = 0; i < tch.length; i++) - { - if (tch[i] == nullChain) - { - tch[i] = null; - } - } - chains[pe] = tch; - } - else - { - chains[pe] = null; - } } /** - * - * @param pdbfile - * @return text report of alignment between pdbfile and any associated - * alignment sequences + * ComponentListener method */ - public String printMapping(String pdbfile) + @Override + public void componentShown(ComponentEvent e) { - return ssm.printMapping(pdbfile); + showConsole(true); } + /** + * ComponentListener method + */ @Override - public void resizeInnerPanel(String data) + public void componentHidden(ComponentEvent e) { - // Jalview doesn't honour resize panel requests - + showConsole(false); } } diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index b5bfbaa..cb2a9ca 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -23,8 +23,6 @@ package jalview.ext.rbvi.chimera; import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; -import jalview.api.SequenceStructureBinding; -import jalview.api.StructureSelectionManagerProvider; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; @@ -32,10 +30,11 @@ import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; -import jalview.structure.StructureListener; import jalview.structure.StructureMapping; +import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; -import jalview.structures.models.SequenceStructureBindingModel; +import jalview.structures.models.AAStructureBindingModel; +import jalview.util.Comparison; import jalview.util.MessageManager; import java.awt.Color; @@ -53,10 +52,7 @@ import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel; import ext.edu.ucsf.rbvi.strucviz2.StructureManager; import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType; -public abstract class JalviewChimeraBinding extends - SequenceStructureBindingModel implements StructureListener, - SequenceStructureBinding, StructureSelectionManagerProvider - +public abstract class JalviewChimeraBinding extends AAStructureBindingModel { private static final boolean debug = false; @@ -112,13 +108,6 @@ public abstract class JalviewChimeraBinding extends private Map chainFile; - /** - * array of target chains for sequences - tied to pdbentry and sequence[] - */ - protected String[][] chains; - - boolean colourBySequence = true; - StringBuffer eval = new StringBuffer(); public String fileLoadingError; @@ -180,9 +169,9 @@ public abstract class JalviewChimeraBinding extends // Explicitly map to the filename used by Chimera ; // pdbentry[pe].getFile(), protocol); - if (ssm != null) + if (getSsm() != null) { - ssm.addStructureViewerListener(this); + getSsm().addStructureViewerListener(this); // ssm.addSelectionListener(this); FeatureRenderer fr = getFeatureRenderer(null); if (fr != null) @@ -207,46 +196,40 @@ public abstract class JalviewChimeraBinding extends */ String[] modelFileNames = null; - public PDBEntry[] pdbentry; - - /** - * datasource protocol for access to PDBEntrylatest - */ - String protocol = null; StringBuffer resetLastRes = new StringBuffer(); - /** - * sequences mapped to each pdbentry - */ - public SequenceI[][] sequence; - - public StructureSelectionManager ssm; - private List lastReply; + /** + * Constructor + * + * @param ssm + * @param pdbentry + * @param sequenceIs + * @param chains + * @param protocol + */ public JalviewChimeraBinding(StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, String protocol) { - this.ssm = ssm; - this.sequence = sequenceIs; - this.chains = chains; - this.pdbentry = pdbentry; - this.protocol = protocol; - if (chains == null) - { - this.chains = new String[pdbentry.length][]; - } + super(ssm, pdbentry, sequenceIs, chains, protocol); viewer = new ChimeraManager( csm = new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true)); } + /** + * Constructor + * + * @param ssm + * @param theViewer + */ public JalviewChimeraBinding(StructureSelectionManager ssm, - ChimeraManager viewer2) + ChimeraManager theViewer) { - this.ssm = ssm; - viewer = viewer2; + super(ssm, null); + viewer = theViewer; csm = viewer.getStructureManager(); } @@ -259,34 +242,7 @@ public abstract class JalviewChimeraBinding extends */ public String getViewerTitle(boolean verbose) { - if (sequence == null || pdbentry == null || sequence.length < 1 - || pdbentry.length < 1 || sequence[0].length < 1) - { - return ("Jalview Chimera Window"); - } - // TODO: give a more informative title when multiple structures are - // displayed. - StringBuilder title = new StringBuilder(64); - title.append("Chimera view for " + sequence[0][0].getName() + ":" - + pdbentry[0].getId()); - - if (verbose) - { - if (pdbentry[0].getProperty() != null) - { - if (pdbentry[0].getProperty().get("method") != null) - { - title.append(" Method: "); - title.append(pdbentry[0].getProperty().get("method")); - } - if (pdbentry[0].getProperty().get("chains") != null) - { - title.append(" Chain:"); - title.append(pdbentry[0].getProperty().get("chains")); - } - } - } - return title.toString(); + return getViewerTitle("Chimera", verbose); } /** @@ -322,12 +278,12 @@ public abstract class JalviewChimeraBinding extends } /** - * Close down the Jalview viewer, and (optionally) the associate Chimera + * Close down the Jalview viewer, and (optionally) the associated Chimera * window. */ public void closeViewer(boolean closeChimera) { - ssm.removeStructureViewerListener(this, this.getPdbFile()); + getSsm().removeStructureViewerListener(this, this.getPdbFile()); if (closeChimera) { viewer.exitChimera(); @@ -337,12 +293,6 @@ public abstract class JalviewChimeraBinding extends releaseUIResources(); } - /** - * called by JalviewChimerabinding after closeViewer is called - release any - * resources and references so they can be garbage collected. - */ - protected abstract void releaseUIResources(); - public void colourByChain() { colourBySequence = false; @@ -416,7 +366,7 @@ public abstract class JalviewChimeraBinding extends { // HACK - in Jalview 2.8 this call may not be threadsafe so we catch // every possible exception - StructureMapping[] sm = ssm.getMapping(file); + StructureMapping[] sm = getSsm().getMapping(file); if (sm == null || sm.length == 0) { waiting = true; @@ -478,7 +428,7 @@ public abstract class JalviewChimeraBinding extends String[] atomSpec = new String[files.length]; for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { - StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); + StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]); // RACE CONDITION - getMapping only returns Jmol loaded filenames once // Jmol callback has completed. if (mapping == null || mapping.length < 1) @@ -486,12 +436,14 @@ public abstract class JalviewChimeraBinding extends throw new Error(MessageManager.getString("error.implementation_error_chimera_getting_data")); } int lastPos = -1; - for (int s = 0; s < sequence[pdbfnum].length; s++) + final int seqCountForPdbFile = getSequence()[pdbfnum].length; + for (int s = 0; s < seqCountForPdbFile; s++) { for (int sp, m = 0; m < mapping.length; m++) { - if (mapping[m].getSequence() == sequence[pdbfnum][s] - && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1) + final SequenceI theSequence = getSequence()[pdbfnum][s]; + if (mapping[m].getSequence() == theSequence + && (sp = alignment.findIndex(theSequence)) > -1) { if (refStructure == -1) { @@ -510,7 +462,7 @@ public abstract class JalviewChimeraBinding extends continue; } - if (jalview.util.Comparison.isGap(asp.getCharAt(r))) + if (Comparison.isGap(asp.getCharAt(r))) { // no mapping to gaps in sequence continue; @@ -544,7 +496,7 @@ public abstract class JalviewChimeraBinding extends + targetC[pdbfnum]; atomSpec[pdbfnum] = asp.getRNA() != null ? PHOSPHORUS : ALPHACARBON; // move on to next pdb file - s = sequence[pdbfnum].length; + s = seqCountForPdbFile; break; } } @@ -760,7 +712,7 @@ public abstract class JalviewChimeraBinding extends { return; } - if (ssm == null) + if (getSsm() == null) { return; } @@ -775,19 +727,42 @@ public abstract class JalviewChimeraBinding extends } AlignmentI alignment = alignmentv.getAlignment(); - for (jalview.structure.StructureMappingcommandSet cpdbbyseq : ChimeraCommands - .getColourBySequenceCommand(ssm, files, sequence, sr, fr, - alignment)) + for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(files, sr, fr, alignment)) { - for (String cbyseq : cpdbbyseq.commands) + for (String command : cpdbbyseq.commands) { - waitForChimera(); - evalStateCommand(cbyseq, false); - waitForChimera(); + executeWhenReady(command); } } } + /** + * @param files + * @param sr + * @param fr + * @param alignment + * @return + */ + protected StructureMappingcommandSet[] getColourBySequenceCommands( + String[] files, SequenceRenderer sr, FeatureRenderer fr, + AlignmentI alignment) + { + return ChimeraCommands + .getColourBySequenceCommand(getSsm(), files, getSequence(), sr, + fr, + alignment); + } + + /** + * @param command + */ + protected void executeWhenReady(String command) + { + waitForChimera(); + evalStateCommand(command, false); + waitForChimera(); + } + private void waitForChimera() { while (viewer != null && viewer.isBusy()) @@ -799,30 +774,11 @@ public abstract class JalviewChimeraBinding extends } } - public boolean isColourBySequence() - { - return colourBySequence; - } - - public void setColourBySequence(boolean colourBySequence) - { - this.colourBySequence = colourBySequence; - } + // End StructureListener // ////////////////////////// - public float[][] functionXY(String functionName, int x, int y) - { - return null; - } - - public float[][][] functionXYZ(String functionName, int nx, int ny, int nz) - { - // TODO Auto-generated method stub - return null; - } - public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile) { @@ -1063,7 +1019,7 @@ public abstract class JalviewChimeraBinding extends } if (lastMessage == null || !lastMessage.equals(strInfo)) { - ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename); + getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename); } lastMessage = strInfo; @@ -1188,13 +1144,13 @@ public abstract class JalviewChimeraBinding extends } // deregister the Jmol instance for these structures - we'll add // ourselves again at the end for the current structure set. - ssm.removeStructureViewerListener(this, oldmfn); + getSsm().removeStructureViewerListener(this, oldmfn); } } // register ourselves as a listener and notify the gui that it needs to // update itself. - ssm.addStructureViewerListener(this); + getSsm().addStructureViewerListener(this); if (notifyLoaded) { @@ -1254,24 +1210,6 @@ public abstract class JalviewChimeraBinding extends */ public abstract void refreshGUI(); - public void componentResized(ComponentEvent e) - { - - } - - public void componentMoved(ComponentEvent e) - { - - } - - public void componentShown(ComponentEvent e) - { - } - - public void componentHidden(ComponentEvent e) - { - } - public void setLoadingFromArchive(boolean loadingFromArchive) { this.loadingFromArchive = loadingFromArchive; @@ -1318,154 +1256,32 @@ public abstract class JalviewChimeraBinding extends } /** - * add structures and any known sequence associations * - * @returns the pdb entries added to the current set. + * @param pdbfile + * @return text report of alignment between pdbfile and any associated + * alignment sequences */ - public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe, - SequenceI[][] seq, String[][] chns) + public String printMapping(String pdbfile) { - List v = new ArrayList(); - List rtn = new ArrayList(); - for (int i = 0; i < pdbentry.length; i++) - { - v.add(pdbentry[i]); - } - for (int i = 0; i < pdbe.length; i++) - { - int r = v.indexOf(pdbe[i]); - if (r == -1 || r >= pdbentry.length) - { - rtn.add(new int[] - { v.size(), i }); - v.add(pdbe[i]); - } - else - { - // just make sure the sequence/chain entries are all up to date - addSequenceAndChain(r, seq[i], chns[i]); - } - } - pdbe = v.toArray(new PDBEntry[v.size()]); - pdbentry = pdbe; - if (rtn.size() > 0) - { - // expand the tied sequence[] and string[] arrays - SequenceI[][] sqs = new SequenceI[pdbentry.length][]; - String[][] sch = new String[pdbentry.length][]; - System.arraycopy(sequence, 0, sqs, 0, sequence.length); - System.arraycopy(chains, 0, sch, 0, this.chains.length); - sequence = sqs; - chains = sch; - pdbe = new PDBEntry[rtn.size()]; - for (int r = 0; r < pdbe.length; r++) - { - int[] stri = (rtn.get(r)); - // record the pdb file as a new addition - pdbe[r] = pdbentry[stri[0]]; - // and add the new sequence/chain entries - addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]); - } - } - else - { - pdbe = null; - } - return pdbe; + return getSsm().printMapping(pdbfile); } /** - * Adds sequences to the pe'th pdbentry's sequence set. + * Ask Chimera to save its session to the given file. Returns true if + * successful, else false. * - * @param pe - * @param seq + * @param filepath + * @return */ - public void addSequence(int pe, SequenceI[] seq) - { - addSequenceAndChain(pe, seq, null); - } - - private void addSequenceAndChain(int pe, SequenceI[] seq, String[] tchain) + public boolean saveSession(String filepath) { - if (pe < 0 || pe >= pdbentry.length) - { - throw new Error(MessageManager.formatMessage( - "error.implementation_error_no_pdbentry_from_index", - new Object[] - { Integer.valueOf(pe).toString() })); - } - final String nullChain = "TheNullChain"; - List s = new ArrayList(); - List c = new ArrayList(); - if (chains == null) - { - chains = new String[pdbentry.length][]; - } - if (sequence[pe] != null) - { - for (int i = 0; i < sequence[pe].length; i++) - { - s.add(sequence[pe][i]); - if (chains[pe] != null) - { - if (i < chains[pe].length) - { - c.add(chains[pe][i]); - } - else - { - c.add(nullChain); - } - } - else - { - if (tchain != null && tchain.length > 0) - { - c.add(nullChain); - } - } - } - } - for (int i = 0; i < seq.length; i++) + if (isChimeraRunning()) { - if (!s.contains(seq[i])) - { - s.add(seq[i]); - if (tchain != null && i < tchain.length) - { - c.add(tchain[i] == null ? nullChain : tchain[i]); - } - } + List reply = viewer.sendChimeraCommand("save " + filepath, + true); + System.out.println(reply); } - SequenceI[] tmp = s.toArray(new SequenceI[s.size()]); - sequence[pe] = tmp; - if (c.size() > 0) - { - String[] tch = c.toArray(new String[c.size()]); - for (int i = 0; i < tch.length; i++) - { - if (tch[i] == nullChain) - { - tch[i] = null; - } - } - chains[pe] = tch; - } - else - { - chains[pe] = null; - } - } - - /** - * - * @param pdbfile - * @return text report of alignment between pdbfile and any associated - * alignment sequences - */ - public String printMapping(String pdbfile) - { - return ssm.printMapping(pdbfile); + return false; } } diff --git a/src/jalview/ext/varna/JalviewVarnaBinding.java b/src/jalview/ext/varna/JalviewVarnaBinding.java index 6a32f30..0df55b1 100644 --- a/src/jalview/ext/varna/JalviewVarnaBinding.java +++ b/src/jalview/ext/varna/JalviewVarnaBinding.java @@ -20,16 +20,15 @@ */ package jalview.ext.varna; -import java.awt.event.*; - -import jalview.api.SequenceStructureBinding; import jalview.api.StructureSelectionManagerProvider; -import jalview.structure.*; +import jalview.structure.StructureListener; import jalview.structures.models.SequenceStructureBindingModel; -public abstract class JalviewVarnaBinding extends SequenceStructureBindingModel implements StructureListener, - SequenceStructureBinding, ComponentListener, - StructureSelectionManagerProvider +import java.awt.event.ComponentListener; + +public abstract class JalviewVarnaBinding extends + SequenceStructureBindingModel implements StructureListener, + ComponentListener, StructureSelectionManagerProvider { diff --git a/src/jalview/gui/AppJmol.java b/src/jalview/gui/AppJmol.java index 4dfd18a..90d3b15 100644 --- a/src/jalview/gui/AppJmol.java +++ b/src/jalview/gui/AppJmol.java @@ -20,14 +20,12 @@ */ package jalview.gui; -import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; -import jalview.ext.jmol.JalviewJmolBinding; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AppletFormatAdapter; import jalview.io.JalviewFileChooser; @@ -42,6 +40,7 @@ import jalview.schemes.StrandColourScheme; import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; import jalview.schemes.ZappoColourScheme; +import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; import jalview.util.Platform; @@ -61,7 +60,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.PrintWriter; -import java.util.ArrayList; import java.util.Enumeration; import java.util.Vector; @@ -79,7 +77,7 @@ import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; public class AppJmol extends GStructureViewer implements Runnable, - ViewSetProvider, JalviewStructureDisplayI + ViewSetProvider { AppJmolBinding jmb; @@ -187,7 +185,7 @@ public class AppJmol extends GStructureViewer implements Runnable, } this.setBounds(bounds); initMenus(); - viewId = viewid; + setViewId(viewid); // jalview.gui.Desktop.addInternalFrame(this, "Loading File", // bounds.width,bounds.height); @@ -332,9 +330,10 @@ public class AppJmol extends GStructureViewer implements Runnable, final AppJmol topJmol = ((AppJmol) frames[i]); // JBPNOTE: this looks like a binding routine, rather than a gui // routine - for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++) + for (int pe = 0; pe < topJmol.jmb.getPdbCount(); pe++) { - if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped)) + if (topJmol.jmb.getPdbEntry(pe).getFile() + .equals(alreadyMapped)) { topJmol.jmb.addSequence(pe, seq); topJmol.addAlignmentPanel(ap); @@ -435,11 +434,6 @@ public class AppJmol extends GStructureViewer implements Runnable, openNewJmol(ap, pe, seqs); } - /** - * list of sequenceSet ids associated with the view - */ - ArrayList _aps = new ArrayList(); - public AlignmentPanel[] getAllAlignmentPanels() { AlignmentPanel[] t, list = new AlignmentPanel[0]; @@ -459,17 +453,6 @@ public class AppJmol extends GStructureViewer implements Runnable, } /** - * list of alignment panels to use for superposition - */ - Vector _alignwith = new Vector(); - - /** - * list of alignment panels that are used for colouring structures by aligned - * sequences - */ - Vector _colourwith = new Vector(); - - /** * set the primary alignmentPanel reference and add another alignPanel to the * list of ones to use for colouring and aligning * @@ -632,7 +615,7 @@ public class AppJmol extends GStructureViewer implements Runnable, { if (frame instanceof AppJmol) { - if (((AppJmol) frame).isLinkedWith(apanel)) + if (((GStructureViewer) frame).isLinkedWith(apanel)) { result.addElement(frame); } @@ -768,14 +751,14 @@ public class AppJmol extends GStructureViewer implements Runnable, // TODO: replace with reference fetching/transfer code (validate PDBentry // as a DBRef?) jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb(); - for (int pi = 0; pi < jmb.pdbentry.length; pi++) + for (int pi = 0; pi < jmb.getPdbCount(); pi++) { - String file = jmb.pdbentry[pi].getFile(); + String file = jmb.getPdbEntry(pi).getFile(); if (file == null) { // retrieve the pdb and store it locally AlignmentI pdbseq = null; - pdbid = jmb.pdbentry[pi].getId(); + pdbid = jmb.getPdbEntry(pi).getId(); long hdl = pdbid.hashCode() - System.currentTimeMillis(); if (progressBar != null) { @@ -783,7 +766,8 @@ public class AppJmol extends GStructureViewer implements Runnable, } try { - pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi] + pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.getPdbEntry( + pi) .getId()); } catch (OutOfMemoryError oomerror) { @@ -803,7 +787,7 @@ public class AppJmol extends GStructureViewer implements Runnable, // PDBEntry file = new File(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId() .elementAt(0)).getFile()).getAbsolutePath(); - jmb.pdbentry[pi].setFile(file); + jmb.getPdbEntry(pi).setFile(file); files.append(" \"" + Platform.escapeString(file) + "\""); } @@ -898,7 +882,7 @@ public class AppJmol extends GStructureViewer implements Runnable, // need to wait around until script has finished while (addingStructures ? lastnotify >= jmb.getLoadNotifiesHandled() : (jmb.isFinishedInit() && jmb.getPdbFile() != null && jmb - .getPdbFile().length != jmb.pdbentry.length)) + .getPdbFile().length != jmb.getPdbCount())) { try { @@ -977,9 +961,9 @@ public class AppJmol extends GStructureViewer implements Runnable, jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); try { - for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++) + for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++) { - cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile())); + cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile())); cap.appendText("\n"); } } catch (OutOfMemoryError e) @@ -1232,15 +1216,15 @@ public class AppJmol extends GStructureViewer implements Runnable, + "...", 20, currentSize.height / 2); StringBuffer sb = new StringBuffer(); int lines = 0; - for (int e = 0; e < jmb.pdbentry.length; e++) + for (int e = 0; e < jmb.getPdbCount(); e++) { - sb.append(jmb.pdbentry[e].getId()); - if (e < jmb.pdbentry.length - 1) + sb.append(jmb.getPdbEntry(e).getId()); + if (e < jmb.getPdbCount() - 1) { sb.append(","); } - if (e == jmb.pdbentry.length - 1 || sb.length() > 20) + if (e == jmb.getPdbCount() - 1 || sb.length() > 20) { lines++; g.drawString(sb.toString(), 20, currentSize.height / 2 - lines @@ -1264,17 +1248,6 @@ public class AppJmol extends GStructureViewer implements Runnable, } } - String viewId = null; - - public String getViewId() - { - if (viewId == null) - { - viewId = System.currentTimeMillis() + "." + this.hashCode(); - } - return viewId; - } - public void updateTitleAndMenus() { if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0) @@ -1285,7 +1258,7 @@ public class AppJmol extends GStructureViewer implements Runnable, setChainMenuItems(jmb.chainNames); this.setTitle(jmb.getViewerTitle()); - if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1) + if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1) { viewerActionMenu.setVisible(true); } @@ -1393,39 +1366,16 @@ public class AppJmol extends GStructureViewer implements Runnable, return ap; } - /** - * - * @param ap2 - * @return true if this Jmol instance is linked with the given alignPanel - */ - public boolean isLinkedWith(AlignmentPanel ap2) - { - return _aps.contains(ap2.av.getSequenceSetId()); - } - - public boolean isUsedforaligment(AlignmentPanel ap2) - { - - return (_alignwith != null) && _alignwith.contains(ap2); - } - - public boolean isUsedforcolourby(AlignmentPanel ap2) - { - return (_colourwith != null) && _colourwith.contains(ap2); - } - - /** - * - * @return TRUE if the view is NOT being coloured by sequence associations. - */ - public boolean isColouredByJmol() + @Override + public AAStructureBindingModel getBinding() { - return !jmb.isColourBySequence(); + return this.jmb; } - public JalviewJmolBinding getBinding() + @Override + public String getStateInfo() { - return jmb; + return jmb == null ? null : jmb.viewer.getStateInfo(); } } diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 7fa300e..a64072e 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -20,28 +20,27 @@ */ package jalview.gui; -import java.awt.Container; -import java.util.BitSet; - import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.ext.jmol.JalviewJmolBinding; import jalview.structure.StructureSelectionManager; +import java.awt.Container; +import java.util.BitSet; + import org.jmol.api.JmolAppConsoleInterface; import org.jmol.api.JmolViewer; import org.jmol.popup.JmolPopup; import org.openscience.jmol.app.jmolpanel.AppConsole; -public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding +public class AppJmolBinding extends JalviewJmolBinding { - - /** - * - */ private AppJmol appJmolWindow; + private FeatureRenderer fr = null; + public AppJmolBinding(AppJmol appJmol, StructureSelectionManager sSm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, String protocol) @@ -50,10 +49,8 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding appJmolWindow = appJmol; } - FeatureRenderer fr = null; - @Override - public jalview.api.FeatureRenderer getFeatureRenderer( + public FeatureRenderer getFeatureRenderer( AlignmentViewPanel alignment) { AlignmentPanel ap = (alignment == null) ? appJmolWindow.ap @@ -74,7 +71,7 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding } @Override - public jalview.api.SequenceRenderer getSequenceRenderer( + public SequenceRenderer getSequenceRenderer( AlignmentViewPanel alignment) { return new SequenceRenderer(((AlignmentPanel) alignment).av); @@ -130,7 +127,9 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding AlignmentPanel ap = (AlignmentPanel) source, topap; // ignore events from panels not used to colour this view if (!appJmolWindow.isUsedforcolourby(ap)) + { return; + } if (!isLoadingFromArchive()) { colourBySequence(ap.av.getShowSequenceFeatures(), ap); @@ -153,7 +152,6 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding public void newJmolPopup(boolean translateLocale, String menuName, boolean asPopup) { - jmolpopup = new JmolPopup(); jmolpopup.initialize(viewer, translateLocale, menuName, asPopup); } @@ -185,9 +183,9 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding */ public void addSequenceForStructFile(String pdbFile, SequenceI[] seq) { - for (int pe = 0; pe < pdbentry.length; pe++) + for (int pe = 0; pe < getPdbCount(); pe++) { - if (pdbentry[pe].getFile().equals(pdbFile)) + if (getPdbEntry(pe).getFile().equals(pdbFile)) { addSequence(pe, seq); } @@ -205,20 +203,7 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding protected void releaseUIResources() { appJmolWindow = null; - if (console != null) - { - try - { - console.setVisible(false); - } catch (Error e) - { - } catch (Exception x) - { - } - ; - console = null; - } - + closeConsole(); } @Override @@ -227,8 +212,6 @@ public class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding if (svl instanceof SeqPanel) { appJmolWindow.removeAlignmentPanel(((SeqPanel) svl).ap); - } - ; } } diff --git a/src/jalview/gui/ChimeraViewFrame.java b/src/jalview/gui/ChimeraViewFrame.java index 74d4aac..567a14c 100644 --- a/src/jalview/gui/ChimeraViewFrame.java +++ b/src/jalview/gui/ChimeraViewFrame.java @@ -20,14 +20,13 @@ */ package jalview.gui; -import jalview.api.SequenceStructureBinding; -import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.ext.rbvi.chimera.JalviewChimeraBinding; import jalview.gui.ViewSelectionMenu.ViewSetProvider; import jalview.io.AppletFormatAdapter; import jalview.io.JalviewFileChooser; @@ -42,6 +41,7 @@ import jalview.schemes.StrandColourScheme; import jalview.schemes.TaylorColourScheme; import jalview.schemes.TurnColourScheme; import jalview.schemes.ZappoColourScheme; +import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.ws.dbsources.Pdb; @@ -79,26 +79,9 @@ import javax.swing.event.MenuListener; * */ public class ChimeraViewFrame extends GStructureViewer implements Runnable, - ViewSetProvider, JalviewStructureDisplayI - + ViewSetProvider { - private JalviewChimeraBindingModel jmb; - - /* - * list of sequenceSet ids associated with the view - */ - private ArrayList _aps = new ArrayList(); - - /* - * list of alignment panels to use for superposition - */ - private Vector _alignwith = new Vector(); - - /* - * list of alignment panels that are used for colouring structures by aligned - * sequences - */ - private Vector _colourwith = new Vector(); + private JalviewChimeraBinding jmb; private boolean allChainsSelected = false; @@ -115,8 +98,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, private IProgressIndicator progressBar = null; - private String viewId = null; - /* * pdb retrieval thread. */ @@ -261,9 +242,11 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, final ChimeraViewFrame topView = ((ChimeraViewFrame) frame); // JBPNOTE: this looks like a binding routine, rather than a gui // routine - for (int pe = 0; pe < topView.jmb.pdbentry.length; pe++) + for (int pe = 0; pe < topView.jmb.getPdbCount(); pe++) { - if (topView.jmb.pdbentry[pe].getFile().equals(alreadyMapped)) + if (topView.jmb.getPdbEntry(pe).getFile() + .equals( + alreadyMapped)) { topView.jmb.addSequence(pe, seq); topView.addAlignmentPanel(ap); @@ -549,7 +532,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, jmb.setFinishedInit(false); // TODO: consider waiting until the structure/view is fully loaded before // displaying - jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(true), + jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle("Chimera", true), getBounds().width, getBounds().height); if (command == null) { @@ -633,7 +616,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, { String prompt = MessageManager .formatMessage("label.confirm_close_chimera", new Object[] - { jmb.getViewerTitle(false) }); + { jmb.getViewerTitle("Chimera", false) }); prompt = JvSwingUtils.wrapTooltip(true, prompt); int confirm = JOptionPane.showConfirmDialog(this, prompt, MessageManager.getString("label.close_viewer"), @@ -667,10 +650,10 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, String[] curfiles = jmb.getPdbFile(); // files currently in viewer // TODO: replace with reference fetching/transfer code (validate PDBentry // as a DBRef?) - for (int pi = 0; pi < jmb.pdbentry.length; pi++) + for (int pi = 0; pi < jmb.getPdbCount(); pi++) { String file = null; - thePdbEntry = jmb.pdbentry[pi]; + thePdbEntry = jmb.getPdbEntry(pi); if (thePdbEntry.getFile() == null) { /* @@ -752,7 +735,7 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, { int pos = filePDBpos.get(num).intValue(); jmb.openFile(pe); - jmb.addSequence(pos, jmb.sequence[pos]); + jmb.addSequence(pos, jmb.getSequence()[pos]); File fl = new File(pe.getFile()); String protocol = AppletFormatAdapter.URL; try @@ -766,7 +749,8 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, } // Explicitly map to the filename used by Chimera ; // TODO: use pe.getId() instead of pe.getFile() ? - jmb.ssm.setMapping(jmb.sequence[pos], null, pe.getFile(), + jmb.getSsm().setMapping(jmb.getSequence()[pos], null, + pe.getFile(), protocol); } catch (OutOfMemoryError oomerror) { @@ -919,9 +903,9 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer(); try { - for (int pdbe = 0; pdbe < jmb.pdbentry.length; pdbe++) + for (int pdbe = 0; pdbe < jmb.getPdbCount(); pdbe++) { - cap.appendText(jmb.printMapping(jmb.pdbentry[pdbe].getFile())); + cap.appendText(jmb.printMapping(jmb.getPdbEntry(pdbe).getFile())); cap.appendText("\n"); } } catch (OutOfMemoryError e) @@ -1089,15 +1073,6 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, } } - public String getViewId() - { - if (viewId == null) - { - viewId = System.currentTimeMillis() + "." + this.hashCode(); - } - return viewId; - } - public void updateTitleAndMenus() { if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0) @@ -1107,8 +1082,8 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, } setChainMenuItems(jmb.chainNames); - this.setTitle(jmb.getViewerTitle(true)); - if (jmb.getPdbFile().length > 1 && jmb.sequence.length > 1) + this.setTitle(jmb.getViewerTitle("Chimera", true)); + if (jmb.getPdbFile().length > 1 && jmb.getSequence().length > 1) { viewerActionMenu.setVisible(true); } @@ -1215,39 +1190,20 @@ public class ChimeraViewFrame extends GStructureViewer implements Runnable, return ap; } - /** - * - * @param ap2 - * @return true if this Chimera instance is linked with the given alignPanel - */ - public boolean isLinkedWith(AlignmentPanel ap2) - { - return _aps.contains(ap2.av.getSequenceSetId()); - } - - public boolean isUsedforaligment(AlignmentPanel ap2) - { - - return (_alignwith != null) && _alignwith.contains(ap2); - } - - public boolean isUsedforcolourby(AlignmentPanel ap2) + @Override + public AAStructureBindingModel getBinding() { - return (_colourwith != null) && _colourwith.contains(ap2); + return jmb; } /** + * Ask Chimera to save its session to the designated file path. Returns true + * if successful, else false. * - * @return TRUE if the view is NOT being coloured by sequence associations. + * @param filepath */ - public boolean isColouredByChimera() - { - return !jmb.isColourBySequence(); - } - - public SequenceStructureBinding getBinding() + public boolean saveSession(String filepath) { - return jmb; + return jmb.saveSession(filepath); } - } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index b8f629a..9871c27 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -26,6 +26,7 @@ import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; +import jalview.jbgui.GStructureViewer; import jalview.structure.StructureSelectionManager; import jalview.util.ImageMaker; import jalview.util.MessageManager; @@ -113,6 +114,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ private BlogReader jvnews = null; + private File projectFile; + /** * @param listener * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener) @@ -1462,6 +1465,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements { final Desktop me = this; final java.io.File choice = chooser.getSelectedFile(); + setProjectFile(choice); + new Thread(new Runnable() { public void run() @@ -1497,6 +1502,16 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + private void setProjectFile(File choice) + { + this.projectFile = choice; + } + + public File getProjectFile() + { + return this.projectFile; + } + /** * DOCUMENT ME! * @@ -1517,9 +1532,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements if (value == JalviewFileChooser.APPROVE_OPTION) { - final String choice = chooser.getSelectedFile().getAbsolutePath(); - jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser - .getSelectedFile().getParent()); + final File selectedFile = chooser.getSelectedFile(); + setProjectFile(selectedFile); + final String choice = selectedFile.getAbsolutePath(); + jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent()); new Thread(new Runnable() { public void run() @@ -2312,7 +2328,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements return afs; } - public AppJmol[] getJmols() + public GStructureViewer[] getJmols() { JInternalFrame[] frames = Desktop.desktop.getAllFrames(); @@ -2328,7 +2344,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { if (frames[i] instanceof AppJmol) { - AppJmol af = (AppJmol) frames[i]; + GStructureViewer af = (GStructureViewer) frames[i]; avp.addElement(af); } } @@ -2340,10 +2356,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements { return null; } - AppJmol afs[] = new AppJmol[avp.size()]; + GStructureViewer afs[] = new GStructureViewer[avp.size()]; for (int i = 0, j = avp.size(); i < j; i++) { - afs[i] = (AppJmol) avp.elementAt(i); + afs[i] = (GStructureViewer) avp.elementAt(i); } avp.clear(); return afs; diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index 4e72236..830b791 100644 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -25,7 +25,9 @@ import jalview.bin.Cache; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; +import jalview.datamodel.PDBEntry; import jalview.datamodel.SequenceI; +import jalview.jbgui.GStructureViewer; import jalview.schemabinding.version2.AlcodMap; import jalview.schemabinding.version2.Alcodon; import jalview.schemabinding.version2.AlcodonFrame; @@ -64,7 +66,9 @@ import jalview.schemes.ColourSchemeProperty; import jalview.schemes.GraduatedColor; import jalview.schemes.ResidueColourScheme; import jalview.schemes.ResidueProperties; +import jalview.schemes.UserColourScheme; import jalview.structure.StructureSelectionManager; +import jalview.structures.models.AAStructureBindingModel; import jalview.util.MessageManager; import jalview.util.Platform; import jalview.util.jarInputStreamProvider; @@ -527,7 +531,7 @@ public class Jalview2XML } /** - * create a JalviewModel from an algnment view and marshall it to a + * create a JalviewModel from an alignment view and marshall it to a * JarOutputStream * * @param ap @@ -546,8 +550,8 @@ public class Jalview2XML boolean storeDS, JarOutputStream jout) { initSeqRefs(); - Vector jmolViewIds = new Vector(); // - Vector userColours = new Vector(); + List chimeraViewIds = new ArrayList(); + List userColours = new ArrayList(); AlignViewport av = ap.av; @@ -717,80 +721,20 @@ public class Jalview2XML pdb.setId(entry.getId()); pdb.setType(entry.getType()); // - // store any JMol views associated with this seqeunce + // store any JMol views associated with this sequence // this section copes with duplicate entries in the project, so a // dataset only view *should* be coped with sensibly - AppJmol jmol; + List jmolViewIds = new ArrayList(); // This must have been loaded, is it still visible? JInternalFrame[] frames = Desktop.desktop.getAllFrames(); String matchedFile = null; for (int f = frames.length - 1; f > -1; f--) { - if (frames[f] instanceof AppJmol) + if (frames[f] instanceof GStructureViewer) { - jmol = (AppJmol) frames[f]; - for (int peid = 0; peid < jmol.jmb.pdbentry.length; peid++) - { - if (!jmol.jmb.pdbentry[peid].getId().equals(entry.getId()) - && !(entry.getId().length() > 4 && entry - .getId() - .toLowerCase() - .startsWith( - jmol.jmb.pdbentry[peid].getId() - .toLowerCase()))) - { - continue; - } - if (matchedFile == null) - { - matchedFile = jmol.jmb.pdbentry[peid].getFile(); - } - else if (!matchedFile.equals(jmol.jmb.pdbentry[peid] - .getFile())) - { - Cache.log - .warn("Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): " - + jmol.jmb.pdbentry[peid].getFile()); - ; // record the - } - // file so we - // can get at it if the ID - // match is ambiguous (e.g. - // 1QIP==1qipA) - String statestring = jmol.jmb.viewer.getStateInfo(); - - for (int smap = 0; smap < jmol.jmb.sequence[peid].length; smap++) - { - // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1) - if (jds == jmol.jmb.sequence[peid][smap]) - { - StructureState state = new StructureState(); - state.setVisible(true); - state.setXpos(jmol.getX()); - state.setYpos(jmol.getY()); - state.setWidth(jmol.getWidth()); - state.setHeight(jmol.getHeight()); - state.setViewId(jmol.getViewId()); - state.setAlignwithAlignPanel(jmol.isUsedforaligment(ap)); - state.setColourwithAlignPanel(jmol - .isUsedforcolourby(ap)); - state.setColourByJmol(jmol.isColouredByJmol()); - if (!jmolViewIds.contains(state.getViewId())) - { - // Make sure we only store a Jmol state once in each XML - // document. - jmolViewIds.addElement(state.getViewId()); - state.setContent(statestring.replaceAll("\n", "")); - } - else - { - state.setContent("# duplicate state"); - } - pdb.addStructureState(state); - } - - } - } + GStructureViewer viewFrame = (GStructureViewer) frames[f]; + matchedFile = saveStructureState(ap, jds, pdb, entry, + jmolViewIds, matchedFile, viewFrame); } } @@ -1308,8 +1252,91 @@ public class Jalview2XML return object; } + /** + * @param ap + * @param jds + * @param pdb + * @param entry + * @param jmolViewIds + * @param matchedFile + * @param viewFrame + * @return + */ + protected String saveStructureState(AlignmentPanel ap, + jalview.datamodel.SequenceI jds, Pdbids pdb, + jalview.datamodel.PDBEntry entry, List jmolViewIds, + String matchedFile, GStructureViewer viewFrame) + { + final AAStructureBindingModel bindingModel = viewFrame + .getBinding(); + for (int peid = 0; peid < bindingModel + .getPdbCount(); peid++) + { + final PDBEntry pdbentry = bindingModel.getPdbEntry(peid); + final String pdbId = pdbentry.getId(); + if (!pdbId.equals(entry.getId()) + && !(entry.getId().length() > 4 && entry.getId() + .toLowerCase() + .startsWith(pdbId.toLowerCase()))) + { + continue; + } + if (matchedFile == null) + { + matchedFile = pdbentry.getFile(); + } + else if (!matchedFile.equals(pdbentry + .getFile())) + { + Cache.log + .warn("Probably lost some PDB-Sequence mappings for this structure file (which apparently has same PDB Entry code): " + + pdbentry.getFile()); + } + // record the + // file so we + // can get at it if the ID + // match is ambiguous (e.g. + // 1QIP==1qipA) + String statestring = viewFrame.getStateInfo(); + + for (int smap = 0; smap < viewFrame.getBinding() + .getSequence()[peid].length; smap++) + { + // if (jal.findIndex(jmol.jmb.sequence[peid][smap]) > -1) + if (jds == viewFrame.getBinding().getSequence()[peid][smap]) + { + StructureState state = new StructureState(); + state.setVisible(true); + state.setXpos(viewFrame.getX()); + state.setYpos(viewFrame.getY()); + state.setWidth(viewFrame.getWidth()); + state.setHeight(viewFrame.getHeight()); + state.setViewId(viewFrame.getViewId()); + state.setAlignwithAlignPanel(viewFrame.isUsedforaligment(ap)); + state.setColourwithAlignPanel(viewFrame + .isUsedforcolourby(ap)); + state.setColourByJmol(viewFrame.isColouredByViewer()); + if (!jmolViewIds.contains(state.getViewId())) + { + // Make sure we only store a Jmol state once in each XML + // document. + jmolViewIds.add(state.getViewId()); + state.setContent(statestring.replaceAll("\n", "")); + } + else + { + state.setContent("# duplicate state"); + } + pdb.addStructureState(state); + } + + } + } + return matchedFile; + } + private AnnotationColours constructAnnotationColours( - AnnotationColourGradient acg, Vector userColours, + AnnotationColourGradient acg, List userColours, JalviewModelSequence jms) { AnnotationColours ac = new AnnotationColours(); @@ -1763,7 +1790,7 @@ public class Jalview2XML } String SetUserColourScheme(jalview.schemes.ColourSchemeI cs, - Vector userColours, JalviewModelSequence jms) + List userColours, JalviewModelSequence jms) { String id = null; jalview.schemes.UserColourScheme ucs = (jalview.schemes.UserColourScheme) cs; @@ -3112,7 +3139,7 @@ public class Jalview2XML if (frames[f] instanceof AppJmol) { if (sviewid != null - && ((AppJmol) frames[f]).getViewId().equals(sviewid)) + && ((GStructureViewer) frames[f]).getViewId().equals(sviewid)) { // post jalview 2.4 schema includes structure view id comp = (AppJmol) frames[f]; @@ -3283,7 +3310,7 @@ public class Jalview2XML String pdbFile = (String) filedat[0]; SequenceI[] seq = ((Vector) filedat[2]) .toArray(new SequenceI[0]); - comp.jmb.ssm.setMapping(seq, null, pdbFile, + comp.jmb.getSsm().setMapping(seq, null, pdbFile, jalview.io.AppletFormatAdapter.FILE); comp.jmb.addSequenceForStructFile(pdbFile, seq); } diff --git a/src/jalview/gui/JalviewChimeraBindingModel.java b/src/jalview/gui/JalviewChimeraBindingModel.java index f68b585..9d1f18f 100644 --- a/src/jalview/gui/JalviewChimeraBindingModel.java +++ b/src/jalview/gui/JalviewChimeraBindingModel.java @@ -10,6 +10,8 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding { private ChimeraViewFrame cvf; + private FeatureRenderer fr = null; + public JalviewChimeraBindingModel(ChimeraViewFrame chimeraViewFrame, StructureSelectionManager ssm, PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, String protocol) @@ -18,10 +20,8 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding cvf = chimeraViewFrame; } - FeatureRenderer fr = null; - @Override - public jalview.api.FeatureRenderer getFeatureRenderer( + public FeatureRenderer getFeatureRenderer( AlignmentViewPanel alignment) { AlignmentPanel ap = (alignment == null) ? cvf.ap @@ -47,10 +47,10 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding { return new SequenceRenderer(((AlignmentPanel) alignment).av); } + @Override public void refreshGUI() { - // appJmolWindow.repaint(); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() @@ -63,7 +63,7 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding public void updateColours(Object source) { - AlignmentPanel ap = (AlignmentPanel) source, topap; + AlignmentPanel ap = (AlignmentPanel) source; // ignore events from panels not used to colour this view if (!cvf.isUsedforcolourby(ap)) { @@ -74,24 +74,19 @@ public class JalviewChimeraBindingModel extends JalviewChimeraBinding colourBySequence(ap.av.getShowSequenceFeatures(), ap); } } + @Override public void releaseReferences(Object svl) { - // TODO Auto-generated method stub - } @Override protected void releaseUIResources() { - // TODO Auto-generated method stub - } @Override public void refreshPdbEntries() { - // TODO Auto-generated method stub - } } diff --git a/src/jalview/gui/ScriptWindow.java b/src/jalview/gui/ScriptWindow.java index d935eb7..641efcb 100644 --- a/src/jalview/gui/ScriptWindow.java +++ b/src/jalview/gui/ScriptWindow.java @@ -22,10 +22,14 @@ package jalview.gui; import org.jmol.api.*; +import jalview.jbgui.GStructureViewer; + import java.awt.*; import java.awt.event.*; + import javax.swing.*; import javax.swing.text.*; + import java.util.Vector; import org.jmol.i18n.GT; @@ -53,7 +57,7 @@ public final class ScriptWindow extends JPanel implements ActionListener, JmolViewer viewer; - AppJmol appJmol; + GStructureViewer appJmol; public ScriptWindow(AppJmol appJmol) { diff --git a/src/jalview/jbgui/GStructureViewer.java b/src/jalview/jbgui/GStructureViewer.java index 58b2eb1..4471bbb 100644 --- a/src/jalview/jbgui/GStructureViewer.java +++ b/src/jalview/jbgui/GStructureViewer.java @@ -20,10 +20,14 @@ */ package jalview.jbgui; +import jalview.api.structures.JalviewStructureDisplayI; +import jalview.gui.AlignmentPanel; import jalview.util.MessageManager; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.Vector; import javax.swing.ButtonGroup; import javax.swing.JInternalFrame; @@ -32,8 +36,70 @@ import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; -public class GStructureViewer extends JInternalFrame +public abstract class GStructureViewer extends JInternalFrame implements + JalviewStructureDisplayI { + // private AAStructureBindingModel bindingModel; + + protected JMenu savemenu = new JMenu(); + + protected JMenu viewMenu = new JMenu(); + + protected JMenu chainMenu = new JMenu(); + + protected JMenu viewerActionMenu = new JMenu(); + + protected JMenuItem alignStructs = new JMenuItem(); + + protected JRadioButtonMenuItem seqColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem chainColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem chargeColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem hydroColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem(); + + protected JRadioButtonMenuItem viewerColour = new JRadioButtonMenuItem(); + + protected JMenuItem helpItem = new JMenuItem(); + + /** + * list of sequenceSet ids associated with the view + */ + protected ArrayList _aps = new ArrayList(); + + /** + * list of alignment panels to use for superposition + */ + protected Vector _alignwith = new Vector(); + + /** + * list of alignment panels that are used for colouring structures by aligned + * sequences + */ + protected Vector _colourwith = new Vector(); + + private String viewId = null; + + /** + * Constructor + */ public GStructureViewer() { try @@ -47,10 +113,16 @@ public class GStructureViewer extends JInternalFrame private void jbInit() throws Exception { + JMenuBar menuBar = new JMenuBar(); this.setJMenuBar(menuBar); + + JMenu fileMenu = new JMenu(); fileMenu.setText(MessageManager.getString("action.file")); + savemenu.setActionCommand(MessageManager.getString("action.save_image")); savemenu.setText(MessageManager.getString("action.save_as")); + + JMenuItem pdbFile = new JMenuItem(); pdbFile.setText(MessageManager.getString("label.pdb_file")); pdbFile.addActionListener(new ActionListener() { @@ -59,6 +131,8 @@ public class GStructureViewer extends JInternalFrame pdbFile_actionPerformed(actionEvent); } }); + + JMenuItem png = new JMenuItem(); png.setText("PNG"); png.addActionListener(new ActionListener() { @@ -67,6 +141,8 @@ public class GStructureViewer extends JInternalFrame png_actionPerformed(actionEvent); } }); + + JMenuItem eps = new JMenuItem(); eps.setText("EPS"); eps.addActionListener(new ActionListener() { @@ -75,6 +151,8 @@ public class GStructureViewer extends JInternalFrame eps_actionPerformed(actionEvent); } }); + + JMenuItem viewMapping = new JMenuItem(); viewMapping.setText(MessageManager.getString("label.view_mapping")); viewMapping.addActionListener(new ActionListener() { @@ -85,7 +163,11 @@ public class GStructureViewer extends JInternalFrame }); viewMenu.setText(MessageManager.getString("action.view")); chainMenu.setText(MessageManager.getString("action.show_chain")); + + JMenu colourMenu = new JMenu(); colourMenu.setText(MessageManager.getString("label.colours")); + + JMenuItem backGround = new JMenuItem(); backGround.setText(MessageManager.getString("label.background_colour") + "..."); backGround.addActionListener(new ActionListener() @@ -207,6 +289,8 @@ public class GStructureViewer extends JInternalFrame viewerColour_actionPerformed(actionEvent); } }); + + JMenu helpMenu = new JMenu(); helpMenu.setText(MessageManager.getString("action.help")); helpItem.setText(MessageManager.getString("label.jmol_help")); helpItem.addActionListener(new ActionListener() @@ -254,6 +338,8 @@ public class GStructureViewer extends JInternalFrame colourMenu.add(viewerColour); colourMenu.add(backGround); + ButtonGroup colourButtons = new ButtonGroup(); + colourButtons.add(seqColour); colourButtons.add(chainColour); colourButtons.add(chargeColour); @@ -279,66 +365,6 @@ public class GStructureViewer extends JInternalFrame { } - JMenuBar menuBar = new JMenuBar(); - - JMenu fileMenu = new JMenu(); - - protected JMenu savemenu = new JMenu(); - - JMenuItem pdbFile = new JMenuItem(); - - JMenuItem png = new JMenuItem(); - - JMenuItem eps = new JMenuItem(); - - JMenuItem viewMapping = new JMenuItem(); - - protected JMenu viewMenu = new JMenu(); - - protected JMenu chainMenu = new JMenu(); - - JMenu jMenu1 = new JMenu(); - - protected JMenu colourMenu = new JMenu(); - - protected JMenu viewerActionMenu = new JMenu(); - - protected JMenuItem alignStructs = new JMenuItem(); - - JMenuItem backGround = new JMenuItem(); - - protected JRadioButtonMenuItem seqColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem chainColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem chargeColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem hydroColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem purinePyrimidineColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem userColour = new JRadioButtonMenuItem(); - - protected JRadioButtonMenuItem viewerColour = new JRadioButtonMenuItem(); - - protected ButtonGroup colourButtons = new ButtonGroup(); - - JMenu helpMenu = new JMenu(); - - protected JMenuItem helpItem = new JMenuItem(); - public void pdbFile_actionPerformed(ActionEvent actionEvent) { @@ -428,4 +454,62 @@ public class GStructureViewer extends JInternalFrame { } + + // { + // return bindingModel; + // } + + // public void setBindingModel(AAStructureBindingModel bindingModel) + // { + // this.bindingModel = bindingModel; + // } + + /** + * + * @param ap2 + * @return true if this Jmol instance is linked with the given alignPanel + */ + public boolean isLinkedWith(AlignmentPanel ap2) + { + return _aps.contains(ap2.av.getSequenceSetId()); + } + + public boolean isUsedforaligment(AlignmentPanel ap2) + { + + return (_alignwith != null) && _alignwith.contains(ap2); + } + + public boolean isUsedforcolourby(AlignmentPanel ap2) + { + return (_colourwith != null) && _colourwith.contains(ap2); + } + + /** + * + * @return TRUE if the view is NOT being coloured by the alignment colours. + */ + public boolean isColouredByViewer() + { + return !getBinding().isColourBySequence(); + } + + public String getViewId() + { + if (viewId == null) + { + viewId = System.currentTimeMillis() + "." + this.hashCode(); + } + return viewId; + } + + protected void setViewId(String viewId) + { + this.viewId = viewId; + } + + public String getStateInfo() + { + return null; + } } diff --git a/src/jalview/structures/models/AAStructureBindingModel.java b/src/jalview/structures/models/AAStructureBindingModel.java new file mode 100644 index 0000000..12be239 --- /dev/null +++ b/src/jalview/structures/models/AAStructureBindingModel.java @@ -0,0 +1,345 @@ +package jalview.structures.models; + +import jalview.api.StructureSelectionManagerProvider; +import jalview.datamodel.PDBEntry; +import jalview.datamodel.SequenceI; +import jalview.structure.StructureListener; +import jalview.structure.StructureSelectionManager; +import jalview.util.MessageManager; + +import java.awt.event.ComponentEvent; +import java.util.ArrayList; +import java.util.List; + +/** + * A base class to hold common function for protein structure model binding. + * Initial version created by refactoring JMol and Chimera binding models, but + * other structure viewers could in principle be accommodated in future. + * + * @author gmcarstairs + * + */ +public abstract class AAStructureBindingModel extends + SequenceStructureBindingModel implements StructureListener, + StructureSelectionManagerProvider +{ + + private StructureSelectionManager ssm; + + private PDBEntry[] pdbEntry; + + /* + * sequences mapped to each pdbentry + */ + private SequenceI[][] sequence; + + /* + * array of target chains for sequences - tied to pdbentry and sequence[] + */ + private String[][] chains; + + /* + * datasource protocol for access to PDBEntrylatest + */ + String protocol = null; + + protected boolean colourBySequence = true; + + /** + * Constructor + * + * @param ssm + * @param seqs + */ + public AAStructureBindingModel(StructureSelectionManager ssm, + SequenceI[][] seqs) + { + this.ssm = ssm; + this.sequence = seqs; + } + + /** + * Constructor + * + * @param ssm + * @param pdbentry + * @param sequenceIs + * @param chains + * @param protocol + */ + public AAStructureBindingModel(StructureSelectionManager ssm, + PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains, + String protocol) + { + this.ssm = ssm; + this.sequence = sequenceIs; + this.chains = chains; + this.pdbEntry = pdbentry; + this.protocol = protocol; + if (chains == null) + { + this.chains = new String[pdbentry.length][]; + } + } + + public StructureSelectionManager getSsm() + { + return ssm; + } + + /** + * Returns the i'th PDBEntry (or null) + * + * @param i + * @return + */ + public PDBEntry getPdbEntry(int i) + { + return (pdbEntry != null && pdbEntry.length > i) ? pdbEntry[i] : null; + } + + /** + * Returns the number of modelled PDB file entries. + * + * @return + */ + public int getPdbCount() + { + return pdbEntry == null ? 0 : pdbEntry.length; + } + + public SequenceI[][] getSequence() + { + return sequence; + } + + public String[][] getChains() + { + return chains; + } + + public String getProtocol() + { + return protocol; + } + + // TODO may remove this if calling methods can be pulled up here + protected void setPdbentry(PDBEntry[] pdbentry) + { + this.pdbEntry = pdbentry; + } + + protected void setSequence(SequenceI[][] sequence) + { + this.sequence = sequence; + } + + protected void setChains(String[][] chains) + { + this.chains = chains; + } + + /** + * Construct a title string for the viewer window based on the data Jalview + * knows about + * @param viewerName TODO + * @param verbose + * + * @return + */ + public String getViewerTitle(String viewerName, boolean verbose) + { + if (getSequence() == null || getSequence().length < 1 + || getPdbCount() < 1 + || getSequence()[0].length < 1) + { + return ("Jalview " + viewerName + " Window"); + } + // TODO: give a more informative title when multiple structures are + // displayed. + StringBuilder title = new StringBuilder(64); + final PDBEntry pdbEntry = getPdbEntry(0); + title.append(viewerName + " view for " + getSequence()[0][0].getName() + + ":" + + pdbEntry.getId()); + + if (verbose) + { + if (pdbEntry.getProperty() != null) + { + if (pdbEntry.getProperty().get("method") != null) + { + title.append(" Method: "); + title.append(pdbEntry.getProperty().get("method")); + } + if (pdbEntry.getProperty().get("chains") != null) + { + title.append(" Chain:"); + title.append(pdbEntry.getProperty().get("chains")); + } + } + } + return title.toString(); + } + + /** + * Called by after closeViewer is called, to release any resources and + * references so they can be garbage collected. Override if needed. + */ + protected void releaseUIResources() + { + + } + + public boolean isColourBySequence() + { + return colourBySequence; + } + + public void setColourBySequence(boolean colourBySequence) + { + this.colourBySequence = colourBySequence; + } + + protected void addSequenceAndChain(int pe, SequenceI[] seq, + String[] tchain) + { + if (pe < 0 || pe >= getPdbCount()) + { + throw new Error(MessageManager.formatMessage( + "error.implementation_error_no_pdbentry_from_index", + new Object[] + { Integer.valueOf(pe).toString() })); + } + final String nullChain = "TheNullChain"; + List s = new ArrayList(); + List c = new ArrayList(); + if (getChains() == null) + { + setChains(new String[getPdbCount()][]); + } + if (getSequence()[pe] != null) + { + for (int i = 0; i < getSequence()[pe].length; i++) + { + s.add(getSequence()[pe][i]); + if (getChains()[pe] != null) + { + if (i < getChains()[pe].length) + { + c.add(getChains()[pe][i]); + } + else + { + c.add(nullChain); + } + } + else + { + if (tchain != null && tchain.length > 0) + { + c.add(nullChain); + } + } + } + } + for (int i = 0; i < seq.length; i++) + { + if (!s.contains(seq[i])) + { + s.add(seq[i]); + if (tchain != null && i < tchain.length) + { + c.add(tchain[i] == null ? nullChain : tchain[i]); + } + } + } + SequenceI[] tmp = s.toArray(new SequenceI[s.size()]); + getSequence()[pe] = tmp; + if (c.size() > 0) + { + String[] tch = c.toArray(new String[c.size()]); + for (int i = 0; i < tch.length; i++) + { + if (tch[i] == nullChain) + { + tch[i] = null; + } + } + getChains()[pe] = tch; + } + else + { + getChains()[pe] = null; + } + } + + /** + * add structures and any known sequence associations + * + * @returns the pdb entries added to the current set. + */ + public synchronized PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe, SequenceI[][] seq, + String[][] chns) + { + List v = new ArrayList(); + List rtn = new ArrayList(); + for (int i = 0; i < getPdbCount(); i++) + { + v.add(getPdbEntry(i)); + } + for (int i = 0; i < pdbe.length; i++) + { + int r = v.indexOf(pdbe[i]); + if (r == -1 || r >= getPdbCount()) + { + rtn.add(new int[] + { v.size(), i }); + v.add(pdbe[i]); + } + else + { + // just make sure the sequence/chain entries are all up to date + addSequenceAndChain(r, seq[i], chns[i]); + } + } + pdbe = v.toArray(new PDBEntry[v.size()]); + setPdbentry(pdbe); + if (rtn.size() > 0) + { + // expand the tied sequence[] and string[] arrays + SequenceI[][] sqs = new SequenceI[getPdbCount()][]; + String[][] sch = new String[getPdbCount()][]; + System.arraycopy(getSequence(), 0, sqs, 0, getSequence().length); + System.arraycopy(getChains(), 0, sch, 0, this.getChains().length); + setSequence(sqs); + setChains(sch); + pdbe = new PDBEntry[rtn.size()]; + for (int r = 0; r < pdbe.length; r++) + { + int[] stri = (rtn.get(r)); + // record the pdb file as a new addition + pdbe[r] = getPdbEntry(stri[0]); + // and add the new sequence/chain entries + addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]); + } + } + else + { + pdbe = null; + } + return pdbe; + } + + /** + * Add sequences to the pe'th pdbentry's sequence set. + * + * @param pe + * @param seq + */ + public void addSequence(int pe, SequenceI[] seq) + { + addSequenceAndChain(pe, seq, null); + } + +} \ No newline at end of file diff --git a/src/jalview/structures/models/SequenceStructureBindingModel.java b/src/jalview/structures/models/SequenceStructureBindingModel.java index 7d023a8..d758726 100644 --- a/src/jalview/structures/models/SequenceStructureBindingModel.java +++ b/src/jalview/structures/models/SequenceStructureBindingModel.java @@ -48,8 +48,8 @@ public class SequenceStructureBindingModel implements /** * - * @return true if Jmol is still restoring state or loading is still going on - * (see setFinsihedLoadingFromArchive) + * @return true if viewer is still restoring state or loading is still going + * on (see setFinishedLoadingFromArchive) */ @Override public boolean isLoadingFromArchive()