chimodels = viewer.getChimeraModels();
// _modelFileNameMap = new int[chimodels.size()];
// int j = 0;
// for (ChimeraModel chimodel : chimodels)
// {
// String mdlName = chimodel.getModelName();
// }
// modelFileNames = new String[j];
// // System.arraycopy(mset, 0, modelFileNames, 0, j);
// }
return chimeraMaps.keySet().toArray(
modelFileNames = new String[chimeraMaps.size()]);
}
/**
* map from string to applet
*/
public Map getRegistryInfo()
{
// TODO Auto-generated method stub
return null;
}
/**
* returns the current sequenceRenderer that should be used to colour the
* structures
*
* @param alignment
*
* @return
*/
public abstract SequenceRenderer getSequenceRenderer(
AlignmentViewPanel alignment);
/**
* Construct and send a command to highlight an atom.
*
*
* Done by generating a command like (to 'highlight' position 44)
* ~show #0:43.C;show #0:44.C
* Note this removes the highlight from the previous position.
*
*/
public void highlightAtom(int atomIndex, int pdbResNum, String chain,
String pdbfile)
{
List cms = chimeraMaps.get(pdbfile);
if (cms != null)
{
StringBuilder sb = new StringBuilder();
sb.append(" #" + cms.get(0).getModelNumber());
sb.append(":" + pdbResNum);
if (!chain.equals(" "))
{
sb.append("." + chain);
}
String atomSpec = sb.toString();
StringBuilder command = new StringBuilder(32);
if (lastMousedOverAtomSpec != null)
{
command.append("~show " + lastMousedOverAtomSpec + ";");
}
viewerCommandHistory(false);
command.append("show ").append(atomSpec);
String cmd = command.toString();
if (cmd.length() > 0)
{
viewer.stopListening(chimeraListener.getUri());
viewer.sendChimeraCommand(cmd, false);
viewer.startListening(chimeraListener.getUri());
}
viewerCommandHistory(true);
this.lastMousedOverAtomSpec = atomSpec;
}
}
/**
* Query Chimera for its current selection, and highlight it on the alignment
*/
public void highlightChimeraSelection()
{
/*
* Ask Chimera for its current selection
*/
List selection = viewer.getSelectedResidueSpecs();
/*
* Parse model number, residue and chain for each selected position,
* formatted as #0:123.A or #1.2:87.B (#model.submodel:residue.chain)
*/
List atomSpecs = new ArrayList();
for (String atomSpec : selection)
{
int colonPos = atomSpec.indexOf(":");
if (colonPos == -1)
{
continue; // malformed
}
int hashPos = atomSpec.indexOf("#");
String modelSubmodel = atomSpec.substring(hashPos + 1, colonPos);
int dotPos = modelSubmodel.indexOf(".");
int modelId = 0;
try {
modelId = Integer.valueOf(dotPos == -1 ? modelSubmodel
: modelSubmodel.substring(0, dotPos));
} catch (NumberFormatException e) {
// ignore, default to model 0
}
String residueChain = atomSpec.substring(colonPos + 1);
dotPos = residueChain.indexOf(".");
int pdbResNum = Integer.parseInt(dotPos == -1 ? residueChain
: residueChain.substring(0, dotPos));
String chainId = dotPos == -1 ? "" : residueChain
.substring(dotPos + 1);
/*
* Work out the pdbfilename from the model number
*/
String pdbfilename = modelFileNames[frameNo];
findfileloop: for (String pdbfile : this.chimeraMaps.keySet())
{
for (ChimeraModel cm : chimeraMaps.get(pdbfile))
{
if (cm.getModelNumber() == modelId)
{
pdbfilename = pdbfile;
break findfileloop;
}
}
}
atomSpecs.add(new AtomSpec(pdbfilename, chainId, pdbResNum, 0));
}
/*
* Broadcast the selection (which may be empty, if the user just cleared all
* selections)
*/
getSsm().mouseOverStructure(atomSpecs);
}
private void log(String message)
{
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;
}
public void setJalviewColourScheme(ColourSchemeI cs)
{
colourBySequence = false;
if (cs == null)
{
return;
}
int index;
Color col;
// Chimera expects RBG values in the range 0-1
final double normalise = 255D;
viewerCommandHistory(false);
// TODO: Switch between nucleotide or aa selection expressions
StringBuilder command = new StringBuilder(128);
command.append("color white;");
for (String res : ResidueProperties.aa3Hash.keySet())
{
index = ResidueProperties.aa3Hash.get(res).intValue();
if (index > 20)
{
continue;
}
col = cs.findColour(ResidueProperties.aa[index].charAt(0));
command.append("color " + col.getRed() / normalise + ","
+ col.getGreen() / normalise + "," + col.getBlue()
/ normalise + " ::" + res + ";");
}
evalStateCommand(command.toString(),false);
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();
public void setLoadingFromArchive(boolean loadingFromArchive)
{
this.loadingFromArchive = loadingFromArchive;
}
/**
*
* @return true if Chimeral is still restoring state or loading is still going
* on (see setFinsihedLoadingFromArchive)
*/
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
*/
public void setFinishedLoadingFromArchive(boolean finishedLoading)
{
loadingFinished = finishedLoading;
}
/**
* Send the Chimera 'background solid " command.
*
* @see https
* ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
* .html
* @param col
*/
public void setBackgroundColour(Color col)
{
viewerCommandHistory(false);
double normalise = 255D;
final String command = "background solid " + col.getRed() / normalise + ","
+ col.getGreen() / normalise + "," + col.getBlue()
/ normalise + ";";
viewer.sendChimeraCommand(command, false);
viewerCommandHistory(true);
}
/**
*
* @param pdbfile
* @return text report of alignment between pdbfile and any associated
* alignment sequences
*/
public String printMapping(String pdbfile)
{
return getSsm().printMapping(pdbfile);
}
/**
* 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())
{
List reply = viewer.sendChimeraCommand("save " + 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 extension for this command to work.
*
* @param filepath
* @return
*/
public boolean openSession(String filepath)
{
evalStateCommand("open " + filepath, true);
// todo: test for failure - how?
return true;
}
public boolean isFinishedInit()
{
return finishedInit;
}
public void setFinishedInit(boolean finishedInit)
{
this.finishedInit = finishedInit;
}
public List getChainNames()
{
return chainNames;
}
}