X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Frbvi%2Fchimera%2FJalviewChimeraBinding.java;h=3498f239ab9929b7d8f11ddd69808fbc2098ac99;hb=ec1c914a99011e20634fbff19df71e2627766dfd;hp=fc6dd265cef3c8a582cc5fe33dec725824e5430d;hpb=e34c8452beda2cf80c2a3224f236d3096db69ae9;p=jalview.git diff --git a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java index fc6dd26..3498f23 100644 --- a/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java +++ b/src/jalview/ext/rbvi/chimera/JalviewChimeraBinding.java @@ -36,11 +36,11 @@ import jalview.io.DataSourceType; import jalview.schemes.ColourSchemeI; import jalview.schemes.ResidueProperties; import jalview.structure.AtomSpec; -import jalview.structure.StructureMapping; 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.io.File; @@ -52,7 +52,6 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.util.Hashtable; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -78,8 +77,6 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel private static final String ALPHACARBON = "CA"; - private List chainNames = new ArrayList<>(); - private Hashtable chainFile = new Hashtable<>(); /* @@ -464,7 +461,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * @see * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html */ - command.append("match ").append(getModelSpec(pdbfnum)).append(":"); + command.append("match ").append(getModelSpec(pdbfnum)) + .append(":"); command.append(selcom[pdbfnum]); command.append("@").append( structures[pdbfnum].isRna ? PHOSPHORUS : ALPHACARBON); @@ -541,7 +539,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel * @param pdbfnum * @return */ - protected String getModelSpec(int pdbfnum) + @Override + public String getModelSpec(int pdbfnum) { if (pdbfnum < 0 || pdbfnum >= getPdbCount()) { @@ -556,7 +555,8 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel */ List maps = chimeraMaps.get(getStructureFiles()[pdbfnum]); boolean hasSubModels = maps != null && maps.size() > 1; - return "#" + String.valueOf(pdbfnum) + (hasSubModels ? ".1" : ""); + String spec = "#" + String.valueOf(pdbfnum); + return hasSubModels ? spec + ".1" : spec; } /** @@ -647,37 +647,26 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel String progressMsg); /** - * Sends a set of colour commands to the structure viewer + * Constructs a set of colour commands and sends them to the structure viewer * - * @param colourBySequenceCommands + * @param viewPanel */ @Override - protected void colourBySequence( - StructureMappingcommandSet[] colourBySequenceCommands) + protected void colourBySequence(AlignmentViewPanel viewPanel) { - for (StructureMappingcommandSet cpdbbyseq : colourBySequenceCommands) + Map colourMap = StructureCommands + .buildColoursMap(this, viewPanel); + + String[] commands = ChimeraCommands + .getColourBySequenceCommand(colourMap, this); + + for (String command : commands) { - for (String command : cpdbbyseq.commands) - { - sendAsynchronousCommand(command, COLOURING_CHIMERA); - } + sendAsynchronousCommand(command, COLOURING_CHIMERA); } } /** - * @param files - * @param viewPanel - * @return - */ - @Override - protected StructureMappingcommandSet[] getColourBySequenceCommands( - String[] files, AlignmentViewPanel viewPanel) - { - return ChimeraCommands.getColourBySequenceCommand(getSsm(), files, - this, viewPanel); - } - - /** * @param command */ protected void executeWhenReady(String command) @@ -899,7 +888,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel return; } - // Chimera expects RBG values in the range 0-1 + // Chimera expects RGB values in the range 0-1 final double normalise = 255D; viewerCommandHistory(false); StringBuilder command = new StringBuilder(128); @@ -912,9 +901,11 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel ? ResidueProperties.getSingleCharacterCode(resName) : resName.charAt(0); Color col = cs.findColour(res, 0, null, null, 0f); - command.append("color " + col.getRed() / normalise + "," - + col.getGreen() / normalise + "," + col.getBlue() / normalise - + " ::" + resName + ";"); + command.append("color ") + .append(String.valueOf(col.getRed() / normalise)).append(",") + .append(String.valueOf(col.getGreen() / normalise)) + .append(",").append(String.valueOf(col.getBlue() / normalise)) + .append(" ::").append(resName).append(";"); } sendAsynchronousCommand(command.toString(), COLOURING_CHIMERA); @@ -1018,20 +1009,9 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel } /** - * Returns a list of chains mapped in this viewer. Note this list is not - * currently scoped per structure. - * - * @return - */ - @Override - public List getChainNames() - { - return chainNames; - } - - /** * Send a 'focus' command to Chimera to recentre the visible display */ + @Override public void focusView() { sendChimeraCommand("focus", false); @@ -1084,8 +1064,7 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel } StructureMappingcommandSet commandSet = ChimeraCommands - .getSetAttributeCommandsForFeatures(getSsm(), files, - getSequence(), avp); + .getSetAttributeCommandsForFeatures(avp, this); String[] commands = commandSet.commands; if (commands.length > 10) { @@ -1289,11 +1268,14 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel { StringBuilder cmd = new StringBuilder(128); cmd.append("~display; ~ribbon;"); - String atomSpec = getMappedResidues(av); + + AtomSpecModel model = getShownResidues(av); + String atomSpec = ChimeraCommands.getAtomSpec(model, this); + cmd.append("ribbon ").append(atomSpec); if (!isShowAlignmentOnly()) { - cmd.append("chain @CA|P; ribbon"); + cmd.append("; chain @CA|P"); } if (refocus) { @@ -1302,94 +1284,17 @@ public abstract class JalviewChimeraBinding extends AAStructureBindingModel sendChimeraCommand(cmd.toString(), false); } - /** - * Builds a Chimera atomSpec of residues mapped from sequences, of the format - * (#model:residues.chain) - * - *
-   * #0:2-94.A | #1:1-93.C | #2:1-93.A
-   * 
- * - * Only residues visible in the alignment are included, that is, hidden columns - * and sequences are excluded. - * - * @param av - * @return - */ - private String getMappedResidues(AlignViewportI av) + @Override + public int getModelForPdbFile(String fileName, int fileIndex) { - AlignmentI alignment = av.getAlignment(); - final int width = alignment.getWidth(); - - String[] files = getStructureFiles(); - - StringBuilder atomSpec = new StringBuilder(256); - - for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) + if (chimeraMaps.containsKey(fileName)) { - StructureMapping[] mappings = getSsm().getMapping(files[pdbfnum]); - - /* - * Find the first mapped sequence (if any) for this PDB entry which is in - * the alignment - */ - final int seqCountForPdbFile = getSequence()[pdbfnum].length; - for (int s = 0; s < seqCountForPdbFile; s++) + List models = chimeraMaps.get(fileName); + if (!models.isEmpty()) { - for (StructureMapping mapping : mappings) - { - final SequenceI theSequence = getSequence()[pdbfnum][s]; - if (mapping.getSequence() == theSequence - && alignment.findIndex(theSequence) > -1) - { - String chainCd = mapping.getChain(); - if (!isShowChain(mapping.getPdbId(), chainCd)) - { - continue; - } - Iterator visible; - if (isShowAlignmentOnly() && isHideHiddenRegions()) - { - visible = alignment.getHiddenColumns() - .getVisContigsIterator(0, width, true); - } - else - { - visible = Collections.singletonList(new int[] { 0, width }) - .iterator(); - } - while (visible.hasNext()) - { - int[] visibleRegion = visible.next(); - int seqStartPos = theSequence.findPosition(visibleRegion[0]); - int seqEndPos = theSequence.findPosition(visibleRegion[1]); - List residueRanges = mapping - .getPDBResNumRanges(seqStartPos, seqEndPos); - if (!residueRanges.isEmpty()) - { - if (atomSpec.length() > 0) - { - atomSpec.append("| "); - } - atomSpec.append(getModelSpec(pdbfnum)).append(":"); - boolean first = true; - for (int[] range : residueRanges) - { - if (!first) - { - atomSpec.append(","); - } - first = false; - atomSpec.append(range[0]).append("-").append(range[1]); - atomSpec.append(".").append(chainCd); - } - } - } - } - } + return models.get(0).getModelNumber(); } } - - return atomSpec.toString(); + return -1; } }