From f39645b94f7fc0540fd449dffd8a8d9fdce1d3b8 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Mon, 8 Nov 2021 18:22:35 +0000 Subject: [PATCH] JAL-3855 JAL-1731 reuse the StructureViewer.fetchPdbFile(PDBEntry) method in JmolBinding - avoid code duplication for retrieval and import of 3d data --- src/jalview/gui/AppJmolBinding.java | 50 +++++------------------------------ 1 file changed, 7 insertions(+), 43 deletions(-) diff --git a/src/jalview/gui/AppJmolBinding.java b/src/jalview/gui/AppJmolBinding.java index 037b97e..6b06e56 100644 --- a/src/jalview/gui/AppJmolBinding.java +++ b/src/jalview/gui/AppJmolBinding.java @@ -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 -- 1.7.10.2