JAL-3855 detect an alphafold model and import its temperature factor as reliability
[jalview.git] / src / jalview / ext / jmol / JmolParser.java
index 975846d..ae8ff7a 100644 (file)
@@ -45,9 +45,11 @@ import org.jmol.c.STR;
 import org.jmol.modelset.ModelSet;
 import org.jmol.viewer.Viewer;
 
-import MCview.Atom;
-import MCview.PDBChain;
-import MCview.Residue;
+import com.stevesoft.pat.Regex;
+
+import mc_view.Atom;
+import mc_view.PDBChain;
+import mc_view.Residue;
 
 /**
  * Import and process files with Jmol for file like PDB, mmCIF
@@ -59,13 +61,16 @@ public class JmolParser extends StructureFile implements JmolStatusListener
 {
   Viewer viewer = null;
 
-  public JmolParser(boolean immediate, String inFile,
+  private boolean alphaFoldModel;
+
+  public JmolParser(boolean immediate, Object inFile,
           DataSourceType sourceType) throws IOException
   {
+    // BH 2018 File or String for filename
     super(immediate, inFile, sourceType);
   }
 
-  public JmolParser(String inFile, DataSourceType sourceType)
+  public JmolParser(Object inFile, DataSourceType sourceType)
           throws IOException
   {
     super(inFile, sourceType);
@@ -133,8 +138,8 @@ public class JmolParser extends StructureFile implements JmolStatusListener
          * params -o (output to sysout) -n (nodisplay) -x (exit when finished)
          * see http://wiki.jmol.org/index.php/Jmol_Application
          */
-        viewer = (Viewer) JmolViewer.allocateViewer(null, null, null, null,
-                null, "-x -o -n", this);
+        
+        viewer = JalviewJmolBinding.getJmolData(this);
         // ensure the 'new' (DSSP) not 'old' (Ramachandran) SS method is used
         viewer.setBooleanProperty("defaultStructureDSSP", true);
       } catch (ClassCastException x)
@@ -147,16 +152,26 @@ public class JmolParser extends StructureFile implements JmolStatusListener
     }
     return viewer;
   }
+  
+  public static Regex getNewAlphafoldValidator()
+  {
+    Regex validator =  new Regex("(AF-[A-Z]+[0-9]+[A-Z0-9]+-F1)");
+    validator.setIgnoreCase(true);
+    return validator;
+  }
+
 
   public void transformJmolModelToJalview(ModelSet ms) throws IOException
   {
     try
     {
+      Regex alphaFold = getNewAlphafoldValidator();
       String lastID = "";
       List<SequenceI> rna = new ArrayList<SequenceI>();
       List<SequenceI> prot = new ArrayList<SequenceI>();
       PDBChain tmpchain;
       String pdbId = (String) ms.getInfo(0, "title");
+      String isMMCIF = (String) ms.getInfo(0, "fileType");
 
       if (pdbId == null)
       {
@@ -167,28 +182,34 @@ public class JmolParser extends StructureFile implements JmolStatusListener
       {
         setId(pdbId);
         setPDBIdAvailable(true);
+        alphaFoldModel = alphaFold.search(pdbId) && isMMCIF!=null && isMMCIF.equalsIgnoreCase("mmcif");  
+
       }
       List<Atom> significantAtoms = convertSignificantAtoms(ms);
       for (Atom tmpatom : significantAtoms)
       {
-        try
+        if (tmpatom.resNumIns.trim().equals(lastID))
+        {
+          // phosphorylated protein - seen both CA and P..
+          continue;
+        }
+        tmpchain = findChain(tmpatom.chain);
+        if (tmpchain != null)
         {
-          tmpchain = findChain(tmpatom.chain);
-          if (tmpatom.resNumIns.trim().equals(lastID))
-          {
-            // phosphorylated protein - seen both CA and P..
-            continue;
-          }
           tmpchain.atoms.addElement(tmpatom);
-        } catch (Exception e)
+        } else
         {
-          tmpchain = new PDBChain(getId(), tmpatom.chain);
+          tmpchain = new PDBChain(getId(), tmpatom.chain,isAlphafoldModel());
           getChains().add(tmpchain);
           tmpchain.atoms.addElement(tmpatom);
         }
         lastID = tmpatom.resNumIns.trim();
       }
-      xferSettings();
+      if (isParseImmediately())
+      {
+        // configure parsing settings from the static singleton
+        xferSettings();
+      }
 
       makeResidueList();
       makeCaBondList();
@@ -205,7 +226,8 @@ public class JmolParser extends StructureFile implements JmolStatusListener
           prot.add(chainseq);
         }
 
-        if (StructureImportSettings.isProcessSecondaryStructure())
+        // look at local setting for adding secondary tructure
+        if (predictSecondaryStructure)
         {
           createAnnotation(chainseq, chain, ms.at);
         }
@@ -219,6 +241,11 @@ public class JmolParser extends StructureFile implements JmolStatusListener
     }
   }
 
+  private boolean isAlphafoldModel()
+  {
+    return alphaFoldModel;
+  }
+
   private List<Atom> convertSignificantAtoms(ModelSet ms)
   {
     List<Atom> significantAtoms = new ArrayList<Atom>();
@@ -345,7 +372,7 @@ public class JmolParser extends StructureFile implements JmolStatusListener
 
   /**
    * Helper method that adds an AlignmentAnnotation for secondary structure to
-   * the sequence, provided at least one secondary structure prediction has been
+   * the sequence, provided at least one secondary structure assignment has been
    * made
    * 
    * @param modelTitle