File size: 1,599 Bytes
71174bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { runWorker } from "@/Core/WebWorkers/RunWorker";
import { QueueParent } from "@/Queue/QueueParent";
import { IJobInfo } from "@/Queue/QueueTypes";
import { IFpocketParams } from "./FPocketWebTypes";
import { FileInfo } from "@/FileSystem/FileInfo";

/**
 * A calculate mol props queue.
 */
export class FPocketWebQueue extends QueueParent {
    /**
     * Run a batch of jobs.
     *
     * @param {IJobInfo[]} inputBatch  The input batch.
     * @param {number}     procs       The number of processors to use.
     * @returns {Promise<IJobInfo[]>}  The output batch.
     */
    public runJobBatch(
        inputBatch: IJobInfo[],
        procs: number
    ): Promise<IJobInfo[]> {
        const inputs = inputBatch.map((jobInfo) => jobInfo.input);
        
        const inputs2 = inputs.map((i) => {
            const pdbFile = i.pdbFile as FileInfo;
            return {
                pdbName: pdbFile.name,
                pdbContents: pdbFile.contents,
                userArgs: i.fpocketParams as IFpocketParams
            };
        });

        return runWorker(
            new Worker(new URL("./FPocketWeb.worker", import.meta.url)),
            inputs2,
            true // auto terminate the worker.
        )
            .then((outputBatch) => {
                // Update .output value of each jobInfo.
                for (let i = 0; i < inputBatch.length; i++) {
                    inputBatch[i].output = outputBatch[i];
                }
                return inputBatch;
            })
            .catch((err) => {
                throw err;
            });
    }
}