BINANA.worker.ts 1.38 KB
Newer Older
jdurrant's avatar
jdurrant committed
1
2
// This file is part of BINANA, released under the Apache 2.0 License. See
// LICENSE.md or go to https://opensource.org/licenses/Apache-2.0 for full
jdurrant's avatar
jdurrant committed
3
// details. Copyright 2021 Jacob D. Durrant.
jdurrant's avatar
jdurrant committed
4

jdurrant's avatar
jdurrant committed
5
import * as binana from "./binanajs/binana";
jdurrant's avatar
jdurrant committed
6
7
8
9
10
11
12

self.onmessage = function(e) {
    let pdbtxt = e.data[0];
    let ligtxt = e.data[1];
    let binanaParams = e.data[2];

    // Save to the fake file system
jdurrant's avatar
jdurrant committed
13

jdurrant's avatar
jdurrant committed
14
15
    binana["fs"]["save_file"]("receptor.pdb", pdbtxt);
    binana["fs"]["save_file"]("ligand.pdb", ligtxt);
jdurrant's avatar
jdurrant committed
16

jdurrant's avatar
jdurrant committed
17
18
    let params = [
        "-receptor", "receptor.pdb", "-ligand", "ligand.pdb",
19
20
        "-output_dir", "/vmd/"
        // "-output_json", "ligand_receptor_output.json"
jdurrant's avatar
jdurrant committed
21
    ];
jdurrant's avatar
jdurrant committed
22
23
24
25
26
27
28
29
30
31
32
33

    const binanaParamNames = Object.keys(binanaParams);
    const binanaParamNamesLen = binanaParamNames.length;
    for (let i = 0; i < binanaParamNamesLen; i++) {
        const binanaParamName = binanaParamNames[i];
        const paramVal = binanaParams[binanaParamName];
        params.push("-" + binanaParamName);
        params.push(paramVal);
    }

    binana["run"](params);

34
35
36
37
38
39
40
41
42
43
    // Get the output.
    let fakeFS = binana["fs"]["shim"]["fake_fs"];
    let newFS = {};
    for (let flnm of Object.keys(fakeFS)) {
        if (flnm.startsWith("/vmd/")) {
            let content = fakeFS[flnm];
            flnm = flnm.slice(5);
            newFS[flnm] = content;
        }
    }
jdurrant's avatar
jdurrant committed
44
45

    // @ts-ignore
46
    postMessage(newFS);
jdurrant's avatar
jdurrant committed
47
}