- if (refStructure<-1)
- {
- refStructure=-1;
- }
- StringBuffer command = new StringBuffer(), selectioncom = new StringBuffer();
-
- boolean matched[] = new boolean[alignment.getWidth()];
- for (int m = 0; m < matched.length; m++)
- {
-
- matched[m] = (hiddenCols!=null) ? hiddenCols.isVisible(m) : true;
- }
-
- int commonrpositions[][] = new int[files.length][alignment.getWidth()];
- String isel[] = new String[files.length];
- // reference structure - all others are superposed in it
- String[] targetC = new String[files.length];
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]);
-
- if (mapping == null || mapping.length < 1)
- continue;
-
- int lastPos = -1;
- for (int s = 0; s < sequence[pdbfnum].length; s++)
- {
- for (int sp, m = 0; m < mapping.length; m++)
- {
- if (mapping[m].getSequence() == sequence[pdbfnum][s]
- && (sp = alignment.findIndex(sequence[pdbfnum][s])) > -1)
- {
- if (refStructure == -1)
- {
- refStructure = pdbfnum;
- }
- SequenceI asp = alignment.getSequenceAt(sp);
- for (int r = 0; r < matched.length; r++)
- {
- if (!matched[r])
- {
- continue;
- }
- matched[r] = false; // assume this is not a good site
- if (r >= asp.getLength())
- {
- continue;
- }
-
- if (jalview.util.Comparison.isGap(asp.getCharAt(r)))
- {
- // no mapping to gaps in sequence
- continue;
- }
- int t = asp.findPosition(r); // sequence position
- int apos = mapping[m].getAtomNum(t);
- int pos = mapping[m].getPDBResNum(t);
-
- if (pos < 1 || pos == lastPos)
- {
- // can't align unmapped sequence
- continue;
- }
- matched[r] = true; // this is a good ite
- lastPos = pos;
- // just record this residue position
- commonrpositions[pdbfnum][r] = pos;
- }
- // create model selection suffix
- isel[pdbfnum] = "/" + (pdbfnum + 1) + ".1";
- if (mapping[m].getChain() == null
- || mapping[m].getChain().trim().length() == 0)
- {
- targetC[pdbfnum] = "";
- }
- else
- {
- targetC[pdbfnum] = ":" + mapping[m].getChain();
- }
- // move on to next pdb file
- s = sequence[pdbfnum].length;
- break;
- }
- }
- }
- }
- String[] selcom = new String[files.length];
- // generate select statements to select regions to superimpose structures
- {
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- String chainCd = targetC[pdbfnum];
- int lpos = -1;
- boolean run = false;
- StringBuffer molsel = new StringBuffer();
- molsel.append("{");
- for (int r = 0; r < matched.length; r++)
- {
- if (matched[r])
- {
-
- if (lpos != commonrpositions[pdbfnum][r] - 1)
- {
- // discontinuity
- if (lpos != -1)
- {
- molsel.append(lpos);
- molsel.append(chainCd);
- // molsel.append("} {");
- molsel.append("|");
- }
- }
- else
- {
- // continuous run - and lpos >-1
- if (!run)
- {
- // at the beginning, so add dash
- molsel.append(lpos);
- molsel.append("-");
- }
- run = true;
- }
- lpos = commonrpositions[pdbfnum][r];
- // molsel.append(lpos);
- }
- }
- // add final selection phrase
- if (lpos != -1)
- {
- molsel.append(lpos);
- molsel.append(chainCd);
- molsel.append("}");
- }
- selcom[pdbfnum] = molsel.toString();
- selectioncom.append("((");
- selectioncom.append(selcom[pdbfnum].substring(1, selcom[pdbfnum].length()-1));
- selectioncom.append(" )& ");
- selectioncom.append(pdbfnum+1);
- selectioncom.append(".1)");
- if (pdbfnum<files.length-1)
- {
- selectioncom.append("|");
- }
- }
- }
-
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)
- {
- if (pdbfnum == refStructure)
- {
- continue;
- }
- command.append("compare ");
- command.append("{");
- command.append(1 + pdbfnum);
- command.append(".1} {");
- command.append(1 + refStructure);
- command.append(".1} SUBSET {*.CA | *.P} ATOMS ");
-
- // form the matched pair strings
- String sep = "";
- for (int s = 0; s < 2; s++)
- {
- command.append(selcom[(s == 0 ? pdbfnum : refStructure)]);
- }
- command.append(" ROTATE TRANSLATE;\n");
- }
- System.out.println("Select regions:\n" + selectioncom.toString());
- evalStateCommand("select *; cartoons off; backbone; select ("+selectioncom.toString()+"); cartoons; ");
- // selcom.append("; ribbons; ");
- System.out.println("Superimpose command(s):\n" + command.toString());
-
- evalStateCommand(command.toString());
-
- // evalStateCommand("select *; backbone; select "+selcom.toString()+"; cartoons; center "+selcom.toString());
- }
-
- public void evalStateCommand(String command)
- {
- jmolHistory(false);
- if (lastCommand == null || !lastCommand.equals(command))
- {
- viewer.evalStringQuiet(command + "\n");
- }
- jmolHistory(true);
- lastCommand = command;
- }
-
- /**
- * colour any structures associated with sequences in the given alignment
- * using the getFeatureRenderer() and getSequenceRenderer() renderers but only
- * if colourBySequence is enabled.
- */
- public void colourBySequence(boolean showFeatures, AlignmentI alignment)
- {
- if (!colourBySequence)
- return;
- if (ssm == null)
- {
- return;
- }
- String[] files = getPdbFile();
- SequenceRenderer sr = getSequenceRenderer();
-
- FeatureRenderer fr = null;
- if (showFeatures)
- {
- fr = getFeatureRenderer();
- }
-
- StringBuffer command = new StringBuffer();
-
- for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++)