JAL-1919 code improvement to make PDB sequence fetcher file format configurable....
[jalview.git] / src / jalview / structure / StructureSelectionManager.java
index 00b3143..6bb04ab 100644 (file)
@@ -34,6 +34,7 @@ import jalview.datamodel.SearchResults;
 import jalview.datamodel.SequenceI;
 import jalview.gui.IProgressIndicator;
 import jalview.io.AppletFormatAdapter;
+import jalview.io.StructureFile;
 import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 import jalview.ws.sifts.SiftsClient;
@@ -319,12 +320,13 @@ public class StructureSelectionManager
    *          - how to resolve data from resource
    * @return null or the structure data parsed as a pdb file
    */
-  synchronized public PDBfile setMapping(SequenceI[] sequence,
+  synchronized public StructureFile setMapping(SequenceI[] sequence,
           String[] targetChains, String pdbFile, String protocol)
   {
     return setMapping(true, sequence, targetChains, pdbFile, protocol);
   }
 
+
   /**
    * create sequence structure mappings between each sequence and the given
    * pdbFile (retrieved via the given protocol).
@@ -343,7 +345,7 @@ public class StructureSelectionManager
    *          - how to resolve data from resource
    * @return null or the structure data parsed as a pdb file
    */
-  synchronized public PDBfile setMapping(boolean forStructureView,
+  synchronized public StructureFile setMapping(boolean forStructureView,
           SequenceI[] sequenceArray, String[] targetChainIds,
           String pdbFile,
           String protocol)
@@ -378,12 +380,21 @@ public class StructureSelectionManager
         }
       }
     }
-    PDBfile pdb = null;
+    StructureFile pdb = null;
     boolean isMapUsingSIFTs = SiftsSettings.isMapWithSifts();
     try
     {
-      pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices,
-              pdbFile, protocol);
+
+      if (pdbFile != null && isCIFFile(pdbFile))
+      {
+        pdb = new jalview.ext.jmol.JmolParser(addTempFacAnnot, parseSecStr,
+                secStructServices, pdbFile, protocol);
+      }
+      else
+      {
+        pdb = new PDBfile(addTempFacAnnot, parseSecStr, secStructServices,
+                pdbFile, protocol);
+      }
 
       if (pdb.getId() != null && pdb.getId().trim().length() > 0
               && AppletFormatAdapter.FILE.equals(protocol))
@@ -525,8 +536,15 @@ public class StructureSelectionManager
     return pdb;
   }
 
+  private boolean isCIFFile(String filename)
+  {
+    String fileExt = filename.substring(filename.lastIndexOf(".") + 1,
+            filename.length());
+    return "cif".equalsIgnoreCase(fileExt);
+  }
+
   private StructureMapping getStructureMapping(SequenceI seq,
-          String pdbFile, String targetChainId, PDBfile pdb,
+          String pdbFile, String targetChainId, StructureFile pdb,
           PDBChain maxChain, jalview.datamodel.Mapping sqmpping,
           AlignSeq maxAlignseq)
   {
@@ -560,7 +578,7 @@ public class StructureSelectionManager
 
   private StructureMapping getNWMappings(SequenceI seq,
           String pdbFile,
-          String maxChainId, PDBChain maxChain, PDBfile pdb,
+          String maxChainId, PDBChain maxChain, StructureFile pdb,
           AlignSeq maxAlignseq)
   {
     final StringBuilder mappingDetails = new StringBuilder(128);