From: j.procter@dundee.ac.uk Date: Fri, 18 Jul 2014 12:35:06 +0000 (+0100) Subject: JAL-1333 more refinements - deadlocks still possible with this version X-Git-Tag: Jalview_2_9~179^2~4 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d5e0347a23e42cc177aad275819df0fdd7e21a8f;p=jalview.git JAL-1333 more refinements - deadlocks still possible with this version --- diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java index a82a6fb..95ea0d7 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java @@ -627,7 +627,7 @@ public class ChimeraManager } return values; } - + private volatile boolean busy=false; /** * Send a command to Chimera. * @@ -645,7 +645,13 @@ public class ChimeraManager { return null; } - + while (busy) + { + try { + Thread.sleep(25); + } catch (InterruptedException q) {}; + } + busy=true; chimeraListenerThreads.clearResponse(command); String text = command.concat("\n"); // System.out.println("send command to chimera: " + text); @@ -661,13 +667,17 @@ public class ChimeraManager logger.warn("Unable to execute command: " + text); logger.warn("Exiting..."); clearOnChimeraExit(); + busy=false; return null; } if (!reply) { + busy=false; return null; } - return chimeraListenerThreads.getResponse(command); + List rsp = chimeraListenerThreads.getResponse(command); + busy=false; + return rsp; } public StructureManager getStructureManager() diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/port/ListenerThreads.java b/src/ext/edu/ucsf/rbvi/strucviz2/port/ListenerThreads.java index 8391e49..dee027b 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/port/ListenerThreads.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/port/ListenerThreads.java @@ -186,7 +186,8 @@ public class ListenerThreads extends Thread { public void run() { try { -// structureManager.chimeraSelectionChanged(); + logger.info("Responding to chimera selection"); + structureManager.chimeraSelectionChanged(); } catch (Exception e) { logger.warn("Could not update selection", e); } diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index 7e72d8f..5fc3a6f 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -164,7 +164,7 @@ public abstract class JalviewChimeraBinding extends chimmaps.put(file, newList); for (ChimeraModel cm : newList) { - while (mdlToFile.size()<1+cm.getModelNumber()) + while (mdlToFile.size() < 1 + cm.getModelNumber()) { mdlToFile.add(new String("")); } @@ -444,23 +444,8 @@ public abstract class JalviewChimeraBinding extends .println("RUNTIME PROBLEM: Jmol seems to be taking a long time to process all the structures."); return; } + refreshPdbEntries(); StringBuffer selectioncom = new StringBuffer(); - // In principle - nSeconds specifies the speed of animation for each - // superposition - but is seems to behave weirdly, so we don't specify it. - String nSeconds = " "; - if (files.length > 10) - { - nSeconds = " 0.00001 "; - } - else - { - nSeconds = " " + (2.0 / files.length) + " "; - // if (nSeconds).substring(0,5)+" "; - } - // see JAL-1345 - should really automatically turn off the animation for - // large numbers of structures, but Jmol doesn't seem to allow that. - nSeconds = " "; - // union of all aligned positions are collected together. for (int a = 0; a < _alignment.length; a++) { int refStructure = _refStructure[a]; @@ -469,9 +454,9 @@ public abstract class JalviewChimeraBinding extends if (a > 0 && selectioncom.length() > 0 && !selectioncom.substring(selectioncom.length() - 1).equals( - "|")) + " ")) { - selectioncom.append("|"); + selectioncom.append(" "); } // process this alignment if (refStructure >= files.length) @@ -506,7 +491,7 @@ public abstract class JalviewChimeraBinding extends if (mapping == null || mapping.length < 1) { throw new Error( - "Implementation error - Jmol seems to be still working on getting its data - report at http://issues.jalview.org/browse/JAL-1016"); + "Implementation error - Chimera seems to be still working on getting its data - report at http://issues.jalview.org/browse/JAL-1016"); } int lastPos = -1; for (int s = 0; s < sequence[pdbfnum].length; s++) @@ -553,7 +538,7 @@ public abstract class JalviewChimeraBinding extends commonrpositions[pdbfnum][r] = pos; } // create model selection suffix - isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1"; + isel[pdbfnum] = "#" + pdbfnum; if (mapping[m].getChain() == null || mapping[m].getChain().trim().length() == 0) { @@ -561,7 +546,7 @@ public abstract class JalviewChimeraBinding extends } else { - targetC[pdbfnum] = ":" + mapping[m].getChain(); + targetC[pdbfnum] = "." + mapping[m].getChain(); } chainNames[pdbfnum] = mapping[m].getPdbId() + targetC[pdbfnum]; @@ -581,6 +566,7 @@ public abstract class JalviewChimeraBinding extends String[] selcom = new String[files.length]; int nmatched = 0; + String sep = ""; // generate select statements to select regions to superimpose structures { for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) @@ -589,7 +575,6 @@ public abstract class JalviewChimeraBinding extends int lpos = -1; boolean run = false; StringBuffer molsel = new StringBuffer(); - molsel.append("{"); for (int r = 0; r < matched.length; r++) { if (matched[r]) @@ -603,10 +588,10 @@ public abstract class JalviewChimeraBinding extends // discontinuity if (lpos != -1) { - molsel.append(lpos); + molsel.append((run ? "" : ":") + lpos); molsel.append(chainCd); // molsel.append("} {"); - molsel.append("|"); + // molsel.append(","); } } else @@ -615,7 +600,7 @@ public abstract class JalviewChimeraBinding extends if (!run) { // at the beginning, so add dash - molsel.append(lpos); + molsel.append(":" + lpos); molsel.append("-"); } run = true; @@ -627,19 +612,17 @@ public abstract class JalviewChimeraBinding extends // add final selection phrase if (lpos != -1) { - molsel.append(lpos); + molsel.append((run ? "" : ":") + lpos); molsel.append(chainCd); - molsel.append("}"); + // molsel.append(""); } if (molsel.length() > 1) { selcom[pdbfnum] = molsel.toString(); - selectioncom.append("(("); + selectioncom.append("#" + pdbfnum); selectioncom.append(selcom[pdbfnum].substring(1, selcom[pdbfnum].length() - 1)); - selectioncom.append(" )& "); - selectioncom.append(pdbfnum + 1); - selectioncom.append(".1)"); + selectioncom.append(" "); if (pdbfnum < files.length - 1) { selectioncom.append("|"); @@ -658,31 +641,19 @@ public abstract class JalviewChimeraBinding extends { continue; } - command.append("echo "); - command.append("\"Superposing ("); - command.append(chainNames[pdbfnum]); - command.append(") against reference ("); - command.append(chainNames[refStructure]); - command.append(")\";\ncompare " + nSeconds); - command.append("{"); - command.append(1 + pdbfnum); - command.append(".1} {"); - command.append(1 + refStructure); - command.append(".1} SUBSET {*.CA | *.P} ATOMS "); + command.append("match "); // form the matched pair strings - String sep = ""; for (int s = 0; s < 2; s++) { command.append(selcom[(s == 0 ? pdbfnum : refStructure)]); } - command.append(" ROTATE TRANSLATE;\n"); } if (selectioncom.length() > 0) { System.out.println("Select regions:\n" + selectioncom.toString()); - evalStateCommand("select *; cartoons off; backbone; select (" - + selectioncom.toString() + "); cartoons; "); + evalStateCommand("~display *; trace *; ribbons " + + selectioncom.toString() + ""); // selcom.append("; ribbons; "); System.out .println("Superimpose command(s):\n" + command.toString()); @@ -697,8 +668,8 @@ public abstract class JalviewChimeraBinding extends selectioncom.setLength(selectioncom.length() - 1); } System.out.println("Select regions:\n" + selectioncom.toString()); - evalStateCommand("select *; cartoons off; backbone; select (" - + selectioncom.toString() + "); cartoons; "); + evalStateCommand("~display *; trace *; ribbons " + + selectioncom.toString() + ""); // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString()); } } @@ -715,18 +686,33 @@ public abstract class JalviewChimeraBinding extends } } - public void evalStateCommand(String command) + public void evalStateCommand(final String command) { viewerCommandHistory(false); checkLaunched(); if (lastCommand == null || !lastCommand.equals(command)) { - - lastReply = viewer.sendChimeraCommand(command, true); - if (debug) - { - log("Response from command ('" + command + "') was:\n" + lastReply); - } +// Thread t = new Thread(new Runnable() +// { +// @Override +// public void run() +// { + lastReply = viewer.sendChimeraCommand(command, true); + if (debug) + { + log("Response from command ('" + command + "') was:\n" + + lastReply); + } +// } +// }); + // TODO - use j7/8 thread management +// try +// { +// t.join(); +// } catch (InterruptedException foo) +// { +// } +// ; } viewerCommandHistory(true); lastCommand = command; @@ -866,18 +852,18 @@ public abstract class JalviewChimeraBinding extends { return new String[0]; } -// if (modelFileNames == null) -// { -// Collection chimodels = viewer.getChimeraModels(); -// _modelFileNameMap = new int[chimodels.size()]; -// int j = 0; -// for (ChimeraModel chimodel : chimodels) -// { -// String mdlName = chimodel.getModelName(); -// } -// modelFileNames = new String[j]; -// // System.arraycopy(mset, 0, modelFileNames, 0, j); -// } + // if (modelFileNames == null) + // { + // Collection chimodels = viewer.getChimeraModels(); + // _modelFileNameMap = new int[chimodels.size()]; + // int j = 0; + // for (ChimeraModel chimodel : chimodels) + // { + // String mdlName = chimodel.getModelName(); + // } + // modelFileNames = new String[j]; + // // System.arraycopy(mset, 0, modelFileNames, 0, j); + // } return chimmaps.keySet().toArray( modelFileNames = new String[chimmaps.size()]); @@ -916,17 +902,17 @@ public abstract class JalviewChimeraBinding extends viewer.stopListening(); if (resetLastRes.length() > 0) { - viewer.sendChimeraCommand(resetLastRes.toString(), false); + eval.setLength(0); + eval.append(resetLastRes.toString() + ";"); } - eval.setLength(0); eval.append("display "); // +modelNum resetLastRes.setLength(0); resetLastRes.append("~display "); { eval.append(" #" + (mdlNum)); - resetLastRes.append("#" + (mdlNum)); + resetLastRes.append(" #" + (mdlNum)); } // complete select string @@ -937,11 +923,7 @@ public abstract class JalviewChimeraBinding extends eval.append("." + chain); resetLastRes.append("." + chain); } - eval.append(eval.toString()); - - resetLastRes.append(resetLastRes.toString() - ); - + viewer.sendChimeraCommand(eval.toString(), false); viewerCommandHistory(true); viewer.startListening();