/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
import jalview.api.SequenceRenderer;
+import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.httpserver.AbstractRequestHandler;
+import jalview.io.DataSourceType;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.structure.AtomSpec;
import java.awt.Color;
import java.net.BindException;
import java.util.ArrayList;
+import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
private static final String ALPHACARBON = "CA";
+ private List<String> chainNames = new ArrayList<String>();
+
+ private Hashtable<String, String> chainFile = new Hashtable<String, String>();
+
/*
* Object through which we talk to Chimera
*/
*/
private boolean loadingFinished = true;
- public String fileLoadingError;
-
/*
* Map of ChimeraModel objects keyed by PDB full local file name
*/
private String lastCommand;
- /*
- * current set of model filenames loaded
- */
- String[] modelFileNames = null;
-
String lastHighlightCommand;
/*
*/
private long loadNotifiesHandled = 0;
+ private Thread chimeraMonitor;
+
/**
* Open a PDB structure file in Chimera and set up mappings from Jalview.
*
* @param ssm
* @param pdbentry
* @param sequenceIs
- * @param chains
* @param protocol
*/
public JalviewChimeraBinding(StructureSelectionManager ssm,
- PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
- String protocol)
+ PDBEntry[] pdbentry, SequenceI[][] sequenceIs, DataSourceType protocol)
{
- super(ssm, pdbentry, sequenceIs, chains, protocol);
- viewer = new ChimeraManager(
- new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
+ super(ssm, pdbentry, sequenceIs, protocol);
+ viewer = new ChimeraManager(new StructureManager(true));
+ }
+
+ /**
+ * Starts a thread that waits for the Chimera process to finish, so that we
+ * can then close the associated resources. This avoids leaving orphaned
+ * Chimera viewer panels in Jalview if the user closes Chimera.
+ */
+ protected void startChimeraProcessMonitor()
+ {
+ final Process p = viewer.getChimeraProcess();
+ chimeraMonitor = new Thread(new Runnable()
+ {
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ p.waitFor();
+ JalviewStructureDisplayI display = getViewer();
+ if (display != null)
+ {
+ display.closeViewer(false);
+ }
+ } catch (InterruptedException e)
+ {
+ // exit thread if Chimera Viewer is closed in Jalview
+ }
+ }
+ });
+ chimeraMonitor.start();
}
/**
}
/**
- * Construct a title string for the viewer window based on the data Jalview
- * knows about
- *
- * @param verbose
- * @return
- */
- public String getViewerTitle(boolean verbose)
- {
- return getViewerTitle("Chimera", verbose);
- }
-
- /**
* Tells Chimera to display only the specified chains
*
* @param toshow
boolean first = true;
for (String chain : toshow)
{
+ int modelNumber = getModelNoForChain(chain);
+ String showChainCmd = modelNumber == -1 ? "" : modelNumber + ":."
+ + chain.split(":")[1];
if (!first)
{
cmd.append(",");
}
- cmd.append(":.").append(chain);
+ cmd.append(showChainCmd);
first = false;
}
* window, but it looks more helpful not to (easier to relate chains to the
* whole)
*/
- final String command = "~display #*; ~ribbon #*; ribbon "
+ final String command = "~display #*; ~ribbon #*; ribbon :"
+ cmd.toString();
sendChimeraCommand(command, false);
}
lastCommand = null;
viewer = null;
+ if (chimeraMonitor != null)
+ {
+ chimeraMonitor.interrupt();
+ }
releaseUIResources();
}
+ @Override
public void colourByChain()
{
colourBySequence = false;
* <li>all others - white</li>
* </ul>
*/
+ @Override
public void colourByCharge()
{
colourBySequence = false;
* @param _hiddenCols
* an array of corresponding hidden columns for each alignment
*/
+ @Override
public void superposeStructures(AlignmentI[] _alignment,
int[] _refStructure, ColumnSelection[] _hiddenCols)
{
/**
* Launch Chimera, unless an instance linked to this object is already
- * running. Returns true if chimera is successfully launched, or already
+ * running. Returns true if Chimera is successfully launched, or already
* running, else false.
*
* @return
*/
public boolean launchChimera()
{
- if (!viewer.isChimeraLaunched())
- {
- return viewer.launchChimera(StructureManager.getChimeraPaths());
- }
if (viewer.isChimeraLaunched())
{
return true;
}
- log("Failed to launch Chimera!");
- return false;
+
+ boolean launched = viewer.launchChimera(StructureManager
+ .getChimeraPaths());
+ if (launched)
+ {
+ startChimeraProcessMonitor();
+ }
+ else
+ {
+ log("Failed to launch Chimera!");
+ }
+ return launched;
}
/**
String progressMsg);
/**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
+ * Sends a set of colour commands to the structure viewer
+ *
+ * @param colourBySequenceCommands
*/
- public void colourBySequence(boolean showFeatures,
- jalview.api.AlignmentViewPanel alignmentv)
+ @Override
+ protected void colourBySequence(
+ StructureMappingcommandSet[] colourBySequenceCommands)
{
- if (!colourBySequence || !loadingFinished)
- {
- return;
- }
- if (getSsm() == null)
- {
- return;
- }
- String[] files = getPdbFile();
-
- SequenceRenderer sr = getSequenceRenderer(alignmentv);
-
- FeatureRenderer fr = null;
- if (showFeatures)
- {
- fr = getFeatureRenderer(alignmentv);
- }
- AlignmentI alignment = alignmentv.getAlignment();
-
- for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
- files, sr, fr, alignment))
+ for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
{
for (String command : cpdbbyseq.commands)
{
* @param alignment
* @return
*/
+ @Override
protected StructureMappingcommandSet[] getColourBySequenceCommands(
String[] files, SequenceRenderer sr, FeatureRenderer fr,
AlignmentI alignment)
// //////////////////////////
/**
- * returns the current featureRenderer that should be used to colour the
- * structures
- *
- * @param alignment
- *
- * @return
- */
- public abstract FeatureRenderer getFeatureRenderer(
- AlignmentViewPanel alignment);
-
- /**
* instruct the Jalview binding to update the pdbentries vector if necessary
* prior to matching the viewer's contents to the list of structure files
* Jalview knows about.
*/
public abstract void refreshPdbEntries();
- private int getModelNum(String modelFileName)
- {
- String[] mfn = getPdbFile();
- if (mfn == null)
- {
- return -1;
- }
- for (int i = 0; i < mfn.length; i++)
- {
- if (mfn[i].equalsIgnoreCase(modelFileName))
- {
- return i;
- }
- }
- return -1;
- }
-
/**
* map between index of model filename returned from getPdbFile and the first
* index of models from this file in the viewer. Note - this is not trimmed -
{
return new String[0];
}
- // if (modelFileNames == null)
- // {
- // Collection<ChimeraModel> 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()]);
}
/**
- * 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. We do
* this by sending an "rlabel" command to show the residue label at that
* position.
return loadNotifiesHandled;
}
+ @Override
public void setJalviewColourScheme(ColourSchemeI cs)
{
colourBySequence = false;
List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
false);
- for (String res : residueSet)
+ for (String resName : residueSet)
{
- Color col = cs.findColour(res.charAt(0));
+ char res = resName.length() == 3 ? ResidueProperties
+ .getSingleCharacterCode(resName) : resName.charAt(0);
+ Color col = cs.findColour(res);
command.append("color " + col.getRed() / normalise + ","
+ col.getGreen() / normalise + "," + col.getBlue()
- / normalise + " ::" + res + ";");
+ / normalise + " ::" + resName + ";");
}
sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA);
* .html
* @param col
*/
+ @Override
public void setBackgroundColour(Color col)
{
viewerCommandHistory(false);
}
/**
- * Returns a list of chains mapped in this viewer. Note this list is not
- * currently scoped per structure.
- *
- * @return
- */
- public List<String> getChainNames()
- {
- List<String> names = new ArrayList<String>();
- 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()
sm.highlightStructure(this, seq, positions);
}
}
+
+
+ @Override
+ public List<String> getChainNames()
+ {
+ return chainNames;
+ }
+
+ public Hashtable<String, String> getChainFile()
+ {
+ return chainFile;
+ }
+
+ public List<ChimeraModel> getChimeraModelByChain(String chain)
+ {
+ return chimeraMaps.get(chainFile.get(chain));
+ }
+
+ public int getModelNoForChain(String chain)
+ {
+ List<ChimeraModel> foundModels = getChimeraModelByChain(chain);
+ if (foundModels != null && !foundModels.isEmpty())
+ {
+ return foundModels.get(0).getModelNumber();
+ }
+ return -1;
+ }
}