-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA\r
- */\r
-package jalview.gui;\r
-\r
-import java.util.regex.*;\r
-import java.util.*;\r
-import java.awt.*;\r
-import javax.swing.*;\r
-import javax.swing.event.*;\r
-import java.awt.event.*;\r
-import java.io.*;\r
-\r
-import jalview.jbgui.GStructureViewer;\r
-import jalview.datamodel.*;\r
-import jalview.gui.*;\r
-import jalview.structure.*;\r
-import jalview.datamodel.PDBEntry;\r
-import jalview.io.*;\r
-import jalview.schemes.*;\r
-\r
-import org.jmol.api.*;\r
-import org.jmol.adapter.smarter.SmarterJmolAdapter;\r
-import org.jmol.popup.*;\r
-\r
-\r
-public class AppJMol\r
- extends GStructureViewer\r
- implements StructureListener, JmolStatusListener, Runnable\r
-\r
-{\r
- JmolViewer viewer;\r
- JmolPopup jmolpopup;\r
- ScriptWindow scriptWindow;\r
- PDBEntry pdbentry;\r
- SequenceI[] sequence;\r
- StructureSelectionManager ssm;\r
- JSplitPane splitPane;\r
- RenderPanel renderPanel;\r
- AlignmentPanel ap;\r
- String fileLoadingError;\r
- boolean colourBySequence = true;\r
- boolean loadingFromArchive = false;\r
-\r
- public AppJMol(String file, String id,\r
- SequenceI[] seq,\r
- AlignmentPanel ap,\r
- String loadStatus,\r
- Rectangle bounds)\r
- {\r
- loadingFromArchive = true;\r
- pdbentry = new PDBEntry();\r
- pdbentry.setFile(file);\r
- pdbentry.setId(id);\r
- this.sequence = seq;\r
- this.ap = ap;\r
- this.setBounds(bounds);\r
-\r
- colourBySequence = false;\r
- seqColour.setSelected(false);\r
-\r
- jalview.gui.Desktop.addInternalFrame(this, "Loading File",\r
- bounds.width,bounds.height);\r
-\r
- initJmol(loadStatus);\r
-\r
- this.addInternalFrameListener(new InternalFrameAdapter()\r
- {\r
- public void internalFrameClosing(InternalFrameEvent internalFrameEvent)\r
- {\r
- closeViewer();\r
- }\r
- });\r
- }\r
-\r
- public AppJMol(PDBEntry pdbentry, SequenceI[] seq, AlignmentPanel ap)\r
- {\r
- //////////////////////////////////\r
- //Is the pdb file already loaded?\r
- String alreadyMapped = StructureSelectionManager\r
- .getStructureSelectionManager()\r
- .alreadyMappedToFile(pdbentry.getId());\r
-\r
- if (alreadyMapped != null)\r
- {\r
- int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,\r
- pdbentry.getId() + " is already displayed."\r
- + "\nDo you want to map sequences to the visible structure?",\r
- "Map Sequences to Visible Window: " + pdbentry.getId(),\r
- JOptionPane.YES_NO_OPTION);\r
-\r
- if (option == JOptionPane.YES_OPTION)\r
- {\r
- StructureSelectionManager.getStructureSelectionManager()\r
- .setMapping(seq, alreadyMapped, AppletFormatAdapter.FILE);\r
- return;\r
- }\r
- }\r
- ///////////////////////////////////\r
-\r
- this.ap = ap;\r
- this.pdbentry = pdbentry;\r
- this.sequence = seq;\r
-\r
- jalview.gui.Desktop.addInternalFrame(this, "Loading File", 400, 400);\r
-\r
- if (pdbentry.getFile() != null)\r
- {\r
- initJmol("load \""+pdbentry.getFile()+"\"");\r
- }\r
- else\r
- {\r
- Thread worker = new Thread(this);\r
- worker.start();\r
- }\r
-\r
- this.addInternalFrameListener(new InternalFrameAdapter()\r
- {\r
- public void internalFrameClosing(InternalFrameEvent internalFrameEvent)\r
- {\r
- closeViewer();\r
- }\r
- });\r
- }\r
-\r
- void initJmol(String command)\r
- {\r
- renderPanel = new RenderPanel();\r
-\r
- this.getContentPane().add(renderPanel, java.awt.BorderLayout.CENTER);\r
-\r
- StringBuffer title = new StringBuffer(sequence[0].getName() + ":" +\r
- pdbentry.getId());\r
-\r
- if (pdbentry.getProperty() != null)\r
- {\r
- if (pdbentry.getProperty().get("method") != null)\r
- {\r
- title.append(" Method: ");\r
- title.append(pdbentry.getProperty().get("method"));\r
- }\r
- if (pdbentry.getProperty().get("chains") != null)\r
- {\r
- title.append(" Chain:");\r
- title.append(pdbentry.getProperty().get("chains"));\r
- }\r
- }\r
-\r
- this.setTitle(title.toString());\r
-\r
- viewer = org.jmol.api.JmolViewer.allocateViewer(renderPanel,\r
- new SmarterJmolAdapter());\r
-\r
-\r
- viewer.setAppletContext("", null, null, "");\r
-\r
- viewer.setJmolStatusListener(this);\r
-\r
- jmolpopup = JmolPopup.newJmolPopup(viewer);\r
-\r
- viewer.evalStringQuiet(command);\r
- }\r
-\r
-\r
- void setChainMenuItems(Vector chains)\r
- {\r
- chainMenu.removeAll();\r
-\r
- JMenuItem menuItem = new JMenuItem("All");\r
- menuItem.addActionListener(new ActionListener()\r
- {\r
- public void actionPerformed(ActionEvent evt)\r
- {\r
- allChainsSelected = true;\r
- for(int i=0; i<chainMenu.getItemCount(); i++)\r
- {\r
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)\r
- ( (JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);\r
- }\r
- centerViewer();\r
- allChainsSelected = false;\r
- }\r
- });\r
-\r
- chainMenu.add(menuItem);\r
-\r
- for (int c = 0; c < chains.size(); c++)\r
- {\r
- menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);\r
- menuItem.addItemListener(new ItemListener()\r
- {\r
- public void itemStateChanged(ItemEvent evt)\r
- {\r
- if (!allChainsSelected)\r
- centerViewer();\r
- }\r
- });\r
-\r
- chainMenu.add(menuItem);\r
- }\r
- }\r
-\r
- boolean allChainsSelected = false;\r
- void centerViewer()\r
- {\r
- StringBuffer cmd = new StringBuffer();\r
- for(int i=0; i<chainMenu.getItemCount(); i++)\r
- {\r
- if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)\r
- {\r
- JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);\r
- if(item.isSelected())\r
- cmd.append(":"+item.getText()+" or ");\r
- }\r
- }\r
-\r
- if (cmd.length() > 0)\r
- cmd.setLength(cmd.length() - 4);\r
-\r
- viewer.evalStringQuiet("select *;restrict "\r
- +cmd+";cartoon;center "+cmd);\r
- }\r
-\r
- void closeViewer()\r
- {\r
- viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);\r
- viewer.evalStringQuiet("zap");\r
- viewer.setJmolStatusListener(null);\r
- viewer = null;\r
-\r
- //We'll need to find out what other\r
- // listeners need to be shut down in Jmol\r
- StructureSelectionManager\r
- .getStructureSelectionManager()\r
- .removeStructureViewerListener(this, pdbentry.getFile());\r
- }\r
-\r
- public void run()\r
- {\r
- try\r
- {\r
- EBIFetchClient ebi = new EBIFetchClient();\r
- String query = "pdb:" + pdbentry.getId();\r
- pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")\r
- .getAbsolutePath());\r
- initJmol("load "+pdbentry.getFile());\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
- }\r
-\r
- public void pdbFile_actionPerformed(ActionEvent actionEvent)\r
- {\r
- JalviewFileChooser chooser = new JalviewFileChooser(\r
- jalview.bin.Cache.getProperty(\r
- "LAST_DIRECTORY"));\r
-\r
- chooser.setFileView(new JalviewFileView());\r
- chooser.setDialogTitle("Save PDB File");\r
- chooser.setToolTipText("Save");\r
-\r
- int value = chooser.showSaveDialog(this);\r
-\r
- if (value == JalviewFileChooser.APPROVE_OPTION)\r
- {\r
- try\r
- {\r
- BufferedReader in = new BufferedReader(new FileReader(pdbentry.getFile()));\r
- File outFile = chooser.getSelectedFile();\r
-\r
- PrintWriter out = new PrintWriter(new FileOutputStream(outFile));\r
- String data;\r
- while ( (data = in.readLine()) != null)\r
- {\r
- if (\r
- ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)\r
- )\r
- {\r
- out.println(data);\r
- }\r
- }\r
- out.close();\r
- }\r
- catch (Exception ex)\r
- {\r
- ex.printStackTrace();\r
- }\r
- }\r
- }\r
-\r
- public void viewMapping_actionPerformed(ActionEvent actionEvent)\r
- {\r
- jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();\r
- jalview.gui.Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550,\r
- 600);\r
- cap.setText(\r
- StructureSelectionManager.getStructureSelectionManager().printMapping(\r
- pdbentry.getFile())\r
- );\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void eps_actionPerformed(ActionEvent e)\r
- {\r
- makePDBImage(jalview.util.ImageMaker.EPS);\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void png_actionPerformed(ActionEvent e)\r
- {\r
- makePDBImage(jalview.util.ImageMaker.PNG);\r
- }\r
-\r
- void makePDBImage(int type)\r
- {\r
- int width = getWidth();\r
- int height = getHeight();\r
-\r
- jalview.util.ImageMaker im;\r
-\r
- if (type == jalview.util.ImageMaker.PNG)\r
- {\r
- im = new jalview.util.ImageMaker(this,\r
- jalview.util.ImageMaker.PNG,\r
- "Make PNG image from view",\r
- width, height,\r
- null, null);\r
- }\r
- else\r
- {\r
- im = new jalview.util.ImageMaker(this,\r
- jalview.util.ImageMaker.EPS,\r
- "Make EPS file from view",\r
- width, height,\r
- null, this.getTitle());\r
- }\r
-\r
- if (im.getGraphics() != null)\r
- {\r
- Rectangle rect = new Rectangle(width, height);\r
- viewer.renderScreenImage(im.getGraphics(),\r
- rect.getSize(), rect);\r
- im.writeImage();\r
- }\r
- }\r
-\r
-\r
- public void seqColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- colourBySequence = seqColour.isSelected();\r
- colourBySequence(ap);\r
- }\r
-\r
- public void chainColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- colourBySequence = false;\r
- seqColour.setSelected(false);\r
- viewer.evalStringQuiet("select *;color chain");\r
- }\r
-\r
- public void chargeColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- colourBySequence = false;\r
- seqColour.setSelected(false);\r
- viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"\r
- +"select LYS,ARG;color blue;select CYS;color yellow");\r
- }\r
-\r
- public void zappoColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new ZappoColourScheme());\r
- }\r
-\r
- public void taylorColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new TaylorColourScheme());\r
- }\r
-\r
- public void hydroColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new HydrophobicColourScheme());\r
- }\r
-\r
- public void helixColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new HelixColourScheme());\r
- }\r
-\r
- public void strandColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new StrandColourScheme());\r
- }\r
-\r
- public void turnColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new TurnColourScheme());\r
- }\r
-\r
- public void buriedColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- setJalviewColourScheme(new BuriedColourScheme());\r
- }\r
-\r
- public void setJalviewColourScheme(ColourSchemeI cs)\r
- {\r
- colourBySequence = false;\r
- seqColour.setSelected(false);\r
-\r
- if(cs==null)\r
- return;\r
-\r
- String res;\r
- int index;\r
- Color col;\r
-\r
- Enumeration en = ResidueProperties.aa3Hash.keys();\r
- StringBuffer command = new StringBuffer("select *;color white;");\r
- while(en.hasMoreElements())\r
- {\r
- res = en.nextElement().toString();\r
- index = ((Integer) ResidueProperties.aa3Hash.get(res)).intValue();\r
- if(index>20)\r
- continue;\r
-\r
- col = cs.findColour(ResidueProperties.aa[index].charAt(0));\r
-\r
- command.append("select "+res+";color["\r
- + col.getRed() + ","\r
- + col.getGreen() + ","\r
- + col.getBlue() + "];");\r
- }\r
-\r
- viewer.evalStringQuiet(command.toString());\r
- }\r
-\r
- public void userColour_actionPerformed(ActionEvent actionEvent)\r
- {\r
- new UserDefinedColours(this, null);\r
- }\r
-\r
- public void backGround_actionPerformed(ActionEvent actionEvent)\r
- {\r
- java.awt.Color col = JColorChooser.showDialog(this,\r
- "Select Background Colour",\r
- null);\r
-\r
- if (col != null)\r
- {\r
- viewer.evalStringQuiet("background ["\r
- + col.getRed() + ","\r
- + col.getGreen() + ","\r
- + col.getBlue() + "];");\r
- }\r
- }\r
-\r
-\r
- public void jmolHelp_actionPerformed(ActionEvent actionEvent)\r
- {\r
- try{\r
- jalview.util.BrowserLauncher.openURL(\r
- "http://jmol.sourceforge.net/docs/JmolUserGuide/");\r
- }catch(Exception ex){}\r
- }\r
-\r
-\r
- //////////////////////////////////\r
- ///StructureListener\r
- public String getPdbFile()\r
- {\r
- return pdbentry.getFile();\r
- }\r
-\r
- Pattern pattern = Pattern.compile(\r
- "\\[(.*)\\]([0-9]+)(:[a-zA-Z]*)?\\.([a-zA-Z]+)(/[0-9]*)?"\r
- );\r
-\r
- String lastMessage;\r
- public void mouseOverStructure(int atomIndex, String strInfo)\r
- {\r
- Matcher matcher = pattern.matcher(strInfo);\r
- matcher.find();\r
- matcher.group(1);\r
- int pdbResNum = Integer.parseInt(matcher.group(2));\r
- String chainId = matcher.group(3);\r
-\r
- if (chainId != null)\r
- chainId = chainId.substring(1, chainId.length());\r
- else\r
- {\r
- chainId = " ";\r
- }\r
-\r
- if (lastMessage == null || !lastMessage.equals(strInfo))\r
- ssm.mouseOverStructure(pdbResNum, chainId, pdbentry.getFile());\r
-\r
- lastMessage = strInfo;\r
- }\r
-\r
- StringBuffer resetLastRes = new StringBuffer();\r
- StringBuffer eval = new StringBuffer();\r
-\r
- public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)\r
- {\r
- if (!pdbfile.equals(pdbentry.getFile()))\r
- return;\r
-\r
- if (resetLastRes.length() > 0)\r
- {\r
- viewer.evalStringQuiet(resetLastRes.toString());\r
- }\r
-\r
- eval.setLength(0);\r
- eval.append("select " + pdbResNum);\r
-\r
- resetLastRes.setLength(0);\r
- resetLastRes.append("select " + pdbResNum);\r
-\r
- if (!chain.equals(" "))\r
- {\r
- eval.append(":" + chain);\r
- resetLastRes.append(":" + chain);\r
- }\r
-\r
- eval.append(";color gold;wireframe 100");\r
-\r
- Color col = new Color(viewer.getAtomArgb(atomIndex));\r
-\r
- resetLastRes.append(";color["\r
- + col.getRed() + ","\r
- + col.getGreen() + ","\r
- + col.getBlue() + "];wireframe 0");\r
-\r
- viewer.evalStringQuiet(eval.toString());\r
-\r
- }\r
-\r
- public void updateColours(Object source)\r
- {\r
- colourBySequence( (AlignmentPanel) source);\r
- }\r
-\r
-\r
-//End StructureListener\r
-////////////////////////////\r
-\r
- FeatureRenderer fr;\r
- public void colourBySequence(AlignmentPanel ap)\r
- {\r
- if(!colourBySequence)\r
- return;\r
-\r
-\r
- StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());\r
-\r
- if (mapping.length < 1)\r
- return;\r
-\r
- SequenceRenderer sr = ap.seqPanel.seqCanvas.getSequenceRenderer();\r
-\r
- boolean showFeatures = false;\r
- if (ap.av.showSequenceFeatures)\r
- {\r
- showFeatures = true;\r
- if (fr == null)\r
- {\r
- fr = new jalview.gui.FeatureRenderer(ap.av);\r
- }\r
-\r
- fr.transferSettings(ap.seqPanel.seqCanvas.getFeatureRenderer());\r
- }\r
-\r
- StringBuffer command = new StringBuffer();\r
-\r
- int lastPos = -1;\r
- for (int s = 0; s < sequence.length; s++)\r
- {\r
- for (int m = 0; m < mapping.length; m++)\r
- {\r
- if (mapping[m].getSequence() == sequence[s])\r
- {\r
- for (int r = 0; r < sequence[s].getLength(); r++)\r
- {\r
- int pos = mapping[m].getPDBResNum(\r
- sequence[s].findPosition(r));\r
-\r
- if (pos < 1 || pos==lastPos)\r
- continue;\r
-\r
- lastPos = pos;\r
-\r
- Color col = sr.getResidueBoxColour(sequence[s], r);\r
-\r
- if (showFeatures)\r
- col = fr.findFeatureColour(col, sequence[s], r);\r
-\r
- if (command.toString().endsWith(":" + mapping[m].getChain()+\r
- ";color["\r
- + col.getRed() + ","\r
- + col.getGreen() + ","\r
- + col.getBlue() + "]"))\r
- {\r
- command = condenseCommand(command, pos);\r
- continue;\r
- }\r
-\r
- command.append(";select " + pos);\r
-\r
- if (!mapping[m].getChain().equals(" "))\r
- {\r
- command.append(":" + mapping[m].getChain());\r
- }\r
-\r
- command.append(";color["\r
- + col.getRed() + ","\r
- + col.getGreen() + ","\r
- + col.getBlue() + "]");\r
-\r
- }\r
- break;\r
- }\r
- }\r
- }\r
-\r
- viewer.evalStringQuiet(command.toString());\r
- }\r
-\r
- StringBuffer condenseCommand(StringBuffer command, int pos)\r
- {\r
- StringBuffer sb = new StringBuffer(command.substring(0, command.lastIndexOf("select")+7));\r
-\r
- command.delete(0, sb.length());\r
-\r
- String start;\r
-\r
- if (command.indexOf("-") > -1)\r
- {\r
- start = command.substring(0,command.indexOf("-"));\r
- }\r
- else\r
- {\r
- start = command.substring(0, command.indexOf(":"));\r
- }\r
-\r
- sb.append(start+"-"+pos+command.substring(command.indexOf(":")));\r
-\r
- return sb;\r
- }\r
-\r
- /////////////////////////////////\r
- //JmolStatusListener\r
-\r
- public String eval(String strEval)\r
- {\r
- // System.out.println(strEval);\r
- //"# 'eval' is implemented only for the applet.";\r
- return null;\r
- }\r
-\r
- public void createImage(String file, String type, int quality)\r
- {\r
- System.out.println("JMOL CREATE IMAGE");\r
- }\r
-\r
- public void setCallbackFunction(String callbackType,\r
- String callbackFunction)\r
- {}\r
-\r
- public void notifyFileLoaded(String fullPathName, String fileName,\r
- String modelName, Object clientFile,\r
- String errorMsg)\r
- {\r
- if(errorMsg!=null)\r
- {\r
- fileLoadingError = errorMsg;\r
- repaint();\r
- return;\r
- }\r
-\r
- fileLoadingError = null;\r
-\r
- if (fileName != null)\r
- {\r
-\r
- //FILE LOADED OK\r
- ssm = StructureSelectionManager.getStructureSelectionManager();\r
- MCview.PDBfile pdbFile = ssm.setMapping(sequence, pdbentry.getFile(), AppletFormatAdapter.FILE);\r
- ssm.addStructureViewerListener(this);\r
-\r
- Vector chains = new Vector();\r
- for(int i=0; i<pdbFile.chains.size(); i++)\r
- {\r
- chains.addElement(((MCview.PDBChain)pdbFile.chains.elementAt(i)).id);\r
- }\r
- setChainMenuItems(chains);\r
-\r
- jmolpopup.updateComputedMenus();\r
-\r
- if(!loadingFromArchive)\r
- {\r
- viewer.evalStringQuiet(\r
- "select backbone;restrict;cartoon;wireframe off;spacefill off");\r
-\r
- colourBySequence(ap);\r
- }\r
-\r
- loadingFromArchive = false;\r
- }\r
- else\r
- return;\r
- }\r
-\r
- public void notifyFrameChanged(int frameNo)\r
- {\r
- boolean isAnimationRunning = (frameNo <= -2);\r
- }\r
-\r
- public void notifyScriptStart(String statusMessage, String additionalInfo)\r
- {}\r
-\r
- public void sendConsoleEcho(String strEcho)\r
- {\r
- if (scriptWindow != null)\r
- scriptWindow.sendConsoleEcho(strEcho);\r
- }\r
-\r
- public void sendConsoleMessage(String strStatus)\r
- {\r
- if (scriptWindow != null)\r
- scriptWindow.sendConsoleMessage(strStatus);\r
- }\r
-\r
- public void notifyScriptTermination(String strStatus, int msWalltime)\r
- {\r
- if (scriptWindow != null)\r
- scriptWindow.notifyScriptTermination(strStatus, msWalltime);\r
- }\r
-\r
- public void handlePopupMenu(int x, int y)\r
- {\r
- jmolpopup.show(x, y);\r
- }\r
-\r
- public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)\r
- {\r
- notifyAtomPicked(iatom, strMeasure);\r
- }\r
-\r
- public void notifyNewDefaultModeMeasurement(int count, String strInfo)\r
- {}\r
-\r
- public void notifyAtomPicked(int atomIndex, String strInfo)\r
- {\r
- if (scriptWindow != null)\r
- {\r
- scriptWindow.sendConsoleMessage(strInfo);\r
- scriptWindow.sendConsoleMessage("\n");\r
- }\r
- }\r
-\r
- public void notifyAtomHovered(int atomIndex, String strInfo)\r
- {\r
- mouseOverStructure(atomIndex, strInfo);\r
- }\r
-\r
- public void sendSyncScript(String script, String appletName)\r
- {}\r
-\r
- public void showUrl(String url)\r
- {}\r
-\r
- public void showConsole(boolean showConsole)\r
- {\r
- if (scriptWindow == null)\r
- scriptWindow = new ScriptWindow(this);\r
-\r
- if(showConsole)\r
- {\r
- if(splitPane==null)\r
- {\r
- splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);\r
- splitPane.setTopComponent(renderPanel);\r
- splitPane.setBottomComponent(scriptWindow);\r
- this.getContentPane().add(splitPane, BorderLayout.CENTER);\r
- }\r
-\r
- splitPane.setDividerLocation(getHeight()-200);\r
- splitPane.validate();\r
- }\r
- else\r
- {\r
- if (splitPane != null)\r
- splitPane.setVisible(false);\r
-\r
- splitPane = null;\r
-\r
- this.getContentPane().add(renderPanel, BorderLayout.CENTER);\r
- }\r
-\r
- validate();\r
- }\r
-\r
- public float functionXY(String functionName, int x, int y)\r
- {\r
- return 0;\r
- }\r
-\r
- ///End JmolStatusListener\r
- ///////////////////////////////\r
-\r
-\r
- class RenderPanel\r
- extends JPanel\r
- {\r
- final Dimension currentSize = new Dimension();\r
- final Rectangle rectClip = new Rectangle();\r
-\r
- public void paintComponent(Graphics g)\r
- {\r
- getSize(currentSize);\r
- g.getClipBounds(rectClip);\r
-\r
- if (viewer == null)\r
- {\r
- g.setColor(Color.black);\r
- g.fillRect(0, 0, currentSize.width, currentSize.height);\r
- g.setColor(Color.white);\r
- g.setFont(new Font("Verdana", Font.BOLD, 14));\r
- g.drawString("Retrieving PDB data....", 20, currentSize.height / 2);\r
- }\r
- else if(fileLoadingError!=null)\r
- {\r
- g.setColor(Color.black);\r
- g.fillRect(0, 0, currentSize.width, currentSize.height);\r
- g.setColor(Color.white);\r
- g.setFont(new Font("Verdana", Font.BOLD, 14));\r
- g.drawString("Error loading file..." + pdbentry.getId(), 20,\r
- currentSize.height / 2);\r
- }\r
- else\r
- {\r
- viewer.renderScreenImage(g, currentSize, rectClip);\r
- }\r
- }\r
- }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+package jalview.gui;
+
+import java.util.regex.*;
+import java.util.*;
+import java.awt.*;
+import javax.swing.*;
+import javax.swing.event.*;
+import java.awt.event.*;
+import java.io.*;
+
+import jalview.jbgui.GStructureViewer;
+import jalview.datamodel.*;
+import jalview.gui.*;
+import jalview.structure.*;
+import jalview.datamodel.PDBEntry;
+import jalview.io.*;
+import jalview.schemes.*;
+
+import org.jmol.api.*;
+import org.jmol.adapter.smarter.SmarterJmolAdapter;
+import org.jmol.popup.*;
+
+
+public class AppJMol
+ extends GStructureViewer
+ implements StructureListener, JmolStatusListener, Runnable
+
+{
+ JmolViewer viewer;
+ JmolPopup jmolpopup;
+ 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)
+ {
+ loadingFromArchive = true;
+ pdbentry = new PDBEntry();
+ pdbentry.setFile(file);
+ pdbentry.setId(id);
+ this.chains = chains;
+ this.sequence = seq;
+ this.ap = ap;
+ this.setBounds(bounds);
+
+ colourBySequence = false;
+ seqColour.setSelected(false);
+
+ jalview.gui.Desktop.addInternalFrame(this, "Loading File",
+ bounds.width,bounds.height);
+
+ initJmol(loadStatus);
+
+ this.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
+ {
+ closeViewer();
+ }
+ });
+ }
+
+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, AlignmentPanel ap)
+ {
+ //////////////////////////////////
+ //Is the pdb file already loaded?
+ String alreadyMapped = StructureSelectionManager
+ .getStructureSelectionManager()
+ .alreadyMappedToFile(pdbentry.getId());
+
+ if (alreadyMapped != null)
+ {
+ int option = JOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ pdbentry.getId() + " is already displayed."
+ + "\nDo you want to map sequences to the visible structure?",
+ "Map Sequences to Visible Window: " + pdbentry.getId(),
+ JOptionPane.YES_NO_OPTION);
+
+ if (option == JOptionPane.YES_OPTION)
+ {
+ StructureSelectionManager.getStructureSelectionManager()
+ .setMapping(seq, chains, alreadyMapped, AppletFormatAdapter.FILE);
+ if (ap.seqPanel.seqCanvas.fr!=null) {
+ ap.seqPanel.seqCanvas.fr.featuresAdded();
+ ap.paintAlignment(true);
+ }
+ return;
+ }
+ }
+ ///////////////////////////////////
+
+ this.ap = ap;
+ this.pdbentry = pdbentry;
+ this.sequence = seq;
+
+ jalview.gui.Desktop.addInternalFrame(this, "Loading File", 400, 400);
+
+ if (pdbentry.getFile() != null)
+ {
+ initJmol("load \""+pdbentry.getFile()+"\"");
+ }
+ else
+ {
+ Thread worker = new Thread(this);
+ worker.start();
+ }
+
+ this.addInternalFrameListener(new InternalFrameAdapter()
+ {
+ public void internalFrameClosing(InternalFrameEvent internalFrameEvent)
+ {
+ closeViewer();
+ }
+ });
+ }
+
+
+ void initJmol(String command)
+ {
+ renderPanel = new RenderPanel();
+
+ 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());
+
+ viewer = org.jmol.api.JmolViewer.allocateViewer(renderPanel,
+ new SmarterJmolAdapter());
+
+
+ viewer.setAppletContext("", null, null, "");
+
+ viewer.setJmolStatusListener(this);
+
+ jmolpopup = JmolPopup.newJmolPopup(viewer);
+
+ viewer.evalStringQuiet(command);
+ }
+
+
+ void setChainMenuItems(Vector chains)
+ {
+ chainMenu.removeAll();
+
+ JMenuItem menuItem = new JMenuItem("All");
+ menuItem.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent evt)
+ {
+ allChainsSelected = true;
+ for(int i=0; i<chainMenu.getItemCount(); i++)
+ {
+ if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
+ ( (JCheckBoxMenuItem) chainMenu.getItem(i)).setSelected(true);
+ }
+ centerViewer();
+ allChainsSelected = false;
+ }
+ });
+
+ chainMenu.add(menuItem);
+
+ for (int c = 0; c < chains.size(); c++)
+ {
+ menuItem = new JCheckBoxMenuItem(chains.elementAt(c).toString(), true);
+ menuItem.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent evt)
+ {
+ if (!allChainsSelected)
+ centerViewer();
+ }
+ });
+
+ chainMenu.add(menuItem);
+ }
+ }
+
+ boolean allChainsSelected = false;
+ void centerViewer()
+ {
+ StringBuffer cmd = new StringBuffer();
+ for(int i=0; i<chainMenu.getItemCount(); i++)
+ {
+ if (chainMenu.getItem(i) instanceof JCheckBoxMenuItem)
+ {
+ JCheckBoxMenuItem item = (JCheckBoxMenuItem) chainMenu.getItem(i);
+ if(item.isSelected())
+ cmd.append(":"+item.getText()+" or ");
+ }
+ }
+
+ if (cmd.length() > 0)
+ cmd.setLength(cmd.length() - 4);
+
+ viewer.evalStringQuiet("select *;restrict "
+ +cmd+";cartoon;center "+cmd);
+ }
+
+ void closeViewer()
+ {
+ viewer.setModeMouse(org.jmol.viewer.JmolConstants.MOUSE_NONE);
+ viewer.evalStringQuiet("zap");
+ viewer.setJmolStatusListener(null);
+ viewer = null;
+
+ //We'll need to find out what other
+ // listeners need to be shut down in Jmol
+ StructureSelectionManager
+ .getStructureSelectionManager()
+ .removeStructureViewerListener(this, pdbentry.getFile());
+ }
+
+ public void run()
+ {
+ try
+ {
+ EBIFetchClient ebi = new EBIFetchClient();
+ String query = "pdb:" + pdbentry.getId();
+ pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
+ .getAbsolutePath());
+ initJmol("load "+pdbentry.getFile());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void pdbFile_actionPerformed(ActionEvent actionEvent)
+ {
+ JalviewFileChooser chooser = new JalviewFileChooser(
+ jalview.bin.Cache.getProperty(
+ "LAST_DIRECTORY"));
+
+ chooser.setFileView(new JalviewFileView());
+ chooser.setDialogTitle("Save PDB File");
+ chooser.setToolTipText("Save");
+
+ int value = chooser.showSaveDialog(this);
+
+ if (value == JalviewFileChooser.APPROVE_OPTION)
+ {
+ try
+ {
+ BufferedReader in = new BufferedReader(new FileReader(pdbentry.getFile()));
+ File outFile = chooser.getSelectedFile();
+
+ PrintWriter out = new PrintWriter(new FileOutputStream(outFile));
+ String data;
+ while ( (data = in.readLine()) != null)
+ {
+ if (
+ ! (data.indexOf("<PRE>") > -1 || data.indexOf("</PRE>") > -1)
+ )
+ {
+ out.println(data);
+ }
+ }
+ out.close();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public void viewMapping_actionPerformed(ActionEvent actionEvent)
+ {
+ 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())
+ );
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void eps_actionPerformed(ActionEvent e)
+ {
+ makePDBImage(jalview.util.ImageMaker.EPS);
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void png_actionPerformed(ActionEvent e)
+ {
+ makePDBImage(jalview.util.ImageMaker.PNG);
+ }
+
+ void makePDBImage(int type)
+ {
+ int width = getWidth();
+ int height = getHeight();
+
+ jalview.util.ImageMaker im;
+
+ if (type == jalview.util.ImageMaker.PNG)
+ {
+ im = new jalview.util.ImageMaker(this,
+ jalview.util.ImageMaker.PNG,
+ "Make PNG image from view",
+ width, height,
+ null, null);
+ }
+ else
+ {
+ im = new jalview.util.ImageMaker(this,
+ jalview.util.ImageMaker.EPS,
+ "Make EPS file from view",
+ width, height,
+ null, this.getTitle());
+ }
+
+ if (im.getGraphics() != null)
+ {
+ Rectangle rect = new Rectangle(width, height);
+ viewer.renderScreenImage(im.getGraphics(),
+ rect.getSize(), rect);
+ im.writeImage();
+ }
+ }
+
+
+ public void seqColour_actionPerformed(ActionEvent actionEvent)
+ {
+ colourBySequence = seqColour.isSelected();
+ colourBySequence(ap);
+ }
+
+ public void chainColour_actionPerformed(ActionEvent actionEvent)
+ {
+ colourBySequence = false;
+ seqColour.setSelected(false);
+ viewer.evalStringQuiet("select *;color chain");
+ }
+
+ public void chargeColour_actionPerformed(ActionEvent actionEvent)
+ {
+ colourBySequence = false;
+ seqColour.setSelected(false);
+ viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;"
+ +"select LYS,ARG;color blue;select CYS;color yellow");
+ }
+
+ public void zappoColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new ZappoColourScheme());
+ }
+
+ public void taylorColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new TaylorColourScheme());
+ }
+
+ public void hydroColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new HydrophobicColourScheme());
+ }
+
+ public void helixColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new HelixColourScheme());
+ }
+
+ public void strandColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new StrandColourScheme());
+ }
+
+ public void turnColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new TurnColourScheme());
+ }
+
+ public void buriedColour_actionPerformed(ActionEvent actionEvent)
+ {
+ setJalviewColourScheme(new BuriedColourScheme());
+ }
+
+ public void setJalviewColourScheme(ColourSchemeI cs)
+ {
+ 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());
+ }
+
+ public void userColour_actionPerformed(ActionEvent actionEvent)
+ {
+ new UserDefinedColours(this, null);
+ }
+
+ public void backGround_actionPerformed(ActionEvent actionEvent)
+ {
+ java.awt.Color col = JColorChooser.showDialog(this,
+ "Select Background Colour",
+ null);
+
+ if (col != null)
+ {
+ viewer.evalStringQuiet("background ["
+ + col.getRed() + ","
+ + col.getGreen() + ","
+ + col.getBlue() + "];");
+ }
+ }
+
+
+ public void jmolHelp_actionPerformed(ActionEvent actionEvent)
+ {
+ try{
+ jalview.util.BrowserLauncher.openURL(
+ "http://jmol.sourceforge.net/docs/JmolUserGuide/");
+ }catch(Exception ex){}
+ }
+
+
+ //////////////////////////////////
+ ///StructureListener
+ public String getPdbFile()
+ {
+ return pdbentry.getFile();
+ }
+
+ Pattern pattern = Pattern.compile(
+ "\\[(.*)\\]([0-9]+)(:[a-zA-Z]*)?\\.([a-zA-Z]+)(/[0-9]*)?"
+ );
+
+ String lastMessage;
+ public void mouseOverStructure(int atomIndex, String strInfo)
+ {
+ 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 = " ";
+ }
+
+ if (lastMessage == null || !lastMessage.equals(strInfo))
+ ssm.mouseOverStructure(pdbResNum, chainId, pdbentry.getFile());
+
+ lastMessage = strInfo;
+ }
+
+ StringBuffer resetLastRes = new StringBuffer();
+ StringBuffer eval = new StringBuffer();
+
+ public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)
+ {
+ if (!pdbfile.equals(pdbentry.getFile()))
+ return;
+
+ if (resetLastRes.length() > 0)
+ {
+ viewer.evalStringQuiet(resetLastRes.toString());
+ }
+
+ eval.setLength(0);
+ eval.append("select " + pdbResNum);
+
+ resetLastRes.setLength(0);
+ resetLastRes.append("select " + pdbResNum);
+
+ if (!chain.equals(" "))
+ {
+ eval.append(":" + chain);
+ resetLastRes.append(":" + chain);
+ }
+
+ eval.append(";color gold;wireframe 100");
+
+ Color col = new Color(viewer.getAtomArgb(atomIndex));
+
+ resetLastRes.append(";color["
+ + col.getRed() + ","
+ + col.getGreen() + ","
+ + col.getBlue() + "];wireframe 0");
+
+ viewer.evalStringQuiet(eval.toString());
+
+ }
+
+ 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
+////////////////////////////
+
+ FeatureRenderer fr=null;
+ public void colourBySequence(AlignmentPanel ap)
+ {
+ if(!colourBySequence)
+ return;
+
+
+ StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
+
+ if (mapping.length < 1)
+ return;
+
+ SequenceRenderer sr = ap.seqPanel.seqCanvas.getSequenceRenderer();
+
+ 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();
+
+ int lastPos = -1;
+ for (int s = 0; s < sequence.length; s++)
+ {
+ for (int m = 0; m < mapping.length; m++)
+ {
+ if (mapping[m].getSequence() == sequence[s]
+ && ap.av.alignment.findIndex(sequence[s])>-1)
+ {
+ for (int r = 0; r < sequence[s].getLength(); r++)
+ {
+ int pos = mapping[m].getPDBResNum(
+ sequence[s].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);
+
+ if (command.toString().endsWith(":" + mapping[m].getChain()+
+ ";color["
+ + col.getRed() + ","
+ + col.getGreen() + ","
+ + col.getBlue() + "]"))
+ {
+ command = condenseCommand(command, pos);
+ continue;
+ }
+
+ command.append(";select " + pos);
+
+ if (!mapping[m].getChain().equals(" "))
+ {
+ command.append(":" + mapping[m].getChain());
+ }
+
+ command.append(";color["
+ + col.getRed() + ","
+ + col.getGreen() + ","
+ + col.getBlue() + "]");
+
+ }
+ break;
+ }
+ }
+ }
+
+ viewer.evalStringQuiet(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 setCallbackFunction(String callbackType,
+ String callbackFunction)
+ {}
+
+ public void notifyFileLoaded(String fullPathName, String fileName,
+ String modelName, Object clientFile,
+ String errorMsg)
+ {
+ if(errorMsg!=null)
+ {
+ fileLoadingError = errorMsg;
+ repaint();
+ return;
+ }
+
+ fileLoadingError = null;
+
+ if (fileName != null)
+ {
+
+ //FILE LOADED OK
+ ssm = StructureSelectionManager.getStructureSelectionManager();
+ MCview.PDBfile pdbFile = ssm.setMapping(sequence,chains,pdbentry.getFile(), AppletFormatAdapter.FILE);
+ ssm.addStructureViewerListener(this);
+ Vector chains = new Vector();
+ for(int i=0; i<pdbFile.chains.size(); i++)
+ {
+ chains.addElement(((MCview.PDBChain)pdbFile.chains.elementAt(i)).id);
+ }
+ setChainMenuItems(chains);
+
+ jmolpopup.updateComputedMenus();
+
+ if(!loadingFromArchive)
+ {
+ viewer.evalStringQuiet(
+ "select backbone;restrict;cartoon;wireframe off;spacefill off");
+
+ colourBySequence(ap);
+ }
+ if (fr!=null)
+ fr.featuresAdded();
+
+ loadingFromArchive = false;
+ }
+ else
+ return;
+ }
+
+ public void notifyFrameChanged(int frameNo)
+ {
+ boolean isAnimationRunning = (frameNo <= -2);
+ }
+
+ public void notifyScriptStart(String statusMessage, String additionalInfo)
+ {}
+
+ 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);
+ }
+
+ public void notifyNewDefaultModeMeasurement(int count, String strInfo)
+ {}
+
+ public void notifyAtomPicked(int atomIndex, String strInfo)
+ {
+ 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()));
+
+ picked+=".C";
+
+ if (!atomsPicked.contains(picked))
+ {
+ 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);
+ }
+
+ if (scriptWindow != null)
+ {
+ scriptWindow.sendConsoleMessage(strInfo);
+ scriptWindow.sendConsoleMessage("\n");
+ }
+ }
+
+ public void notifyAtomHovered(int atomIndex, String strInfo)
+ {
+ mouseOverStructure(atomIndex, strInfo);
+ }
+
+ public void sendSyncScript(String script, String appletName)
+ {}
+
+ public void showUrl(String url)
+ {}
+
+ public void showConsole(boolean showConsole)
+ {
+ if (scriptWindow == null)
+ scriptWindow = new ScriptWindow(this);
+
+ if(showConsole)
+ {
+ if(splitPane==null)
+ {
+ splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+ splitPane.setTopComponent(renderPanel);
+ splitPane.setBottomComponent(scriptWindow);
+ this.getContentPane().add(splitPane, BorderLayout.CENTER);
+ }
+
+ splitPane.setDividerLocation(getHeight()-200);
+ splitPane.validate();
+ }
+ else
+ {
+ if (splitPane != null)
+ splitPane.setVisible(false);
+
+ splitPane = null;
+
+ this.getContentPane().add(renderPanel, BorderLayout.CENTER);
+ }
+
+ validate();
+ }
+
+ public float functionXY(String functionName, int x, int y)
+ {
+ return 0;
+ }
+
+ ///End JmolStatusListener
+ ///////////////////////////////
+
+
+ class RenderPanel
+ extends JPanel
+ {
+ final Dimension currentSize = new Dimension();
+ final Rectangle rectClip = new Rectangle();
+
+ public void paintComponent(Graphics g)
+ {
+ 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)
+ {
+ 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,
+ currentSize.height / 2);
+ }
+ else
+ {
+ viewer.renderScreenImage(g, currentSize, rectClip);
+ }
+ }
+ }
+
+}