X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fext%2Fedu%2Fucsf%2Frbvi%2Fstrucviz2%2FChimeraManager.java;h=a910a5a6df161cde886d8fc7faf5c235ab55078b;hb=a3ca1aac6c00fc2240fa21be9df43adcc1b964ff;hp=699ca5999e7ece8abc7dd354c6566058fadc8660;hpb=5965127c38ff1a35d10d806c4b4537cdc1e39579;p=jalview.git diff --git a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java index 699ca59..a910a5a 100644 --- a/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java +++ b/src/ext/edu/ucsf/rbvi/strucviz2/ChimeraManager.java @@ -40,6 +40,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -83,7 +84,7 @@ public class ChimeraManager this.structureManager = structureManager; chimera = null; chimeraListenerThread = null; - currentModelsMap = new HashMap(); + currentModelsMap = new HashMap<>(); } @@ -98,7 +99,7 @@ public class ChimeraManager public List getChimeraModels(String modelName, ModelType modelType) { - List models = new ArrayList(); + List models = new ArrayList<>(); for (ChimeraModel model : currentModelsMap.values()) { if (modelName.equals(model.getModelName()) @@ -112,7 +113,7 @@ public class ChimeraManager public Map> getChimeraModelsMap() { - Map> models = new HashMap>(); + Map> models = new HashMap<>(); for (ChimeraModel model : currentModelsMap.values()) { String modelName = model.getModelName(); @@ -380,6 +381,8 @@ public class ChimeraManager sendChimeraCommand("stop really", false); try { + // TODO is this too violent? could it force close the process + // before it has done an orderly shutdown? chimera.destroy(); } catch (Exception ex) { @@ -391,7 +394,7 @@ public class ChimeraManager public Map getSelectedModels() { - Map selectedModelsMap = new HashMap(); + Map selectedModelsMap = new HashMap<>(); List chimeraReply = sendChimeraCommand( "list selection level molecule", true); if (chimeraReply != null) @@ -416,7 +419,7 @@ public class ChimeraManager */ public List getSelectedResidueSpecs() { - List selectedResidues = new ArrayList(); + List selectedResidues = new ArrayList<>(); List chimeraReply = sendChimeraCommand( "list selection level residue", true); if (chimeraReply != null) @@ -469,7 +472,7 @@ public class ChimeraManager // TODO: [Optional] Handle smiles names in a better way in Chimera? public List getModelList() { - List modelList = new ArrayList(); + List modelList = new ArrayList<>(); List list = sendChimeraCommand("list models type molecule", true); if (list != null) @@ -492,7 +495,7 @@ public class ChimeraManager */ public List getPresets() { - ArrayList presetList = new ArrayList(); + ArrayList presetList = new ArrayList<>(); List output = sendChimeraCommand("preset list", true); if (output != null) { @@ -548,17 +551,19 @@ public class ChimeraManager // iterate over possible paths for starting Chimera for (String chimeraPath : chimeraPaths) { - File path = new File(chimeraPath); - // uncomment the next line to simulate Chimera not installed - // path = new File(chimeraPath + "x"); - if (!path.canExecute()) - { - error += "File '" + path + "' does not exist.\n"; - continue; - } try { - List args = new ArrayList(); + // ensure symbolic links are resolved + chimeraPath = Paths.get(chimeraPath).toRealPath().toString(); + File path = new File(chimeraPath); + // uncomment the next line to simulate Chimera not installed + // path = new File(chimeraPath + "x"); + if (!path.canExecute()) + { + error += "File '" + path + "' does not exist.\n"; + continue; + } + List args = new ArrayList<>(); args.add(chimeraPath); // shows Chimera output window but suppresses REST responses: // args.add("--debug"); @@ -571,7 +576,7 @@ public class ChimeraManager break; } catch (Exception e) { - // Chimera could not be started + // Chimera could not be started using this path error += e.getMessage(); } } @@ -697,7 +702,7 @@ public class ChimeraManager public List getAttrList() { - List attributes = new ArrayList(); + List attributes = new ArrayList<>(); final List reply = sendChimeraCommand("list resattr", true); if (reply != null) { @@ -716,7 +721,7 @@ public class ChimeraManager public Map getAttrValues(String aCommand, ChimeraModel model) { - Map values = new HashMap(); + Map values = new HashMap<>(); final List reply = sendChimeraCommand("list residue spec " + model.toSpec() + " attribute " + aCommand, true); if (reply != null) @@ -816,10 +821,10 @@ public class ChimeraManager protected List sendRestCommand(String command) { String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run"; - List commands = new ArrayList(1); + List commands = new ArrayList<>(1); commands.add(new BasicNameValuePair("command", command)); - List reply = new ArrayList(); + List reply = new ArrayList<>(); BufferedReader response = null; try { @@ -891,4 +896,9 @@ public class ChimeraManager { return busy; } + + public Process getChimeraProcess() + { + return chimera; + } }