- System.err.println("## Chimera log: " + message);
- }
-
- private void viewerCommandHistory(boolean enable)
- {
- // log("(Not yet implemented) History "
- // + ((debug || enable) ? "on" : "off"));
- }
-
- public long getLoadNotifiesHandled()
- {
- return loadNotifiesHandled;
- }
-
- @Override
- public void setJalviewColourScheme(ColourSchemeI cs)
- {
- colourBySequence = false;
-
- if (cs == null)
- {
- return;
- }
-
- viewerCommandHistory(false);
- StringBuilder command = new StringBuilder(128);
-
- List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
- false);
-
- /*
- * concatenate colour commands, one per residue symbol
- * Chimera format: color colorCode ::VAL
- * ChimeraX format: color :VAL colourCode
- */
- boolean chimeraX = viewer.isChimeraX();
- for (String resName : residueSet)
- {
- char res = resName.length() == 3
- ? ResidueProperties.getSingleCharacterCode(resName)
- : resName.charAt(0);
- Color col = cs.findColour(res, 0, null, null, 0f);
- command.append("color ");
- String colorSpec = ColorUtils.toTkCode(col);
- if (chimeraX)
- {
- command.append(":").append(resName).append(" ").append(colorSpec);
- }
- else
- {
- command.append(colorSpec).append(" ::").append(resName);
- }
- command.append(";");
- }
-
- sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA);
- viewerCommandHistory(true);
- }
-
- /**
- * called when the binding thinks the UI needs to be refreshed after a Chimera
- * state change. this could be because structures were loaded, or because an
- * error has occurred.
- */
- public abstract void refreshGUI();
-
- @Override
- public void setLoadingFromArchive(boolean loadingFromArchive)
- {
- this.loadingFromArchive = loadingFromArchive;
- }
-
- /**
- *
- * @return true if Chimeral is still restoring state or loading is still going
- * on (see setFinsihedLoadingFromArchive)
- */
- @Override
- public boolean isLoadingFromArchive()
- {
- return loadingFromArchive && !loadingFinished;
- }
-
- /**
- * modify flag which controls if sequence colouring events are honoured by the
- * binding. Should be true for normal operation
- *
- * @param finishedLoading
- */
- @Override
- public void setFinishedLoadingFromArchive(boolean finishedLoading)
- {
- loadingFinished = finishedLoading;
- }
-
- /**
- * Send the Chimera 'background solid <color>" command.
- *
- * @see https
- * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
- * .html
- * @param col
- */
- @Override
- public void setBackgroundColour(Color col)
- {
- viewerCommandHistory(false);
- String command = "set bgColor " + ColorUtils.toTkCode(col);
- viewer.sendChimeraCommand(command, false);
- viewerCommandHistory(true);
- }
-
- /**
- * Ask Chimera to save its session to the given file. Returns true if
- * successful, else false.
- *
- * @param filepath
- * @return
- */
- public boolean saveSession(String filepath)
- {
- if (isChimeraRunning())
- {
- /*
- * Chimera: https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/save.html
- * ChimeraX: https://www.cgl.ucsf.edu/chimerax/docs/user/commands/save.html
- */
- String command = isChimeraX() ? "save session " : "save ";
- List<String> reply = viewer.sendChimeraCommand(command + filepath,
- true);
- if (reply.contains("Session written"))
- {
- return true;
- }
- else
- {
- Cache.log
- .error("Error saving Chimera session: " + reply.toString());
- }
- }
- return false;
- }
-
- /**
- * Ask Chimera to open a session file. Returns true if successful, else false.
- * The filename must have a .py (Chimera) or .cxs (ChimeraX) extension for
- * this command to work.
- *
- * @param filepath
- * @return
- */
- public boolean openSession(String filepath)
- {
- /*
- * Chimera: https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/open.html
- * ChimeraX: https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html
- */
- sendChimeraCommand("open " + filepath, true);
- // todo: test for failure - how?
- return true;
- }
-
- /**
- * Returns a list of chains mapped in this viewer. Note this list is not
- * currently scoped per structure.
- *
- * @return
- */
- @Override
- public List<String> getChainNames()
- {
- return chainNames;
- }
-
- /**
- * Send a 'focus' command to Chimera to recentre the visible display
- */
- public void focusView()
- {
- sendChimeraCommand(viewer.isChimeraX() ? "view" : "focus", false);
- }
-
- /**
- * Send a 'show' command for all atoms in the currently selected columns
- *
- * TODO: pull up to abstract structure viewer interface
- *
- * @param vp
- */
- public void highlightSelection(AlignmentViewPanel vp)
- {
- List<Integer> cols = vp.getAlignViewport().getColumnSelection()
- .getSelected();
- AlignmentI alignment = vp.getAlignment();
- StructureSelectionManager sm = getSsm();
- for (SequenceI seq : alignment.getSequences())
- {
- /*
- * convert selected columns into sequence positions
- */
- int[] positions = new int[cols.size()];
- int i = 0;
- for (Integer col : cols)
- {
- positions[i++] = seq.findPosition(col);
- }
- sm.highlightStructure(this, seq, positions);
- }