*/
public void startListening(String uri)
{
+ /*
+ * listen for model changes
+ */
String command = isChimeraX
? ("info notify start models prefix ModelChanged jalview url "
- + uri
- + "; info notify start selection jalview prefix SelectionChanged url "
+ uri)
- : ("listen start models url " + uri
- + ";listen start select prefix SelectionChanged url "
- + uri);
+ : ("listen start models url " + uri);
+ sendChimeraCommand(command, false);
+
+ /*
+ * listen for selection changes
+ */
+ command = isChimeraX
+ ? ("info notify start selection jalview prefix SelectionChanged url "
+ + uri)
+ : ("listen start select prefix SelectionChanged url " + uri);
sendChimeraCommand(command, false);
}
*/
if (isChimeraX)
{
- return selectedResidues;
+ // return selectedResidues;
}
// in fact 'listinfo' (undocumented) works in ChimeraX
- String command = (isChimeraX ? "info" : "list")
- + " selection level residue";
+ String command = (isChimeraX
+ ? "view" /*"info selection level residue" */
+ : "list selection level residue");
List<String> chimeraReply = sendChimeraCommand(command, true);
if (chimeraReply != null)
{
public List<ChimeraModel> getModelList()
{
List<ChimeraModel> modelList = new ArrayList<>();
- 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;
+ String command = "list models type "
+ + (isChimeraX ? "AtomicStructure" : "molecule");
+ List<String> list = sendChimeraCommand(command, true);
+ if (list != null)
+ {
+ for (String modelLine : list)
+ {
+ try
+ {
+ ChimeraModel chimeraModel = new ChimeraModel(modelLine);
+ modelList.add(chimeraModel);
+ } catch (NullPointerException e)
+ {
+ // hack for now
+ }
+ }
+ }
+ return modelList;
}
/**
{
String restUrl = "http://127.0.0.1:" + this.chimeraRestPort + "/run";
List<NameValuePair> commands = new ArrayList<>(1);
- String encoded = command.replace(" ", "+").replace("#", "%23")
- .replace("|", "%7C").replace(";", "%3B");
- commands.add(new BasicNameValuePair("command", encoded));
+ String method = isChimeraX() ? "GET" : "POST";
+ if ("GET".equals(method))
+ {
+ command = command.replace(" ", "+").replace("#", "%23")
+ .replace("|", "%7C").replace(";", "%3B");
+ }
+ commands.add(new BasicNameValuePair("command", command));
List<String> reply = new ArrayList<>();
BufferedReader response = null;
try
{
- 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);
- }
+ response = "GET".equals(method)
+ ? HttpClientUtils.doHttpGet(restUrl, commands,
+ CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS)
+ : HttpClientUtils.doHttpUrlPost(restUrl, commands,
+ CONNECTION_TIMEOUT_MS, REST_REPLY_TIMEOUT_MS);
String line = "";
while ((line = response.readLine()) != null)
{
import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel;
+import jalview.util.ColorUtils;
import jalview.util.MessageManager;
import java.awt.Color;
try
{
List<ChimeraModel> modelsToMap = new ArrayList<>();
- List<ChimeraModel> oldList = viewer.isChimeraX() ? new ArrayList<>()
- : viewer.getModelList();
+ List<ChimeraModel> oldList = viewer.getModelList();
boolean alreadyOpen = false;
/*
/*
* concatenate colour commands, one per residue symbol
- * Chimera format: color 0.000000,0.372549,0.627451 ::VAL
- * ChimeraX format: color :VAL rgb(73,73,182)
+ * Chimera format: color colorCode ::VAL
+ * ChimeraX format: color :VAL colourCode
*/
boolean chimeraX = viewer.isChimeraX();
for (String resName : residueSet)
: resName.charAt(0);
Color col = cs.findColour(res, 0, null, null, 0f);
command.append("color ");
- String colorSpec = getRgbDescriptor(col, chimeraX);
+ String colorSpec = ColorUtils.toTkCode(col);
if (chimeraX)
{
command.append(":").append(resName).append(" ").append(colorSpec);
public void setBackgroundColour(Color col)
{
viewerCommandHistory(false);
- String command = "set bgColor "
- + getRgbDescriptor(col, viewer.isChimeraX());
+ String command = "set bgColor " + ColorUtils.toTkCode(col);
viewer.sendChimeraCommand(command, false);
viewerCommandHistory(true);
}
/**
- * Answers the Chimera/X format for RGB values of the given colour.
- *
- * <pre>
- * Chimera: r,g,b with values scaled [0=1]
- * ChimeraX: rgb(r,g,b) with values scaled 0-255
- * </pre>
- *
- * @param col
- * @param chimeraX
- * @return
- */
- private static String getRgbDescriptor(Color col, boolean chimeraX)
- {
- if (chimeraX)
- {
- return String.format("rgb(%d,%d,%d)", col.getRed(), col.getGreen(),
- col.getBlue());
- }
- else
- {
- double scale = 255D;
- return String.format("%f,%f,%f", col.getRed() / scale,
- col.getGreen() / scale, col.getBlue() / scale);
- }
- }
-
- /**
* Ask Chimera to save its session to the given file. Returns true if
* successful, else false.
*