Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / datamodel / PDBEntry.java
index 741ef07..a966ca1 100755 (executable)
  */
 package jalview.datamodel;
 
-import jalview.util.CaseInsensitiveString;
-
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
+import jalview.util.CaseInsensitiveString;
+
 public class PDBEntry
 {
 
@@ -39,11 +39,14 @@ public class PDBEntry
   private static final int PDB_ID_LENGTH = 4;
 
   /**
-   * property set when id is a 'manufactured' identifier from the structure data's filename
+   * property set when id is a 'manufactured' identifier from the structure
+   * data's filename
    */
   private static final String FAKED_ID = "faked_pdbid";
+
   /**
-   * property set when the id is authoritative, and should be used in preference to any identifiers in the structure data
+   * property set when the id is authoritative, and should be used in preference
+   * to any identifiers in the structure data
    */
   private static final String AUTHORITATIVE_ID = "authoritative_pdbid";
 
@@ -57,7 +60,8 @@ public class PDBEntry
   {
     // TODO is FILE needed; if not is this enum needed, or can we
     // use FileFormatI for PDB, MMCIF?
-    PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), BCIF("bcif","bcif"),FILE("?", "?");
+    PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), BCIF("bcif", "bcif"),
+    FILE("?", "?");
 
     /*
      * file extension for cached structure file; must be one that
@@ -161,6 +165,32 @@ public class PDBEntry
   {
   }
 
+  /**
+   * Entry point when file is not known and fileType may be string
+   * @param pdbId
+   * @param chain may be null
+   * @param fileType "pdb", "mmcif", or "bcif"; null defaults to mmcif
+   */
+  public PDBEntry(String pdbId, String chain, String fileType) {
+    this.id = pdbId.toLowerCase();
+    setChainCode(chain); // I note that PDB Chains ARE case-sensitive now
+    if (fileType == null)
+      fileType = "mmcif";
+    switch (fileType.toLowerCase()) {
+    case "pdb":
+      this.type = Type.PDB.toString();
+      break;
+    case "mmcif":
+      this.type = Type.MMCIF.toString();
+      break;
+    default:
+    case "bcif":
+      System.out.println("format " + fileType + " has not been implemented; using mmCIF");
+      this.type = Type.MMCIF.toString();
+      break;
+    }
+  }
+  
   public PDBEntry(String pdbId, String chain, PDBEntry.Type type,
           String filePath)
   {
@@ -262,6 +292,12 @@ public class PDBEntry
     return id;
   }
 
+  /**
+   * TODO 
+   * 
+   * @param key  "protocol" 
+   * @param value
+   */
   public void setProperty(String key, Object value)
   {
     if (this.properties == null)
@@ -493,12 +529,12 @@ public class PDBEntry
     }
     return true;
   }
-  
+
   public void setAuthoritative(boolean isAuthoritative)
   {
     setProperty(AUTHORITATIVE_ID, Boolean.valueOf(isAuthoritative));
   }
-  
+
   /**
    * 
    * @return true if the identifier should be preferred over any identifiers
@@ -508,13 +544,14 @@ public class PDBEntry
   {
     if (_hasProperty(AUTHORITATIVE_ID))
     {
-      return ((Boolean)getProperty(AUTHORITATIVE_ID));
+      return ((Boolean) getProperty(AUTHORITATIVE_ID));
     }
     return false;
   }
 
   /**
    * set when Jalview has manufactured the ID using a local filename
+   * 
    * @return
    */
   public boolean fakedPDBId()
@@ -525,15 +562,17 @@ public class PDBEntry
     }
     return false;
   }
+
   public void setFakedPDBId(boolean faked)
   {
     if (faked)
     {
       setProperty(FAKED_ID, Boolean.TRUE);
     }
-    else 
+    else
     {
-      if (properties!=null) {
+      if (properties != null)
+      {
         properties.remove(FAKED_ID);
       }
     }