2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.rbvi.chimera;
23 import jalview.api.AlignmentViewPanel;
24 import jalview.api.FeatureRenderer;
25 import jalview.api.SequenceRenderer;
26 import jalview.bin.Cache;
27 import jalview.datamodel.AlignmentI;
28 import jalview.datamodel.ColumnSelection;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.SequenceFeature;
31 import jalview.datamodel.SequenceI;
32 import jalview.httpserver.AbstractRequestHandler;
33 import jalview.schemes.ColourSchemeI;
34 import jalview.schemes.ResidueProperties;
35 import jalview.structure.AtomSpec;
36 import jalview.structure.StructureMapping;
37 import jalview.structure.StructureMappingcommandSet;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.structures.models.AAStructureBindingModel;
40 import jalview.util.Comparison;
41 import jalview.util.MessageManager;
43 import java.awt.Color;
44 import java.net.BindException;
45 import java.util.ArrayList;
46 import java.util.LinkedHashMap;
47 import java.util.List;
50 import ext.edu.ucsf.rbvi.strucviz2.ChimeraManager;
51 import ext.edu.ucsf.rbvi.strucviz2.ChimeraModel;
52 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
53 import ext.edu.ucsf.rbvi.strucviz2.StructureManager.ModelType;
55 public abstract class JalviewChimeraBinding extends AAStructureBindingModel
57 // Chimera clause to exclude alternate locations in atom selection
58 private static final String NO_ALTLOCS = "&~@.B-Z&~@.2-9";
60 private static final String COLOURING_CHIMERA = MessageManager
61 .getString("status.colouring_chimera");
63 private static final boolean debug = false;
65 private static final String PHOSPHORUS = "P";
67 private static final String ALPHACARBON = "CA";
70 * Object through which we talk to Chimera
72 private ChimeraManager viewer;
75 * Object which listens to Chimera notifications
77 private AbstractRequestHandler chimeraListener;
80 * set if chimera state is being restored from some source - instructs binding
81 * not to apply default display style when structure set is updated for first
84 private boolean loadingFromArchive = false;
87 * flag to indicate if the Chimera viewer should ignore sequence colouring
88 * events from the structure manager because the GUI is still setting up
90 private boolean loadingFinished = true;
92 public String fileLoadingError;
95 * Map of ChimeraModel objects keyed by PDB full local file name
97 private Map<String, List<ChimeraModel>> chimeraMaps = new LinkedHashMap<String, List<ChimeraModel>>();
100 * the default or current model displayed if the model cannot be identified
101 * from the selection message
103 private int frameNo = 0;
105 private String lastCommand;
107 String lastHighlightCommand;
110 * incremented every time a load notification is successfully handled -
111 * lightweight mechanism for other threads to detect when they can start
112 * referring to new structures.
114 private long loadNotifiesHandled = 0;
117 * Open a PDB structure file in Chimera and set up mappings from Jalview.
119 * We check if the PDB model id is already loaded in Chimera, if so don't
120 * reopen it. This is the case if Chimera has opened a saved session file.
125 public boolean openFile(PDBEntry pe)
127 String file = pe.getFile();
130 List<ChimeraModel> modelsToMap = new ArrayList<ChimeraModel>();
131 List<ChimeraModel> oldList = viewer.getModelList();
132 boolean alreadyOpen = false;
135 * If Chimera already has this model, don't reopen it, but do remap it.
137 for (ChimeraModel open : oldList)
139 if (open.getModelName().equals(pe.getId()))
142 modelsToMap.add(open);
147 * If Chimera doesn't yet have this model, ask it to open it, and retrieve
148 * the model name(s) added by Chimera.
152 viewer.openModel(file, pe.getId(), ModelType.PDB_MODEL);
153 List<ChimeraModel> newList = viewer.getModelList();
154 // JAL-1728 newList.removeAll(oldList) does not work
155 for (ChimeraModel cm : newList)
157 if (cm.getModelName().equals(pe.getId()))
164 chimeraMaps.put(file, modelsToMap);
166 if (getSsm() != null)
168 getSsm().addStructureViewerListener(this);
169 // ssm.addSelectionListener(this);
170 FeatureRenderer fr = getFeatureRenderer(null);
178 } catch (Exception q)
180 log("Exception when trying to open model " + file + "\n"
196 public JalviewChimeraBinding(StructureSelectionManager ssm,
197 PDBEntry[] pdbentry, SequenceI[][] sequenceIs, String[][] chains,
200 super(ssm, pdbentry, sequenceIs, chains, protocol);
201 viewer = new ChimeraManager(
202 new ext.edu.ucsf.rbvi.strucviz2.StructureManager(true));
206 * Start a dedicated HttpServer to listen for Chimera notifications, and tell
207 * it to start listening
209 public void startChimeraListener()
213 chimeraListener = new ChimeraListener(this);
214 viewer.startListening(chimeraListener.getUri());
215 } catch (BindException e)
217 System.err.println("Failed to start Chimera listener: "
223 * Construct a title string for the viewer window based on the data Jalview
229 public String getViewerTitle(boolean verbose)
231 return getViewerTitle("Chimera", verbose);
235 * Tells Chimera to display only the specified chains
239 public void showChains(List<String> toshow)
242 * Construct a chimera command like
244 * ~display #*;~ribbon #*;ribbon :.A,:.B
246 StringBuilder cmd = new StringBuilder(64);
247 boolean first = true;
248 for (String chain : toshow)
254 cmd.append(":.").append(chain);
259 * could append ";focus" to this command to resize the display to fill the
260 * window, but it looks more helpful not to (easier to relate chains to the
263 final String command = "~display #*; ~ribbon #*; ribbon "
265 sendChimeraCommand(command, false);
269 * Close down the Jalview viewer and listener, and (optionally) the associated
272 public void closeViewer(boolean closeChimera)
274 getSsm().removeStructureViewerListener(this, this.getPdbFile());
277 viewer.exitChimera();
279 if (this.chimeraListener != null)
281 chimeraListener.shutdown();
282 chimeraListener = null;
287 releaseUIResources();
290 public void colourByChain()
292 colourBySequence = false;
293 sendAsynchronousCommand("rainbow chain", COLOURING_CHIMERA);
297 * Constructs and sends a Chimera command to colour by charge
299 * <li>Aspartic acid and Glutamic acid (negative charge) red</li>
300 * <li>Lysine and Arginine (positive charge) blue</li>
301 * <li>Cysteine - yellow</li>
302 * <li>all others - white</li>
305 public void colourByCharge()
307 colourBySequence = false;
308 String command = "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS";
309 sendAsynchronousCommand(command, COLOURING_CHIMERA);
313 * Construct and send a command to align structures against a reference
314 * structure, based on one or more sequence alignments
317 * an array of alignments to process
318 * @param _refStructure
319 * an array of corresponding reference structures (index into pdb
320 * file array); if a negative value is passed, the first PDB file
321 * mapped to an alignment sequence is used as the reference for
324 * an array of corresponding hidden columns for each alignment
326 public void superposeStructures(AlignmentI[] _alignment,
327 int[] _refStructure, ColumnSelection[] _hiddenCols)
329 StringBuilder allComs = new StringBuilder(128);
330 String[] files = getPdbFile();
332 if (!waitForFileLoad(files))
338 StringBuilder selectioncom = new StringBuilder(256);
339 for (int a = 0; a < _alignment.length; a++)
341 int refStructure = _refStructure[a];
342 AlignmentI alignment = _alignment[a];
343 ColumnSelection hiddenCols = _hiddenCols[a];
345 if (refStructure >= files.length)
347 System.err.println("Ignoring invalid reference structure value "
353 * 'matched' array will hold 'true' for visible alignment columns where
354 * all sequences have a residue with a mapping to the PDB structure
356 boolean matched[] = new boolean[alignment.getWidth()];
357 for (int m = 0; m < matched.length; m++)
359 matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
362 SuperposeData[] structures = new SuperposeData[files.length];
363 for (int f = 0; f < files.length; f++)
365 structures[f] = new SuperposeData(alignment.getWidth());
369 * Calculate the superposable alignment columns ('matched'), and the
370 * corresponding structure residue positions (structures.pdbResNo)
372 int candidateRefStructure = findSuperposableResidues(alignment,
373 matched, structures);
374 if (refStructure < 0)
377 * If no reference structure was specified, pick the first one that has
378 * a mapping in the alignment
380 refStructure = candidateRefStructure;
384 for (boolean b : matched)
393 // TODO: bail out here because superposition illdefined?
397 * Generate select statements to select regions to superimpose structures
399 String[] selcom = new String[files.length];
400 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
402 String chainCd = "." + structures[pdbfnum].chain;
405 StringBuilder molsel = new StringBuilder();
406 for (int r = 0; r < matched.length; r++)
410 int pdbResNum = structures[pdbfnum].pdbResNo[r];
411 if (lpos != pdbResNum - 1)
414 * discontiguous - append last residue now
418 molsel.append(String.valueOf(lpos));
419 molsel.append(chainCd);
427 * extending a contiguous run
432 * start the range selection
434 molsel.append(String.valueOf(lpos));
444 * and terminate final selection
448 molsel.append(String.valueOf(lpos));
449 molsel.append(chainCd);
451 if (molsel.length() > 1)
453 selcom[pdbfnum] = molsel.toString();
454 selectioncom.append("#").append(String.valueOf(pdbfnum))
456 selectioncom.append(selcom[pdbfnum]);
457 selectioncom.append(" ");
458 if (pdbfnum < files.length - 1)
460 selectioncom.append("| ");
465 selcom[pdbfnum] = null;
469 StringBuilder command = new StringBuilder(256);
470 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
472 if (pdbfnum == refStructure || selcom[pdbfnum] == null
473 || selcom[refStructure] == null)
477 if (command.length() > 0)
483 * Form Chimera match command, from the 'new' structure to the
484 * 'reference' structure e.g. (50 residues, chain B/A, alphacarbons):
486 * match #1:1-30.B,81-100.B@CA #0:21-40.A,61-90.A@CA
489 * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
491 command.append("match ").append(getModelSpec(pdbfnum)).append(":");
492 command.append(selcom[pdbfnum]);
493 command.append("@").append(
494 structures[pdbfnum].isRna ? PHOSPHORUS : ALPHACARBON);
495 // JAL-1757 exclude alternate CA locations
496 command.append(NO_ALTLOCS);
497 command.append(" ").append(getModelSpec(refStructure)).append(":");
498 command.append(selcom[refStructure]);
499 command.append("@").append(
500 structures[refStructure].isRna ? PHOSPHORUS : ALPHACARBON);
501 command.append(NO_ALTLOCS);
503 if (selectioncom.length() > 0)
507 System.out.println("Select regions:\n" + selectioncom.toString());
508 System.out.println("Superimpose command(s):\n"
509 + command.toString());
511 allComs.append("~display all; chain @CA|P; ribbon ")
512 .append(selectioncom.toString())
513 .append(";" + command.toString());
516 if (selectioncom.length() > 0)
518 // TODO: visually distinguish regions that were superposed
519 if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
521 selectioncom.setLength(selectioncom.length() - 1);
525 System.out.println("Select regions:\n" + selectioncom.toString());
527 allComs.append("; ~display all; chain @CA|P; ribbon ")
528 .append(selectioncom.toString()).append("; focus");
529 sendChimeraCommand(allComs.toString(), false);
535 * Helper method to construct model spec in Chimera format:
537 * <li>#0 (#1 etc) for a PDB file with no sub-models</li>
538 * <li>#0.1 (#1.1 etc) for a PDB file with sub-models</li>
540 * Note for now we only ever choose the first of multiple models. This
541 * corresponds to the hard-coded Jmol equivalent (compare {1.1}). Refactor in
542 * future if there is a need to select specific sub-models.
547 protected String getModelSpec(int pdbfnum)
549 if (pdbfnum < 0 || pdbfnum >= getPdbCount())
555 * For now, the test for having sub-models is whether multiple Chimera
556 * models are mapped for the PDB file; the models are returned as a response
557 * to the Chimera command 'list models type molecule', see
558 * ChimeraManager.getModelList().
560 List<ChimeraModel> maps = chimeraMaps.get(getPdbFile()[pdbfnum]);
561 boolean hasSubModels = maps != null && maps.size() > 1;
562 return "#" + String.valueOf(pdbfnum) + (hasSubModels ? ".1" : "");
566 * Launch Chimera, unless an instance linked to this object is already
567 * running. Returns true if chimera is successfully launched, or already
568 * running, else false.
572 public boolean launchChimera()
574 if (!viewer.isChimeraLaunched())
576 return viewer.launchChimera(StructureManager.getChimeraPaths());
578 if (viewer.isChimeraLaunched())
582 log("Failed to launch Chimera!");
587 * Answers true if the Chimera process is still running, false if ended or not
592 public boolean isChimeraRunning()
594 return viewer.isChimeraLaunched();
598 * Send a command to Chimera, and optionally log any responses.
603 public void sendChimeraCommand(final String command, boolean logResponse)
607 // ? thread running after viewer shut down
610 viewerCommandHistory(false);
611 if (lastCommand == null || !lastCommand.equals(command))
613 // trim command or it may never find a match in the replyLog!!
614 List<String> lastReply = viewer.sendChimeraCommand(command.trim(),
616 if (logResponse && debug)
618 log("Response from command ('" + command + "') was:\n" + lastReply);
621 viewerCommandHistory(true);
622 lastCommand = command;
626 * Send a Chimera command asynchronously in a new thread. If the progress
627 * message is not null, display this message while the command is executing.
632 protected abstract void sendAsynchronousCommand(String command,
636 * colour any structures associated with sequences in the given alignment
637 * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
638 * if colourBySequence is enabled.
640 public void colourBySequence(boolean showFeatures,
641 jalview.api.AlignmentViewPanel alignmentv)
643 if (!colourBySequence || !loadingFinished)
647 if (getSsm() == null)
651 String[] files = getPdbFile();
653 SequenceRenderer sr = getSequenceRenderer(alignmentv);
655 FeatureRenderer fr = null;
658 fr = getFeatureRenderer(alignmentv);
660 AlignmentI alignment = alignmentv.getAlignment();
662 for (jalview.structure.StructureMappingcommandSet cpdbbyseq : getColourBySequenceCommands(
663 files, sr, fr, alignment))
665 for (String command : cpdbbyseq.commands)
667 sendAsynchronousCommand(command, COLOURING_CHIMERA);
679 protected StructureMappingcommandSet[] getColourBySequenceCommands(
680 String[] files, SequenceRenderer sr, FeatureRenderer fr,
681 AlignmentI alignment)
683 return ChimeraCommands.getColourBySequenceCommand(getSsm(), files,
684 getSequence(), sr, fr, alignment);
690 protected void executeWhenReady(String command)
693 sendChimeraCommand(command, false);
697 private void waitForChimera()
699 while (viewer != null && viewer.isBusy())
704 } catch (InterruptedException q)
710 // End StructureListener
711 // //////////////////////////
714 * returns the current featureRenderer that should be used to colour the
721 public abstract FeatureRenderer getFeatureRenderer(
722 AlignmentViewPanel alignment);
725 * instruct the Jalview binding to update the pdbentries vector if necessary
726 * prior to matching the viewer's contents to the list of structure files
727 * Jalview knows about.
729 public abstract void refreshPdbEntries();
731 private int getModelNum(String modelFileName)
733 String[] mfn = getPdbFile();
738 for (int i = 0; i < mfn.length; i++)
740 if (mfn[i].equalsIgnoreCase(modelFileName))
749 * map between index of model filename returned from getPdbFile and the first
750 * index of models from this file in the viewer. Note - this is not trimmed -
751 * use getPdbFile to get number of unique models.
753 private int _modelFileNameMap[];
755 // ////////////////////////////////
756 // /StructureListener
758 public synchronized String[] getPdbFile()
762 return new String[0];
764 // if (modelFileNames == null)
766 // Collection<ChimeraModel> chimodels = viewer.getChimeraModels();
767 // _modelFileNameMap = new int[chimodels.size()];
769 // for (ChimeraModel chimodel : chimodels)
771 // String mdlName = chimodel.getModelName();
773 // modelFileNames = new String[j];
774 // // System.arraycopy(mset, 0, modelFileNames, 0, j);
777 return chimeraMaps.keySet().toArray(
778 modelFileNames = new String[chimeraMaps.size()]);
782 * returns the current sequenceRenderer that should be used to colour the
789 public abstract SequenceRenderer getSequenceRenderer(
790 AlignmentViewPanel alignment);
793 * Construct and send a command to highlight zero, one or more atoms. We do
794 * this by sending an "rlabel" command to show the residue label at that
798 public void highlightAtoms(List<AtomSpec> atoms)
800 if (atoms == null || atoms.size() == 0)
805 StringBuilder cmd = new StringBuilder(128);
806 boolean first = true;
807 boolean found = false;
809 for (AtomSpec atom : atoms)
811 int pdbResNum = atom.getPdbResNum();
812 String chain = atom.getChain();
813 String pdbfile = atom.getPdbFile();
814 List<ChimeraModel> cms = chimeraMaps.get(pdbfile);
815 if (cms != null && !cms.isEmpty())
819 cmd.append("rlabel #").append(cms.get(0).getModelNumber())
827 cmd.append(pdbResNum);
828 if (!chain.equals(" "))
830 cmd.append(".").append(chain);
835 String command = cmd.toString();
838 * avoid repeated commands for the same residue
840 if (command.equals(lastHighlightCommand))
846 * unshow the label for the previous residue
848 if (lastHighlightCommand != null)
850 viewer.sendChimeraCommand("~" + lastHighlightCommand, false);
854 viewer.sendChimeraCommand(command, false);
856 this.lastHighlightCommand = command;
860 * Query Chimera for its current selection, and highlight it on the alignment
862 public void highlightChimeraSelection()
865 * Ask Chimera for its current selection
867 List<String> selection = viewer.getSelectedResidueSpecs();
870 * Parse model number, residue and chain for each selected position,
871 * formatted as #0:123.A or #1.2:87.B (#model.submodel:residue.chain)
873 List<AtomSpec> atomSpecs = new ArrayList<AtomSpec>();
874 for (String atomSpec : selection)
876 int colonPos = atomSpec.indexOf(":");
879 continue; // malformed
882 int hashPos = atomSpec.indexOf("#");
883 String modelSubmodel = atomSpec.substring(hashPos + 1, colonPos);
884 int dotPos = modelSubmodel.indexOf(".");
888 modelId = Integer.valueOf(dotPos == -1 ? modelSubmodel
889 : modelSubmodel.substring(0, dotPos));
890 } catch (NumberFormatException e)
892 // ignore, default to model 0
895 String residueChain = atomSpec.substring(colonPos + 1);
896 dotPos = residueChain.indexOf(".");
897 int pdbResNum = Integer.parseInt(dotPos == -1 ? residueChain
898 : residueChain.substring(0, dotPos));
900 String chainId = dotPos == -1 ? "" : residueChain
901 .substring(dotPos + 1);
904 * Work out the pdbfilename from the model number
906 String pdbfilename = modelFileNames[frameNo];
907 findfileloop: for (String pdbfile : this.chimeraMaps.keySet())
909 for (ChimeraModel cm : chimeraMaps.get(pdbfile))
911 if (cm.getModelNumber() == modelId)
913 pdbfilename = pdbfile;
918 atomSpecs.add(new AtomSpec(pdbfilename, chainId, pdbResNum, 0));
922 * Broadcast the selection (which may be empty, if the user just cleared all
925 getSsm().mouseOverStructure(atomSpecs);
928 private void log(String message)
930 System.err.println("## Chimera log: " + message);
933 private void viewerCommandHistory(boolean enable)
935 // log("(Not yet implemented) History "
936 // + ((debug || enable) ? "on" : "off"));
939 public long getLoadNotifiesHandled()
941 return loadNotifiesHandled;
944 public void setJalviewColourScheme(ColourSchemeI cs)
946 colourBySequence = false;
953 // Chimera expects RBG values in the range 0-1
954 final double normalise = 255D;
955 viewerCommandHistory(false);
956 StringBuilder command = new StringBuilder(128);
958 List<String> residueSet = ResidueProperties.getResidues(isNucleotide(),
960 for (String res : residueSet)
962 Color col = cs.findColour(res.charAt(0));
963 command.append("color " + col.getRed() / normalise + ","
964 + col.getGreen() / normalise + "," + col.getBlue()
965 / normalise + " ::" + res + ";");
968 sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA);
969 viewerCommandHistory(true);
973 * called when the binding thinks the UI needs to be refreshed after a Chimera
974 * state change. this could be because structures were loaded, or because an
975 * error has occurred.
977 public abstract void refreshGUI();
980 public void setLoadingFromArchive(boolean loadingFromArchive)
982 this.loadingFromArchive = loadingFromArchive;
987 * @return true if Chimeral is still restoring state or loading is still going
988 * on (see setFinsihedLoadingFromArchive)
991 public boolean isLoadingFromArchive()
993 return loadingFromArchive && !loadingFinished;
997 * modify flag which controls if sequence colouring events are honoured by the
998 * binding. Should be true for normal operation
1000 * @param finishedLoading
1003 public void setFinishedLoadingFromArchive(boolean finishedLoading)
1005 loadingFinished = finishedLoading;
1009 * Send the Chimera 'background solid <color>" command.
1012 * ://www.cgl.ucsf.edu/chimera/current/docs/UsersGuide/midas/background
1016 public void setBackgroundColour(Color col)
1018 viewerCommandHistory(false);
1019 double normalise = 255D;
1020 final String command = "background solid " + col.getRed() / normalise
1021 + "," + col.getGreen() / normalise + "," + col.getBlue()
1023 viewer.sendChimeraCommand(command, false);
1024 viewerCommandHistory(true);
1028 * Ask Chimera to save its session to the given file. Returns true if
1029 * successful, else false.
1034 public boolean saveSession(String filepath)
1036 if (isChimeraRunning())
1038 List<String> reply = viewer.sendChimeraCommand("save " + filepath,
1040 if (reply.contains("Session written"))
1047 .error("Error saving Chimera session: " + reply.toString());
1054 * Ask Chimera to open a session file. Returns true if successful, else false.
1055 * The filename must have a .py extension for this command to work.
1060 public boolean openSession(String filepath)
1062 sendChimeraCommand("open " + filepath, true);
1063 // todo: test for failure - how?
1068 * Returns a list of chains mapped in this viewer. Note this list is not
1069 * currently scoped per structure.
1073 public List<String> getChainNames()
1075 List<String> names = new ArrayList<String>();
1076 String[][] allNames = getChains();
1077 if (allNames != null)
1079 for (String[] chainsForPdb : allNames)
1081 if (chainsForPdb != null)
1083 for (String chain : chainsForPdb)
1085 if (chain != null && !names.contains(chain))
1097 * Send a 'focus' command to Chimera to recentre the visible display
1099 public void focusView()
1101 sendChimeraCommand("focus", false);
1105 * Send a 'show' command for all atoms in the currently selected columns
1107 * TODO: pull up to abstract structure viewer interface
1111 public void highlightSelection(AlignmentViewPanel vp)
1113 List<Integer> cols = vp.getAlignViewport().getColumnSelection()
1115 AlignmentI alignment = vp.getAlignment();
1116 StructureSelectionManager sm = getSsm();
1117 for (SequenceI seq : alignment.getSequences())
1120 * convert selected columns into sequence positions
1122 int[] positions = new int[cols.size()];
1124 for (Integer col : cols)
1126 positions[i++] = seq.findPosition(col);
1128 sm.highlightStructure(this, seq, positions);
1133 * Constructs and send commands to Chimera to set attributes on residues for
1134 * features visible in Jalview
1138 public void sendFeaturesToChimera(AlignmentViewPanel avp)
1140 // TODO send a command per feature with the range of residues it applies to
1141 AlignmentI alignment = avp.getAlignment();
1142 FeatureRenderer fr = getFeatureRenderer(avp);
1145 * fr is null if feature display is turned off
1152 String[] files = getPdbFile();
1157 for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
1159 StructureMapping[] mapping = getSsm().getMapping(files[pdbfnum]);
1161 if (mapping == null || mapping.length < 1)
1167 for (int seqNo = 0; seqNo < getSequence()[pdbfnum].length; seqNo++)
1169 for (int m = 0; m < mapping.length; m++)
1171 final SequenceI seq = getSequence()[pdbfnum][seqNo];
1172 int sp = alignment.findIndex(seq);
1173 if (mapping[m].getSequence() == seq && sp > -1)
1175 SequenceI asp = alignment.getSequenceAt(sp);
1176 for (int r = 0; r < asp.getLength(); r++)
1178 // no mapping to gaps in sequence
1179 if (Comparison.isGap(asp.getCharAt(r)))
1183 int residuePos = asp.findPosition(r);
1184 int pos = mapping[m].getPDBResNum(residuePos);
1186 if (pos < 1 || pos == lastPos)
1190 final String chain = mapping[m].getChain();
1191 List<SequenceFeature> features = fr.findFeaturesAtRes(asp,
1193 for (SequenceFeature feature : features)
1195 String desc = feature.getDescription();
1196 float score = feature.getScore();
1197 if (score != 0 && score != Float.NaN)
1199 desc = Float.toString(score);
1201 String attName = "jv:"
1202 + feature.getType().replace(" ", "_");
1203 String cmd = "setattr r " + attName + " \""
1204 + desc + "\" #" + pdbfnum + ":" + pos + "." + chain;
1205 System.out.println(cmd);
1206 sendAsynchronousCommand(cmd, null);