From a69b975b0f7ba9d1004f9c7769ba6acc4140d074 Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 31 Aug 2010 16:16:31 +0000 Subject: [PATCH] fixed various null pointer exceptions that occur when PDB files imported into Jmol which do not map to a sequence. Notes re JAL-623 --- src/jalview/ext/jmol/JalviewJmolBinding.java | 191 ++++++++++++++++---------- 1 file changed, 120 insertions(+), 71 deletions(-) diff --git a/src/jalview/ext/jmol/JalviewJmolBinding.java b/src/jalview/ext/jmol/JalviewJmolBinding.java index 80cc8af..5a36b7c 100644 --- a/src/jalview/ext/jmol/JalviewJmolBinding.java +++ b/src/jalview/ext/jmol/JalviewJmolBinding.java @@ -161,10 +161,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()); @@ -229,7 +231,8 @@ public abstract class JalviewJmolBinding implements StructureListener, 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 +269,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 @@ -413,13 +420,14 @@ 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