Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
ishitani committed Feb 20, 2025
1 parent a38c886 commit a9bb2e6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 79 deletions.
166 changes: 90 additions & 76 deletions uxp_gui/cuemol2/base/content/tools/netpdbopen.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function StreamListener(tid)
this.m_window = null;
this.mChannel = null;
this.mFuncs = null;
this.mLoadFunc = null;

this.mLoadPDB = false;
this.mLoadEDS_2fofc = false;
Expand Down Expand Up @@ -83,9 +84,25 @@ StreamListener.prototype.onStopRequest = function (aRequest, aContext, aStatus)
if (!obj) {
dd("onStopReq: strmgr.waitLoadAsync obj is null");
}
obj.name = this.mNewObjName;

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
Expand Down Expand Up @@ -127,7 +144,6 @@ StreamListener.prototype.onStopRequest = function (aRequest, aContext, aStatus)
this.m_window.close();

if (this.mFuncs) {
// let pdbid = this.mPDBID;
let funcs = this.mFuncs;
window.setTimeout(function () {
if (funcs.length>0)
Expand Down Expand Up @@ -213,32 +229,30 @@ Qm2Main.prototype.onOpenPDBsite = function () {
});

let pdbid = result.pdbid;
let bpdb = result.bpdb;
let bmap_2fofc = result.bmap_2fofc;
let bmap_fofc = result.bmap_fofc;
let url_pdb = result.url_pdb;
let url_map = result.url_map_2fofc;
let url_map_fofc = result.url_map_fofc;

if (!pdbid)
return;

var funcs = new Array();

if (bpdb) {
if (url_pdb != null) {
funcs.push( function () {
gQm2Main.openPDBsiteImpl(pdbid, url_pdb, funcs);
});
}

if (bmap_2fofc) {
if (url_map != null) {
funcs.push( function () {
gQm2Main.openEDSsiteImpl(pdbid, url_map, true, funcs);
gQm2Main.openMapImpl(pdbid, url_map, true, funcs);
});
}

if (bmap_fofc) {
if (url_map_fofc != null) {
funcs.push( function () {
gQm2Main.openEDSsiteImpl(pdbid, url_map, false, funcs);
gQm2Main.openMapImpl(pdbid, url_map_fofc, false, funcs);
});
}

Expand All @@ -247,6 +261,42 @@ Qm2Main.prototype.onOpenPDBsite = function () {
funcs.shift().call();
}

const startAsyncLoad = (pdbid, pdb_url, reader, loadFunc, chainFuncs) => {
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
const uri = ioService.newURI(pdb_url, null, null);

const smg = cuemol.getService("StreamManager");
const tid = smg.loadObjectAsync(reader);
let listener = new StreamListener(tid);
// listener.m_scene = scene;
listener.m_strmgr = smg;
// listener.mNewObjName = new_obj_name;
listener.mPDBID = pdbid;
// listener.mDlgRes = dlgdata;
listener.mChannel = ioService.newChannelFromURI(uri);
listener.mFuncs = chainFuncs;
listener.mLoadFunc = loadFunc;

const onLoad = (aDlg) => {
listener.m_window = aDlg;
listener.mChannel.notificationCallbacks = listener;
listener.mChannel.asyncOpen(listener, null);
return listener;
}

window.openDialog("chrome://cuemol2/content/tools/netpdb-progress-dlg.xul",
"openPDB",
"chrome,modal,resizable=no,dependent,centerscreen",
onLoad);
}

const getObjRendTypes = (reader) => {
let tmpobj = reader.createDefaultObj();
let obj_type = tmpobj._wrapped.getClassName();
let rend_types = tmpobj.searchCompatibleRendererNames();
tmpobj = null;
return {obj_type, rend_types};
}

Qm2Main.prototype.openPDBsiteImpl = function (pdbid, aPDBURL, afuncs)
{
Expand All @@ -256,11 +306,6 @@ Qm2Main.prototype.openPDBsiteImpl = function (pdbid, aPDBURL, afuncs)
var scene = this.mMainWnd.currentSceneW;
var listener;

//pdb_url = "http://www.rcsb.org/pdb/download/downloadFile.do?"+"fileFormat=pdb&compression=YES&structureId="+pdbid;
//pdb_url = "http://www.rcsb.org/pdb/files/"+pdbid+".pdb.gz";
//pdb_url = "http://www.rcsb.org/pdb/files/"+pdbid+".pdb"
//pdb_url = "ftp://ftp.wwpdb.org/pub/pdb/data/structures/divided/pdb/"+mid+"/pdb"+pdbid+".ent.gz"

var rdr_type=null;
var cmp_type=null;

Expand All @@ -282,33 +327,20 @@ Qm2Main.prototype.openPDBsiteImpl = function (pdbid, aPDBURL, afuncs)
rdr_type = "mmcif";
cmp_type = null;
}


cuemol.println("Open PDB site: URL=\""+pdb_url+"\"");
dd("open PDB site: URL=\""+pdb_url+"\"");
// alert("OK PDBID="+pdb_url);

var new_obj_name = pdbid;
var smg = cuemol.getService("StreamManager");

//////////
// show the setup-rend dialog

var smg = cuemol.getService("StreamManager");

var obj_type;
var rend_types;
var reader;

reader = smg.createHandler(rdr_type, 0);
var new_obj_name = pdbid;
let reader = smg.createHandler(rdr_type, 0);
if (cmp_type)
reader.compress = cmp_type;

( function () {
var tmpobj = reader.createDefaultObj();
obj_type = tmpobj._wrapped.getClassName();
rend_types = tmpobj.searchCompatibleRendererNames();
tmpobj = null;
}) ();
var {obj_type, rend_types} = getObjRendTypes(reader);

var dlgdata = new Object();
dlgdata.sceneID = scene.uid;
Expand All @@ -319,7 +351,6 @@ Qm2Main.prototype.openPDBsiteImpl = function (pdbid, aPDBURL, afuncs)
dlgdata.target[0].obj_type = obj_type;
dlgdata.target[0].rend_types = rend_types;
dlgdata.target[0].reader_name = "xxx";
// dlgdata.target[0].reader = reader;
dlgdata.target[0].preset_types = this.getCompatibleRendPresetNames(obj_type, scene.uid);

this.doSetupRendDlg(dlgdata);
Expand All @@ -329,43 +360,32 @@ Qm2Main.prototype.openPDBsiteImpl = function (pdbid, aPDBURL, afuncs)
//////////
// start asynchronous loading

var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var uri = ioService.newURI(pdb_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.mPDBID = pdbid;
listener.mDlgRes = dlgdata;
listener.mChannel = ioService.newChannelFromURI(uri);
listener.mFuncs = afuncs;
listener.mLoadPDB = 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 PDB");
try {
scene.addObject(obj);
dlgdata.obj_id = obj.uid;
dlgdata.new_obj = true;
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, pdb_url, reader, loadFunc, afuncs);
}

Qm2Main.prototype.openEDSsiteImpl = function (pdbid, aURLMap, b2fofc, afuncs)
Qm2Main.prototype.openMapImpl = function (pdbid, map_url, b2fofc, afuncs)
{
var scene = this.mMainWnd.currentSceneW;
var eds_url=aURLMap;

var listener;

dd("open map URL=\""+eds_url+"\"");
cuemol.println("Open map: URL=\""+eds_url+"\"");
dd("open map URL=\""+map_url+"\"");
cuemol.println("Open map: URL=\""+map_url+"\"");

var new_obj_name;
if (b2fofc)
Expand All @@ -382,13 +402,13 @@ Qm2Main.prototype.openEDSsiteImpl = function (pdbid, aURLMap, b2fofc, afuncs)
var rend_types;

let reader;
if (eds_url.endsWith("_map_coef.cif.gz")) {
dd("Open MMCIF URL: "+eds_url);
if (map_url.endsWith("_map_coef.cif.gz")) {
dd("Open MMCIF URL: "+map_url);
reader = smg.createHandler("mmcifmap", 0);
reader.compress = "gzip";
}
else if (eds_url.endsWith("_map.mtz")) {
dd("Open MTZ URL: "+eds_url);
else if (map_url.endsWith("_map.mtz")) {
dd("Open MTZ URL: "+map_url);
reader = smg.createHandler("mtzmap", 0);
if (b2fofc) {
reader.clmn_F = "FWT";
Expand All @@ -400,17 +420,12 @@ Qm2Main.prototype.openEDSsiteImpl = function (pdbid, aURLMap, b2fofc, afuncs)
}
}
else {
dd("Unknown type URL: "+eds_url);
dd("Unknown type URL: "+map_url);
return;
}

reader.gridsize = 0.25;
( function () {
var tmpobj = reader.createDefaultObj();
obj_type = tmpobj._wrapped.getClassName();
rend_types = tmpobj.searchCompatibleRendererNames();
tmpobj = null;
}) ();
var {obj_type, rend_types} = getObjRendTypes(reader);

var dlgdata = new Object();
dlgdata.sceneID = scene.uid;
Expand All @@ -423,15 +438,15 @@ Qm2Main.prototype.openEDSsiteImpl = function (pdbid, aURLMap, b2fofc, afuncs)
dlgdata.target[0].reader_name = "xxx";
// dlgdata.target[0].reader = reader;

dlgdata.center = true;
dlgdata.center = false;
dlgdata.rendtype = "contour";
dlgdata.rendname = "contour1";

//////////
// start asynchronous loading

var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var uri = ioService.newURI(eds_url, null, null);
var uri = ioService.newURI(map_url, null, null);

var tid = smg.loadObjectAsync(reader);
listener = new StreamListener(tid);
Expand Down Expand Up @@ -462,4 +477,3 @@ Qm2Main.prototype.openEDSsiteImpl = function (pdbid, aURLMap, b2fofc, afuncs)
onLoad);

}

3 changes: 0 additions & 3 deletions uxp_gui/cuemol2/base/content/tools/openPDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ window.gPdbDlg = {

this.mArgs[0]({
pdbid: pdbid,
bpdb: pdbchk,
bmap_2fofc: mapchk_2fofc,
bmap_fofc: mapchk_fofc,
url_pdb: url_pdb,
url_map_2fofc: url_map_2fofc,
url_map_fofc: url_map_fofc
Expand Down

0 comments on commit a9bb2e6

Please sign in to comment.