import java.util.BitSet;
import java.util.Collections;
import java.util.Hashtable;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public void colourByCharge()
{
colourBySequence = false;
- String command = "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS";
+ String command = viewer.isChimeraX()
+ ? "color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow"
+ : "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS";
sendAsynchronousCommand(command, COLOURING_CHIMERA);
}
refreshPdbEntries();
StringBuilder selectioncom = new StringBuilder(256);
+ boolean chimeraX = viewer.isChimeraX();
for (int a = 0; a < _alignment.length; a++)
{
int refStructure = _refStructure[a];
String[] selcom = new String[files.length];
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
+ final int modelNo = pdbfnum + (chimeraX ? 1 : 0);
+ // todo correct resolution to model number
String chainCd = "." + structures[pdbfnum].chain;
int lpos = -1;
boolean run = false;
StringBuilder molsel = new StringBuilder();
+ if (chimeraX)
+ {
+ molsel.append("/" + structures[pdbfnum].chain + ":");
+ }
int nextColumnMatch = matched.nextSetBit(0);
while (nextColumnMatch != -1)
if (lpos != -1)
{
molsel.append(String.valueOf(lpos));
- molsel.append(chainCd);
+ if (!chimeraX)
+ {
+ molsel.append(chainCd);
+ }
molsel.append(",");
}
run = false;
if (lpos != -1)
{
molsel.append(String.valueOf(lpos));
- molsel.append(chainCd);
+ if (!chimeraX)
+ {
+ molsel.append(chainCd);
+ }
}
if (molsel.length() > 1)
{
selcom[pdbfnum] = molsel.toString();
- selectioncom.append("#").append(String.valueOf(pdbfnum))
- .append(":");
+ selectioncom.append("#").append(String.valueOf(modelNo));
+ if (!chimeraX)
+ {
+ selectioncom.append(":");
+ }
selectioncom.append(selcom[pdbfnum]);
- selectioncom.append(" ");
+ // selectioncom.append(" ");
if (pdbfnum < files.length - 1)
{
- selectioncom.append("| ");
+ selectioncom.append("|");
}
}
else
StringBuilder command = new StringBuilder(256);
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
{
+ final int modelNo = pdbfnum + (chimeraX ? 1 : 0);
if (pdbfnum == refStructure || selcom[pdbfnum] == null
|| selcom[refStructure] == null)
{
* @see
* https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
*/
- command.append("match ").append(getModelSpec(pdbfnum)).append(":");
+ command.append(chimeraX ? "align " : "match ");
+ command.append(getModelSpec(modelNo));
+ if (!chimeraX)
+ {
+ command.append(":");
+ }
command.append(selcom[pdbfnum]);
command.append("@").append(
structures[pdbfnum].isRna ? PHOSPHORUS : ALPHACARBON);
- // JAL-1757 exclude alternate CA locations
- command.append(NO_ALTLOCS);
- command.append(" ").append(getModelSpec(refStructure)).append(":");
+ // JAL-1757 exclude alternate CA locations - ChimeraX syntax tbd
+ if (!chimeraX)
+ {
+ command.append(NO_ALTLOCS);
+ }
+ command.append(chimeraX ? " toAtoms " : " ")
+ .append(getModelSpec(refStructure + (chimeraX ? 1 : 0)));
+ if (!chimeraX)
+ {
+ command.append(":");
+ }
command.append(selcom[refStructure]);
command.append("@").append(
structures[refStructure].isRna ? PHOSPHORUS : ALPHACARBON);
- command.append(NO_ALTLOCS);
+ if (!chimeraX)
+ {
+ command.append(NO_ALTLOCS);
+ }
}
if (selectioncom.length() > 0)
{
System.out.println(
"Superimpose command(s):\n" + command.toString());
}
- allComs.append("~display all; chain @CA|P; ribbon ")
- .append(selectioncom.toString())
- .append(";" + command.toString());
+ // allComs.append("~display all; ");
+ // if (chimeraX)
+ // {
+ // allComs.append("show ").append(selectioncom.toString())
+ // .append(" pbonds");
+ // }
+ // else
+ // {
+ // allComs.append("chain @CA|P; ribbon ");
+ // allComs.append(selectioncom.toString());
+ // }
+ if (allComs.length() > 0) {
+ allComs.append(";");
+ }
+ allComs.append(command.toString());
}
}
{
System.out.println("Select regions:\n" + selectioncom.toString());
}
- allComs.append("; ~display all; chain @CA|P; ribbon ")
- .append(selectioncom.toString()).append("; focus");
+ allComs.append(";~display all; ");
+ if (chimeraX)
+ {
+ allComs.append("show @CA|P pbonds; show ")
+ .append(selectioncom.toString()).append(" ribbons; view");
+ }
+ else
+ {
+ allComs.append("chain @CA|P; ribbon ; focus");
+ allComs.append(selectioncom.toString());
+ }
+ // allComs.append("; ~display all; chain @CA|P; ribbon ")
+ // .append(selectioncom.toString()).append("; focus");
List<String> chimeraReplies = sendChimeraCommand(allComs.toString(),
true);
for (String reply : chimeraReplies)
{
if (pdbfnum < 0 || pdbfnum >= getPdbCount())
{
- return "";
+ return "#" + pdbfnum; // temp hack for ChimeraX
}
/*
protected List<AtomSpec> convertStructureResiduesToAlignment(
List<String> structureSelection)
{
+ boolean chimeraX = viewer.isChimeraX();
List<AtomSpec> atomSpecs = new ArrayList<>();
for (String atomSpec : structureSelection)
{
try
{
- AtomSpec spec = AtomSpec.fromChimeraAtomspec(atomSpec);
+ AtomSpec spec = AtomSpec.fromChimeraAtomspec(atomSpec, chimeraX);
String pdbfilename = getPdbFileForModel(spec.getModelNumber());
spec.setPdbFile(pdbfilename);
atomSpecs.add(spec);
return;
}
- // Chimera expects RBG values in the range 0-1
- final double normalise = 255D;
viewerCommandHistory(false);
StringBuilder command = new StringBuilder(128);
List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
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)
+ */
+ 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 " + col.getRed() / normalise + ","
- + col.getGreen() / normalise + "," + col.getBlue() / normalise
- + " ::" + resName + ";");
+ command.append("color ");
+ String colorSpec = getRgbDescriptor(col, chimeraX);
+ if (chimeraX)
+ {
+ command.append(":").append(resName).append(" ").append(colorSpec);
+ }
+ else
+ {
+ command.append(colorSpec).append(" ::").append(resName);
+ }
+ command.append(";");
}
sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA);
public void setBackgroundColour(Color col)
{
viewerCommandHistory(false);
- double normalise = 255D;
- final String command = "background solid " + col.getRed() / normalise
- + "," + col.getGreen() / normalise + ","
- + col.getBlue() / normalise + ";";
+ String command = "set bgColor "
+ + getRgbDescriptor(col, viewer.isChimeraX());
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.
*
*/
public void focusView()
{
- sendChimeraCommand("focus", false);
+ sendChimeraCommand(viewer.isChimeraX() ? "view" : "focus", false);
}
/**
{
boolean featureAdded = false;
String featureGroup = getViewerFeatureGroup();
+ boolean chimeraX = viewer.isChimeraX();
for (String residue : residues)
{
try
{
- spec = AtomSpec.fromChimeraAtomspec(atomSpec);
+ spec = AtomSpec.fromChimeraAtomspec(atomSpec, chimeraX);
} catch (IllegalArgumentException e)
{
System.err.println("Problem parsing atomspec " + atomSpec);
}
return -1;
}
+
+ /**
+ * Answers a (possibly empty) list of attribute names in Chimera[X], excluding
+ * any which were added from Jalview
+ *
+ * @return
+ */
+ public List<String> getChimeraAttributes()
+ {
+ List<String> atts = viewer.getAttrList();
+ Iterator<String> it = atts.iterator();
+ while (it.hasNext())
+ {
+ if (it.next().startsWith(ChimeraCommands.NAMESPACE_PREFIX))
+ {
+ /*
+ * attribute added from Jalview - exclude it
+ */
+ it.remove();
+ }
+ }
+ return atts;
+ }
}