X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fext%2Fjmol%2FJalviewJmolBinding.java;h=3bac3bc1f9bb67c082b371fca52f54c9697f41f3;hb=1b5f1de68f3f4dadcd4eecc80a5db17441eb7ab6;hp=80cc8af16df0f3009d9ff28d6f4ba41c7bdd617c;hpb=b3d9ad42a4cc73a11a1478d8735dfe66a88a2953;p=jalview.git diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 80cc8af..3bac3bc 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -24,6 +24,8 @@ import java.applet.Applet; import java.awt.*; import java.awt.event.*; +import javax.swing.JPanel; + import jalview.api.FeatureRenderer; import jalview.api.SequenceRenderer; import jalview.api.SequenceStructureBinding; @@ -36,11 +38,13 @@ import org.jmol.adapter.smarter.SmarterJmolAdapter; import org.jmol.popup.*; import org.jmol.viewer.JmolConstants; +import org.jmol.viewer.Viewer; import jalview.schemes.*; public abstract class JalviewJmolBinding implements StructureListener, - JmolStatusListener, SequenceStructureBinding, JmolSelectionListener + JmolStatusListener, SequenceStructureBinding, + JmolSelectionListener, ComponentListener { /** @@ -77,6 +81,8 @@ public abstract class JalviewJmolBinding implements StructureListener, public Vector chainNames; + Hashtable chainFile; + /** * array of target chains for seuqences - tied to pdbentry and sequence[] */ @@ -161,10 +167,12 @@ public abstract class JalviewJmolBinding implements StructureListener, public String getViewerTitle() { if (sequence == null || pdbentry == null || sequence.length < 1 - || pdbentry.length < 1) + || pdbentry.length < 1 || sequence[0].length < 1) { return ("Jalview Jmol Window"); } + // TODO: give a more informative title when multiple structures are + // displayed. StringBuffer title = new StringBuffer(sequence[0][0].getName() + ":" + pdbentry[0].getId()); @@ -205,8 +213,9 @@ public abstract class JalviewJmolBinding implements StructureListener, p = mlength; mlength = lbl.indexOf(":", p); } while (p < mlength && mlength < (lbl.length() - 2)); + // TODO: lookup each pdb id and recover proper model number for it. cmd.append(":" + lbl.substring(mlength + 1) + " /" - + getModelNum(lbl.substring(0, mlength)) + " or "); + + (1 + getModelNum((String) chainFile.get(lbl))) + " or "); } if (cmd.length() > 0) cmd.setLength(cmd.length() - 4); @@ -224,12 +233,20 @@ public abstract class JalviewJmolBinding implements StructureListener, viewer.setJmolStatusListener(null); lastCommand = null; viewer = null; + releaseUIResources(); } + /** + * called by JalviewJmolbinding after closeViewer is called - release any + * resources and references so they can be garbage collected. + */ + protected abstract void releaseUIResources(); + public void colourByChain() { colourBySequence = false; - // TODO: colour by chain should colour each chain distinctly across all visible models + // TODO: colour by chain should colour each chain distinctly across all + // visible models // TODO: http://issues.jalview.org/browse/JAL-628 evalStateCommand("select *;color chain"); } @@ -266,32 +283,36 @@ public abstract class JalviewJmolBinding implements StructureListener, /** * superpose the structures associated with sequences in the alignment * according to their corresponding positions. ded) + * * @param refStructure * - select which pdb file to use as reference (default is -1 - the * first structure in the alignment) - * @param hiddenCols TODO + * @param hiddenCols + * TODO */ - public void superposeStructures(AlignmentI alignment, int refStructure, ColumnSelection hiddenCols) + public void superposeStructures(AlignmentI alignment, int refStructure, + ColumnSelection hiddenCols) { String[] files = getPdbFile(); - if (refStructure>=files.length) + if (refStructure >= files.length) { - System.err.println("Invalid reference structure value "+refStructure); - refStructure= -1; + System.err.println("Invalid reference structure value " + + refStructure); + refStructure = -1; } - if (refStructure<-1) + if (refStructure < -1) { - 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; + + 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 @@ -366,6 +387,7 @@ public abstract class JalviewJmolBinding implements StructureListener, } } String[] selcom = new String[files.length]; + int nmatched = 0; // generate select statements to select regions to superimpose structures { for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) @@ -379,7 +401,10 @@ public abstract class JalviewJmolBinding implements StructureListener, { if (matched[r]) { - + if (pdbfnum == 0) + { + nmatched++; + } if (lpos != commonrpositions[pdbfnum][r] - 1) { // discontinuity @@ -413,19 +438,23 @@ public abstract class JalviewJmolBinding implements StructureListener, molsel.append(chainCd); molsel.append("}"); } - selcom[pdbfnum] = molsel.toString(); + selcom[pdbfnum] = molsel.toString(); selectioncom.append("(("); - selectioncom.append(selcom[pdbfnum].substring(1, selcom[pdbfnum].length()-1)); + selectioncom.append(selcom[pdbfnum].substring(1, + selcom[pdbfnum].length() - 1)); selectioncom.append(" )& "); - selectioncom.append(pdbfnum+1); + selectioncom.append(pdbfnum + 1); selectioncom.append(".1)"); - if (pdbfnum