JAL-1925 update source version in license
[jalview.git] / src / jalview / ext / jmol / PDBFileWithJmol.java
index 2f117d3..8171f9d 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
- * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
+ * Copyright (C) 2015 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -45,7 +45,6 @@ import org.jmol.modelset.ModelSet;
 import org.jmol.modelsetbio.BioModel;
 import org.jmol.modelsetbio.BioPolymer;
 import org.jmol.viewer.Viewer;
-import org.openscience.jmol.app.JmolApp;
 
 /**
  * Import and process PDB files with Jmol
@@ -56,9 +55,6 @@ import org.openscience.jmol.app.JmolApp;
 public class PDBFileWithJmol extends AlignFile implements
         JmolStatusListener
 {
-
-  JmolApp jmolApp = null;
-
   Viewer viewer = null;
 
   public PDBFileWithJmol(String inFile, String type) throws IOException
@@ -73,7 +69,6 @@ public class PDBFileWithJmol extends AlignFile implements
 
   public PDBFileWithJmol()
   {
-    // TODO Auto-generated constructor stub
   }
 
   /**
@@ -84,22 +79,16 @@ public class PDBFileWithJmol extends AlignFile implements
   private Viewer getJmolData()
   {
     if (viewer == null)
-    { // note that -o -n -x are all implied // TODO check for Jmol 14.2
-      jmolApp = new JmolApp();
-      jmolApp.isDataOnly = true;
-      jmolApp.haveConsole = false;
-      jmolApp.haveDisplay = false;
+    {
       try
       {
         viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
                 null, "-x -o -n", this);
-        viewer.setScreenDimension(jmolApp.startupWidth,
-                jmolApp.startupHeight);
-        jmolApp.startViewer(viewer, null, false);
       } catch (ClassCastException x)
       {
-        throw new Error(MessageManager.formatMessage("error.jmol_version_not_compatible_with_jalview_version", new String[]{JmolViewer.getJmolVersion()}),
-                x);
+        throw new Error(MessageManager.formatMessage(
+                "error.jmol_version_not_compatible_with_jalview_version",
+                new String[] { JmolViewer.getJmolVersion() }), x);
       }
     }
     return viewer;
@@ -144,7 +133,9 @@ public class PDBFileWithJmol extends AlignFile implements
         modelIndex++;
         for (BioPolymer bp : ((BioModel) model).bioPolymers)
         {
-          int _lastChainId = 0;
+          int lastChainId = 0; // int value of character e.g. 65 for A
+          String lastChainIdAlpha = "";
+
           int[] groups = bp.getLeadAtomIndices();
           char seq[] = new char[groups.length], secstr[] = new char[groups.length], secstrcode[] = new char[groups.length];
           int groupc = 0, len = 0, firstrnum = 1, lastrnum = 0;
@@ -152,7 +143,7 @@ public class PDBFileWithJmol extends AlignFile implements
           do
           {
             if (groupc >= groups.length
-                    || ms.at[groups[groupc]].group.chain.chainID != _lastChainId)
+                    || ms.at[groups[groupc]].group.chain.chainID != lastChainId)
             {
               /*
                * on change of chain (or at end), construct the sequence and
@@ -174,21 +165,27 @@ public class PDBFileWithJmol extends AlignFile implements
                   newseq[p] = cinds[seq[p]] == nonGap ? ngc : seq[p];
                   if (secstr[p] >= 'A' && secstr[p] <= 'z')
                   {
-                    asecstr[p] = new Annotation("" + secstr[p], null,
-                            secstrcode[p], Float.NaN);
+                    try
+                    {
+                      asecstr[p] = new Annotation("" + secstr[p], null,
+                              secstrcode[p], Float.NaN);
+                    } catch (ArrayIndexOutOfBoundsException e)
+                    {
+                      // skip - patch for JAL-1836
+                    }
                   }
                 }
                 String modelTitle = (String) ms
                         .getInfo(modelIndex, "title");
                 SequenceI sq = new Sequence("" + getDataName() + "|"
-                        + modelTitle + "|" + _lastChainId, newseq,
+                        + modelTitle + "|" + lastChainIdAlpha, newseq,
                         firstrnum, lastrnum);
                 PDBEntry pdbe = new PDBEntry();
                 pdbe.setFile(getDataName());
                 pdbe.setId(getDataName());
                 pdbe.setProperty(new Hashtable());
                 // pdbe.getProperty().put("CHAIN", "" + _lastChainId);
-                pdbe.setChainCode(String.valueOf(_lastChainId));
+                pdbe.setChainCode(lastChainIdAlpha);
                 sq.addPDBId(pdbe);
                 // JAL-1533
                 // Need to put the number of models for this polymer somewhere
@@ -199,9 +196,9 @@ public class PDBFileWithJmol extends AlignFile implements
                 {
                   String mt = modelTitle == null ? getDataName()
                           : modelTitle;
-                  if (_lastChainId >= ' ')
+                  if (lastChainId >= ' ')
                   {
-                    mt += _lastChainId;
+                    mt += lastChainIdAlpha;
                   }
                   AlignmentAnnotation ann = new AlignmentAnnotation(
                           "Secondary Structure", "Secondary Structure for "
@@ -226,13 +223,28 @@ public class PDBFileWithJmol extends AlignFile implements
               if (len == 0)
               {
                 firstrnum = group.getResno();
-                _lastChainId = group.chain.chainID;
+                lastChainId = group.chain.chainID;
+                lastChainIdAlpha = group.chain.getIDStr();
               }
               else
               {
                 lastrnum = group.getResno();
               }
               seq[len] = group.getGroup1();
+
+              /*
+               * JAL-1828 replace a modified amino acid with its standard
+               * equivalent (e.g. MSE with MET->M) to maximise sequence matching
+               */
+              String threeLetterCode = group.getGroup3();
+              String canonical = ResidueProperties
+                      .getCanonicalAminoAcid(threeLetterCode);
+              if (canonical != null
+                      && !canonical.equalsIgnoreCase(threeLetterCode))
+              {
+                seq[len] = ResidueProperties
+                        .getSingleCharacterCode(canonical);
+              }
               switch (group.getProteinStructureSubType())
               {
               case HELIX310: