public List<ChimeraModel> openModel(String modelPath, ModelType type)
{
+ return openModel(modelPath, getFileNameFromPath(modelPath), type);
+ }
+
+ /**
+ * Overloaded method to allow Jalview to pass in a model name.
+ *
+ * @param modelPath
+ * @param modelName
+ * @param type
+ * @return
+ */
+ public List<ChimeraModel> openModel(String modelPath, String modelName,
+ ModelType type)
+ {
logger.info("chimera open " + modelPath);
stopListening();
List<String> response = null;
{
continue;
}
- String modelName = modelPath;
- // TODO: [Optional] Convert path to name in a better way
- if (modelPath.lastIndexOf(File.separator) > 0)
- {
- modelName = modelPath.substring(modelPath
- .lastIndexOf(File.separator) + 1);
- }
- else if (modelPath.lastIndexOf("/") > 0)
- {
- modelName = modelPath
- .substring(modelPath.lastIndexOf("/") + 1);
- }
ChimeraModel newModel = new ChimeraModel(modelName, type,
modelNumbers[0], modelNumbers[1]);
currentModelsMap.put(modelNumber, newModel);
models.add(newModel);
+ // patch for Jalview - set model name in Chimera
+ sendChimeraCommand("setattr M name " + modelName + " #"
+ + modelNumbers[0], false);
+ // end patch for Jalview
modelNumbers = null;
}
}
return models;
}
+ /**
+ * Refactored method to extract the last (or only) element delimited by file
+ * path separator.
+ *
+ * @param modelPath
+ * @return
+ */
+ private String getFileNameFromPath(String modelPath)
+ {
+ String modelName = modelPath;
+ if (modelPath == null)
+ {
+ return null;
+ }
+ // TODO: [Optional] Convert path to name in a better way
+ if (modelPath.lastIndexOf(File.separator) > 0)
+ {
+ modelName = modelPath.substring(modelPath
+ .lastIndexOf(File.separator) + 1);
+ }
+ else if (modelPath.lastIndexOf("/") > 0)
+ {
+ modelName = modelPath
+ .substring(modelPath.lastIndexOf("/") + 1);
+ }
+ return modelName;
+ }
+
public void closeModel(ChimeraModel model)
{
// int model = structure.modelNumber();
public boolean isChimeraLaunched()
{
- // TODO: [Optional] What is the best way to test if chimera is launched?
-
- // sendChimeraCommand("test", true) !=null
+ boolean launched = false;
if (chimera != null)
{
- return true;
+ try
+ {
+ chimera.exitValue();
+ // if we get here, process has ended
+ } catch (IllegalThreadStateException e)
+ {
+ // ok - not yet terminated
+ launched = true;
+ }
}
- return false;
+ return launched;
}
public boolean launchChimera(List<String> chimeraPaths)
{
return null;
}
- return ChimUtils.parseModelColor((String) colorLines.get(0));
+ return ChimUtils.parseModelColor(colorLines.get(0));
}
/**
{
return null;
}
+ // TODO do we need a maximum wait time before aborting?
while (busy)
{
try
;
}
busy = true;
- chimeraListenerThreads.clearResponse(command);
- String text = command.concat("\n");
- // System.out.println("send command to chimera: " + text);
try
{
- // send the command
- chimera.getOutputStream().write(text.getBytes());
- chimera.getOutputStream().flush();
- } catch (IOException e)
- {
- // logger.info("Unable to execute command: " + text);
- // logger.info("Exiting...");
- logger.warn("Unable to execute command: " + text);
- logger.warn("Exiting...");
- clearOnChimeraExit();
- busy = false;
- return null;
- }
- if (!reply)
+ chimeraListenerThreads.clearResponse(command);
+ String text = command.concat("\n");
+ // System.out.println("send command to chimera: " + text);
+ try
+ {
+ // send the command
+ chimera.getOutputStream().write(text.getBytes());
+ chimera.getOutputStream().flush();
+ } catch (IOException e)
+ {
+ // logger.info("Unable to execute command: " + text);
+ // logger.info("Exiting...");
+ logger.warn("Unable to execute command: " + text);
+ logger.warn("Exiting...");
+ clearOnChimeraExit();
+ // busy = false;
+ return null;
+ }
+ if (!reply)
+ {
+ // busy = false;
+ return null;
+ }
+ List<String> rsp = chimeraListenerThreads.getResponse(command);
+ // busy = false;
+ return rsp;
+ } finally
{
busy = false;
- return null;
}
- List<String> rsp = chimeraListenerThreads.getResponse(command);
- busy = false;
- return rsp;
}
public StructureManager getStructureManager()