- lastCommand = null;
- viewer = null;
-
- if (chimeraMonitor != null)
- {
- chimeraMonitor.interrupt();
- }
- releaseUIResources();
- }
-
- @Override
- public void colourByChain()
- {
- colourBySequence = false;
- sendAsynchronousCommand("rainbow chain", COLOURING_CHIMERA);
- }
-
- /**
- * Constructs and sends a Chimera command to colour by charge
- * <ul>
- * <li>Aspartic acid and Glutamic acid (negative charge) red</li>
- * <li>Lysine and Arginine (positive charge) blue</li>
- * <li>Cysteine - yellow</li>
- * <li>all others - white</li>
- * </ul>
- */
- @Override
- public void colourByCharge()
- {
- colourBySequence = false;
- String command = "color white;color red ::ASP;color red ::GLU;color blue ::LYS;color blue ::ARG;color yellow ::CYS";
- sendAsynchronousCommand(command, COLOURING_CHIMERA);
- }
-
- /**
- * Construct and send a command to align structures against a reference
- * structure, based on one or more sequence alignments
- *
- * @param _alignment
- * an array of alignments to process
- * @param _refStructure
- * an array of corresponding reference structures (index into pdb
- * file array); if a negative value is passed, the first PDB file
- * mapped to an alignment sequence is used as the reference for
- * superposition
- * @param _hiddenCols
- * an array of corresponding hidden columns for each alignment
- */
- @Override
- public void superposeStructures(AlignmentI[] _alignment,
- int[] _refStructure, ColumnSelection[] _hiddenCols)
- {
- StringBuilder allComs = new StringBuilder(128);
- String[] files = getPdbFile();
-
- if (!waitForFileLoad(files))
- {
- return;
- }
-
- refreshPdbEntries();
- StringBuilder selectioncom = new StringBuilder(256);
- for (int a = 0; a < _alignment.length; a++)
- {
- int refStructure = _refStructure[a];
- AlignmentI alignment = _alignment[a];
- ColumnSelection hiddenCols = _hiddenCols[a];
-
- if (refStructure >= files.length)
- {
- System.err.println("Ignoring invalid reference structure value "
- + refStructure);
- refStructure = -1;
- }
-
- /*
- * 'matched' array will hold 'true' for visible alignment columns where
- * all sequences have a residue with a mapping to the PDB structure
- */
- boolean matched[] = new boolean[alignment.getWidth()];
- for (int m = 0; m < matched.length; m++)
- {
- matched[m] = (hiddenCols != null) ? hiddenCols.isVisible(m) : true;
- }
-
- SuperposeData[] structures = new SuperposeData[files.length];
- for (int f = 0; f < files.length; f++)
- {
- structures[f] = new SuperposeData(alignment.getWidth());
- }
-
- /*
- * Calculate the superposable alignment columns ('matched'), and the
- * corresponding structure residue positions (structures.pdbResNo)
- */
- int candidateRefStructure = findSuperposableResidues(alignment,
- matched, structures);
- if (refStructure < 0)
- {
- /*
- * If no reference structure was specified, pick the first one that has
- * a mapping in the alignment
- */
- refStructure = candidateRefStructure;
- }
-
- int nmatched = 0;
- for (boolean b : matched)
- {
- if (b)
- {
- nmatched++;
- }
- }
- if (nmatched < 4)
- {
- // TODO: bail out here because superposition illdefined?
- }
-
- /*
- * Generate select statements to select regions to superimpose structures
- */
- String[] selcom = new String[files.length];
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- String chainCd = "." + structures[pdbfnum].chain;
- int lpos = -1;
- boolean run = false;
- StringBuilder molsel = new StringBuilder();
- for (int r = 0; r < matched.length; r++)
- {
- if (matched[r])
- {
- int pdbResNum = structures[pdbfnum].pdbResNo[r];
- if (lpos != pdbResNum - 1)
- {
- /*
- * discontiguous - append last residue now
- */
- if (lpos != -1)
- {
- molsel.append(String.valueOf(lpos));
- molsel.append(chainCd);
- molsel.append(",");
- }
- run = false;
- }
- else
- {
- /*
- * extending a contiguous run
- */
- if (!run)
- {
- /*
- * start the range selection
- */
- molsel.append(String.valueOf(lpos));
- molsel.append("-");
- }
- run = true;
- }
- lpos = pdbResNum;
- }
- }
-
- /*
- * and terminate final selection
- */
- if (lpos != -1)
- {
- molsel.append(String.valueOf(lpos));
- molsel.append(chainCd);
- }
- if (molsel.length() > 1)
- {
- selcom[pdbfnum] = molsel.toString();
- selectioncom.append("#").append(String.valueOf(pdbfnum))
- .append(":");
- selectioncom.append(selcom[pdbfnum]);
- selectioncom.append(" ");
- if (pdbfnum < files.length - 1)
- {
- selectioncom.append("| ");
- }
- }
- else
- {
- selcom[pdbfnum] = null;
- }
- }
-
- StringBuilder command = new StringBuilder(256);
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- if (pdbfnum == refStructure || selcom[pdbfnum] == null
- || selcom[refStructure] == null)
- {
- continue;
- }
- if (command.length() > 0)
- {
- command.append(";");
- }
-
- /*
- * Form Chimera match command, from the 'new' structure to the
- * 'reference' structure e.g. (50 residues, chain B/A, alphacarbons):
- *
- * match #1:1-30.B,81-100.B@CA #0:21-40.A,61-90.A@CA
- *
- * @see
- * https://www.cgl.ucsf.edu/chimera/docs/UsersGuide/midas/match.html
- */
- command.append("match ").append(getModelSpec(pdbfnum)).append(":");
- command.append(selcom[pdbfnum]);
- command.append("@").append(
- structures[pdbfnum].isRna ? PHOSPHORUS : ALPHACARBON);
- // JAL-1757 exclude alternate CA locations
- command.append(NO_ALTLOCS);
- command.append(" ").append(getModelSpec(refStructure)).append(":");
- command.append(selcom[refStructure]);
- command.append("@").append(
- structures[refStructure].isRna ? PHOSPHORUS : ALPHACARBON);
- command.append(NO_ALTLOCS);
- }
- if (selectioncom.length() > 0)
- {
- if (debug)
- {
- System.out.println("Select regions:\n" + selectioncom.toString());
- System.out.println("Superimpose command(s):\n"
- + command.toString());
- }
- allComs.append("~display all; chain @CA|P; ribbon ")
- .append(selectioncom.toString())
- .append(";" + command.toString());
- }
- }
- if (selectioncom.length() > 0)
- {
- // TODO: visually distinguish regions that were superposed
- if (selectioncom.substring(selectioncom.length() - 1).equals("|"))
- {
- selectioncom.setLength(selectioncom.length() - 1);
- }
- if (debug)
- {
- System.out.println("Select regions:\n" + selectioncom.toString());
- }
- allComs.append("; ~display all; chain @CA|P; ribbon ")
- .append(selectioncom.toString()).append("; focus");
- sendChimeraCommand(allComs.toString(), false);
- }
-