X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fext%2Fedu%2Fucsf%2Frbvi%2Fstrucviz2%2FChimeraManager.java;h=19d6a8b3489b2d29f0e13a438e2007db40f8360a;hb=3efc24bc7b7855ff135fa96e35ab1004eaeb4f5e;hp=375fa4ad0d2e1919c2f38f6f2ccb189d65ddc01a;hpb=81185d3e4c3897e59411bca01808c8f86bb4044e;p=jalview.git diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java index 375fa4a..19d6a8b 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java @@ -38,6 +38,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; @@ -174,10 +177,11 @@ public class ChimeraManager return hasChimeraModel(modelNubmer, 0); } - public boolean hasChimeraModel(Integer modelNubmer, Integer subModelNumber) + public boolean hasChimeraModel(Integer modelNubmer, + Integer subModelNumber) { - return currentModelsMap.containsKey(ChimUtils.makeModelKey(modelNubmer, - subModelNumber)); + return currentModelsMap.containsKey( + ChimUtils.makeModelKey(modelNubmer, subModelNumber)); } public void addChimeraModel(Integer modelNumber, Integer subModelNumber, @@ -187,7 +191,8 @@ public class ChimeraManager ChimUtils.makeModelKey(modelNumber, subModelNumber), model); } - public void removeChimeraModel(Integer modelNumber, Integer subModelNumber) + public void removeChimeraModel(Integer modelNumber, + Integer subModelNumber) { int modelKey = ChimUtils.makeModelKey(modelNumber, subModelNumber); if (currentModelsMap.containsKey(modelKey)) @@ -242,9 +247,8 @@ public class ChimeraManager if (!modelList.contains(newModel)) { newModel.setModelName(modelName); - sendChimeraCommand( - "setattr M name " + modelName + " #" - + newModel.getModelNumber(), false); + sendChimeraCommand("setattr M name " + modelName + " #" + + newModel.getModelNumber(), false); modelList.add(newModel); } } @@ -314,8 +318,8 @@ public class ChimeraManager { sendChimeraCommand("close " + model.toSpec(), false); // currentModelNamesMap.remove(model.getModelName()); - currentModelsMap.remove(ChimUtils.makeModelKey( - model.getModelNumber(), model.getSubModelNumber())); + currentModelsMap.remove(ChimUtils.makeModelKey(model.getModelNumber(), + model.getSubModelNumber())); // selectionList.remove(chimeraModel); } else @@ -328,7 +332,8 @@ public class ChimeraManager public void startListening() { - sendChimeraCommand("listen start models; listen start selection", false); + sendChimeraCommand("listen start models; listen start selection", + false); } public void stopListening() @@ -361,7 +366,7 @@ public class ChimeraManager * Select something in Chimera * * @param command - * the selection command to pass to Chimera + * the selection command to pass to Chimera */ public void select(String command) { @@ -507,8 +512,8 @@ public class ChimeraManager /** * Return the list of depiction presets available from within Chimera. Chimera - * will return the list as a series of lines with the format: Preset type - * number "description" + * will return the list as a series of lines with the format: Preset type number + * "description" * * @return list of presets */ @@ -549,9 +554,9 @@ public class ChimeraManager } /** - * Launch Chimera, unless an instance linked to this object is already - * running. Returns true if chimera is successfully launched, or already - * running, else false. + * Launch Chimera, unless an instance linked to this object is already running. + * Returns true if chimera is successfully launched, or already running, else + * false. * * @param chimeraPaths * @return @@ -602,8 +607,8 @@ public class ChimeraManager if (error.length() == 0) { this.chimeraRestPort = getPortNumber(); - System.out.println("Chimera REST API started on port " - + chimeraRestPort); + System.out.println( + "Chimera REST API started on port " + chimeraRestPort); // structureManager.initChimTable(); structureManager.setChimeraPathProperty(workingPath); // TODO: [Optional] Check Chimera version and show a warning if below 1.8 @@ -621,6 +626,7 @@ public class ChimeraManager * Adds command-line arguments to start the REST server *

* Method extracted for Jalview to allow override in ChimeraXManager + * * @param args */ protected void addLaunchArguments(List args) @@ -636,8 +642,8 @@ public class ChimeraManager { int port = 0; InputStream readChan = chimera.getInputStream(); - BufferedReader lineReader = new BufferedReader(new InputStreamReader( - readChan)); + BufferedReader lineReader = new BufferedReader( + new InputStreamReader(readChan)); StringBuilder responses = new StringBuilder(); try { @@ -667,8 +673,8 @@ public class ChimeraManager } } catch (Exception e) { - logger.error("Failed to get REST port number from " + responses - + ": " + e.getMessage()); + logger.error("Failed to get REST port number from " + responses + ": " + + e.getMessage()); } finally { try @@ -680,11 +686,12 @@ public class ChimeraManager } if (port == 0) { - System.err - .println("Failed to start Chimera with REST service, response was: " + System.err.println( + "Failed to start Chimera with REST service, response was: " + responses); } - logger.info("Chimera REST service listening on port " + chimeraRestPort); + logger.info( + "Chimera REST service listening on port " + chimeraRestPort); return port; } @@ -692,7 +699,7 @@ public class ChimeraManager * Determine the color that Chimera is using for this model. * * @param model - * the ChimeraModel we want to get the Color for + * the ChimeraModel we want to get the Color for * @return the default model Color for this model in Chimera */ public Color getModelColor(ChimeraModel model) @@ -709,11 +716,11 @@ public class ChimeraManager /** * * Get information about the residues associated with a model. This uses the - * Chimera listr command. We don't return the resulting residues, but we add - * the residues to the model. + * Chimera listr command. We don't return the resulting residues, but we add the + * residues to the model. * * @param model - * the ChimeraModel to get residue information for + * the ChimeraModel to get residue information for * */ public void addResidues(ChimeraModel model) @@ -770,8 +777,8 @@ public class ChimeraManager String[] lineParts = inputLine.split("\\s"); if (lineParts.length == 5) { - ChimeraResidue residue = ChimUtils - .getResidue(lineParts[2], model); + ChimeraResidue residue = ChimUtils.getResidue(lineParts[2], + model); String value = lineParts[4]; if (residue != null) { @@ -805,16 +812,17 @@ public class ChimeraManager * Send a command to Chimera. * * @param command - * Command string to be send. + * Command string to be send. * @param reply - * Flag indicating whether the method should return the reply from - * Chimera or not. + * Flag indicating whether the method should return the reply + * from Chimera or not. * @return List of Strings corresponding to the lines in the Chimera reply or * null. */ public List sendChimeraCommand(String command, boolean reply) { - if (debug) { + if (debug) + { System.out.println("chimeradebug>> " + command); } if (!isChimeraLaunched() || command == null @@ -822,12 +830,18 @@ public class ChimeraManager { return null; } - // TODO do we need a maximum wait time before aborting? - while (busy) + /* + * set a maximum wait time before trying anyway + * to avoid hanging indefinitely + */ + int waited = 0; + int pause = 25; + while (busy && waited < 1001) { try { - Thread.sleep(25); + Thread.sleep(pause); + waited += pause; } catch (InterruptedException q) { } @@ -849,7 +863,6 @@ public class ChimeraManager + (System.currentTimeMillis() - startTime) + "ms: " + command); } - } } @@ -866,8 +879,15 @@ public class ChimeraManager String method = getHttpRequestMethod(); if ("GET".equals(method)) { - command = command.replace(" ", "+").replace("#", "%23") - .replace("|", "%7C").replace(";", "%3B"); + try + { + command = URLEncoder.encode(command, StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) + { + command = command.replace(" ", "+").replace("#", "%23") + .replace("|", "%7C").replace(";", "%3B") + .replace(":", "%3A"); + } } commands.add(new BasicNameValuePair("command", command)); @@ -904,7 +924,9 @@ public class ChimeraManager } /** - * Returns "POST" as the HTTP request method to use for REST service calls to Chimera + * Returns "POST" as the HTTP request method to use for REST service calls to + * Chimera + * * @return */ protected String getHttpRequestMethod()