*/
package jalview.ext.jmol;
+import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeatureRenderer;
-import jalview.api.SequenceRenderer;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
+import jalview.ext.rbvi.chimera.AtomSpecModel;
import jalview.gui.IProgressIndicator;
import jalview.io.DataSourceType;
import jalview.io.StructureFile;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ResidueProperties;
import jalview.structure.AtomSpec;
-import jalview.structure.StructureMappingcommandSet;
import jalview.structure.StructureSelectionManager;
import jalview.structures.models.AAStructureBindingModel;
import jalview.util.MessageManager;
+import jalview.util.StructureCommands;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ComponentListener;
import java.io.File;
import java.net.URL;
-import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.StringTokenizer;
import java.util.Vector;
import org.jmol.adapter.smarter.SmarterJmolAdapter;
import org.jmol.api.JmolStatusListener;
import org.jmol.api.JmolViewer;
import org.jmol.c.CBK;
-import org.jmol.script.T;
import org.jmol.viewer.Viewer;
public abstract class JalviewJmolBinding extends AAStructureBindingModel
implements JmolStatusListener, JmolSelectionListener,
ComponentListener
{
+ private String lastMessage;
+
boolean allChainsSelected = false;
/*
Vector<String> atomsPicked = new Vector<>();
- private List<String> chainNames;
-
Hashtable<String, String> chainFile;
/*
String lastCommand;
- String lastMessage;
-
boolean loadedInline;
StringBuffer resetLastRes = new StringBuffer();
}
/**
- * prepare the view for a given set of models/chains. chainList contains
- * strings of the form 'pdbfilename:Chaincode'
+ * prepare the view for a given set of models/chains. chainList contains strings
+ * of the form 'pdbfilename:Chaincode'
*
- * @param chainList
- * list of chains to make visible
+ * @deprecated now only used by applet code
*/
- public void centerViewer(Vector<String> chainList)
+ @Deprecated
+ public void centerViewer()
{
StringBuilder cmd = new StringBuilder(128);
int mlength, p;
- for (String lbl : chainList)
+ for (String lbl : chainsToShow)
{
mlength = 0;
do
{
cmd.setLength(cmd.length() - 4);
}
- evalStateCommand("select *;restrict " + cmd + ";cartoon;center " + cmd);
+ String command = "select *;restrict " + cmd + ";cartoon;center " + cmd;
+ evalStateCommand(command);
}
public void closeViewer()
}
// System.out.println("Select regions:\n" + selectioncom.toString());
evalStateCommand("select *; cartoons off; backbone; select ("
- + selectioncom.toString() + "); cartoons; ");
+ + selectioncom.toString() + "); cartoons; zoom 0");
// evalStateCommand("select *; backbone; select "+selcom.toString()+";
// cartoons; center "+selcom.toString());
}
}
Thread colourby = null;
+
/**
* Sends a set of colour commands to the structure viewer
*
- * @param colourBySequenceCommands
+ * @param commands
*/
@Override
- protected void colourBySequence(
- final StructureMappingcommandSet[] colourBySequenceCommands)
+ protected void colourBySequence(AlignmentViewPanel viewPanel)
{
+ Map<Object, AtomSpecModel> map = StructureCommands.buildColoursMap(this,
+ viewPanel);
+
+ String[] commands = JmolCommands.getColourBySequenceCommand(map);
+
if (colourby != null)
{
colourby.interrupt();
@Override
public void run()
{
- for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands)
+ for (String cmd : commands)
{
- for (String cbyseq : cpdbbyseq.commands)
- {
- executeWhenReady(cbyseq);
- }
+ executeWhenReady(cmd);
}
}
});
}
/**
- * @param files
- * @param sr
- * @param viewPanel
- * @return
- */
- @Override
- protected StructureMappingcommandSet[] getColourBySequenceCommands(
- String[] files, SequenceRenderer sr, AlignmentViewPanel viewPanel)
- {
- return JmolCommands.getColourBySequenceCommand(getSsm(), files,
- getSequence(), sr, viewPanel);
- }
-
- /**
* @param command
*/
protected void executeWhenReady(String command)
return null;
}
- public Color getColour(int atomIndex, int pdbResNum, String chain,
- String pdbfile)
- {
- if (getModelNum(pdbfile) < 0)
- {
- return null;
- }
- // TODO: verify atomIndex is selecting correct model.
- // return new Color(viewer.getAtomArgb(atomIndex)); Jmol 12.2.4
- int colour = viewer.ms.at[atomIndex].atomPropertyInt(T.color);
- return new Color(colour);
- }
-
/**
* instruct the Jalview binding to update the pdbentries vector if necessary
* prior to matching the jmol view's contents to the list of structure files
*/
private int _modelFileNameMap[];
- // ////////////////////////////////
- // /StructureListener
- // @Override
- public synchronized String[] getPdbFilex()
- {
- if (viewer == null)
- {
- return new String[0];
- }
- if (modelFileNames == null)
- {
- List<String> mset = new ArrayList<>();
- _modelFileNameMap = new int[viewer.ms.mc];
- String m = viewer.ms.getModelFileName(0);
- if (m != null)
- {
- String filePath = m;
- try
- {
- filePath = new File(m).getAbsolutePath();
- } catch (AccessControlException x)
- {
- // usually not allowed to do this in applet
- System.err.println(
- "jmolBinding: Using local file string from Jmol: " + m);
- }
- if (filePath.indexOf("/file:") != -1)
- {
- // applet path with docroot - discard as format won't match pdbfile
- filePath = m;
- }
- mset.add(filePath);
- _modelFileNameMap[0] = 0; // filename index for first model is always 0.
- }
- int j = 1;
- for (int i = 1; i < viewer.ms.mc; i++)
- {
- m = viewer.ms.getModelFileName(i);
- String filePath = m;
- if (m != null)
- {
- try
- {
- filePath = new File(m).getAbsolutePath();
- } catch (AccessControlException x)
- {
- // usually not allowed to do this in applet, so keep raw handle
- // System.err.println("jmolBinding: Using local file string from
- // Jmol: "+m);
- }
- }
-
- /*
- * add this model unless it is read from a structure file we have
- * already seen (example: 2MJW is an NMR structure with 10 models)
- */
- if (!mset.contains(filePath))
- {
- mset.add(filePath);
- _modelFileNameMap[j] = i; // record the model index for the filename
- j++;
- }
- }
- modelFileNames = mset.toArray(new String[mset.size()]);
- }
- return modelFileNames;
- }
-
@Override
public synchronized String[] getStructureFiles()
{
- List<String> mset = new ArrayList<>();
if (viewer == null)
{
return new String[0];
if (modelFileNames == null)
{
+ List<String> mset = new ArrayList<>();
int modelCount = viewer.ms.mc;
String filePath = null;
for (int i = 0; i < modelCount; ++i)
viewer.openStringInline(string);
}
- public void mouseOverStructure(int atomIndex, String strInfo)
+ protected void mouseOverStructure(int atomIndex, final String strInfo)
{
int pdbResNum;
int alocsep = strInfo.indexOf("^");
try
{
// recover PDB filename for the model hovered over.
- int mnumber = new Integer(mdlId).intValue() - 1;
+ int mnumber = Integer.valueOf(mdlId).intValue() - 1;
if (_modelFileNameMap != null)
{
int _mp = _modelFileNameMap.length - 1;
} catch (Exception e)
{
}
- ;
}
- if (lastMessage == null || !lastMessage.equals(strInfo))
+
+ /*
+ * highlight position on alignment(s); if some text is returned,
+ * show this as a second line on the structure hover tooltip
+ */
+ String label = getSsm().mouseOverStructure(pdbResNum, chainId,
+ pdbfilename);
+ if (label != null)
{
- getSsm().mouseOverStructure(pdbResNum, chainId, pdbfilename);
+ // change comma to pipe separator (newline token for Jmol)
+ label = label.replace(',', '|');
+ StringTokenizer toks = new StringTokenizer(strInfo, " ");
+ StringBuilder sb = new StringBuilder();
+ sb.append("select ").append(String.valueOf(pdbResNum)).append(":")
+ .append(chainId).append("/1");
+ sb.append(";set hoverLabel \"").append(toks.nextToken()).append(" ")
+ .append(toks.nextToken());
+ sb.append("|").append(label).append("\"");
+ evalStateCommand(sb.toString());
}
-
- lastMessage = strInfo;
}
public void notifyAtomHovered(int atomIndex, String strInfo, String data)
{
+ if (strInfo.equals(lastMessage))
+ {
+ return;
+ }
+ lastMessage = strInfo;
if (data != null)
{
System.err.println("Ignoring additional hover info: " + data
setLoadingFromArchive(false);
}
- @Override
- public List<String> getChainNames()
+ protected IProgressIndicator getIProgressIndicator()
{
- return chainNames;
+ return null;
}
- protected abstract IProgressIndicator getIProgressIndicator();
-
public void notifyNewPickingModeMeasurement(int iatom, String strMeasure)
{
notifyAtomPicked(iatom, strMeasure, null);
{
showConsole(false);
}
+
+ @Override
+ public void showStructures(AlignViewportI av, boolean refocus)
+ {
+ StringBuilder cmd = new StringBuilder(128);
+ if (isShowAlignmentOnly())
+ {
+ AtomSpecModel model = getShownResidues(av);
+ String atomSpec = JmolCommands.getAtomSpec(model);
+
+ cmd.append("hide *;display ").append(atomSpec)
+ .append("; select displayed");
+ }
+ else
+ {
+ cmd.append(";display *");
+ }
+ cmd.append("; cartoon only");
+ if (refocus)
+ {
+ cmd.append("; zoom 0");
+ }
+ evalStateCommand(cmd.toString());
+ }
+
+ /**
+ * Answers a Jmol syntax style structure model specification. Model number 0, 1,
+ * 2... is formatted as "1.1", "2.1", "3.1" etc.
+ */
+ @Override
+ public String getModelSpec(int model)
+ {
+ return String.valueOf(model + 1) + ".1";
+ }
+
+ /**
+ * Sends a command to recentre the display
+ */
+ @Override
+ public void focusView()
+ {
+ /*
+ * don't use evalStateCommand because it ignores a command that is the same
+ * as the last command (why?); but user may have adjusted the display since
+ */
+ viewer.evalString("zoom 0");
+ }
+
+ @Override
+ public int getModelForPdbFile(String fileName, int fileIndex)
+ {
+ return fileIndex;
+ }
}