Merge branch 'develop' into releases/Release_2_11_2_Branch
authorJim Procter <j.procter@dundee.ac.uk>
Mon, 8 Nov 2021 18:47:33 +0000 (18:47 +0000)
committerJim Procter <j.procter@dundee.ac.uk>
Mon, 8 Nov 2021 18:47:33 +0000 (18:47 +0000)
src/jalview/gui/AppJmolBinding.java
src/jalview/gui/StructureViewerBase.java
src/jalview/structure/StructureSelectionManager.java
test/jalview/project/Jalview2xmlTests.java

index 037b97e..6b06e56 100644 (file)
@@ -222,45 +222,17 @@ public class AppJmolBinding extends JalviewJmolBinding
       String[] filesInViewer = getStructureFiles();
       // TODO: replace with reference fetching/transfer code (validate PDBentry
       // as a DBRef?)
-      Pdb pdbclient = new Pdb();
-      EBIAlfaFold afclient = new EBIAlfaFold();
       
       for (int pi = 0; pi < getPdbCount(); pi++)
       {
-        String file = getPdbEntry(pi).getFile();
+        PDBEntry strucEntry = getPdbEntry(pi);
+
+        String file = strucEntry.getFile();
         if (file == null)
         {
-          // todo: extract block as method and pull up (also ChimeraViewFrame)
-          // retrieve the pdb and store it locally
-          AlignmentI pdbseq = null;
-          PDBEntry strucEntry = getPdbEntry(pi);
           pdbid = strucEntry.getId();
-          long hdl = pdbid.hashCode() - System.currentTimeMillis();
-          structureViewer.setProgressMessage(MessageManager
-                  .formatMessage("status.fetching_pdb", new String[]
-                  { pdbid }), hdl);
-          try
-          {
-            if (afclient.isValidReference(pdbid))
-            {
-              pdbseq = afclient.getSequenceRecords(pdbid);
-            } else {
-              if (strucEntry.hasRetrievalUrl())
-              {
-                File tmpFile = File.createTempFile(pdbid, ".cif");
-                String fromUrl = strucEntry.getRetrievalUrl();
-                UrlDownloadClient.download(fromUrl, tmpFile);
-                
-                // may not need this check ?
-                file = tmpFile.getAbsolutePath();
-                if (file != null)
-                {
-                  pdbseq = EBIAlfaFold.importDownloadedStructureFromUrl(fromUrl,tmpFile,pdbid,null,null,null);
-                }
-              } else {
-                pdbseq = pdbclient.getSequenceRecords(pdbid);
-              }
-            }
+          try{ 
+            file = structureViewer.fetchPdbFile(strucEntry);
           } catch (OutOfMemoryError oomerror)
           {
             new OOMWarning("Retrieving PDB id " + pdbid, oomerror);
@@ -268,18 +240,10 @@ public class AppJmolBinding extends JalviewJmolBinding
           {
             ex.printStackTrace();
             errormsgs.append("'").append(pdbid).append("'");
-          } finally
-          {
-            structureViewer.setProgressMessage(
-                    MessageManager.getString("label.state_completed"), hdl);
           }
-          if (pdbseq != null)
+          if (file!=null)
           {
-            // just transfer the file name from the first sequence's first
-            // PDBEntry
-            file = new File(pdbseq.getSequenceAt(0).getAllPDBEntries()
-                    .elementAt(0).getFile()).getAbsolutePath();
-            getPdbEntry(pi).setFile(file);
+            // success
             files.add(file);
           }
           else
index 4f746cb..1c0f43e 100644 (file)
@@ -1210,8 +1210,23 @@ public abstract class StructureViewerBase extends GStructureViewer
    */
   public File saveSession()
   {
-    // TODO: a wait loop to ensure the file is written fully before returning?
-    return getBinding() == null ? null : getBinding().saveSession();
+    if (getBinding() == null) { return  null;}
+    File session = getBinding().saveSession();
+    long l = session.length();
+    int wait=50;
+    do {
+      try {
+        Thread.sleep(5);
+      } catch (InterruptedException e) {
+      } 
+      long nextl = session.length();
+      if (nextl!=l)
+      {
+        wait = 50;
+        l=nextl;
+      }
+    } while (--wait>0);
+    return session;
   }
 
   /**
index 1fcbbf5..ad57831 100644 (file)
@@ -413,7 +413,14 @@ public class StructureSelectionManager
       // TODO: JAL-3868 need to know if structure is actually from 
       // PDB (has valid PDB ID and has provenance suggesting it 
       // actually came from PDB)
-      isMapUsingSIFTs = isMapUsingSIFTs && pdb.isPPDBIdAvailable() && !pdb.getId().startsWith("AF-");
+      boolean isProtein = false;
+      for (SequenceI s:sequenceArray) {
+        if (s.isProtein()) {
+          isProtein = true;
+          break;
+        }
+      }
+      isMapUsingSIFTs = isMapUsingSIFTs && pdb.isPPDBIdAvailable() && !pdb.getId().startsWith("AF-") && isProtein;
 
     } catch (Exception ex)
     {
index eb66416..42d68a9 100644 (file)
@@ -33,6 +33,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import javax.swing.JInternalFrame;
@@ -804,6 +805,7 @@ public class Jalview2xmlTests extends Jalview2xmlBase
               "Mismatch PDBEntry 'Type'");
       Assert.assertNotNull(recov.getFile(),
               "Recovered PDBEntry should have a non-null file entry");
+      Assert.assertEquals(recov.getFile().toLowerCase(Locale.ENGLISH).lastIndexOf("pdb"),recov.getFile().length()-3, "Recovered PDBEntry file should have PDB suffix");
     }
   }