Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / datamodel / PDBEntry.java
index fc4ee46..ae8523d 100755 (executable)
  */
 package jalview.datamodel;
 
-import jalview.util.CaseInsensitiveString;
-
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
+import jalview.io.StructureFile;
+import jalview.util.CaseInsensitiveString;
+
 public class PDBEntry
 {
 
@@ -38,19 +39,32 @@ 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
+   */
   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
+   */
+  private static final String AUTHORITATIVE_ID = "authoritative_pdbid";
+
   private String file;
 
   private String type;
 
   private String id;
 
+  private StructureFile sf = null;
+
   public enum Type
   {
     // TODO is FILE needed; if not is this enum needed, or can we
     // use FileFormatI for PDB, MMCIF?
-    PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), FILE("?", "?");
+    PDB("pdb", "pdb"), MMCIF("mmcif", "cif"), BCIF("bcif", "bcif"),
+    FILE("?", "?");
 
     /*
      * file extension for cached structure file; must be one that
@@ -406,7 +420,7 @@ public class PDBEntry
           // this shouldn't happen, but could do if the id from the
           // file is not the same as the id from the authority that provided
           // the file
-          if (!newEntry.fakedPDBId())
+          if (!newEntry.fakedPDBId() && !isAuthoritative())
           {
             return false;
           } // otherwise we can update
@@ -474,7 +488,7 @@ public class PDBEntry
        */
       String key = newProps.nextElement();
       Object value = newEntry.getProperty(key);
-      if (FAKED_ID.equals(key))
+      if (FAKED_ID.equals(key) || AUTHORITATIVE_ID.equals(key))
       {
         // we never update the fake ID property
         continue;
@@ -486,9 +500,29 @@ 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
+   *         embedded in the structure data
+   */
+  public boolean isAuthoritative()
+  {
+    if (_hasProperty(AUTHORITATIVE_ID))
+    {
+      return ((Boolean) getProperty(AUTHORITATIVE_ID));
+    }
+    return false;
+  }
+
   /**
    * set when Jalview has manufactured the ID using a local filename
+   * 
    * @return
    */
   public boolean fakedPDBId()
@@ -499,15 +533,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);
       }
     }
@@ -593,4 +629,19 @@ public class PDBEntry
   {
     return _hasProperty(PROVIDER);
   }
+
+  public StructureFile getStructureFile()
+  {
+    return sf;
+  }
+
+  public void setStructureFile(StructureFile f)
+  {
+    sf = f;
+  }
+
+  public boolean hasStructureFile()
+  {
+    return sf != null && sf.inFile != null && sf.inFile.exists();
+  }
 }