X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FAppletJmol.java;h=f3d7fa7b1f1f0ec9618a1facb72c6375c26e9234;hb=2026a420963f094072607c0495b6369ba96e60c0;hp=980985914e65256fe435aada4bd5d9d3f63c2242;hpb=f8456d4c0b253ae32a4b569e12bb8bf7f7096d65;p=jalview.git diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 9809859..f3d7fa7 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5) - * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle * * This file is part of Jalview. * @@ -27,15 +27,15 @@ import jalview.structure.*; import jalview.io.*; import org.jmol.api.*; -import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.popup.*; import org.jmol.viewer.JmolConstants; import jalview.schemes.*; -public class AppletJmol extends EmbmenuFrame implements StructureListener, - JmolStatusListener, KeyListener, ActionListener, ItemListener, SequenceStructureBinding +public class AppletJmol extends EmbmenuFrame implements +// StructureListener, + KeyListener, ActionListener, ItemListener, SequenceStructureBinding { Menu fileMenu = new Menu("File"); @@ -52,6 +52,8 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, CheckboxMenuItem seqColour = new CheckboxMenuItem("By Sequence", true); + CheckboxMenuItem jmolColour = new CheckboxMenuItem("Using Jmol", false); + MenuItem chain = new MenuItem("By Chain"); MenuItem charge = new MenuItem("Charge & Cysteine"); @@ -69,54 +71,74 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, MenuItem turn = new MenuItem("Turn Propensity"); MenuItem buried = new MenuItem("Buried Index"); + + MenuItem purinepyrimidine = new MenuItem("Purine/Pyrimidine"); MenuItem user = new MenuItem("User Defined Colours"); MenuItem jmolHelp = new MenuItem("Jmol Help"); - JmolViewer viewer; - - JmolPopup jmolpopup; - Panel scriptWindow; TextField inputLine; TextArea history; - SequenceI[] sequence; - - String[] chains; - - StructureSelectionManager ssm; - RenderPanel renderPanel; AlignmentPanel ap; + ArrayList _aps = new ArrayList(); String fileLoadingError; boolean loadedInline; - PDBEntry pdbentry; + // boolean colourBySequence = true; - boolean colourBySequence = true; + FeatureRenderer fr = null; - Vector atomsPicked = new Vector(); + AppletJmolBinding jmb; /** * datasource protocol for access to PDBEntry */ String protocol = null; + /** + * Load a bunch of pdb entries associated with sequences in the alignment and + * display them - aligning them if necessary. + * + * @param pdbentries + * each pdb file (at least one needed) + * @param boundseqs + * each set of sequences for each pdb file (must match number of pdb + * files) + * @param boundchains + * the target pdb chain corresponding with each sequence associated + * with each pdb file (may be null at any level) + * @param align + * true/false + * @param ap + * associated alignment + * @param protocol + * how to get pdb data + */ + public AppletJmol(PDBEntry[] pdbentries, SequenceI[][] boundseqs, + String[][] boundchains, boolean align, AlignmentPanel ap, + String protocol) + { + throw new Error("Not yet implemented."); + } + public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains, AlignmentPanel ap, String protocol) { this.ap = ap; - this.sequence = seq; - this.chains = chains; - this.pdbentry = pdbentry; - this.protocol = protocol; + jmb = new AppletJmolBinding(this, ap.getStructureSelectionManager(), new PDBEntry[] + { pdbentry }, new SequenceI[][] + { seq }, new String[][] + { chains }, protocol); + jmb.setColourBySequence(true); if (pdbentry.getId() == null || pdbentry.getId().length() < 1) { if (protocol.equals(AppletFormatAdapter.PASTE)) @@ -137,12 +159,12 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, } String alreadyMapped = StructureSelectionManager - .getStructureSelectionManager().alreadyMappedToFile( + .getStructureSelectionManager(ap.av.applet).alreadyMappedToFile( pdbentry.getId()); MCview.PDBfile reader = null; if (alreadyMapped != null) { - reader = StructureSelectionManager.getStructureSelectionManager() + reader = StructureSelectionManager.getStructureSelectionManager(ap.av.applet) .setMapping(seq, chains, pdbentry.getFile(), protocol); // PROMPT USER HERE TO ADD TO NEW OR EXISTING VIEW? // FOR NOW, LETS JUST OPEN A NEW WINDOW @@ -160,14 +182,16 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, hydro.addActionListener(this); chain.addActionListener(this); seqColour.addItemListener(this); + jmolColour.addItemListener(this); zappo.addActionListener(this); taylor.addActionListener(this); helix.addActionListener(this); strand.addActionListener(this); turn.addActionListener(this); buried.addActionListener(this); + purinepyrimidine.addActionListener(this); user.addActionListener(this); - + jmolHelp.addActionListener(this); coloursMenu.add(seqColour); @@ -180,21 +204,38 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, coloursMenu.add(strand); coloursMenu.add(turn); coloursMenu.add(buried); + coloursMenu.add(purinepyrimidine); coloursMenu.add(user); - + coloursMenu.add(jmolColour); helpMenu.add(jmolHelp); + this.setLayout(new BorderLayout()); setMenuBar(menuBar); renderPanel = new RenderPanel(); embedMenuIfNeeded(renderPanel); this.add(renderPanel, BorderLayout.CENTER); - viewer = JmolViewer.allocateViewer(renderPanel, - new SmarterJmolAdapter(), "jalviewJmol", ap.av.applet - .getDocumentBase(), ap.av.applet.getCodeBase(), "", - this); + scriptWindow = new Panel(); + scriptWindow.setVisible(false); + // this.add(scriptWindow, BorderLayout.SOUTH); - jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true); + try + { + jmb.allocateViewer(renderPanel, true, ap.av.applet.getName() + + "_jmol_", ap.av.applet.getDocumentBase(), + ap.av.applet.getCodeBase(), "-applet", scriptWindow, null); + } catch (Exception e) + { + System.err + .println("Couldn't create a jmol viewer. Args to allocate viewer were:\nDocumentBase=" + + ap.av.applet.getDocumentBase() + + "\nCodebase=" + + ap.av.applet.getCodeBase()); + e.printStackTrace(); + dispose(); + return; + } + jmb.newJmolPopup(true, "Jmol", true); this.addWindowListener(new WindowAdapter() { @@ -203,18 +244,24 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, closeViewer(); } }); - + if (pdbentry.getProperty() == null) + { + pdbentry.setProperty(new Hashtable()); + pdbentry.getProperty().put("protocol", protocol); + } if (pdbentry.getFile() != null) { // import structure data from pdbentry.getFile based on given protocol if (protocol.equals(AppletFormatAdapter.PASTE)) { + // TODO: JAL-623 : correctly record file contents for matching up later + // pdbentry.getProperty().put("pdbfilehash",""+pdbentry.getFile().hashCode()); loadInline(pdbentry.getFile()); } else if (protocol.equals(AppletFormatAdapter.FILE) || protocol.equals(AppletFormatAdapter.URL)) { - viewer.openFile(pdbentry.getFile()); + jmb.viewer.openFile(pdbentry.getFile()); } else { @@ -257,7 +304,8 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, throw new Exception( "Invalid datasource. Could not obtain Reader."); } - viewer.openReader(pdbentry.getFile(), pdbentry.getId(), freader); + jmb.viewer.openReader(pdbentry.getFile(), pdbentry.getId(), + freader); } catch (Exception e) { // give up! @@ -269,28 +317,13 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, } } - jalview.bin.JalviewLite.addFrame(this, "Jmol", 400, 400); - } - - /** - * create a new binding between structures in an existing jmol viewer instance and - * an alignpanel with sequences that have existing PDBFile entries. Note, this does not open a new Jmol window, - * or modify the display of the structures in the original jmol window. - * @param viewer2 - * @param alignPanel - * @param seqs - sequences to search for associations - */ - public AppletJmol(JmolViewer viewer2, AlignmentPanel alignPanel, - SequenceI[] seqs) - { - - // TODO Auto-generated constructor stub + jalview.bin.JalviewLite.addFrame(this, jmb.getViewerTitle(), 400, 400); } public void loadInline(String string) { loadedInline = true; - viewer.openStringInline(string); + jmb.loadInline(string); } void setChainMenuItems(Vector chains) @@ -316,10 +349,9 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, void centerViewer() { - jmolHistory(false); - StringBuffer cmd = new StringBuffer(); + Vector toshow = new Vector(); String lbl; - int mlength, p,mnum; + int mlength, p, mnum; for (int i = 0; i < chainMenu.getItemCount(); i++) { if (chainMenu.getItem(i) instanceof CheckboxMenuItem) @@ -327,64 +359,22 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, CheckboxMenuItem item = (CheckboxMenuItem) chainMenu.getItem(i); if (item.getState()) { - lbl = item.getLabel(); - mlength = 0; - do - { - p = mlength; - mlength = lbl.indexOf(":", p); - } while (p < mlength && mlength < (lbl.length() - 2)); - mnum = 1+getModelNum(lbl.substring(0, mlength)); - if (mnum>0) - {cmd.append(":" + lbl.substring(mlength + 1) + " /" - + mnum + " or "); - } + toshow.addElement(item.getLabel()); } } } - - if (cmd.length() > 0) - cmd.setLength(cmd.length() - 4); - - viewer - .evalString("select *;restrict " + cmd + ";cartoon;center " - + cmd); - jmolHistory(true); - } - - private int getModelNum(String modelFileName) - { - String[] mfn = getPdbFile(); - if (mfn == null) - { - return -1; - } - for (int i = 0; i < mfn.length; i++) - { - if (mfn[i].equalsIgnoreCase(modelFileName)) - return i; - } - return -1; + jmb.centerViewer(toshow); } void closeViewer() { - viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE); - // remove listeners for all structures in viewer - StructureSelectionManager.getStructureSelectionManager() - .removeStructureViewerListener(this, this.getPdbFile()); - // and shut down jmol - viewer.evalStringQuiet("zap"); - viewer.setJmolStatusListener(null); - - viewer = null; - + jmb.closeViewer(); + jmb = null; this.setVisible(false); } public void actionPerformed(ActionEvent evt) { - jmolHistory(false); if (evt.getSource() == mappingMenuItem) { jalview.appletgui.CutAndPasteTransfer cap = new jalview.appletgui.CutAndPasteTransfer( @@ -392,56 +382,79 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, Frame frame = new Frame(); frame.add(cap); + StringBuffer sb = new StringBuffer(); + try + { + for (int s = 0; s < jmb.pdbentry.length; s++) + { + sb.append(jmb.printMapping( + jmb.pdbentry[s].getFile())); + sb.append("\n"); + } + cap.setText(sb.toString()); + } catch (OutOfMemoryError ex) + { + frame.dispose(); + System.err + .println("Out of memory when trying to create dialog box with sequence-structure mapping."); + return; + } jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping", 550, 600); - cap.setText(StructureSelectionManager.getStructureSelectionManager() - .printMapping(pdbentry.getFile())); } else if (evt.getSource() == charge) { - colourBySequence = false; - seqColour.setState(false); - viewer - .evalStringQuiet("select *;color white;select ASP,GLU;color red;" - + "select LYS,ARG;color blue;select CYS;color yellow"); + setEnabled(charge); + jmb.colourByCharge(); } else if (evt.getSource() == chain) { - colourBySequence = false; - seqColour.setState(false); - viewer.evalStringQuiet("select *;color chain"); + setEnabled(chain); + jmb.colourByChain(); } else if (evt.getSource() == zappo) { - setJalviewColourScheme(new ZappoColourScheme()); + setEnabled(zappo); + jmb.setJalviewColourScheme(new ZappoColourScheme()); } else if (evt.getSource() == taylor) { - setJalviewColourScheme(new TaylorColourScheme()); + setEnabled(taylor); + jmb.setJalviewColourScheme(new TaylorColourScheme()); } else if (evt.getSource() == hydro) { - setJalviewColourScheme(new HydrophobicColourScheme()); + setEnabled(hydro); + jmb.setJalviewColourScheme(new HydrophobicColourScheme()); } else if (evt.getSource() == helix) { - setJalviewColourScheme(new HelixColourScheme()); + setEnabled(helix); + jmb.setJalviewColourScheme(new HelixColourScheme()); } else if (evt.getSource() == strand) { - setJalviewColourScheme(new StrandColourScheme()); + setEnabled(strand); + jmb.setJalviewColourScheme(new StrandColourScheme()); } else if (evt.getSource() == turn) { - setJalviewColourScheme(new TurnColourScheme()); + setEnabled(turn); + jmb.setJalviewColourScheme(new TurnColourScheme()); } else if (evt.getSource() == buried) { - setJalviewColourScheme(new BuriedColourScheme()); + setEnabled(buried); + jmb.setJalviewColourScheme(new BuriedColourScheme()); + } + else if(evt.getSource() == purinepyrimidine) + { + jmb.setJalviewColourScheme(new PurinePyrimidineColourScheme()); } else if (evt.getSource() == user) { + setEnabled(user); new UserDefinedColours(this); } else if (evt.getSource() == jmolHelp) @@ -464,54 +477,36 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, if (chainMenu.getItem(i) instanceof CheckboxMenuItem) ((CheckboxMenuItem) chainMenu.getItem(i)).setState(true); } + centerViewer(); allChainsSelected = false; } - jmolHistory(true); } - private void jmolHistory(boolean enable) - { - viewer.setBooleanProperty("history", enable); - } - public void setJalviewColourScheme(ColourSchemeI cs) - { - colourBySequence = false; - seqColour.setState(false); - - if (cs == null) - return; - - String res; - int index; - Color col; - jmolHistory(false); - - Enumeration en = ResidueProperties.aa3Hash.keys(); - StringBuffer command = new StringBuffer("select *;color white;"); - while (en.hasMoreElements()) - { - res = en.nextElement().toString(); - index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue(); - if (index > 20) - continue; - - col = cs.findColour(ResidueProperties.aa[index].charAt(0)); - command.append("select " + res + ";color[" + col.getRed() + "," - + col.getGreen() + "," + col.getBlue() + "];"); - } - - viewer.evalStringQuiet(command.toString()); - jmolHistory(true); + /** + * tick or untick the seqColour menu entry or jmoColour entry depending upon if it was selected + * or not. + * + * @param itm + */ + private void setEnabled(MenuItem itm) + { + jmolColour.setState(itm == jmolColour); + seqColour.setState(itm == seqColour); + jmb.setColourBySequence(itm == seqColour); } public void itemStateChanged(ItemEvent evt) { + if (evt.getSource() == jmolColour) + { + setEnabled(jmolColour); + jmb.setColourBySequence(false); + } else if (evt.getSource() == seqColour) { - lastCommand = null; - colourBySequence = seqColour.getState(); - colourBySequence(ap); + setEnabled(seqColour); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } else if (!allChainsSelected) centerViewer(); @@ -521,7 +516,7 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, { if (evt.getKeyCode() == KeyEvent.VK_ENTER && scriptWindow.isVisible()) { - viewer.evalString(inputLine.getText()); + jmb.eval(inputLine.getText()); history.append("\n$ " + inputLine.getText()); inputLine.setText(""); } @@ -536,461 +531,23 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, { } - String[] modelFileNames = null; - - // //////////////////////////////// - // /StructureListener - public String[] getPdbFile() - { - if (modelFileNames == null) - { - String mset[] = new String[viewer.getModelCount()]; - for (int i = 0; i < mset.length; i++) - { - mset[i] = viewer.getModelFileName(i); - } - modelFileNames = mset; - } - return modelFileNames; - } - - String lastMessage; - - // jmol/ssm only - public void mouseOverStructure(int atomIndex, String strInfo) - { - int pdbResNum; - int mdlSep = strInfo.indexOf("/"); - int chainSeparator = strInfo.indexOf(":"), chainSeparator1 = -1; - - if (chainSeparator == -1) - { - chainSeparator = strInfo.indexOf("."); - if (mdlSep > -1 && mdlSep < chainSeparator) - { - chainSeparator1 = chainSeparator; - chainSeparator = mdlSep; - } - } - pdbResNum = Integer.parseInt(strInfo.substring( - strInfo.indexOf("]") + 1, chainSeparator)); - - String chainId; - - if (strInfo.indexOf(":") > -1) - chainId = strInfo.substring(strInfo.indexOf(":") + 1, strInfo - .indexOf(".")); - else - { - chainId = " "; - } - - String pdbfilename = pdbentry.getFile(); - if (mdlSep > -1) - { - if (chainSeparator1 == -1) - { - chainSeparator1 = strInfo.indexOf(".", mdlSep); - } - String mdlId = (chainSeparator1 > -1) ? strInfo.substring(mdlSep + 1, - chainSeparator1) : strInfo.substring(mdlSep + 1); - try - { - // recover PDB filename for the model hovered over. - pdbfilename = viewer - .getModelFileName(new Integer(mdlId).intValue() - 1); - } catch (Exception e) - { - } - ; - } - if (lastMessage == null || !lastMessage.equals(strInfo)) - ssm.mouseOverStructure(pdbResNum, chainId, pdbfilename); - - lastMessage = strInfo; - } - - StringBuffer resetLastRes = new StringBuffer(); - - StringBuffer eval = new StringBuffer(); - - // jmol/ssm only - public void highlightAtom(int atomIndex, int pdbResNum, String chain, - String pdbfile) - { - int mdlNum = 1+getModelNum(pdbfile); - if (mdlNum==0) - { - return; - } - - jmolHistory(false); - // if (!pdbfile.equals(pdbentry.getFile())) - // return; - if (resetLastRes.length() > 0) - { - viewer.evalStringQuiet(resetLastRes.toString()); - } - - eval.setLength(0); - eval.append("select " + pdbResNum); // +modelNum - - resetLastRes.setLength(0); - resetLastRes.append("select " + pdbResNum); // +modelNum - - if (!chain.equals(" ")) - { - eval.append(":"); - resetLastRes.append(":"); - eval.append(chain); - resetLastRes.append(chain); - } - // if (mdlNum != 0) - { - eval.append(" /" + (mdlNum)); - resetLastRes.append("/" + (mdlNum)); - } - eval.append(";wireframe 100;" + eval.toString() + " and not hetero;"); - - resetLastRes.append(";wireframe 0;" + resetLastRes.toString() - + " and not hetero; spacefill 0;"); - - eval.append("spacefill 200;select none"); - - viewer.evalStringQuiet(eval.toString()); - jmolHistory(true); - - } - public void updateColours(Object source) { - colourBySequence((AlignmentPanel) source); + AlignmentPanel ap = (AlignmentPanel) source; + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); } - // End StructureListener - // ////////////////////////// - - public Color getColour(int atomIndex, int pdbResNum, String chain, - String pdbfile) + public void updateTitleAndMenus() { - if (!pdbfile.equals(pdbentry.getFile())) - return null; - - return new Color(viewer.getAtomArgb(atomIndex)); - } - - String lastCommand; - - FeatureRenderer fr = null; - - public void colourBySequence(AlignmentPanel sourceap) - { - this.ap = sourceap; - - if (!colourBySequence) - return; - String[] files = getPdbFile(); - SequenceRenderer sr = new SequenceRenderer(ap.av); - - boolean showFeatures = false; - - if (ap.av.showSequenceFeatures) + if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0) { - showFeatures = true; - if (fr == null) - { - fr = new jalview.appletgui.FeatureRenderer(ap.av); - } - - fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer()); - } - - StringBuffer command = new StringBuffer(); - - for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) - { - StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); - - if (mapping == null || mapping.length < 1) - continue; - - int lastPos = -1; - for (int s = 0; s < sequence.length; s++) - { - for (int sp, m = 0; m < mapping.length; m++) - { - if (mapping[m].getSequence() == sequence[s] - && (sp = ap.av.alignment.findIndex(sequence[s])) > -1) - { - SequenceI asp = ap.av.alignment.getSequenceAt(sp); - for (int r = 0; r < asp.getLength(); r++) - { - // no mapping to gaps in sequence - if (jalview.util.Comparison.isGap(asp.getCharAt(r))) - { - continue; - } - int pos = mapping[m].getPDBResNum(asp.findPosition(r)); - - if (pos < 1 || pos == lastPos) - continue; - - lastPos = pos; - - Color col = sr.getResidueBoxColour(sequence[s], r); - - if (showFeatures) - col = fr.findFeatureColour(col, sequence[s], r); - String newSelcom = (mapping[m].getChain() != " " ? ":" - + mapping[m].getChain() : "") - + "/" - + (pdbfnum + 1) - + ".1" - + ";color[" - + col.getRed() - + "," - + col.getGreen() - + "," - + col.getBlue() + "]"; - if (command.toString().endsWith(newSelcom)) - { - command = condenseCommand(command.toString(), pos); - continue; - } - // TODO: deal with case when buffer is too large for Jmol to parse - // - execute command and flush - - command.append(";select " + pos); - command.append(newSelcom); - } - break; - } - } - } - } - - jmolHistory(false); - if (lastCommand == null || !lastCommand.equals(command.toString())) - { - viewer.evalStringQuiet(command.toString()); - } - jmolHistory(true); - lastCommand = command.toString(); - } - - StringBuffer condenseCommand(String command, int pos) - { - - StringBuffer sb = new StringBuffer(command.substring(0, command - .lastIndexOf("select") + 7)); - - command = command.substring(sb.length()); - - String start; - - if (command.indexOf("-") > -1) - { - start = command.substring(0, command.indexOf("-")); - } - else - { - start = command.substring(0, command.indexOf(":")); - } - - sb.append(start + "-" + pos + command.substring(command.indexOf(":"))); - - return sb; - } - - // /////////////////////////////// - // JmolStatusListener - - public String eval(String strEval) - { - // System.out.println(strEval); - // "# 'eval' is implemented only for the applet."; - return null; - } - - public void createImage(String file, String type, int quality) - { - } - - public void notifyFileLoaded(String fullPathName, String fileName2, - String modelName, String errorMsg, int modelParts) - { - if (errorMsg != null) - { - fileLoadingError = errorMsg; repaint(); return; } - fileLoadingError = null; - modelFileNames = null; - - String[] modelfilenames = getPdbFile(); - ssm = StructureSelectionManager.getStructureSelectionManager(); - boolean modelsloaded=false; - for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++) - { - String fileName = modelfilenames[modelnum]; - if (fileName != null) - { - // search pdbentries and sequences to find correct pdbentry and sequence[] pair for this filename - if (pdbentry.getFile().equals(fileName)) - { - modelsloaded=true; - MCview.PDBfile pdb; - if (loadedInline) - { - pdb = ssm.setMapping(sequence, chains, pdbentry.getFile(), - AppletFormatAdapter.PASTE); - pdbentry.setFile("INLINE" + pdb.id); - } - else - { - // 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 - - pdb = ssm.setMapping(sequence, chains, pdbentry.getFile(), - AppletFormatAdapter.URL); + setChainMenuItems(jmb.chainNames); + jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap); - } - - pdbentry.setId(pdb.id); - - Vector chains = new Vector(); - for (int i = 0; i < pdb.chains.size(); i++) - { - chains.addElement(new String(pdb.id + ":" - + ((MCview.PDBChain) pdb.chains.elementAt(i)).id)); - } - setChainMenuItems(chains); - - colourBySequence(ap); - - StringBuffer title = new StringBuffer(sequence[0].getName() + ":" - + pdbentry.getId()); - - 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")); - } - } - - this.setTitle(title.toString()); - - } - else - { - // this is a foreign pdb file that jalview doesn't know about - add it to the dataset - // and try to find a home - either on a matching sequence or as a new sequence. - String pdbcontent = viewer.getData("/" + (modelnum + 1) + ".1", - "PDB"); - // parse pdb file into a chain, etc. - // locate best match for pdb in associated views and add mapping to - // ssm - modelsloaded=true; - } - } - } - if (modelsloaded) { - // FILE LOADED OK - jmolpopup.updateComputedMenus(); - viewer - .evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off"); - - ssm.addStructureViewerListener(this); - } - } - - public void sendConsoleEcho(String strEcho) - { - if (scriptWindow == null) - showConsole(true); - - history.append("\n" + strEcho); - } - - public void sendConsoleMessage(String strStatus) - { - if (history != null && strStatus != null - && !strStatus.equals("Script completed")) - { - history.append("\n" + strStatus); - } - } - - public void notifyScriptTermination(String strStatus, int msWalltime) - { - } - - public void handlePopupMenu(int x, int y) - { - jmolpopup.show(x, y); - } - - public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) - { - notifyAtomPicked(iatom, strMeasure, null); - } - - public void notifyAtomPicked(int atomIndex, String strInfo, String strData) - { - if (strData != null) - { - System.err.println("Ignoring additional pick data string " + strData); - } - 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) - { - mdlString += strInfo.substring(p, strInfo.indexOf(" #")); - } - picked = "((" + picked + ".CA" + mdlString+")|(" + picked + ".P" + mdlString+"))"; - jmolHistory(false); - - if (!atomsPicked.contains(picked)) - { - viewer.evalStringQuiet("select " + picked + ";label %n %r:%c"); - atomsPicked.addElement(picked); - } - else - { - viewer.evalString("select " + picked + ";label off"); - atomsPicked.removeElement(picked); - } - jmolHistory(true); - - } - - public void notifyAtomHovered(int atomIndex, String strInfo, String data) - { - if (data != null) - { - System.err.println("Ignoring additional hover info: " + data); - } - mouseOverStructure(atomIndex, strInfo); + setTitle(jmb.getViewerTitle()); } public void showUrl(String url) @@ -1004,22 +561,30 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, } } + Panel splitPane = null; + public void showConsole(boolean showConsole) { - if (scriptWindow == null) + if (showConsole) + { + remove(renderPanel); + splitPane = new Panel(); + + splitPane.setLayout(new java.awt.GridLayout(2, 1)); + splitPane.add(renderPanel); + splitPane.add(scriptWindow); + scriptWindow.setVisible(true); + this.add(splitPane, BorderLayout.CENTER); + splitPane.setVisible(true); + splitPane.validate(); + } + else { - scriptWindow = new Panel(new BorderLayout()); - inputLine = new TextField(); - history = new TextArea(5, 40); - scriptWindow.add(history, BorderLayout.CENTER); - scriptWindow.add(inputLine, BorderLayout.SOUTH); - add(scriptWindow, BorderLayout.SOUTH); scriptWindow.setVisible(false); - history.setEditable(false); - inputLine.addKeyListener(this); + remove(splitPane); + add(renderPanel, BorderLayout.CENTER); + splitPane = null; } - - scriptWindow.setVisible(!scriptWindow.isVisible()); validate(); } @@ -1047,7 +612,7 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, currentSize = this.getSize(); rectClip = g.getClipBounds(); - if (viewer == null) + if (jmb.viewer == null) { g.setColor(Color.black); g.fillRect(0, 0, currentSize.width, currentSize.height); @@ -1057,102 +622,43 @@ public class AppletJmol extends EmbmenuFrame implements StructureListener, } else { - viewer.renderScreenImage(g, currentSize, rectClip); + jmb.viewer.renderScreenImage(g, currentSize, rectClip); } } } - public String createImage(String fileName, String type, - Object textOrBytes, int quality) - { - // TODO Auto-generated method stub - return null; - } - - public float[][][] functionXYZ(String functionName, int nx, int ny, int nz) - { - // TODO Auto-generated method stub - return null; - } - - public Hashtable getRegistryInfo() + /* + * @Override public Color getColour(int atomIndex, int pdbResNum, String + * chain, String pdbId) { return jmb.getColour(atomIndex, pdbResNum, chain, + * pdbId); } + * + * @Override public String[] getPdbFile() { return jmb.getPdbFile(); } + * + * @Override public void highlightAtom(int atomIndex, int pdbResNum, String + * chain, String pdbId) { jmb.highlightAtom(atomIndex, pdbResNum, chain, + * pdbId); + * + * } + * + * @Override public void mouseOverStructure(int atomIndex, String strInfo) { + * jmb.mouseOverStructure(atomIndex, strInfo); + * + * } + */ + public void setJalviewColourScheme(UserColourScheme ucs) { - // TODO Auto-generated method stub - return null; + jmb.setJalviewColourScheme(ucs); } - public void notifyCallback(int type, Object[] data) + public AlignmentPanel getAlignmentPanelFor(AlignmentI alignment) { - try + for (int i=0;i<_aps.size();i++) { - switch (type) + if (((AlignmentPanel)_aps.get(i)).av.getAlignment()==alignment) { - case JmolConstants.CALLBACK_LOADSTRUCT: - notifyFileLoaded((String) data[1], (String) data[2], - (String) data[3], (String) data[4], ((Integer) data[5]) - .intValue()); - - break; - case JmolConstants.CALLBACK_PICK: - notifyAtomPicked(((Integer) data[2]).intValue(), (String) data[1], - (String) data[0]); - // also highlight in alignment - case JmolConstants.CALLBACK_HOVER: - notifyAtomHovered(((Integer) data[2]).intValue(), (String) data[1], - (String) data[0]); - break; - case JmolConstants.CALLBACK_SCRIPT: - notifyScriptTermination((String) data[2], ((Integer) data[3]) - .intValue()); - break; - case JmolConstants.CALLBACK_ECHO: - sendConsoleEcho((String) data[1]); - break; - case JmolConstants.CALLBACK_MESSAGE: - sendConsoleMessage((data == null) ? ((String) null) - : (String) data[1]); - break; - case JmolConstants.CALLBACK_MEASURE: - case JmolConstants.CALLBACK_CLICK: - default: - System.err.println("Unhandled callback " + type + " " + data); - break; + return ((AlignmentPanel)_aps.get(i)); } - } catch (Exception e) - { - System.err.println("Squashed Jmol callback handler error:"); - e.printStackTrace(); } + return ap; } - - public boolean notifyEnabled(int callbackPick) - { - switch (callbackPick) - { - case JmolConstants.CALLBACK_ECHO: - case JmolConstants.CALLBACK_LOADSTRUCT: - case JmolConstants.CALLBACK_MEASURE: - case JmolConstants.CALLBACK_MESSAGE: - case JmolConstants.CALLBACK_PICK: - case JmolConstants.CALLBACK_SCRIPT: - case JmolConstants.CALLBACK_HOVER: - case JmolConstants.CALLBACK_ERROR: - return true; - case JmolConstants.CALLBACK_CLICK: - case JmolConstants.CALLBACK_ANIMFRAME: - case JmolConstants.CALLBACK_MINIMIZATION: - case JmolConstants.CALLBACK_RESIZE: - case JmolConstants.CALLBACK_SYNC: - } - return false; - } - - public void setCallbackFunction(String callbackType, - String callbackFunction) - { - System.err.println("Ignoring set-callback request to associate " - + callbackType + " with function " + callbackFunction); - - } - }