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 zero, one or more atoms.
*
*
* Done by generating a command like (to 'highlight' positions 44 and 46)
* show #0:44,46.C
*
*/
@Override
public void highlightAtoms(List atoms)
{
if (atoms == null)
{
return;
}
StringBuilder cmd = new StringBuilder(128);
boolean first = true;
boolean found = false;
for (AtomSpec atom : atoms)
{
int pdbResNum = atom.getPdbResNum();
String chain = atom.getChain();
String pdbfile = atom.getPdbFile();
List cms = chimeraMaps.get(pdbfile);
if (cms != null && !cms.isEmpty())
{
if (first)
{
cmd.append("show #").append(cms.get(0).getModelNumber())
.append(":");
}
else
{
cmd.append(",");
}
first = false;
cmd.append(cms.get(0).getModelNumber()).append(":");
cmd.append(pdbResNum);
if (!chain.equals(" "))
{
cmd.append(".").append(chain);
}
found = true;
}
}
String command = cmd.toString();
/*
* Avoid repeated commands for the same residue
*/
if (command.equals(lastHighlightCommand))
{
return;
}
viewerCommandHistory(false);
if (found)
{
viewer.sendChimeraCommand(command.toString(), false);
}
viewerCommandHistory(true);
this.lastHighlightCommand = command;
}
/**
* 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;
}
// Chimera expects RBG values in the range 0-1
final double normalise = 255D;
viewerCommandHistory(false);
StringBuilder command = new StringBuilder(128);
List residueSet = ResidueProperties.getResidues(isNucleotide(),
false);
for (String res : residueSet)
{
Color col = cs.findColour(res.charAt(0));
command.append("color " + col.getRed() / normalise + ","
+ col.getGreen() / normalise + "," + col.getBlue()
/ normalise + " ::" + res + ";");
}
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 " 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);
}
/**
* 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)
{
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
*/
public List getChainNames()
{
List names = new ArrayList();
String[][] allNames = getChains();
if (allNames != null)
{
for (String[] chainsForPdb : allNames)
{
if (chainsForPdb != null)
{
for (String chain : chainsForPdb)
{
if (chain != null && !names.contains(chain))
{
names.add(chain);
}
}
}
}
}
return names;
}
/**
* Send a 'focus' command to Chimera to recentre the visible display
*/
public void focusView()
{
sendChimeraCommand("focus", false);
}
/**
* Send a 'show' command for all atoms in the currently selected columns
*
* @param vp
*/
public void highlightSelection(AlignmentViewPanel vp)
{
List 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);
}
}
}