From ce89ec35928a6cb2f05a655c44c39a0249beb2d6 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 5 Jul 2011 12:10:28 +0100 Subject: [PATCH] refactor to send list of model filenames involved in each set of Jmol commands so they can be sent to the correct Jmol. (JAL-816, JAL-621, JAL-862) --- src/jalview/ext/jmol/JalviewJmolBinding.java | 3 +- src/jalview/ext/jmol/JmolCommands.java | 31 ++++++++++------- .../javascript/MouseOverStructureListener.java | 36 +++++++++++++++----- .../structure/StructureMappingcommandSet.java | 34 ++++++++++++++++++ 4 files changed, 82 insertions(+), 22 deletions(-) create mode 100644 src/jalview/structure/StructureMappingcommandSet.java diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 6747349..da514a2 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -570,7 +570,8 @@ public abstract class JalviewJmolBinding implements StructureListener, } AlignmentI alignment = alignmentv.getAlignment(); - for (String cbyseq : JmolCommands.getColourBySequenceCommand(ssm, files, sequence, sr, fr, alignment)) { + for (jalview.structure.StructureMappingcommandSet cpdbbyseq: JmolCommands.getColourBySequenceCommand(ssm, files, sequence, sr, fr, alignment)) + for (String cbyseq : cpdbbyseq.commands) { evalStateCommand(cbyseq); } } diff --git a/src/jalview/ext/jmol/JmolCommands.java b/src/jalview/ext/jmol/JmolCommands.java index 9d01eab..bfb2766 100644 --- a/src/jalview/ext/jmol/JmolCommands.java +++ b/src/jalview/ext/jmol/JmolCommands.java @@ -8,12 +8,12 @@ import jalview.api.SequenceRenderer; import jalview.datamodel.AlignmentI; import jalview.datamodel.SequenceI; import jalview.structure.StructureMapping; +import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; import jalview.util.Comparison; import java.awt.Color; import java.util.ArrayList; - /** * Routines for generating Jmol commands for Jalview/Jmol binding * another cruisecontrol test. @@ -26,20 +26,24 @@ public class JmolCommands /** * Jmol utility which constructs the commands to colour chains by the given alignment + * @returns Object[] { Object[] { , * */ - public static String[] getColourBySequenceCommand(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment) + public static StructureMappingcommandSet[] getColourBySequenceCommand(StructureSelectionManager ssm, String[] files, SequenceI[][] sequence, SequenceRenderer sr, FeatureRenderer fr, AlignmentI alignment) { - ArrayList str = new ArrayList(); - StringBuffer command = new StringBuffer(); - + + ArrayList cset = new ArrayList(); + for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) { StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); + StringBuffer command = new StringBuffer(); + StructureMappingcommandSet smc; + ArrayList str = new ArrayList(); if (mapping == null || mapping.length < 1) continue; - + int lastPos = -1; for (int s = 0; s < sequence[pdbfnum].length; s++) { @@ -100,13 +104,16 @@ public class JmolCommands } } } + { + // add final chunk + str.add(command.toString()); + command.setLength(0); + } + // Finally, add the command set ready to be returned. + cset.add(new StructureMappingcommandSet(JmolCommands.class,files[pdbfnum], str.toArray(new String[str.size()]))); + } - { - // add final chunk - str.add(command.toString()); - command.setLength(0); - } - return str.toArray(new String[str.size()]); + return cset.toArray(new StructureMappingcommandSet[cset.size()]); } public static StringBuffer condenseCommand(StringBuffer command, int pos) diff --git a/src/jalview/javascript/MouseOverStructureListener.java b/src/jalview/javascript/MouseOverStructureListener.java index 41af88e..085e50d 100644 --- a/src/jalview/javascript/MouseOverStructureListener.java +++ b/src/jalview/javascript/MouseOverStructureListener.java @@ -1,6 +1,8 @@ package jalview.javascript; import java.awt.Color; +import java.util.ArrayList; + import jalview.api.AlignmentViewPanel; import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; @@ -10,6 +12,7 @@ import jalview.datamodel.SequenceI; import jalview.ext.jmol.JmolCommands; import jalview.structure.StructureListener; import jalview.structure.StructureMapping; +import jalview.structure.StructureMappingcommandSet; import jalview.structure.StructureSelectionManager; /** @@ -179,26 +182,41 @@ public class MouseOverStructureListener extends JSFunctionExec implements } ; - // Form a colour command for the given alignment panel - final String[] colcommands = JmolCommands.getColourBySequenceCommand( + + // Form a colour command from the given alignment panel for each distinct structure + ArrayList ccomands=new ArrayList(); + ArrayList pdbfn=new ArrayList(); + StructureMappingcommandSet[] colcommands=JmolCommands.getColourBySequenceCommand( ssm, modelSet, sequence, sr, fr, ((AlignmentViewPanel) source).getAlignment()); - if (colcommands==null) - { - // + if (colcommands==null) { return; } + int sz=0; + for (jalview.structure.StructureMappingcommandSet ccset: colcommands) { + sz+=ccset.commands.length; + ccomands.add(ccset.commands); + pdbfn.add(ccset.mapping); + } + String mclass,mhandle; + String ccomandset[] = new String[sz]; + sz=0; + for (String[] ccset: ccomands) { + System.arraycopy(ccset, 0, ccomandset, sz, ccset.length); + sz+=ccset.length; + } if (jvlite.isJsMessageSetChanged(mclass="colourstruct",mhandle=((jalview.appletgui.AlignmentPanel) source).av - .getViewId(), colcommands)) { - jvlite.setJsMessageSet(mclass, mhandle , colcommands); + .getViewId(), ccomandset)) { + jvlite.setJsMessageSet(mclass, mhandle , ccomandset); // and notify javascript handler String st[] = new String[] { "colourstruct", "" + ((jalview.appletgui.AlignmentPanel) source).av - .getViewId(), ""+colcommands.length, ""+(colcommands[0]!=null ? colcommands[0].length() : 0)}; + .getViewId(), ""+ccomandset.length, jvlite.arrayToSeparatorList(pdbfn.toArray(new String[pdbfn.size()])) + }; try { executeJavascriptFunction( @@ -209,7 +227,7 @@ public class MouseOverStructureListener extends JSFunctionExec implements { System.err.println("Couldn't execute callback with " + _listenerfn + " using args { " + st[0] + ", " - + st[1] + ", " + st[2] + "," + st[3] + "\n"); + + st[1] + ", " + st[2] + "," + st[3]+"}"); // + ","+st[4]+"\n"); ex.printStackTrace(); } diff --git a/src/jalview/structure/StructureMappingcommandSet.java b/src/jalview/structure/StructureMappingcommandSet.java new file mode 100644 index 0000000..5bf6e57 --- /dev/null +++ b/src/jalview/structure/StructureMappingcommandSet.java @@ -0,0 +1,34 @@ +package jalview.structure; + + +/** + * holder for script commands generated for a particular structure mapping + * @author jimp + * + */ +public class StructureMappingcommandSet { + /** + * structure file for which these commands were generated + */ + public String mapping; + /** + * set of commands + */ + public String[] commands; + /** + * some object that indicates what the commands can be parsed by (eg JmolCommands.class implies these are Jmol commands) + */ + public Object handledBy; + /** + * record the originating command generator, the structure mapping involved, and the set of commands to be passed. + * @param handledBy + * @param files + * @param commands + */ + public StructureMappingcommandSet(Object handledBy, String files, String[] commands) + { + this.mapping=files; + this.handledBy=handledBy; + this.commands=commands; + } +} -- 1.7.10.2