/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see .
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ext.rbvi.chimera;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import jalview.structure.AtomSpecModel;
import jalview.structure.StructureCommand;
import jalview.structure.StructureCommandI;
import jalview.structure.StructureCommandsBase;
import jalview.util.ColorUtils;
/**
* Routines for generating Chimera commands for Jalview/Chimera binding
*
* @author JimP
*
*/
public class ChimeraCommands extends StructureCommandsBase
{
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/focus.html
private static final StructureCommand FOCUS_VIEW = new StructureCommand("focus");
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/listen.html#listresattr
private static final StructureCommand LIST_RESIDUE_ATTRIBUTES = new StructureCommand("list resattr");
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/stop.html
private static final StructureCommand CLOSE_CHIMERA = new StructureCommand("stop really");
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/listen.html
private static final StructureCommand STOP_NOTIFY_SELECTION = new StructureCommand("listen stop selection");
private static final StructureCommand STOP_NOTIFY_MODELS = new StructureCommand("listen stop models");
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/listen.html#listselection
private static final StructureCommand GET_SELECTION = new StructureCommand("list selection level residue");
private static final StructureCommand SHOW_BACKBONE = new StructureCommand(
"~display all;~ribbon;chain @CA|P");
private static final StructureCommandI COLOUR_BY_CHARGE = new StructureCommand(
"color white;color red ::ASP,GLU;color blue ::LYS,ARG;color yellow ::CYS");
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/rainbow.html
private static final StructureCommandI COLOUR_BY_CHAIN = new StructureCommand(
"rainbow chain");
// Chimera clause to exclude alternate locations in atom selection
private static final String NO_ALTLOCS = "&~@.B-Z&~@.2-9";
@Override
public StructureCommandI colourResidues(String atomSpec, Color colour)
{
// https://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/color.html
String colourCode = getColourString(colour);
return new StructureCommand("color " + colourCode + " " + atomSpec);
}
/**
* Returns a colour formatted suitable for use in viewer command syntax
*
* @param colour
* @return
*/
protected String getColourString(Color colour)
{
return ColorUtils.toTkCode(colour);
}
/**
* Traverse the map of features/values/models/chains/positions to construct a
* list of 'setattr' commands (one per distinct feature type and value).
*
* The format of each command is
*
*
*
setattr r " " #modelnumber:range.chain
* e.g. setattr r jv_chain <value> #0:2.B,4.B,9-12.B|#1:1.A,2-6.A,...
*
*
*
* @param featureMap
* @return
*/
@Override
public List setAttributes(
Map> featureMap)
{
List commands = new ArrayList<>();
for (String featureType : featureMap.keySet())
{
String attributeName = makeAttributeName(featureType);
/*
* clear down existing attributes for this feature
*/
// 'problem' - sets attribute to None on all residues - overkill?
// commands.add("~setattr r " + attributeName + " :*");
Map