public class ChimeraManager
{
- static private Process chimera;
+ private Process chimera;
- static private ListenerThreads chimeraListenerThreads;
+ private ListenerThreads chimeraListenerThreads;
- static private Map<Integer, ChimeraModel> currentModelsMap;
+ private Map<Integer, ChimeraModel> currentModelsMap;
- private static Logger logger = LoggerFactory
+ private Logger logger = LoggerFactory
.getLogger(ext.edu.ucsf.rbvi.strucviz2.ChimeraManager.class);
private StructureManager structureManager;
chimera = null;
chimeraListenerThreads = null;
currentModelsMap = new HashMap<Integer, ChimeraModel>();
-
+
}
public List<ChimeraModel> getChimeraModels(String modelName)
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 values;
}
+ private volatile boolean busy = false;
+
/**
* Send a command to Chimera.
*
{
return null;
}
-
- 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)
+ // TODO do we need a maximum wait time before aborting?
+ while (busy)
{
- // logger.info("Unable to execute command: " + text);
- // logger.info("Exiting...");
- logger.warn("Unable to execute command: " + text);
- logger.warn("Exiting...");
- clearOnChimeraExit();
- return null;
+ try
+ {
+ Thread.sleep(25);
+ } catch (InterruptedException q)
+ {
+ }
+ ;
}
- if (!reply)
+ busy = true;
+ try
{
- return null;
+ 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 chimeraListenerThreads.getResponse(command);
}
public StructureManager getStructureManager()
return structureManager;
}
+ public boolean isBusy()
+ {
+ return busy;
+ }
+
}