From 1b5b793eb1be4f25de9400b48b31d6dacc19827c Mon Sep 17 00:00:00 2001 From: ishitani Date: Sat, 22 Feb 2025 15:26:31 +0900 Subject: [PATCH] netpbopen refactor/impl --- .bumpversion.cfg | 2 +- src/_version.h | 2 +- .../cuemol2/base/content/tools/netpdbopen.js | 126 ++++--------- uxp_gui/cuemol2/base/content/tools/openPDB.js | 169 ++++++++++++++---- uxp_gui/cuemol2/config/version.txt | 2 +- 5 files changed, 178 insertions(+), 123 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index e027cf04..2b4673a3 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.3.0.454 +current_version = 2.3.0.455 commit = False tag = False parse = (?P\d+)\.(?P\d+)\.(?P\d+)\.(?P\d+) diff --git a/src/_version.h b/src/_version.h index ca20cd08..57585775 100644 --- a/src/_version.h +++ b/src/_version.h @@ -1,3 +1,3 @@ /* Master version info */ -#define QM_VERSION "2.3.0.454" +#define QM_VERSION "2.3.0.455" diff --git a/uxp_gui/cuemol2/base/content/tools/netpdbopen.js b/uxp_gui/cuemol2/base/content/tools/netpdbopen.js index 9ce4155d..f04328f7 100644 --- a/uxp_gui/cuemol2/base/content/tools/netpdbopen.js +++ b/uxp_gui/cuemol2/base/content/tools/netpdbopen.js @@ -85,70 +85,17 @@ StreamListener.prototype.onStopRequest = function (aRequest, aContext, aStatus) dd("onStopReq: strmgr.waitLoadAsync obj is null"); } - if (this.mLoadFunc) { - this.mLoadFunc(obj); - dd("created: "+obj); - this.mChannel = null; - this.m_window.close(); - - if (this.mFuncs) { - let funcs = this.mFuncs; - window.setTimeout(function () { - if (funcs.length>0) - funcs.shift().call(); - }, 0); - } - return; - } - - // EDIT TXN START // - obj.name = this.mNewObjName; - if (this.mLoadPDB) - this.m_scene.startUndoTxn("Get PDB"); - else - this.m_scene.startUndoTxn("Get EDS"); - - try { - this.m_scene.addObject(obj); - this.mDlgRes.obj_id = obj.uid; - this.mDlgRes.new_obj = true; - if (this.mLoadEDS_2fofc) { - this.mDlgRes.rendname = "contour1"; - this.mDlgRes.mapcolor = "#0000FF"; - this.mDlgRes.mapsigma = 1.0; - gQm2Main.doSetupRend(this.m_scene, this.mDlgRes); - } - else if (this.mLoadEDS_fofc) { - this.mDlgRes.rendname = "pos-cont"; - this.mDlgRes.mapcolor = "#00FF00"; - this.mDlgRes.mapsigma = 3.0; - gQm2Main.doSetupRend(this.m_scene, this.mDlgRes); - this.mDlgRes.rendname = "neg-cont"; - this.mDlgRes.mapcolor = "#FF0000"; - this.mDlgRes.mapsigma = -3.0; - gQm2Main.doSetupRend(this.m_scene, this.mDlgRes); - } - else { - gQm2Main.doSetupRend(this.m_scene, this.mDlgRes); - } - } - catch (e) { - dd("Exception occured: "+e); - debug.exception(e); - } - this.m_scene.commitUndoTxn(); - // EDIT TXN END // - + this.mLoadFunc(obj); dd("created: "+obj); this.mChannel = null; this.m_window.close(); - + if (this.mFuncs) { - let funcs = this.mFuncs; - window.setTimeout(function () { - if (funcs.length>0) - funcs.shift().call(); - }, 0); + let funcs = this.mFuncs; + window.setTimeout(function () { + if (funcs.length>0) + funcs.shift().call(); + }, 0); } }; @@ -445,35 +392,36 @@ Qm2Main.prototype.openMapImpl = function (pdbid, map_url, b2fofc, afuncs) ////////// // start asynchronous loading - var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); - var uri = ioService.newURI(map_url, null, null); - - var tid = smg.loadObjectAsync(reader); - listener = new StreamListener(tid); - listener.m_scene = scene; - listener.m_strmgr = smg; - listener.mNewObjName = new_obj_name; - listener.mDlgRes = dlgdata; - listener.mChannel = ioService.newChannelFromURI(uri); - listener.mFuncs = afuncs; - - if (b2fofc) { - listener.mLoadEDS_2fofc = true; - } - else { - listener.mLoadEDS_fofc = true; - } - - function onLoad(aDlg) { - listener.m_window = aDlg; - listener.mChannel.notificationCallbacks = listener; - listener.mChannel.asyncOpen(listener, null); - return listener; + const loadFunc = (obj) => { + obj.name = new_obj_name; + scene.startUndoTxn("Get Density Map"); + try { + scene.addObject(obj); + dlgdata.obj_id = obj.uid; + dlgdata.new_obj = true; + if (b2fofc) { + dlgdata.rendname = "contour1"; + dlgdata.mapcolor = "#0000FF"; + dlgdata.mapsigma = 1.0; + this.doSetupRend(scene, dlgdata); + } + else { + dlgdata.rendname = "pos-cont"; + dlgdata.mapcolor = "#00FF00"; + dlgdata.mapsigma = 3.0; + this.doSetupRend(scene, dlgdata); + dlgdata.rendname = "neg-cont"; + dlgdata.mapcolor = "#FF0000"; + dlgdata.mapsigma = -3.0; + this.doSetupRend(scene, dlgdata); + } + } + catch (e) { + dd("Exception occured: "+e); + debug.exception(e); + } + scene.commitUndoTxn(); } - window.openDialog("chrome://cuemol2/content/tools/netpdb-progress-dlg.xul", - "openPDB", - "chrome,modal,resizable=no,dependent,centerscreen", - onLoad); - + startAsyncLoad(pdbid, map_url, reader, loadFunc, afuncs); } diff --git a/uxp_gui/cuemol2/base/content/tools/openPDB.js b/uxp_gui/cuemol2/base/content/tools/openPDB.js index f95cb811..bd772f8a 100644 --- a/uxp_gui/cuemol2/base/content/tools/openPDB.js +++ b/uxp_gui/cuemol2/base/content/tools/openPDB.js @@ -6,25 +6,102 @@ window.gPdbDlg = { init: function () { - this.mFindBtn = document.getElementById('find-button'); + // this.mFindBtn = document.getElementById('find-button'); + this.mAcceptBtn = document.documentElement.getButton("accept"); + this.mAcceptBtn.disabled = true; + // dd("*** btn="+btn); this.mPdbIdBox = document.getElementById('pdbid'); this.mResBox = document.getElementById('result-text'); + + this.mPdbChk = document.getElementById('chk-get-pdb'); + this.mMap2fofcChk = document.getElementById('chk-get-map-2fofc'); + this.mMapFofcChk = document.getElementById('chk-get-map-fofc'); + + this.mPdbSvrList = document.getElementById('pdb-svr-list'); + this.mMapSvrList = document.getElementById('map-svr-list'); + this.mArgs = window.arguments; this.mIoService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); this.mHis = new util.History("OpenPDB-history"); dd("this.mHis = "+this.mHis); - var his = this.mHis + this.loadPDBHistory(); + + const that = this; + const updateWidgetsFn = (event) => { + try { + that.updateWidgets(event); + } + catch (e) { + debug.exception(e); + } + }; + this.mPdbIdBox.addEventListener("input", updateWidgetsFn, false); + this.mPdbIdBox.addEventListener("select", updateWidgetsFn, false); + this.mPdbChk.addEventListener("click", updateWidgetsFn, false); + this.mMap2fofcChk.addEventListener("click", updateWidgetsFn, false); + this.mMapFofcChk.addEventListener("click", updateWidgetsFn, false); + }, + + loadPDBHistory: function () { + let his = this.mHis his.loadFromPref(); - var nhis = his.getLength(); - for (var i=0; i { + if (pdbchk) { + const url_pdb = this.checkPDBAvail(val, this.mPdbSvrList.value); + if (url_pdb === null) { + this.mAcceptBtn.disabled = true; + return; + } + } + if (mapchk_2fofc) { + const url_map_2fofc = this.checkPDBMapAvail(val, this.mMapSvrList.value, true); + if (url_map_2fofc === null) { + this.mAcceptBtn.disabled = true; + return; + } + } + if (mapchk_fofc) { + const url_map_fofc = this.checkPDBMapAvail(val, this.mMapSvrList.value, false); + if (url_map_fofc === null) { + this.mAcceptBtn.disabled = true; + return; + } + } + }, 0); + + this.mResBox.value = ""; + this.mAcceptBtn.disabled = false; + }, + + isValidPDBID: function (pdbid) { var val = pdbid; if (val.length!="4") return false; @@ -39,6 +116,7 @@ window.gPdbDlg = { }, makePDBURL: function (pdbid, svr_type) { + let url_pdb = null; if (svr_type == "RCSB_CIF") { url_pdb = "https://files.rcsb.org/download/"+pdbid+".cif"; } @@ -54,6 +132,7 @@ window.gPdbDlg = { }, makeMapURL: function (pdbid, svr_type, mapchk_2fofc) { + let url_map = null; if (svr_type=="EBI_MTZ") { url_map = "https://www.ebi.ac.uk/pdbe/coordinates/files/"+pdbid+"_map.mtz"; } @@ -69,7 +148,13 @@ window.gPdbDlg = { return url_map; }, - checkURL: function (url_pdb) { + urlCache: {}, + + checkURLAvail: function (url_pdb) { + if (url_pdb in this.urlCache) { + dd("URL cache hit: "+url_pdb+" => "+this.urlCache[url_pdb]); + return this.urlCache[url_pdb]; + } let uri = this.mIoService.newURI(url_pdb, null, null); let httpChannel; try { @@ -81,13 +166,16 @@ window.gPdbDlg = { } catch (e) { debug.exception(e); + // this.urlCache[url_pdb] = false; return false; } try { dd("Response "+httpChannel.responseStatus+httpChannel.responseStatusText+" for URL: "+url_pdb); if (httpChannel.responseStatus==200) { - return false; + // found --> OK + this.urlCache[url_pdb] = true; + return true; } } catch (e) { @@ -95,59 +183,78 @@ window.gPdbDlg = { return false; } - return true; + // not found + this.urlCache[url_pdb] = false; + return false; }, showErrMsg: function (msg) { + dd("showErrMsg: "+msg); this.mResBox.value = msg; - this.mPdbIdBox.select(); - this.mPdbIdBox.focus(); + // this.mPdbIdBox.select(); + // this.mPdbIdBox.focus(); + }, + + checkPDBAvail : function (pdbid, svr_type) { + const url_pdb = this.makePDBURL(pdbid, svr_type); + dd("Check PDB URL: "+url_pdb); + if (this.checkURLAvail(url_pdb)) { + return url_pdb; + } + this.showErrMsg("PDB Entry " + pdbid + ": not found."); + return null; + }, + + checkPDBMapAvail : function (pdbid, svr_type, b2fofc) { + const url_map = this.makeMapURL(pdbid, svr_type, b2fofc); + dd("Check Map URL: "+url_map); + if (this.checkURLAvail(url_map)) { + return url_map; + } + this.showErrMsg("Map Entry " + pdbid + ": not found."); + return null; }, onFind: function () { let pdbid = this.mPdbIdBox.value.toLowerCase(); - let pdbchk = document.getElementById('chk-get-pdb').checked; - let mapchk_2fofc = document.getElementById('chk-get-map-2fofc').checked; - let mapchk_fofc = document.getElementById('chk-get-map-fofc').checked; + let pdbchk = this.mPdbChk.checked; + let mapchk_2fofc = this.mMap2fofcChk.checked; + let mapchk_fofc = this.mMapFofcChk.checked; if (!pdbchk && !mapchk_2fofc && !mapchk_fofc) { this.mResBox.value = "Neither pdb nor map selected"; return false; } - if (!this.validation(pdbid)) { + if (!this.isValidPDBID(pdbid)) { this.showErrMsg("Invalid PDB ID: "+pdbid); return false; } let url_pdb = null; if (pdbchk) { - let svr = document.getElementById('pdb-svr-list').value; - url_pdb = this.makePDBURL(pdbid, svr); - dd("Check PDB URL: "+url_pdb); - if (this.checkURL(url_pdb)) { - this.showErrMsg("PDB Entry " + pdbid + ": not found."); + url_pdb = this.checkPDBAvail(pdbid, this.mPdbSvrList.value); + if (url_pdb === null) { return false; } } - let map_svr = document.getElementById('map-svr-list').value; - if (mapchk_2fofc || mapchk_fofc) { - url_map = this.makeMapURL(pdbid, map_svr, mapchk_2fofc); - dd("Check Map URL: "+url_map); - if (this.checkURL(url_map)) { - this.showErrMsg("Map Entry " + pdbid + ": not found."); + let url_map_2fofc = null; + if (mapchk_2fofc) { + url_map_2fofc = this.checkPDBMapAvail(pdbid, this.mMapSvrList.value, true); + if (url_map_2fofc === null) { return false; } } - url_map_2fofc = null; - if (mapchk_2fofc) - url_map_2fofc = this.makeMapURL(pdbid, map_svr, mapchk_2fofc); - url_map_fofc = null; - if (mapchk_fofc) - url_map_fofc = this.makeMapURL(pdbid, map_svr, !mapchk_fofc); + let url_map_fofc = null; + if (mapchk_fofc) { + url_map_fofc = this.checkPDBMapAvail(pdbid, this.mMapSvrList.value, false); + if (url_map_fofc === null) { + return false; + } + } this.mArgs[0]({ pdbid: pdbid, diff --git a/uxp_gui/cuemol2/config/version.txt b/uxp_gui/cuemol2/config/version.txt index 062e0485..58798c3c 100644 --- a/uxp_gui/cuemol2/config/version.txt +++ b/uxp_gui/cuemol2/config/version.txt @@ -1 +1 @@ -2.3.0.454 +2.3.0.455