From ddf5e62ae51206236ead85fb2ab6bcf868b48e7e Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Mon, 26 Mar 2007 17:28:56 +0000 Subject: [PATCH] Jalview colour schemes added --- src/jalview/appletgui/AppletJmol.java | 207 ++++++++++++++++++++++++++++++--- 1 file changed, 190 insertions(+), 17 deletions(-) diff --git a/src/jalview/appletgui/AppletJmol.java b/src/jalview/appletgui/AppletJmol.java index 9ff3078..82dab26 100644 --- a/src/jalview/appletgui/AppletJmol.java +++ b/src/jalview/appletgui/AppletJmol.java @@ -30,6 +30,7 @@ import jalview.io.*; import org.jmol.api.*; import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.popup.*; +import jalview.schemes.*; public class AppletJmol extends Frame @@ -39,9 +40,25 @@ public class AppletJmol extends Frame { Menu fileMenu = new Menu("File"); Menu viewMenu = new Menu("View"); + Menu coloursMenu = new Menu("Colours"); Menu chainMenu = new Menu("Show Chain"); + Menu helpMenu = new Menu("Help"); MenuItem mappingMenuItem = new MenuItem("View Mapping"); + CheckboxMenuItem seqColour = new CheckboxMenuItem("By Sequence", true); + MenuItem chain = new MenuItem("By Chain"); + MenuItem charge = new MenuItem("Charge & Cysteine"); + MenuItem zappo = new MenuItem("Zappo"); + MenuItem taylor = new MenuItem("Taylor"); + MenuItem hydro = new MenuItem("Hydrophobicity"); + MenuItem helix = new MenuItem("Helix Propensity"); + MenuItem strand = new MenuItem("Strand Propensity"); + MenuItem turn = new MenuItem("Turn Propensity"); + MenuItem buried = new MenuItem("Buried Index"); + MenuItem user = new MenuItem("User Defined Colours"); + + MenuItem jmolHelp = new MenuItem("Jmol Help"); + JmolViewer viewer; JmolPopup jmolpopup; @@ -56,6 +73,7 @@ public class AppletJmol extends Frame boolean loadedInline; PDBEntry pdbentry; boolean colourBySequence = true; + Vector atomsPicked = new Vector(); public AppletJmol(PDBEntry pdbentry, SequenceI[] seq, @@ -106,6 +124,37 @@ public class AppletJmol extends Frame menuBar.add(viewMenu); mappingMenuItem.addActionListener(this); viewMenu.add(chainMenu); + menuBar.add(coloursMenu); + menuBar.add(helpMenu); + + charge.addActionListener(this); + hydro.addActionListener(this); + chain.addActionListener(this); + seqColour.addItemListener(this); + zappo.addActionListener(this); + taylor.addActionListener(this); + helix.addActionListener(this); + strand.addActionListener(this); + turn.addActionListener(this); + buried.addActionListener(this); + user.addActionListener(this); + + jmolHelp.addActionListener(this); + + coloursMenu.add(seqColour); + coloursMenu.add(chain); + coloursMenu.add(charge); + coloursMenu.add(zappo); + coloursMenu.add(taylor); + coloursMenu.add(hydro); + coloursMenu.add(helix); + coloursMenu.add(strand); + coloursMenu.add(turn); + coloursMenu.add(buried); + coloursMenu.add(user); + + helpMenu.add(jmolHelp); + this.setMenuBar(menuBar); if(pdbentry.getFile()!=null) @@ -200,6 +249,60 @@ public class AppletJmol extends Frame pdbentry.getFile()) ); } + else if (evt.getSource() == charge) + { + colourBySequence = false; + seqColour.setState(false); + viewer.evalStringQuiet("select *;color white;select ASP,GLU;color red;" + +"select LYS,ARG;color blue;select CYS;color yellow"); + } + + else if (evt.getSource() == chain) + { + colourBySequence = false; + seqColour.setState(false); + viewer.evalStringQuiet("select *;color chain"); + } + else if (evt.getSource() == zappo) + { + setJalviewColourScheme(new ZappoColourScheme()); + } + else if (evt.getSource() == taylor) + { + setJalviewColourScheme(new TaylorColourScheme()); + } + else if (evt.getSource() == hydro) + { + setJalviewColourScheme(new HydrophobicColourScheme()); + } + else if (evt.getSource() == helix) + { + setJalviewColourScheme(new HelixColourScheme()); + } + else if (evt.getSource() == strand) + { + setJalviewColourScheme(new StrandColourScheme()); + } + else if (evt.getSource() == turn) + { + setJalviewColourScheme(new TurnColourScheme()); + } + else if (evt.getSource() == buried) + { + setJalviewColourScheme(new BuriedColourScheme()); + } + else if (evt.getSource() == user) + { + new UserDefinedColours(this); + } + else if(evt.getSource() == jmolHelp) + { + try{ + ap.av.applet.getAppletContext().showDocument( + new java.net.URL("http://jmol.sourceforge.net/docs/JmolUserGuide/"), + "jmolHelp"); + }catch(java.net.MalformedURLException ex){} + } else { allChainsSelected = true; @@ -213,9 +316,46 @@ public class AppletJmol extends Frame } } + public void setJalviewColourScheme(ColourSchemeI cs) + { + colourBySequence = false; + seqColour.setState(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 itemStateChanged(ItemEvent evt) { - if (!allChainsSelected) + if (evt.getSource() == seqColour) + { + colourBySequence = seqColour.getState(); + colourBySequence(ap); + } + else if (!allChainsSelected) centerViewer(); } @@ -248,14 +388,21 @@ public class AppletJmol extends Frame String lastMessage; public void mouseOverStructure(int atomIndex, String strInfo) { - int pdbResNum = Integer.parseInt( - strInfo.substring(strInfo.indexOf("]")+ 1, strInfo.indexOf(":"))); + int pdbResNum; + + int chainSeparator = strInfo.indexOf(":"); - String chainId = strInfo.substring - (strInfo.indexOf(":"), strInfo.indexOf(".")); + if(chainSeparator==-1) + chainSeparator = strInfo.indexOf("."); - if (chainId != null) - chainId = chainId.substring(1, chainId.length()); + 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 = " "; @@ -518,8 +665,10 @@ public class AppletJmol extends Frame public void sendConsoleEcho(String strEcho) { - // if (scriptWindow != null) - // scriptWindow.sendConsoleEcho(strEcho); + if (scriptWindow == null) + showConsole(true); + + history.append("\n"+strEcho); } public void sendConsoleMessage(String strStatus) @@ -532,10 +681,7 @@ public class AppletJmol extends Frame } public void notifyScriptTermination(String strStatus, int msWalltime) - { - // if (scriptWindow != null) - // scriptWindow.notifyScriptTermination(strStatus, msWalltime); - } + { } public void handlePopupMenu(int x, int y) { @@ -552,10 +698,31 @@ public class AppletJmol extends Frame public void notifyAtomPicked(int atomIndex, String strInfo) { - // if (scriptWindow != null) + + int chainSeparator = strInfo.indexOf(":"); + + if(chainSeparator==-1) + chainSeparator = strInfo.indexOf("."); + + String picked = + strInfo.substring(strInfo.indexOf("]")+ 1, chainSeparator); + + + if (strInfo.indexOf(":") > -1) + picked+=strInfo.substring(strInfo.indexOf(":")+1, + strInfo.indexOf(".")); + + picked+=".C"; + + if (!atomsPicked.contains(picked)) + { + viewer.evalString("select "+picked+";label %n %r:%c"); + atomsPicked.addElement(picked); + } + else { - // scriptWindow.sendConsoleMessage(strInfo); - // scriptWindow.sendConsoleMessage("\n"); + viewer.evalString("select "+picked+";label off"); + atomsPicked.removeElement(picked); } } @@ -568,7 +735,13 @@ public class AppletJmol extends Frame {} public void showUrl(String url) - {} + { + try{ + ap.av.applet.getAppletContext().showDocument(new java.net.URL(url), + "jmolOutput"); + }catch(java.net.MalformedURLException ex) + {} + } public void showConsole(boolean showConsole) { -- 1.7.10.2