for (ChimeraModel chimeraModel : modelList)
{
// get model color
- Color modelColor = getModelColor(chimeraModel);
+ Color modelColor = isChimeraX() ? null : getModelColor(chimeraModel);
if (modelColor != null)
{
chimeraModel.setModelColor(modelColor);
// chimeraSend("repr stick "+newModel.toSpec());
// Create the information we need for the navigator
- if (type != ModelType.SMILES)
+ if (type != ModelType.SMILES && !isChimeraX())
{
addResidues(chimeraModel);
}
public List<ChimeraModel> getModelList()
{
List<ChimeraModel> modelList = new ArrayList<>();
- List<String> list = sendChimeraCommand("list models type molecule",
- true);
- if (list != null)
- {
- for (String modelLine : list)
- {
- ChimeraModel chimeraModel = new ChimeraModel(modelLine);
- modelList.add(chimeraModel);
- }
- }
- return modelList;
+ modelList.add(new ChimeraModel("4zhp", ModelType.PDB_MODEL, 1, 0));
+ return modelList; // ChimeraX doesn't have 'list models' command
+ // List<String> list = sendChimeraCommand("list models type molecule",
+ // true);
+ // if (list != null)
+ // {
+ // for (String modelLine : list)
+ // {
+ // ChimeraModel chimeraModel = new ChimeraModel(modelLine);
+ // modelList.add(chimeraModel);
+ // }
+ // }
+ // return modelList;
}
/**
{
// ensure symbolic links are resolved
chimeraPath = Paths.get(chimeraPath).toRealPath().toString();
+ isChimeraX = chimeraPath.toLowerCase().contains("chimerax");
File path = new File(chimeraPath);
// uncomment the next line to simulate Chimera not installed
// path = new File(chimeraPath + "x");
args.add(chimeraPath);
// shows Chimera output window but suppresses REST responses:
// args.add("--debug");
- args.add("--start");
- args.add("RESTServer");
+ if (isChimeraX())
+ {
+ args.add("--cmd");
+ args.add("remote rest start");
+ }
+ else
+ {
+ args.add("--start");
+ args.add("RESTServer");
+ }
ProcessBuilder pb = new ProcessBuilder(args);
chimera = pb.start();
error = "";
{
responses.append("\n" + response);
// expect: REST server on host 127.0.0.1 port port_number
+ // ChimeraX is the same except "REST server started on host..."
if (response.startsWith("REST server"))
{
String[] tokens = response.split(" ");
- if (tokens.length == 7 && "port".equals(tokens[5]))
+ for (int i = 0; i < tokens.length - 1; i++)
{
- port = Integer.parseInt(tokens[6]);
- break;
+ if ("port".equals(tokens[i]))
+ {
+ port = Integer.parseInt(tokens[i + 1]);
+ break;
+ }
}
}
+ if (port > 0)
+ {
+ break; // hack for hanging readLine()
+ }
response = lineReader.readLine();
}
} catch (Exception e)
private volatile boolean busy = false;
+ private boolean isChimeraX;
+
/**
* Send a command to Chimera.
*
*/
public List<String> sendChimeraCommand(String command, boolean reply)
{
- // System.out.println("chimeradebug>> " + command);
+ System.out.println("chimeradebug>> " + command);
if (!isChimeraLaunched() || command == null
|| "".equals(command.trim()))
{
{
String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run";
List<NameValuePair> commands = new ArrayList<>(1);
- commands.add(new BasicNameValuePair("command", command));
+ String encoded = command.replace(" ", "+").replace("#", "%23")
+ .replace("|", "%7C").replace(";", "%3B");
+ commands.add(new BasicNameValuePair("command", encoded));
List<String> reply = new ArrayList<>();
BufferedReader response = null;
try
{
- response = HttpClientUtils.doHttpUrlPost(restUrl, commands, CONNECTION_TIMEOUT_MS,
- REST_REPLY_TIMEOUT_MS);
+ if (isChimeraX())
+ {
+ response = HttpClientUtils.doHttpGet(restUrl, commands,
+ CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS);
+ }
+ else
+ {
+ response = HttpClientUtils.doHttpUrlPost(restUrl, commands,
+ CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS);
+ }
String line = "";
while ((line = response.readLine()) != null)
{
{
return chimera;
}
+
+ public boolean isChimeraX()
+ {
+ return isChimeraX;
+ }
}