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");
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;
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
AlignmentPanel ap, String protocol)
{
this.ap = ap;
- this.sequence = seq;
- this.chains = chains;
- this.pdbentry = pdbentry;
- this.protocol = protocol;
+ jmb = new AppletJmolBinding(this, new PDBEntry[]
+ { pdbentry }, seq, chains, protocol);
+ jmb.setColourBySequence(true);
if (pdbentry.getId() == null || pdbentry.getId().length() < 1)
{
if (protocol.equals(AppletFormatAdapter.PASTE))
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);
-
- jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
+ jmb.allocateViewer(renderPanel,
+ "jalviewJmol", ap.av.applet.getDocumentBase(), ap.av.applet
+ .getCodeBase(), "");
+ jmb.newJmolPopup(true, "Jmol", true);
this.addWindowListener(new WindowAdapter()
{
else if (protocol.equals(AppletFormatAdapter.FILE)
|| protocol.equals(AppletFormatAdapter.URL))
{
- viewer.openFile(pdbentry.getFile());
+ jmb.viewer.openFile(pdbentry.getFile());
}
else
{
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!
}
}
- jalview.bin.JalviewLite.addFrame(this, "Jmol", 400, 400);
+ jalview.bin.JalviewLite.addFrame(this, jmb.getViewerTitle(), 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.
+ * 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
+ * @param seqs
+ * - sequences to search for associations
*/
public AppletJmol(JmolViewer viewer2, AlignmentPanel alignPanel,
SequenceI[] seqs)
{
-
+
// TODO Auto-generated constructor stub
}
public void loadInline(String string)
{
loadedInline = true;
- viewer.openStringInline(string);
+ jmb.viewer.openStringInline(string);
}
void setChainMenuItems(Vector chains)
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)
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(
jalview.bin.JalviewLite.addFrame(frame, "PDB - Sequence Mapping",
550, 600);
- cap.setText(StructureSelectionManager.getStructureSelectionManager()
- .printMapping(pdbentry.getFile()));
+ StringBuffer sb = new StringBuffer();
+ for (int s = 0; s < jmb.pdbentry.length; s++)
+ {
+ sb.append(StructureSelectionManager.getStructureSelectionManager()
+ .printMapping(jmb.pdbentry[s].getFile()));
+ sb.append("\n");
+ }
}
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() == user)
{
+ setEnabled(user);
new UserDefinedColours(this);
}
else if (evt.getSource() == jmolHelp)
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 depending upon if it was selected or not.
+ * @param itm
+ */
+ private void setEnabled(MenuItem itm)
+ {
+ seqColour.setState(itm==seqColour);
+ jmb.setColourBySequence(itm==seqColour);
}
public void itemStateChanged(ItemEvent evt)
{
if (evt.getSource() == seqColour)
{
- lastCommand = null;
- colourBySequence = seqColour.getState();
- colourBySequence(ap);
+ setEnabled(seqColour);
+ jmb
+ .colourBySequence(ap.av.getShowSequenceFeatures(),
+ ap.av.alignment);
}
else if (!allChainsSelected)
centerViewer();
{
if (evt.getKeyCode() == KeyEvent.VK_ENTER && scriptWindow.isVisible())
{
- viewer.evalString(inputLine.getText());
+ jmb.eval(inputLine.getText());
history.append("\n$ " + inputLine.getText());
inputLine.setText("");
}
{
}
- 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);
- }
-
- // End StructureListener
- // //////////////////////////
-
- public Color getColour(int atomIndex, int pdbResNum, String chain,
- String pdbfile)
- {
- 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)
- {
- 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)
- {
+ AlignmentPanel ap = (AlignmentPanel) source;
+ jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
}
- public void notifyFileLoaded(String fullPathName, String fileName2,
- String modelName, String errorMsg, int modelParts)
+ public void updateTitleAndMenus()
{
- if (errorMsg != null)
+ if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
{
- 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);
-
- }
-
- 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());
+ setChainMenuItems(jmb.chainNames);
+ jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
- 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)
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);
}
else
{
- viewer.renderScreenImage(g, currentSize, rectClip);
+ jmb.viewer.renderScreenImage(g, currentSize, rectClip);
}
}
}
-
- public String createImage(String fileName, String type,
- Object textOrBytes, int quality)
+/*
+ @Override
+ public Color getColour(int atomIndex, int pdbResNum, String chain,
+ String pdbId)
{
- // TODO Auto-generated method stub
- return null;
+ return jmb.getColour(atomIndex, pdbResNum, chain, pdbId);
}
- public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
+ @Override
+ public String[] getPdbFile()
{
- // TODO Auto-generated method stub
- return null;
+ return jmb.getPdbFile();
}
- public Hashtable getRegistryInfo()
+ @Override
+ public void highlightAtom(int atomIndex, int pdbResNum, String chain,
+ String pdbId)
{
- // TODO Auto-generated method stub
- return null;
- }
+ jmb.highlightAtom(atomIndex, pdbResNum, chain, pdbId);
- public void notifyCallback(int type, Object[] data)
- {
- try
- {
- switch (type)
- {
- 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;
- }
- } catch (Exception e)
- {
- System.err.println("Squashed Jmol callback handler error:");
- e.printStackTrace();
- }
}
- public boolean notifyEnabled(int callbackPick)
+ @Override
+ public void mouseOverStructure(int atomIndex, String strInfo)
{
- 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;
- }
+ jmb.mouseOverStructure(atomIndex, strInfo);
- public void setCallbackFunction(String callbackType,
- String callbackFunction)
+ }
+*/
+ public void setJalviewColourScheme(UserColourScheme ucs)
{
- System.err.println("Ignoring set-callback request to associate "
- + callbackType + " with function " + callbackFunction);
-
+ jmb.setJalviewColourScheme(ucs);
}
-
}
--- /dev/null
+/**
+ *
+ */
+package jalview.appletgui;
+
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+
+import org.jmol.popup.JmolPopup;
+
+class AppletJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
+{
+
+ /**
+ *
+ */
+ private AppletJmol appletJmolBinding;
+
+ public AppletJmolBinding(AppletJmol appletJmol, PDBEntry[] pdbentry, SequenceI[] seq,
+ String[] chains, String protocol)
+ {
+ super(pdbentry, seq, chains, protocol);
+ appletJmolBinding = appletJmol;
+ }
+
+ @Override
+ public jalview.api.FeatureRenderer getFeatureRenderer()
+ {
+ if (appletJmolBinding.ap.av.showSequenceFeatures)
+ {
+ if (appletJmolBinding.fr == null)
+ {
+ appletJmolBinding.fr = new jalview.appletgui.FeatureRenderer(appletJmolBinding.ap.av);
+ }
+
+ appletJmolBinding.fr.transferSettings(appletJmolBinding.ap.seqPanel.seqCanvas.getFeatureRenderer());
+ }
+
+ return appletJmolBinding.fr;
+ }
+
+ @Override
+ public jalview.api.SequenceRenderer getSequenceRenderer()
+ {
+ return new SequenceRenderer(appletJmolBinding.ap.av);
+ }
+
+ public void sendConsoleEcho(String strEcho)
+ {
+ if (appletJmolBinding.scriptWindow == null)
+ appletJmolBinding.showConsole(true);
+
+ appletJmolBinding.history.append("\n" + strEcho);
+ }
+
+ public void sendConsoleMessage(String strStatus)
+ {
+ if (appletJmolBinding.history != null && strStatus != null
+ && !strStatus.equals("Script completed"))
+ {
+ appletJmolBinding.history.append("\n" + strStatus);
+ }
+ }
+
+ @Override
+ public void showUrl(String url, String target)
+ {
+ appletJmolBinding.ap.alignFrame.showURL(url, target);
+
+ }
+
+ @Override
+ public void updateUI()
+ {
+ appletJmolBinding.updateTitleAndMenus();
+ }
+
+ public void updateColours(Object source)
+ {
+ AlignmentPanel ap = (AlignmentPanel) source;
+ colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
+ }
+
+ public void showUrl(String url)
+ {
+ try
+ {
+ appletJmolBinding.ap.av.applet.getAppletContext().showDocument(new java.net.URL(url),
+ "jmol");
+ } catch (java.net.MalformedURLException ex)
+ {
+ }
+ }
+
+ public void newJmolPopup(boolean translateLocale, String menuName, boolean asPopup)
+ {
+
+ jmolpopup = JmolPopup.newJmolPopup(viewer,translateLocale, menuName,asPopup);
+ }
+
+ @Override
+ public void notifyScriptTermination(String strStatus, int msWalltime)
+ {
+ // do nothing.
+ }
+
+}
\ No newline at end of file
*/
package jalview.ext.jmol;
+import java.io.File;
+import java.net.URL;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
JmolStatusListener, SequenceStructureBinding
{
+ /**
+ * set if Jmol state is being restored from some source - instructs binding
+ * not to apply default display style when structure set is updated for first
+ * time.
+ */
+ private boolean loadingFromArchive = false;
+ /**
+ * 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;
Vector atomsPicked = new Vector();
- private Vector chainNames;
+ public Vector chainNames;
String[] chains;
StringBuffer eval = new StringBuffer();
- String fileLoadingError;
+ public String fileLoadingError;
/**
* the default or current model displayed if the model cannot be identified
*/
int frameNo = 0;
- JmolPopup jmolpopup;
+ protected JmolPopup jmolpopup;
String lastCommand;
*/
String[] modelFileNames = null;
- PDBEntry[] pdbentry;
+ public PDBEntry[] pdbentry;
/**
* datasource protocol for access to PDBEntry
StringBuffer resetLastRes = new StringBuffer();
- SequenceI[] sequence;
+ public SequenceI[] sequence;
StructureSelectionManager ssm;
- JmolViewer viewer;
+ public JmolViewer viewer;
public JalviewJmolBinding(PDBEntry[] pdbentry, SequenceI[] seq,
String[] chains, String protocol)
{
+ this.sequence = seq;
+ this.chains = chains;
+ this.pdbentry = pdbentry;
+ this.protocol = protocol;
+
/*
* viewer = JmolViewer.allocateViewer(renderPanel, new SmarterJmolAdapter(),
* "jalviewJmol", ap.av.applet .getDocumentBase(),
}
/**
+ * construct a title string for the viewer window based on the data jalview knows about
+ * @return
+ */
+ public String getViewerTitle() {
+ if (sequence==null || pdbentry==null || sequence.length<1 || pdbentry.length<1)
+ {
+ return("Jalview Jmol Window");
+ }
+ StringBuffer title = new StringBuffer(sequence[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();
+ }
+
+ /**
* prepare the view for a given set of models/chains. chainList contains
* strings of the form 'pdbfilename:Chaincode'
*
* @param chainList
* list of chains to make visible
*/
- void centerViewer(Vector chainList)
+ public void centerViewer(Vector chainList)
{
StringBuffer cmd = new StringBuffer();
String lbl;
}
if (cmd.length() > 0)
cmd.setLength(cmd.length() - 4);
-
- jmolHistory(false);
- viewer
- .evalString("select *;restrict " + cmd + ";cartoon;center "
+ evalStateCommand("select *;restrict " + cmd + ";cartoon;center "
+ cmd);
- jmolHistory(true);
}
- void closeViewer()
+ public void closeViewer()
{
viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);
// remove listeners for all structures in viewer
// and shut down jmol
viewer.evalStringQuiet("zap");
viewer.setJmolStatusListener(null);
-
+ lastCommand=null;
viewer = null;
}
public void colourByChain()
{
- jmolHistory(false);
colourBySequence = false;
- viewer.evalStringQuiet("select *;color chain");
- jmolHistory(true);
- }
+ evalStateCommand("select *;color chain");
+ }
public void colourByCharge()
{
- jmolHistory(false);
colourBySequence = false;
- viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"
+ evalStateCommand("select *;color white;select ASP,GLU;color red;"
+ "select LYS,ARG;color blue;select CYS;color yellow");
- jmolHistory(true);
}
/**
+ * superpose the structures associated with sequences in the alignment
+ * according to their corresponding positions.
+ */
+ public void superposeStructures(AlignmentI alignment)
+ {
+ String[] files = getPdbFile();
+
+ StringBuffer command = new StringBuffer();
+ boolean matched[] = new boolean[alignment.getWidth()];
+ String commonpositions[][] = new String[files.length][alignment
+ .getWidth()];
+ 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 = alignment.findIndex(sequence[s])) > -1)
+ {
+ SequenceI asp = 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)))
+ {
+ matched[r] = false; // exclude from common set
+ continue;
+ }
+ int pos = mapping[m].getPDBResNum(asp.findPosition(r));
+
+ if (pos < 1 || pos == lastPos)
+ continue;
+
+ lastPos = pos;
+
+ commonpositions[m][r] = (mapping[m].getChain() != " " ? ":"
+ + mapping[m].getChain() : "")
+ + "/" + (pdbfnum + 1) + ".1";
+ }
+ break;
+ }
+ }
+ }
+ }
+ command.append("select ");
+ // form the matched pair selection strings
+ String sep = "";
+ for (int r = 0; r < matched.length; r++)
+ {
+ if (matched[r])
+ {
+ command.append(sep);
+ command.append("(");
+ for (int s = 0; s < commonpositions.length; s++)
+ {
+ if (s > 0)
+ {
+ command.append(" | ");
+ }
+ command.append(commonpositions[s][r]);
+ }
+ command.append(")");
+ sep = " | ";
+ }
+ }
+ evalStateCommand(command.toString());
+ }
+
+ public void evalStateCommand(String command) {
+ jmolHistory(false);
+ if (lastCommand == null || !lastCommand.equals(command))
+ {
+ viewer.evalStringQuiet(command+"\n");
+ }
+ jmolHistory(true);
+ lastCommand = command;
+ }
+ /**
* colour any structures associated with sequences in the given alignment
* using the getFeatureRenderer() and getSequenceRenderer() renderers but only
* if colourBySequence is enabled.
{
if (!colourBySequence)
return;
+ if (ssm==null)
+ {
+ return;
+ }
String[] files = getPdbFile();
SequenceRenderer sr = getSequenceRenderer();
}
}
}
+ evalStateCommand(command.toString());
+ }
- jmolHistory(false);
- if (lastCommand == null || !lastCommand.equals(command.toString()))
- {
- viewer.evalStringQuiet(command.toString());
- }
- jmolHistory(true);
- lastCommand = command.toString();
+ public boolean isColourBySequence()
+ {
+ return colourBySequence;
+ }
+
+ public void setColourBySequence(boolean colourBySequence)
+ {
+ this.colourBySequence = colourBySequence;
}
StringBuffer condenseCommand(String command, int pos)
public void createImage(String file, String type, int quality)
{
+ System.out.println("JMOL CREATE IMAGE");
}
public String createImage(String fileName, String type,
Object textOrBytes, int quality)
{
- // TODO Auto-generated method stub
+ System.out.println("JMOL CREATE IMAGE");
return null;
}
*
* @return
*/
- abstract FeatureRenderer getFeatureRenderer();
+ public abstract FeatureRenderer getFeatureRenderer();
private int getModelNum(String modelFileName)
{
*
* @return
*/
- abstract SequenceRenderer getSequenceRenderer();
+ public abstract SequenceRenderer getSequenceRenderer();
// ///////////////////////////////
// JmolStatusListener
}
+ boolean debug = true;
+
private void jmolHistory(boolean enable)
{
- viewer.setBooleanProperty("history", enable);
+ viewer.evalStringQuiet("History " + ((debug || enable) ? "on" : "off"));
}
public void loadInline(String string)
{
if (data != null)
{
- System.err.println("Ignoring additional hover info: " + data);
+ System.err.println("Ignoring additional hover info: " + data+ " (other info: '" + strInfo + "' pos " + atomIndex + ")");
}
mouseOverStructure(atomIndex, strInfo);
}
atomsPicked.removeElement(picked);
}
jmolHistory(true);
+ // TODO: in application this happens
+ //
+//if (scriptWindow != null)
+// {
+// scriptWindow.sendConsoleMessage(strInfo);
+// scriptWindow.sendConsoleMessage("\n");
+// }
+
}
sendConsoleMessage((data == null) ? ((String) null)
: (String) data[1]);
break;
+ case JmolConstants.CALLBACK_ERROR:
+ // System.err.println("Ignoring error callback.");
+ break;
+ case JmolConstants.CALLBACK_SYNC:
+ case JmolConstants.CALLBACK_RESIZE:
+ updateUI();
+ break;
case JmolConstants.CALLBACK_MEASURE:
+
case JmolConstants.CALLBACK_CLICK:
+
default:
- System.err.println("Unhandled callback " + type + " " + data);
+ System.err.println("Unhandled callback " + type + " " + data[1].toString());
break;
}
} catch (Exception e)
case JmolConstants.CALLBACK_HOVER:
case JmolConstants.CALLBACK_ERROR:
return true;
+ case JmolConstants.CALLBACK_RESIZE:
+ case JmolConstants.CALLBACK_SYNC:
case JmolConstants.CALLBACK_CLICK:
case JmolConstants.CALLBACK_ANIMFRAME:
case JmolConstants.CALLBACK_MINIMIZATION:
- case JmolConstants.CALLBACK_RESIZE:
- case JmolConstants.CALLBACK_SYNC:
}
return false;
}
return;
}
fileLoadingError = null;
+ String[] oldmodels = modelFileNames;
modelFileNames = null;
chainNames = new Vector();
boolean notifyLoaded = false;
String[] modelfilenames = getPdbFile();
ssm = StructureSelectionManager.getStructureSelectionManager();
+ // first check if we've lost any structures
+ if (oldmodels!=null && oldmodels.length>0)
+ {
+ int oldm=0;
+ for (int i=0;i<oldmodels.length;i++)
+ {
+ for (int n=0;n<modelfilenames.length; n++)
+ {
+ if (modelfilenames[n]==oldmodels[i])
+ {
+ oldmodels[i]=null;
+ break;
+ }
+ }
+ if (oldmodels[i]!=null)
+ {
+ oldm++;
+ }
+ }
+ if (oldm>0)
+ {
+ String[] oldmfn = new String[oldm];
+ oldm=0;
+ for (int i=0;i<oldmodels.length; i++)
+ {
+ if (oldmodels[i]!=null) {
+ oldmfn[oldm++] = oldmodels[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);
+ }
+ }
for (int modelnum = 0; modelnum < modelfilenames.length; modelnum++)
{
String fileName = modelfilenames[modelnum];
// needs
// to be tested. See mantis bug
// https://mantis.lifesci.dundee.ac.uk/view.php?id=36605
-
+ String protocol = AppletFormatAdapter.URL;
+ try
+ {
+ File fl = new java.io.File(pdbentry[pe].getFile());
+ if (fl.exists())
+ {
+ protocol = AppletFormatAdapter.FILE;
+ }
+ } catch (Exception e)
+ {
+ } catch (Error e)
+ {
+ }
+ ;
pdb = ssm.setMapping(sequence, chains, pdbentry[pe]
- .getFile(), AppletFormatAdapter.URL);
+ .getFile(), protocol);
}
// parse pdb file into a chain, etc.
// locate best match for pdb in associated views and add mapping to
// ssm
- // if properly registered then notifyLoaded=true;
+ // if properly registered then
+ notifyLoaded = true;
}
}
}
// FILE LOADED OK
// so finally, update the jmol bits and pieces
jmolpopup.updateComputedMenus();
- viewer
- .evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
+ if (!isLoadingFromArchive())
+ {
+ viewer
+ .evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
+ }
+ setLoadingFromArchive(false);
// register ourselves as a listener and notify the gui that it needs to
// update itself.
ssm.addStructureViewerListener(this);
if (notifyLoaded)
{
+ FeatureRenderer fr = getFeatureRenderer();
+ if (fr!=null)
+ {
+ fr.featuresAdded();
+ }
updateUI();
}
-
}
public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
notifyAtomPicked(iatom, strMeasure, null);
}
- public void notifyScriptTermination(String strStatus, int msWalltime)
- {
- }
+ public abstract void notifyScriptTermination(String strStatus, int msWalltime);
/**
* display a message echoed from the jmol viewer
int index;
Color col;
jmolHistory(false);
-
+ // TODO: Switch between nucleotide or aa selection expressions
Enumeration en = ResidueProperties.aa3Hash.keys();
StringBuffer command = new StringBuffer("select *;color white;");
while (en.hasMoreElements())
+ col.getGreen() + "," + col.getBlue() + "];");
}
- viewer.evalStringQuiet(command.toString());
+ evalStateCommand(command.toString());
jmolHistory(true);
}
* state change. this could be because structures were loaded, or because an
* error has occured.
*/
- abstract void updateUI();
+ public abstract void updateUI();
+
+ public void allocateViewer(Component renderPanel, String htmlName,
+ URL documentBase, URL codeBase, String commandOptions)
+ {
+ viewer = JmolViewer.allocateViewer(renderPanel,
+ new SmarterJmolAdapter(), htmlName+((Object) this).toString(), documentBase, codeBase,
+ commandOptions, this);
+ }
+ public void setLoadingFromArchive(boolean loadingFromArchive)
+ {
+ this.loadingFromArchive = loadingFromArchive;
+ }
+
+ public boolean isLoadingFromArchive()
+ {
+ return loadingFromArchive;
+ }
+ public void setBackgroundColour(java.awt.Color col)
+ {
+ jmolHistory(false);
+ viewer.evalStringQuiet("background [" + col.getRed() + ","
+ + col.getGreen() + "," + col.getBlue() + "];");
+ jmolHistory(true);
+ }
}
import org.jmol.popup.*;
import org.jmol.viewer.JmolConstants;
-public class AppJmol extends GStructureViewer implements StructureListener,
- JmolStatusListener, Runnable, SequenceStructureBinding
+public class AppJmol extends GStructureViewer implements Runnable,
+ SequenceStructureBinding
{
- JmolViewer viewer;
-
- JmolPopup jmolpopup;
+ AppJmolBinding jmb;
ScriptWindow scriptWindow;
- PDBEntry pdbentry;
-
- SequenceI[] sequence;
-
- String[] chains;
-
- StructureSelectionManager ssm;
-
JSplitPane splitPane;
RenderPanel renderPanel;
AlignmentPanel ap;
- String fileLoadingError;
-
- boolean colourBySequence = true;
-
- boolean loadingFromArchive = false;
-
Vector atomsPicked = new Vector();
public AppJmol(String file, String id, SequenceI[] seq,
AlignmentPanel ap, String loadStatus, Rectangle bounds,
String viewid)
{
- loadingFromArchive = true;
- pdbentry = new PDBEntry();
+ PDBEntry pdbentry = new PDBEntry();
pdbentry.setFile(file);
pdbentry.setId(id);
- this.sequence = seq;
+ // / TODO: check if protocol is needed to be set, and if chains are
+ // autodiscovered.
+ jmb = new AppJmolBinding(this, new PDBEntry[]
+ { pdbentry }, seq, null, null);
+
+ jmb.setLoadingFromArchive(true);
this.ap = ap;
this.setBounds(bounds);
- colourBySequence = false;
+ jmb.setColourBySequence(false);
seqColour.setSelected(false);
viewId = viewid;
// jalview.gui.Desktop.addInternalFrame(this, "Loading File",
// bounds.width,bounds.height);
- initJmol(loadStatus);
-
this.addInternalFrameListener(new InternalFrameAdapter()
{
public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
closeViewer();
}
});
- }
+ initJmol(loadStatus); // pdbentry, seq, JBPCHECK!
- public synchronized void addSequence(SequenceI[] seq)
- {
- Vector v = new Vector();
- for (int i = 0; i < sequence.length; i++)
- v.addElement(sequence[i]);
-
- for (int i = 0; i < seq.length; i++)
- if (!v.contains(seq[i]))
- v.addElement(seq[i]);
-
- SequenceI[] tmp = new SequenceI[v.size()];
- v.copyInto(tmp);
- sequence = tmp;
}
public AppJmol(PDBEntry pdbentry, SequenceI[] seq, String[] chains,
Desktop.desktop,
pdbentry.getId()
+ " is already displayed."
- + "\nDo you want to map sequences to the visible structure?",
+ + "\nDo you want to re-use this viewer ?",
"Map Sequences to Visible Window: "
+ pdbentry.getId(), JOptionPane.YES_NO_OPTION);
if (frames[i] instanceof AppJmol)
{
AppJmol topJmol = ((AppJmol) frames[i]);
- if (topJmol.pdbentry.getFile().equals(alreadyMapped))
+ // JBPNOTE: this looks like a binding routine, rather than a gui
+ // routine
+ for (int pe = 0; pe < topJmol.jmb.pdbentry.length; pe++)
{
- topJmol.addSequence(seq);
- break;
+ if (topJmol.jmb.pdbentry[pe].getFile().equals(alreadyMapped))
+ {
+ topJmol.jmb.addSequence(seq);
+ break;
+ }
}
}
}
}
// /////////////////////////////////
+ jmb = new AppJmolBinding(this, new PDBEntry[]
+ { pdbentry }, seq, null, null);
this.ap = ap;
- this.pdbentry = pdbentry;
- this.sequence = seq;
- this.setSize(400, 400);
- // jalview.gui.Desktop.addInternalFrame(this, "Jmol
- // View"+(pdbentry.getId()!=null ? "for "+pdbentry.getId()
- // : ""), 400, 400);
+ setSize(400, 400); // probably should be a configurable/dynamic default here
if (pdbentry.getFile() != null)
{
closeViewer();
}
});
+
}
void initJmol(String command)
{
+ jmb.setFinishedInit(false);
renderPanel = new RenderPanel();
-
+ // TODO: consider waiting until the structure/view is fully loaded before
+ // displaying
this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);
-
- 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());
- jalview.gui.Desktop.addInternalFrame(this, title.toString(),
+ jalview.gui.Desktop.addInternalFrame(this, jmb.getViewerTitle(),
getBounds().width, getBounds().height);
- // * OK, but safer to assign htmlName, URL bases, comandOptions, and
- // statusListener now.
-
- viewer = org.jmol.api.JmolViewer.allocateViewer(renderPanel,
- new SmarterJmolAdapter(), "", null, null, "", this);
-
- jmolpopup = JmolPopup.newJmolPopup(viewer, true, "Jmol", true);
-
- viewer.evalStringQuiet(command);
+ jmb.allocateViewer(renderPanel, "", null, null, "");
+ jmb.newJmolPopup(true, "Jmol", true);
+ jmb.evalStateCommand(command);
+ jmb.setFinishedInit(true);
}
void setChainMenuItems(Vector chains)
{
chainMenu.removeAll();
-
+ if (chains==null)
+ {
+ return;
+ }
JMenuItem menuItem = new JMenuItem("All");
menuItem.addActionListener(new ActionListener()
{
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 JCheckBoxMenuItem)
{
JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
if (item.isSelected())
- { lbl = item.getText();
- mlength = 0;
- do
- {
- p = mlength;
- mlength = lbl.indexOf(":", p);
- } while (p < mlength && mlength < (lbl.length() - 2));
- if (pdbentry.getId().equals(lbl.substring(0,mlength)))
{
- mnum = 1+getModelNum(pdbentry.getFile());
- if (mnum>0)
- {cmd.append(":" + lbl.substring(mlength + 1) + " /"
- + mnum + " or ");
- }
- }
+ toshow.addElement(item.getText());
}
}
}
-
- if (cmd.length() > 0)
- cmd.setLength(cmd.length() - 4);
-
- viewer.evalStringQuiet("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, getPdbFile());
- // and shut down jmol
- viewer.evalStringQuiet("zap");
- viewer.setJmolStatusListener(null);
- viewer = null;
+ jmb.closeViewer();
+ // TODO: check for memory leaks where instance isn't finalised because jmb
+ // holds a reference to the window
+ jmb = null;
}
public void run()
{
+ String pdbid = "";
+ // todo - record which pdbids were successfuly imported.
+ StringBuffer errormsgs = new StringBuffer(), files = new StringBuffer();
try
{
// TODO: replace with reference fetching/transfer code (validate PDBentry
// as a DBRef?)
jalview.ws.dbsources.Pdb pdbclient = new jalview.ws.dbsources.Pdb();
- AlignmentI pdbseq;
- if ((pdbseq = pdbclient.getSequenceRecords(pdbentry.getId())) != null)
- {
- // just transfer the file name from the first seuqence's first PDBEntry
- pdbentry.setFile(((PDBEntry) pdbseq.getSequenceAt(0).getPDBId()
- .elementAt(0)).getFile());
- initJmol("load " + pdbentry.getFile());
- }
- else
+ for (int pi = 0; pi < jmb.pdbentry.length; pi++)
{
- JOptionPane
- .showInternalMessageDialog(
- Desktop.desktop,
- pdbentry.getId()
- + " could not be retrieved. Please try downloading the file manually.",
- "Couldn't load file", JOptionPane.ERROR_MESSAGE);
-
+ AlignmentI pdbseq;
+ if ((pdbseq = pdbclient.getSequenceRecords(pdbid = jmb.pdbentry[pi]
+ .getId())) != null)
+ {
+ String file;
+ // just transfer the file name from the first sequence's first
+ // PDBEntry
+ jmb.pdbentry[pi].setFile(file = ((PDBEntry) pdbseq.getSequenceAt(
+ 0).getPDBId().elementAt(0)).getFile());
+ files.append("\"" + file + "\"");
+ }
+ else
+ {
+ errormsgs.append("'" + pdbid + "' ");
+ }
}
} catch (OutOfMemoryError oomerror)
{
- new OOMWarning("Retrieving PDB id " + pdbentry.getId() + " from MSD",
- oomerror);
+ new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
} catch (Exception ex)
{
ex.printStackTrace();
+ errormsgs.append("'" + pdbid + "'");
+ }
+ if (errormsgs.length() > 0)
+ {
+
+ JOptionPane.showInternalMessageDialog(Desktop.desktop,
+ "The following pdb entries could not be retrieved from the PDB:\n"
+ + errormsgs.toString()
+ + "\nPlease try downloading them manually.",
+ "Couldn't load file", JOptionPane.ERROR_MESSAGE);
+
+ }
+ if (files.length() > 0)
+ {
+ try
+ {
+ initJmol("load FILES " + files.toString());
+ } catch (OutOfMemoryError oomerror)
+ {
+ new OOMWarning("When trying to open the Jmol viewer!", oomerror);
+ Cache.log.debug("File locations are " + files);
+ } catch (Exception ex)
+ {
+ Cache.log.error("Couldn't open Jmol viewer!", ex);
+ }
}
}
{
try
{
- BufferedReader in = new BufferedReader(new FileReader(pdbentry
- .getFile()));
+ // TODO: cope with multiple PDB files in view
+ BufferedReader in = new BufferedReader(new FileReader(jmb.getPdbFile()[0]));
File outFile = chooser.getSelectedFile();
PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping",
550, 600);
- cap.setText(StructureSelectionManager.getStructureSelectionManager()
- .printMapping(pdbentry.getFile()));
+ for (int pdbe = 0; pdbe<jmb.pdbentry.length; pdbe++) {
+ cap.appendText(StructureSelectionManager.getStructureSelectionManager()
+ .printMapping(jmb.pdbentry[pdbe].getFile()));
+ cap.appendText("\n");
+ }
}
/**
if (im.getGraphics() != null)
{
Rectangle rect = new Rectangle(width, height);
- viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
+ jmb.viewer.renderScreenImage(im.getGraphics(), rect.getSize(), rect);
im.writeImage();
}
}
public void seqColour_actionPerformed(ActionEvent actionEvent)
{
- lastCommand = null;
- colourBySequence = seqColour.isSelected();
- colourBySequence(ap.alignFrame.alignPanel);
+ jmb.setColourBySequence(seqColour.isSelected());
+ // Set the colour using the current view for the associated alignframe
+ jmb.colourBySequence(ap.alignFrame.viewport.showSequenceFeatures, ap.alignFrame.viewport.alignment);
}
public void chainColour_actionPerformed(ActionEvent actionEvent)
{
- colourBySequence = false;
- seqColour.setSelected(false);
- jmolHistory(false);
- viewer.evalStringQuiet("select *;color chain");
- jmolHistory(true);
+ chainColour.setSelected(true);
+ jmb.colourByChain();
}
public void chargeColour_actionPerformed(ActionEvent actionEvent)
{
- colourBySequence = false;
- seqColour.setSelected(false);
- jmolHistory(false);
- viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"
- + "select LYS,ARG;color blue;select CYS;color yellow");
- jmolHistory(true);
+ chargeColour.setSelected(true);
+ jmb.colourByCharge();
}
public void zappoColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new ZappoColourScheme());
+ zappoColour.setSelected(true);
+ jmb.setJalviewColourScheme(new ZappoColourScheme());
}
public void taylorColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new TaylorColourScheme());
+ taylorColour.setSelected(true);
+ jmb.setJalviewColourScheme(new TaylorColourScheme());
}
public void hydroColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new HydrophobicColourScheme());
+ hydroColour.setSelected(true);
+ jmb.setJalviewColourScheme(new HydrophobicColourScheme());
}
public void helixColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new HelixColourScheme());
+ helixColour.setSelected(true);
+ jmb.setJalviewColourScheme(new HelixColourScheme());
}
public void strandColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new StrandColourScheme());
+ strandColour.setSelected(true);
+ jmb.setJalviewColourScheme(new StrandColourScheme());
}
public void turnColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new TurnColourScheme());
+ turnColour.setSelected(true);
+ jmb.setJalviewColourScheme(new TurnColourScheme());
}
public void buriedColour_actionPerformed(ActionEvent actionEvent)
{
- setJalviewColourScheme(new BuriedColourScheme());
+ buriedColour.setSelected(true);
+ jmb.setJalviewColourScheme(new BuriedColourScheme());
}
- public void setJalviewColourScheme(ColourSchemeI cs)
- {
- jmolHistory(false);
- colourBySequence = false;
- seqColour.setSelected(false);
-
- if (cs == null)
- return;
-
- String res;
- int index;
- Color col;
-
- 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);
- }
public void userColour_actionPerformed(ActionEvent actionEvent)
{
+ userColour.setSelected(true);
new UserDefinedColours(this, null);
}
{
java.awt.Color col = JColorChooser.showDialog(this,
"Select Background Colour", null);
-
if (col != null)
{
- jmolHistory(false);
- viewer.evalStringQuiet("background [" + col.getRed() + ","
- + col.getGreen() + "," + col.getBlue() + "];");
- jmolHistory(true);
+ jmb.setBackgroundColour(col);
}
}
- private void jmolHistory(boolean enable)
- {
- viewer.setBooleanProperty("history", enable);
- }
public void jmolHelp_actionPerformed(ActionEvent actionEvent)
{
{
}
}
- String[] modelFileNames = null;
-
- // ////////////////////////////////
- // /StructureListener
- public String[] getPdbFile()
- {
- if (modelFileNames == null)
- {
- String mset[] = new String[viewer.getModelCount()];
- for (int i = 0; i < mset.length; i++)
- {
- try {
- String mname = viewer.getModelFileName(i);
- if (mname==null)
- {
- System.err.println("Model "+i+" has no filename!");
- continue;
- }
- File fpath = new File(mname);
- mset[i] = fpath.toString();
- } catch (Exception e)
- {
- System.err.println("Couldn't parse "+viewer.getModelFileName(i)+" as a file!");
- }
- }
- modelFileNames = mset;
- }
- return modelFileNames;
- }
-
- Pattern pattern = Pattern
- .compile("\\[(.*)\\]([0-9]+)(:[a-zA-Z]*)?\\.([a-zA-Z]+).*(/[0-9]*)?");
-
- String lastMessage;
-
- public void mouseOverStructure(int atomIndex, String strInfo)
- {
- // copied from AppJmol - will be refactored to binding eventually
- 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;
-/*
- * Old Implementation based on Pattern regex.
- Matcher matcher = pattern.matcher(strInfo);
- matcher.find();
- matcher.group(1);
- int pdbResNum = Integer.parseInt(matcher.group(2));
- String chainId = matcher.group(3);
-
- if (chainId != null)
- chainId = chainId.substring(1, chainId.length());
- else
- {
- chainId = " ";
- }
- String mdlId = matcher.group(4);
- String pdbfilename = pdbentry.getFile();
-
- if (mdlId!=null && mdlId.length()>0)
- {
- 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();
-
- 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 Color getColour(int atomIndex, int pdbResNum, String chain,
- String pdbfile)
- {
- if (!pdbfile.equals(pdbentry.getFile()))
- return null;
-
- return new Color(viewer.getAtomArgb(atomIndex));
- }
-
- public void updateColours(Object source)
- {
- colourBySequence((AlignmentPanel) source);
- }
-
- // End StructureListener
- // //////////////////////////
-
- String lastCommand;
-
- FeatureRenderer fr = null;
-
- public void colourBySequence(AlignmentPanel sourceap)
- {
- this.ap = sourceap;
-
- if (!colourBySequence || ap.alignFrame.getCurrentView() != ap.av)
- return;
-
- String[] files = getPdbFile();
-
- SequenceRenderer sr = new SequenceRenderer(ap.av);
-
- boolean showFeatures = false;
-
- if (ap.av.showSequenceFeatures)
- {
- showFeatures = true;
- if (fr == null)
- {
- fr = new jalview.gui.FeatureRenderer(ap);
- }
-
- 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 sp, s = 0; s < sequence.length; s++)
- {
- for (int 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(asp, r);
-
- if (showFeatures)
- col = fr.findFeatureColour(col, asp, 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, pos);
- continue;
- }
-
- 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(StringBuffer command, int pos)
- {
- StringBuffer sb = new StringBuffer(command.substring(0, command
- .lastIndexOf("select") + 7));
-
- command.delete(0, 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)
- {
- System.out.println("JMOL CREATE IMAGE");
- }
-
- 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)
- {
- modelsloaded=true;
- // search pdbentries and sequences to find correct pdbentry and sequence[] pair for this filename
- if (pdbentry.getFile().equals(fileName))
- {
- // TODO: do some checking using the modelPts number of parts against our
- // own estimate of the number of chains
- // FILE LOADED OK
- MCview.PDBfile pdbFile = ssm.setMapping(sequence, chains, pdbentry
- .getFile(), AppletFormatAdapter.FILE);
- Vector chains = new Vector();
- for (int i = 0; i < pdbFile.chains.size(); i++)
- {
- chains
- .addElement(new String(pdbFile.id+":"+((MCview.PDBChain) pdbFile.chains.elementAt(i)).id));
- }
- setChainMenuItems(chains);
-
- if (!loadingFromArchive)
- {
- viewer
- .evalStringQuiet("model 0; select backbone;restrict;cartoon;wireframe off;spacefill off");
-
- colourBySequence(ap);
- }
- if (fr != null)
- fr.featuresAdded();
-
- loadingFromArchive = false;
- }
- 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)
- {
- ssm.addStructureViewerListener(this);
- jmolpopup.updateComputedMenus();
- }
- }
-
- public void sendConsoleEcho(String strEcho)
- {
- if (scriptWindow != null)
- scriptWindow.sendConsoleEcho(strEcho);
- }
-
- public void sendConsoleMessage(String strStatus)
- {
- if (scriptWindow != null)
- scriptWindow.sendConsoleMessage(strStatus);
- }
-
- public void notifyScriptTermination(String strStatus, int msWalltime)
- {
- if (scriptWindow != null)
- scriptWindow.notifyScriptTermination(strStatus, 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)
- {
- Cache.log.info("Non null pick data string: " + strData
- + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
- }
- /*
- Matcher matcher = pattern.matcher(strInfo);
- matcher.find();
-
- matcher.group(1);
- String resnum = new String(matcher.group(2));
- String chainId = matcher.group(3);
-
- String picked = resnum;
-
-
- if (chainId != null)
- picked += (":" + chainId.substring(1, chainId.length()));
-*/
- 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))
- {
- // TODO: re-instate chain ID separator dependent labelling for both applet and application
-// if (chainId != null)
- viewer.evalString("select " + picked + ";label %n %r:%c");
-// else
-// viewer.evalString("select " + picked + ";label %n %r");
- atomsPicked.addElement(picked);
- }
- else
- {
- viewer.evalString("select " + picked + ";label off");
- atomsPicked.removeElement(picked);
- }
- jmolHistory(true);
- if (scriptWindow != null)
- {
- scriptWindow.sendConsoleMessage(strInfo);
- scriptWindow.sendConsoleMessage("\n");
- }
- }
-
- public void notifyAtomHovered(int atomIndex, String strInfo, String data)
- {
- if (data != null)
- {
- Cache.log.info("Non null hover data string: " + data
- + " (other info: '" + strInfo + "' pos " + atomIndex + ")");
- }
- mouseOverStructure(atomIndex, strInfo);
- }
-
- @Override
- public void showUrl(String url)
- {
- try
- {
- jalview.util.BrowserLauncher.openURL(url);
- } catch (IOException e)
- {
- Cache.log.error("Failed to launch Jmol-associated url " + url, e);
- // TODO: 2.6 : warn user if browser was not configured.
- }
- }
public void showConsole(boolean showConsole)
{
validate();
}
- public float[][] functionXY(String functionName, int x, int y)
- {
- return null;
- }
-
- // /End JmolStatusListener
- // /////////////////////////////
-
class RenderPanel extends JPanel
{
final Dimension currentSize = new Dimension();
getSize(currentSize);
g.getClipBounds(rectClip);
- if (viewer == null)
- {
- g.setColor(Color.black);
- g.fillRect(0, 0, currentSize.width, currentSize.height);
- g.setColor(Color.white);
- g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
- }
- else if (fileLoadingError != null)
+ if (jmb.fileLoadingError != null)
{
g.setColor(Color.black);
g.fillRect(0, 0, currentSize.width, currentSize.height);
g.setColor(Color.white);
g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Error loading file..." + pdbentry.getId(), 20,
+ g.drawString("Error loading file...", 20,
currentSize.height / 2);
+ StringBuffer sb = new StringBuffer();
+ int lines=0;
+ for (int e=0;e<jmb.pdbentry.length; e++)
+ {
+ sb.append(jmb.pdbentry[e].getId());
+ if (e<jmb.pdbentry.length-1) {
+ sb.append(",");
+ }
+
+ if (e==jmb.pdbentry.length-1 || sb.length()>20)
+ {
+ lines++;
+ g.drawString(sb.toString(), 20, currentSize.height/2 - lines*g.getFontMetrics().getHeight());
+ }
+ }
}
else
+ if (jmb == null || jmb.viewer == null || !jmb.isFinishedInit())
+ {
+ g.setColor(Color.black);
+ g.fillRect(0, 0, currentSize.width, currentSize.height);
+ g.setColor(Color.white);
+ g.setFont(new Font("Verdana", Font.BOLD, 14));
+ g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);
+ }
+ else
{
- viewer.renderScreenImage(g, currentSize, rectClip);
+ jmb.viewer.renderScreenImage(g, currentSize, rectClip);
}
}
}
}
return viewId;
}
-
- @Override
- public String createImage(String fileName, String type,
- Object textOrBytes, int quality)
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public float[][][] functionXYZ(String functionName, int nx, int ny, int nz)
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Hashtable getRegistryInfo()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void notifyCallback(int type, Object[] data)
+ public void updateTitleAndMenus()
{
- try
- {
- switch (type)
- {
- 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;
- }
- } catch (Exception e)
+ if (jmb.fileLoadingError != null && jmb.fileLoadingError.length() > 0)
{
- Cache.log.warn("Squashed Jmol callback handler error: ", e);
+ repaint();
+ return;
}
- }
+ setChainMenuItems(jmb.chainNames);
+ jmb.colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
- @Override
- 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;
+ this.setTitle(jmb.getViewerTitle());
}
- @Override
- public void setCallbackFunction(String callbackType,
- String callbackFunction)
+ public void setJalviewColourScheme(ColourSchemeI ucs)
{
- Cache.log.debug("Ignoring set-callback request to associate "
- + callbackType + " with function " + callbackFunction);
-
+ jmb.setJalviewColourScheme(ucs);
+
}
}
--- /dev/null
+/**
+ *
+ */
+package jalview.gui;
+
+import java.util.Vector;
+
+import jalview.bin.Cache;
+import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceI;
+
+import org.jmol.popup.JmolPopup;
+
+class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
+{
+
+ /**
+ *
+ */
+ private AppJmol appJmolWindow;
+
+ public AppJmolBinding(AppJmol appJmol, PDBEntry[] pdbentry,
+ SequenceI[] seq, String[] chains, String protocol)
+ {
+ super(pdbentry, seq, chains, protocol);
+ appJmolWindow = appJmol;
+ }
+ FeatureRenderer fr=null;
+ @Override
+ public jalview.api.FeatureRenderer getFeatureRenderer()
+ {
+ if (appJmolWindow.ap.av.showSequenceFeatures)
+ {
+ if (fr == null)
+ {
+ fr = new FeatureRenderer(appJmolWindow.ap);
+ }
+
+ fr.transferSettings(appJmolWindow.ap.seqPanel.seqCanvas
+ .getFeatureRenderer());
+ }
+
+ return fr;
+ }
+
+ @Override
+ public jalview.api.SequenceRenderer getSequenceRenderer()
+ {
+ return new SequenceRenderer(appJmolWindow.ap.av);
+ }
+
+ public void sendConsoleEcho(String strEcho)
+ {
+ if (appJmolWindow.scriptWindow != null)
+ {
+ appJmolWindow.scriptWindow.sendConsoleEcho(strEcho);
+ }
+ }
+
+ public void sendConsoleMessage(String strStatus)
+ {
+ if (appJmolWindow.scriptWindow!=null && strStatus != null
+ )
+ // && !strStatus.equals("Script completed"))
+ // should we squash the script completed string ?
+ {
+ appJmolWindow.scriptWindow.sendConsoleMessage(strStatus);
+ }
+ }
+
+ @Override
+ public void showUrl(String url, String target)
+ {
+ try {
+ jalview.util.BrowserLauncher.openURL(url);
+ } catch (Exception e) {
+ Cache.log.error("Failed to launch Jmol-associated url " + url, e);
+ // TODO: 2.6 : warn user if browser was not configured.
+ }
+ }
+
+ @Override
+ public void updateUI()
+ {
+ // appJmolWindow.repaint();
+ appJmolWindow.updateTitleAndMenus();
+ }
+
+ public void updateColours(Object source)
+ {
+ AlignmentPanel ap = (AlignmentPanel) source;
+ if (appJmolWindow.ap.alignFrame.getCurrentView()!=ap.av)
+ return;
+
+ colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
+ }
+
+ public void notifyScriptTermination(String strStatus, int msWalltime)
+ {
+ if (appJmolWindow.scriptWindow != null)
+ appJmolWindow.scriptWindow.notifyScriptTermination(strStatus, msWalltime);
+ }
+
+ public void showUrl(String url)
+ {
+ showUrl(url,"jmol");
+ }
+
+ public void newJmolPopup(boolean translateLocale, String menuName,
+ boolean asPopup)
+ {
+
+ jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
+ asPopup);
+ }
+ public synchronized void addSequence(SequenceI[] seq)
+ {
+ Vector v = new Vector();
+ for (int i = 0; i < sequence.length; i++)
+ v.addElement(sequence[i]);
+
+ for (int i = 0; i < seq.length; i++)
+ if (!v.contains(seq[i]))
+ v.addElement(seq[i]);
+
+ SequenceI[] tmp = new SequenceI[v.size()];
+ v.copyInto(tmp);
+ sequence = tmp;
+ }
+}
\ No newline at end of file
import org.jmol.util.Logger;
import org.jmol.util.CommandHistory;
+// TODO: this class is copied in from jmol 11.0.2 - upgrade to 12.0.2 ?
public final class ScriptWindow extends JPanel implements ActionListener,
EnterListener
{
public ScriptWindow(AppJmol appJmol)
{
- this.viewer = appJmol.viewer;
+ this.viewer = appJmol.jmb.viewer;
this.appJmol = appJmol;
setLayout(new BorderLayout());