Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Working code.
- Loading branch information
Jacob Durrant
authored and
Jacob Durrant
committed
Nov 13, 2019
0 parents
commit 3b7acc0
Showing
83 changed files
with
63,921 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
old_delme | ||
.DS_Store | ||
testing_openbabel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Porting process of Vina required no modification of the source code. | ||
Vina source code only utilizes Boost libraries as dependencies. | ||
Some parts of Boost libraries are header-only and require no preliminary compilation to include them with Emscripten-compiled projects. | ||
However, those directly called by Vina were not the case. | ||
Hence we had to compile them first as static libraries (for performance considerations). | ||
Also, Vina code base had no modifications since 2011 and the project webpage mentions boost version 1.44 as the one they used for successful compilation. | ||
Boost uses bjam/b2 building system for compilation and there were major changes in the compilation system since version 1.42. | ||
Since we used boost version 1.41 for the compilation. | ||
The following libraries had to be compiled: \emph{system, filesystem, serialization, program\_options and thread/pthread}. | ||
Except for a small (insignificant) bugs with the boost code itself (mostly incompatibilities with C++11) the only “trick” here was to provide boost include files for emscripten. | ||
We used emscripten version 1.38.48 and that required included headers to be linked/copied under \emph{<emsdk\_path>/fastcomp/emscripten/system/include/} The following command been used to compile boost libraries: ./bjam link=static variant=release threading=multi runtime-link=static thread program_options filesystem system serialization The resulting binaries (placed by bjam under <boost>/bin.v2/libs/<lib\_name>/build/gcc-1.38.48/release/link-static/runtime-link-static/threading-multi) had to be linked to em++ during the compilation process. | ||
Since vina uses make to compile and build we modified Makefile to the following contents: | ||
|
||
\hl{Also need to mention which browsers it works on. | ||
|
||
Webassembly is supported in all major browsers except for Internet Explorer (https://developer.mozilla.org/en-US/docs/WebAssembly - see Browser compatibility). However, older versions of browsers have SharedArrayBuffer disabled since 5 January 2018. That is important since webina uses pthreads - i.\,e.~multithreading and SharedArray is mechanism that allows processes to exchange data. As of the time of writing SharedArrayBuffer is disabled in Mozilla browsers starting from version 52 and newer. | ||
|
||
Good to mention Firefox not currently (why?) but that they plan to restore support soon.} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// There are a few variables and functions from vina.js that I want to easily | ||
// access from here. | ||
var WEBINA_Module; | ||
// A shiv for decodeBase64. | ||
var decodeBase64 = "function" == typeof atob ? atob : function (r) { | ||
var e, t, a, i, n, o, f = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", m = "", s = 0; | ||
for (r = r.replace(/[^A-Za-z0-9\+\/\=]/g, ""); e = f.indexOf(r.charAt(s++)) << 2 | (i = f.indexOf(r.charAt(s++))) >> 4, t = (15 & i) << 4 | (n = f.indexOf(r.charAt(s++))) >> 2, a = (3 & n) << 6 | (o = f.indexOf(r.charAt(s++))), m += String.fromCharCode(e), 64 !== n && (m += String.fromCharCode(t)), 64 !== o && (m += String.fromCharCode(a)), s < r.length;) | ||
return m; | ||
}; | ||
// Make Webina global namespace. | ||
var Webina = (function () { | ||
return { | ||
WEBINA_ENVIRONMENT_IS_NODE: window["WEBINA_ENVIRONMENT_IS_NODE"], | ||
WEBINA_lengthBytesUTF8: window["WEBINA_lengthBytesUTF8"], | ||
WEBINA_stringToUTF8Array: window["WEBINA_stringToUTF8Array"], | ||
WEBINA_assert: window["WEBINA_assert"], | ||
WEBINA_ASSERTIONS: 1, | ||
WEBINA_DATA_URI_PREFIX: "data:application/octet-stream;base64,", | ||
WEBINA_BASE_URL: "./", | ||
FS: window["FS"], | ||
start: function start(vinaParams, receptorPDBQTTxt, ligandPDBQTTxt, onDone, onError, baseUrl) { | ||
if (baseUrl !== undefined) { | ||
if (baseUrl.slice(baseUrl.length - 1) !== "/") { | ||
baseUrl += "/"; | ||
} | ||
this.WEBINA_BASE_URL = baseUrl; | ||
console.log("Webina: Using baseUrl = " + baseUrl); | ||
} | ||
else { | ||
console.warn("Webina: No baseUrl specified, so using the main directory ./"); | ||
} | ||
if (onError === undefined) { | ||
onError = function () { | ||
console.log("Webina encountered an error! Does your browser support WebAssembly?"); | ||
}; | ||
} | ||
// Create a module object for WASM. | ||
WEBINA_Module = { | ||
"preRun": [], | ||
"postRun": [], | ||
"stdOut": "", | ||
"stdErr": "", | ||
"print": function () { | ||
return function (e) { | ||
1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" ")), | ||
window["WEBINA_Module"]["stdOut"] += e + "\n"; | ||
}; | ||
}(), | ||
"printErr": function (e) { | ||
// 1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" ")), console.error(e) | ||
1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" ")), | ||
window["WEBINA_Module"]["stdErr"] += e + "\n"; | ||
}, | ||
"setStatus": function (e) { | ||
if (e === "") { | ||
// This happens when it is done running. | ||
if (onDone !== undefined) { | ||
var outTxt = new TextDecoder("utf-8").decode(window["FS"]["readFile"]('ligand_out.pdbqt')); | ||
var stdOut = window["WEBINA_Module"]["stdOut"]; | ||
var stdErr = window["WEBINA_Module"]["stdErr"]; | ||
onDone(outTxt, stdOut, stdErr); | ||
} | ||
} | ||
}, | ||
"onError": onError, | ||
"catchError": function (n) { | ||
onError(n); | ||
// throw n; // Don't throw the errr. You're catching it now. | ||
}, | ||
"receptorPDBQTTxt": receptorPDBQTTxt, | ||
"ligandPDBQTTxt": ligandPDBQTTxt | ||
}; | ||
// Initialize the memory | ||
var memoryInitializer = this.WEBINA_BASE_URL + "vina.html.mem"; | ||
memoryInitializer = WEBINA_Module["locateFile"] ? WEBINA_Module["locateFile"](memoryInitializer, "") : memoryInitializer, WEBINA_Module["memoryInitializerRequestURL"] = memoryInitializer; | ||
var meminitXHR = WEBINA_Module["memoryInitializerRequest"] = new XMLHttpRequest; | ||
meminitXHR.open("GET", memoryInitializer, !0), meminitXHR.responseType = "arraybuffer", meminitXHR.send(null); | ||
if (vinaParams["receptor"] !== undefined) { | ||
console.warn("Webina does not support Vina's --receptor parameter. Instead, pass the content of the receptor file as a string to the webina.start() function."); | ||
} | ||
if (vinaParams["receptor"] !== undefined) { | ||
console.warn("Webina does not support Vina's --ligand parameter. Instead, pass the content of the ligand file as a string to the webina.start() function."); | ||
} | ||
// Receptor and ligand files are always the same. | ||
WEBINA_Module['arguments'] = [ | ||
'--receptor', '/receptor.pdbqt', | ||
'--ligand', '/ligand.pdbqt', | ||
]; | ||
// For some reason, WebAssembly always uses one more processor | ||
// than specified. Compensate for that here. But sometimes it | ||
// doesn't, so commenting out... Confusing. | ||
// if ((vinaParams["cpu"] !== undefined) && (vinaParams["cpu"] > 1)) { | ||
// vinaParams["cpu"] = vinaParams["cpu"] - 1; | ||
// } | ||
// Add in the remaining values. Note that there is no validation here. | ||
var paramNames = Object.keys(vinaParams); | ||
var paramNamesLen = paramNames.length; | ||
for (var i = 0; i < paramNamesLen; i++) { | ||
var key = paramNames[i]; | ||
var val = vinaParams[key]; | ||
WEBINA_Module['arguments'].push('--' + key); | ||
if (typeof (val) !== "boolean") { | ||
WEBINA_Module['arguments'].push(String(val)); | ||
} | ||
} | ||
window["WEBINA_Module"] = WEBINA_Module; | ||
var script = document.createElement("script"); | ||
script.src = this.WEBINA_BASE_URL + "vina.js"; | ||
document.body.appendChild(script); | ||
}, | ||
isDataURI: function (r) { | ||
return String.prototype.startsWith ? r.startsWith(this.WEBINA_DATA_URI_PREFIX) : 0 === r.indexOf(this.WEBINA_DATA_URI_PREFIX); | ||
}, | ||
intArrayFromBase64: function (e) { | ||
if ("boolean" == typeof this.WEBINA_ENVIRONMENT_IS_NODE && this.WEBINA_ENVIRONMENT_IS_NODE) { | ||
var t; | ||
try { | ||
t = Buffer.from(e, "base64"); | ||
} | ||
catch (r) { | ||
t = new Buffer(e, "base64"); | ||
} | ||
return new Uint8Array(t.buffer, t.byteOffset, t.byteLength); | ||
} | ||
try { | ||
for (var r = decodeBase64(e), a = new Uint8Array(r.length), i = 0; i < r.length; ++i) | ||
a[i] = r.charCodeAt(i); | ||
return a; | ||
} | ||
catch (r) { | ||
throw new Error("Converting base64 string to bytes failed."); | ||
} | ||
}, | ||
// Not used? | ||
tryParseAsDataURI: function (r) { | ||
if (this.isDataURI(r)) | ||
return this.intArrayFromBase64(r.slice(this.WEBINA_DATA_URI_PREFIX.length)); | ||
}, | ||
// Not used? | ||
intArrayFromString: function (r, e, t) { | ||
var a = 0 < t ? t : this.WEBINA_lengthBytesUTF8(r) + 1, i = new Array(a), n = this.WEBINA_stringToUTF8Array(r, i, 0, i.length); | ||
return e && (i.length = n), i; | ||
}, | ||
// Not used? | ||
intArrayToString: function (r) { | ||
for (var e = [], t = 0; t < r.length; t++) { | ||
var a = r[t]; | ||
255 < a && (this.WEBINA_ASSERTIONS && this.WEBINA_assert(!1, "Character code " + a + " (" + String.fromCharCode(a) + ") at offset " + t + " not in 0x00-0xFF."), a &= 255), e.push(String.fromCharCode(a)); | ||
} | ||
return e.join(""); | ||
} | ||
}; | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Oops, something went wrong.