JAL-2262 JAL-2195 bug fix for mapping local structure files
[jalview.git] / src / jalview / ext / jmol / JmolParser.java
index 7836d24..c73657f 100644 (file)
@@ -28,6 +28,7 @@ import jalview.io.FileParse;
 import jalview.io.StructureFile;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureImportSettings;
+import jalview.util.Format;
 import jalview.util.MessageManager;
 
 import java.io.IOException;
@@ -60,15 +61,12 @@ public class JmolParser extends StructureFile implements JmolStatusListener
 {
   Viewer viewer = null;
 
-  public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr,
-          boolean externalSecStr, String inFile, String type)
-          throws IOException
+  public JmolParser(String inFile, String type) throws IOException
   {
     super(inFile, type);
   }
 
-  public JmolParser(boolean addAlignmentAnnotations, boolean predictSecStr,
-          boolean externalSecStr, FileParse fp) throws IOException
+  public JmolParser(FileParse fp) throws IOException
   {
     super(fp);
   }
@@ -125,8 +123,13 @@ public class JmolParser extends StructureFile implements JmolStatusListener
     {
       try
       {
+        /*
+         * params -o (output to sysout) -i (no info logging, less verbose)
+         * -n (nodisplay) -x (exit when finished)
+         * see http://wiki.jmol.org/index.php/Jmol_Application
+         */
         viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
-                null, "-x -o -n", this);
+                null, "-x -o -n -i", this);
         // ensure the 'new' (DSSP) not 'old' (Ramachandran) SS method is used
         viewer.setBooleanProperty("defaultStructureDSSP", true);
       } catch (ClassCastException x)
@@ -148,7 +151,15 @@ public class JmolParser extends StructureFile implements JmolStatusListener
       List<SequenceI> prot = new ArrayList<SequenceI>();
       PDBChain tmpchain;
       String pdbId = (String) ms.getInfo(0, "title");
-      setId(pdbId);
+
+      if (pdbId == null)
+      {
+        setId(safeName(getDataName()));
+      }
+      else
+      {
+        setId(pdbId);
+      }
       List<Atom> significantAtoms = convertSignificantAtoms(ms);
       for (Atom tmpatom : significantAtoms)
       {
@@ -163,7 +174,7 @@ public class JmolParser extends StructureFile implements JmolStatusListener
           tmpchain.atoms.addElement(tmpatom);
         } catch (Exception e)
         {
-          tmpchain = new PDBChain(pdbId, tmpatom.chain);
+          tmpchain = new PDBChain(getId(), tmpatom.chain);
           getChains().add(tmpchain);
           tmpchain.atoms.addElement(tmpatom);
         }
@@ -174,10 +185,6 @@ public class JmolParser extends StructureFile implements JmolStatusListener
       makeResidueList();
       makeCaBondList();
 
-      if (getId() == null)
-      {
-        setId(safeName(getDataName()));
-      }
       for (PDBChain chain : getChains())
       {
         SequenceI chainseq = postProcessChain(chain);
@@ -230,8 +237,8 @@ public class JmolParser extends StructureFile implements JmolStatusListener
         curAtom.resNumber = atom.getResno();
         curAtom.occupancy = ms.occupancies != null ? ms.occupancies[atom
                 .getIndex()] : Float.valueOf(atom.getOccupancy100());
-        curAtom.resNumIns = ("" + curAtom.resNumber + curAtom.insCode)
-                .trim();
+        String fmt = new Format("%4i").form(curAtom.resNumber);
+        curAtom.resNumIns = (fmt + curAtom.insCode);
         curAtom.tfactor = atom.getBfactor100() / 100f;
         curAtom.type = 0;
         // significantAtoms.add(curAtom);
@@ -352,9 +359,9 @@ public class JmolParser extends StructureFile implements JmolStatusListener
       {
         try
         {
-        asecstr[p] = new Annotation(String.valueOf(secstr[p]), null,
-                secstrcode[p], Float.NaN);
-        ssFound = true;
+          asecstr[p] = new Annotation(String.valueOf(secstr[p]), null,
+                  secstrcode[p], Float.NaN);
+          ssFound = true;
         } catch (Exception e)
         {
           // e.printStackTrace();