From 20a91b4b406af45e3a24696fce14ce5710812740 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Mon, 14 May 2018 16:54:58 +0200 Subject: [PATCH] Updated mol-task --- src/mol-model/structure/query/modifers.ts | 44 +++++++++++++++++++++++ src/mol-task/execution/observable.ts | 4 +++ src/mol-task/task.ts | 10 +++++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/mol-model/structure/query/modifers.ts diff --git a/src/mol-model/structure/query/modifers.ts b/src/mol-model/structure/query/modifers.ts new file mode 100644 index 000000000..a7868906d --- /dev/null +++ b/src/mol-model/structure/query/modifers.ts @@ -0,0 +1,44 @@ +// /** +// * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. +// * +// * @author David Sehnal <david.sehnal@gmail.com> +// */ + +// import Query from './query' +// import Selection from './selection' +// import P from './properties' +// import { Element, Unit } from '../structure' +// import { OrderedSet, Segmentation } from 'mol-data/int' +// import { LinearGroupingBuilder } from './utils/builders'; + +// export function wholeResidues(query: Query, isFlat: boolean): Query.Provider { +// return async (structure, ctx) => { +// const selection = query(structure).runAsChild(ctx); +// const { units } = structure; +// const l = Element.Location(); +// const builder = structure.subsetBuilder(true); + +// for (const unit of units) { +// l.unit = unit; +// const elements = unit.elements; + +// builder.beginUnit(unit.id); +// for (let j = 0, _j = elements.length; j < _j; j++) { +// l.element = elements[j]; +// if (atomTest(l)) builder.addElement(l.element); +// } +// builder.commitUnit(); + +// if (ctx.shouldUpdate) await ctx.update({ message: 'Atom Groups', current: 0, max: units.length }); +// } + +// return Selection.Singletons(structure, builder.getStructure()); +// }; +// } + +// export interface IncludeSurroundingsParams { +// selection: Selection, +// radius: number, +// atomRadius?: number, +// wholeResidues?: boolean +// } \ No newline at end of file diff --git a/src/mol-task/execution/observable.ts b/src/mol-task/execution/observable.ts index 4f4516287..81fe04efb 100644 --- a/src/mol-task/execution/observable.ts +++ b/src/mol-task/execution/observable.ts @@ -21,6 +21,10 @@ export function ExecuteObservable<T>(task: Task<T>, observer: Progress.Observer, return execute(task as ExposedTask<T>, ctx); } +export function ExecuteInContext<T>(ctx: RuntimeContext, task: Task<T>) { + return execute(task as ExposedTask<T>, ctx as ObservableRuntimeContext); +} + export function ExecuteObservableChild<T>(ctx: RuntimeContext, task: Task<T>, progress?: string | Partial<RuntimeContext.ProgressUpdate>) { return (ctx as ObservableRuntimeContext).runChild(task, progress); } diff --git a/src/mol-task/task.ts b/src/mol-task/task.ts index 34dc45563..ee5474fa9 100644 --- a/src/mol-task/task.ts +++ b/src/mol-task/task.ts @@ -6,7 +6,7 @@ import { RuntimeContext } from './execution/runtime-context' import { Progress } from './execution/progress' -import { ExecuteObservable, ExecuteObservableChild } from './execution/observable'; +import { ExecuteObservable, ExecuteObservableChild, ExecuteInContext } from './execution/observable'; import { SyncRuntimeContext } from 'mol-task/execution/synchronous'; // A "named function wrapper" with built in "computation tree progress tracking". @@ -21,6 +21,9 @@ interface Task<T> { // Allow to pass the progress so that the progress tree can be kept in a "good state" without having to separately call update. runAsChild(ctx: RuntimeContext, progress?: string | Partial<RuntimeContext.ProgressUpdate>): Promise<T> + // Run the task on the specified context. + runInContext(ctx: RuntimeContext): Promise<T> + readonly id: number, readonly name: string } @@ -39,6 +42,11 @@ namespace Task { return ExecuteObservableChild(ctx, this, progress as string | Partial<RuntimeContext.ProgressUpdate>); } + runInContext(ctx: RuntimeContext): Promise<T> { + if (ctx.isSynchronous) return this.f(SyncRuntimeContext); + return ExecuteInContext(ctx, this); + } + constructor(public name: string, public f: (ctx: RuntimeContext) => Promise<T>, public onAbort?: () => void) { this.id = nextId(); } -- GitLab