JAL-629 Some refactoring to allow more flexible use of PAE files. Not working as...
[jalview.git] / src / jalview / ext / jmol / JmolParser.java
index 2bc4869..969d195 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.ext.jmol;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -67,8 +68,6 @@ public class JmolParser extends StructureFile implements JmolStatusListener
 {
   Viewer viewer = null;
 
-  private boolean alphaFoldModel;
-
   public JmolParser(boolean immediate, Object inFile,
           DataSourceType sourceType) throws IOException
   {
@@ -231,8 +230,9 @@ public class JmolParser extends StructureFile implements JmolStatusListener
       {
         setId(pdbId);
         setPDBIdAvailable(true);
-        alphaFoldModel = alphaFold.search(pdbId) && isMMCIF;
-
+        Console.debug("##### DATASOURCETYPE=" + getDataSourceType());
+        setAlphafoldModel(alphaFold.search(pdbId) && isMMCIF
+                && getDataSourceType() == DataSourceType.URL);
       }
       List<Atom> significantAtoms = convertSignificantAtoms(ms);
       for (Atom tmpatom : significantAtoms)
@@ -250,9 +250,8 @@ public class JmolParser extends StructureFile implements JmolStatusListener
         else
         {
           AnnotationRowBuilder builder = null;
-          String tempFString = null;
-          if (isAlphafoldModel() || StructureImportSettings.TFType.PLDDT
-                  .equals(getTemperatureFactorType()))
+          if (isAlphafoldModel()
+                  || getTemperatureFactorType() == StructureImportSettings.TFType.PLDDT)
           {
             builder = new AlphaFoldAnnotationRowBuilder();
           }
@@ -290,28 +289,49 @@ public class JmolParser extends StructureFile implements JmolStatusListener
           createAnnotation(chainseq, chain, ms.at);
         }
       }
-      if (isAlphafoldModel())
+      // if Alphafold, fetch the PAE matrix if doesn't already have one
+      if (isAlphafoldModel() && !hasPAEMatrix())
       {
-        // TODO - work out how to handle different ways that pAE is provided
-        //
         try
         {
           Console.info("retrieving pAE for " + pdbId);
-          Alignment al = new Alignment(prot.toArray(new SequenceI[0]));
-          EBIAlfaFold.retrieve_AlphaFold_pAE(pdbId, al, null);
-          if (al.getAlignmentAnnotation() != null)
-          {
-            for (AlignmentAnnotation alann : al.getAlignmentAnnotation())
-            {
-              annotations.add(alann);
-            }
-          }
-          ;
+          File paeFile = EBIAlfaFold.fetchAlphaFoldPAE(pdbId, null);
+          this.setPAEMatrix(paeFile.getAbsolutePath());
         } catch (Throwable t)
         {
           Console.error("Couldn't get the pAE for " + pdbId, t);
         }
       }
+      // add a PAEMatrix if set (either by above or otherwise)
+      Console.debug("##### hasPAEMatrix()=" + hasPAEMatrix());
+      Console.debug("##### isAlphafoldModel()=" + isAlphafoldModel());
+      Console.debug("##### getPAEMatrix()=" + getPAEMatrix());
+      if (hasPAEMatrix())
+      {
+        Alignment al = new Alignment(prot.toArray(new SequenceI[0]));
+        if (isAlphafoldModel())
+        {
+          EBIAlfaFold.addAlphaFoldPAE(al, new File(this.getPAEMatrix()), 0,
+                  null, false, false);
+        }
+        else
+        {
+          EBIAlfaFold.addPAEToStructure(null, this.getInFile(),
+                  new File(this.getPAEMatrix()));
+        }
+
+        Console.debug("##### al.getAlignmentAnnotation()="
+                + al.getAlignmentAnnotation());
+        if (al.getAlignmentAnnotation() != null)
+        {
+          for (AlignmentAnnotation alann : al.getAlignmentAnnotation())
+          {
+            Console.debug("##### Adding to alann" + alann.annotationId + "("
+                    + alann.getCalcId() + ")");
+            annotations.add(alann);
+          }
+        }
+      }
     } catch (OutOfMemoryError er)
     {
       System.out.println(
@@ -321,16 +341,6 @@ public class JmolParser extends StructureFile implements JmolStatusListener
     }
   }
 
-  public void setAlphafoldModel(boolean afm)
-  {
-    alphaFoldModel = afm;
-  }
-
-  private boolean isAlphafoldModel()
-  {
-    return alphaFoldModel;
-  }
-
   private List<Atom> convertSignificantAtoms(ModelSet ms)
   {
     List<Atom> significantAtoms = new ArrayList<Atom>();