Bladeren bron

moved cellpack to toplevel extensions dir and register as behavior

Alexander Rose 5 jaren geleden
bovenliggende
commit
f363621de3

+ 0 - 168
src/apps/viewer/extensions/jolecule.ts

@@ -1,168 +0,0 @@
-// /**
-//  * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
-//  *
-//  * @author David Sehnal <david.sehnal@gmail.com>
-//  */
-
-// import { StateTree, StateBuilder, StateAction, State } from '../../../mol-state';
-// import { StateTransforms } from '../../../mol-plugin/state/transforms';
-// import { createModelTree } from '../../../mol-plugin/state/actions/structure';
-// import { PluginContext } from '../../../mol-plugin/context';
-// import { PluginStateObject } from '../../../mol-plugin/state/objects';
-// import { ParamDefinition } from '../../../mol-util/param-definition';
-// import { PluginCommands } from '../../../mol-plugin/command';
-// import { Vec3 } from '../../../mol-math/linear-algebra';
-// import { PluginStateSnapshotManager } from '../../../mol-plugin/state/snapshots';
-// import { MolScriptBuilder as MS } from '../../../mol-script/language/builder';
-// import { Text } from '../../../mol-geo/geometry/text/text';
-// import { UUID } from '../../../mol-util';
-// import { ColorNames } from '../../../mol-util/color/names';
-// import { Camera } from '../../../mol-canvas3d/camera';
-// import { createStructureRepresentation3dParamss } from '../../../mol-plugin/state/transforms/representation';
-// import { createDefaultStructureComplex } from '../../../mol-plugin/util/structure-complex-helper';
-
-// export const CreateJoleculeState = StateAction.build({
-//     display: { name: 'Jolecule State Import' },
-//     params: { id: ParamDefinition.Text('1mbo') },
-//     from: PluginStateObject.Root
-// })(async ({ ref, state, params }, plugin: PluginContext) => {
-//     try {
-//         const id = params.id.trim().toLowerCase();
-//         const data = await plugin.runTask(plugin.fetch({ url: `https://jolecule.appspot.com/pdb/${id}.views.json`, type: 'json' })) as JoleculeSnapshot[];
-
-//         data.sort((a, b) => a.order - b.order);
-
-//         await PluginCommands.State.RemoveObject.dispatch(plugin, { state, ref });
-//         plugin.state.snapshots.clear();
-
-//         const template = createTemplate(plugin, state, id);
-//         const snapshots = data.map((e, idx) => buildSnapshot(plugin, template, { e, idx, len: data.length }));
-//         for (const s of snapshots) {
-//             plugin.state.snapshots.add(s);
-//         }
-
-//         PluginCommands.State.Snapshots.Apply.dispatch(plugin, { id: snapshots[0].snapshot.id });
-//     } catch (e) {
-//         plugin.log.error(`Jolecule Failed: ${e}`);
-//     }
-// });
-
-// interface JoleculeSnapshot {
-//     order: number,
-//     distances: { i_atom1: number, i_atom2: number }[],
-//     labels: { i_atom: number, text: string }[],
-//     camera: { up: Vec3, pos: Vec3, in: Vec3, slab: { z_front: number, z_back: number, zoom: number } },
-//     selected: number[],
-//     text: string
-// }
-
-// function createTemplate(plugin: PluginContext, state: State, id: string) {
-//     const b = new StateBuilder.Root(state.tree);
-//     const data = b.toRoot().apply(StateTransforms.Data.Download, { url: `https://www.ebi.ac.uk/pdbe/static/entry/${id}_updated.cif` }, { state: { isGhost: true }});
-//     const model = createModelTree(data, 'cif');
-//     const structure = model.apply(StateTransforms.Model.StructureFromModel);
-//     createDefaultStructureComplex(plugin, structure);
-//     return { tree: b.getTree(), structure: structure.ref };
-// }
-
-// const labelOptions: ParamDefinition.Values<Text.Params> = {
-//     ...ParamDefinition.getDefaultValues(Text.Params),
-//     tether: true,
-//     sizeFactor: 1.3,
-//     attachment: 'bottom-right',
-//     offsetZ: 10,
-//     background: true,
-//     backgroundMargin: 0.2,
-//     backgroundColor: ColorNames.skyblue,
-//     backgroundOpacity: 0.9
-// }
-
-// // const distanceLabelOptions = {
-// //     ...ParamDefinition.getDefaultValues(Text.Params),
-// //     sizeFactor: 1,
-// //     offsetX: 0,
-// //     offsetY: 0,
-// //     offsetZ: 10,
-// //     background: true,
-// //     backgroundMargin: 0.2,
-// //     backgroundColor: ColorNames.snow,
-// //     backgroundOpacity: 0.9
-// // }
-
-// function buildSnapshot(plugin: PluginContext, template: { tree: StateTree, structure: string }, params: { e: JoleculeSnapshot, idx: number, len: number }): PluginStateSnapshotManager.Entry {
-//     const b = new StateBuilder.Root(template.tree);
-
-//     let i = 0;
-//     for (const l of params.e.labels) {
-//         const expression = createExpression([l.i_atom]);
-//         const group = b.to(template.structure)
-//             .group(StateTransforms.Misc.CreateGroup, { label: `Label ${++i}` });
-
-//         group
-//             .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression, label: 'Atom' })
-//             .apply(StateTransforms.Representation.StructureLabels3D, {
-//                 target: { name: 'static-text', params: { value: l.text || '' } },
-//                 options: labelOptions
-//             });
-
-//         group
-//             .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression: MS.struct.modifier.wholeResidues([ expression ]), label: 'Residue' })
-//             .apply(StateTransforms.Representation.StructureRepresentation3D,
-//                 createStructureRepresentation3dParamss.getDefaultParamsStatic(plugin, 'ball-and-stick', {  }));
-//     }
-//     if (params.e.selected && params.e.selected.length > 0) {
-//         b.to(template.structure)
-//             .apply(StateTransforms.Model.StructureSelectionFromExpression, { expression: createExpression(params.e.selected), label: `Selected` })
-//             .apply(StateTransforms.Representation.StructureRepresentation3D,
-//                 createStructureRepresentation3dParamss.getDefaultParamsStatic(plugin, 'ball-and-stick'));
-//     }
-//     // TODO
-//     // for (const l of params.e.distances) {
-//     //     b.to('structure')
-//     //         .apply(StateTransforms.Model.StructureSelectionFromExpression, { query: createQuery([l.i_atom1, l.i_atom2]), label: `Distance ${++i}` })
-//     //         .apply(StateTransforms.Representation.StructureLabels3D, {
-//     //             target: { name: 'static-text', params: { value: l. || '' } },
-//     //             options: labelOptions
-//     //         });
-//     // }
-//     return PluginStateSnapshotManager.Entry({
-//         id: UUID.create22(),
-//         data: { tree: StateTree.toJSON(b.getTree()) },
-//         camera: {
-//             current: getCameraSnapshot(params.e.camera),
-//             transitionStyle: 'animate',
-//             transitionDurationInMs: 350
-//         }
-//     }, {
-//         name:  params.e.text
-//     });
-// }
-
-// function getCameraSnapshot(e: JoleculeSnapshot['camera']): Camera.Snapshot {
-//     const direction = Vec3.sub(Vec3(), e.pos, e.in);
-//     Vec3.normalize(direction, direction);
-//     const up = Vec3.sub(Vec3(), e.pos, e.up);
-//     Vec3.normalize(up, up);
-
-//     const s: Camera.Snapshot = {
-//         mode: 'perspective',
-//         fov: Math.PI / 4,
-//         position: Vec3.scaleAndAdd(Vec3(), e.pos, direction, e.slab.zoom),
-//         target: e.pos,
-//         radius: (e.slab.z_back - e.slab.z_front) / 2,
-//         fog: 50,
-//         up,
-//     };
-//     return s;
-// }
-
-// function createExpression(atomIndices: number[]) {
-//     if (atomIndices.length === 0) return MS.struct.generator.empty();
-
-//     return MS.struct.generator.atomGroups({
-//         'atom-test': atomIndices.length === 1
-//             ? MS.core.rel.eq([MS.struct.atomProperty.core.sourceIndex(), atomIndices[0]])
-//             : MS.core.set.has([MS.set.apply(null, atomIndices), MS.struct.atomProperty.core.sourceIndex()]),
-//         'group-by': 0
-//     });
-// }

+ 6 - 9
src/apps/viewer/index.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -12,10 +12,9 @@ import './favicon.ico';
 import { PluginContext } from '../../mol-plugin/context';
 import { PluginCommands } from '../../mol-plugin/commands';
 import { PluginSpec } from '../../mol-plugin/spec';
-import { LoadCellPackModel } from './extensions/cellpack/model';
-import { StructureFromCellpack } from './extensions/cellpack/state';
 import { DownloadStructure } from '../../mol-plugin-state/actions/structure';
 import { PluginConfig } from '../../mol-plugin/config';
+import { CellPack } from '../../extensions/cellpack';
 require('mol-plugin-ui/skin/light.scss');
 
 function getParam(name: string, regex: string): string {
@@ -27,13 +26,11 @@ const hideControls = getParam('hide-controls', `[^&]+`) === '1';
 
 function init() {
     const spec: PluginSpec = {
-        actions: [
-            ...DefaultPluginSpec.actions,
-            // PluginSpec.Action(CreateJoleculeState),
-            PluginSpec.Action(LoadCellPackModel),
-            PluginSpec.Action(StructureFromCellpack),
+        actions: [...DefaultPluginSpec.actions],
+        behaviors: [
+            ...DefaultPluginSpec.behaviors,
+            PluginSpec.Behavior(CellPack)
         ],
-        behaviors: [...DefaultPluginSpec.behaviors],
         animations: [...DefaultPluginSpec.animations || []],
         customParamEditors: DefaultPluginSpec.customParamEditors,
         layout: {

+ 10 - 10
src/apps/viewer/extensions/cellpack/color.ts → src/extensions/cellpack/color.ts

@@ -4,17 +4,17 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { ThemeDataContext } from '../../../../mol-theme/theme';
-import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
-import { Color } from '../../../../mol-util/color';
-import { getPalette } from '../../../../mol-util/color/palette';
-import { ColorTheme, LocationColor } from '../../../../mol-theme/color';
-import { ScaleLegend, TableLegend } from '../../../../mol-util/legend';
-import { StructureElement, Bond } from '../../../../mol-model/structure';
-import { Location } from '../../../../mol-model/location';
+import { ThemeDataContext } from '../../mol-theme/theme';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
+import { Color } from '../../mol-util/color';
+import { getPalette } from '../../mol-util/color/palette';
+import { ColorTheme, LocationColor } from '../../mol-theme/color';
+import { ScaleLegend, TableLegend } from '../../mol-util/legend';
+import { StructureElement, Bond } from '../../mol-model/structure';
+import { Location } from '../../mol-model/location';
 import { CellPackInfoProvider } from './property';
-import { distinctColors } from '../../../../mol-util/color/distinct';
-import { Hcl } from '../../../../mol-util/color/spaces/hcl';
+import { distinctColors } from '../../mol-util/color/distinct';
+import { Hcl } from '../../mol-util/color/spaces/hcl';
 
 
 const DefaultColor = Color(0xCCCCCC);

+ 2 - 2
src/apps/viewer/extensions/cellpack/curve.ts → src/extensions/cellpack/curve.ts

@@ -5,8 +5,8 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Vec3, Quat, Mat4 } from '../../../../mol-math/linear-algebra';
-import { NumberArray } from '../../../../mol-util/type-helpers';
+import { Vec3, Quat, Mat4 } from '../../mol-math/linear-algebra';
+import { NumberArray } from '../../mol-util/type-helpers';
 
 interface Frame {
     t: Vec3,

+ 1 - 1
src/apps/viewer/extensions/cellpack/data.ts → src/extensions/cellpack/data.ts

@@ -4,7 +4,7 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { Vec3, Quat } from '../../../../mol-math/linear-algebra';
+import { Vec3, Quat } from '../../mol-math/linear-algebra';
 
 export interface CellPack {
     cell: Cell

+ 30 - 0
src/extensions/cellpack/index.ts

@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
+
+import { PluginBehavior } from '../../mol-plugin/behavior';
+import { CellPackColorThemeProvider } from './color';
+import { LoadCellPackModel } from './model';
+
+
+export const CellPack = PluginBehavior.create<{ autoAttach: boolean, showTooltip: boolean }>({
+    name: 'cellpack',
+    category: 'custom-props',
+    display: {
+        name: 'CellPack',
+        description: 'CellPack Model Loading and Viewing.'
+    },
+    ctor: class extends PluginBehavior.Handler<{ autoAttach: boolean, showTooltip: boolean }> {
+        register(): void {
+            this.ctx.state.data.actions.add(LoadCellPackModel);
+            this.ctx.representation.structure.themes.colorThemeRegistry.add(CellPackColorThemeProvider);
+        }
+
+        unregister() {
+            this.ctx.state.data.actions.remove(LoadCellPackModel);
+            this.ctx.representation.structure.themes.colorThemeRegistry.remove(CellPackColorThemeProvider);
+        }
+    }
+});

+ 19 - 24
src/apps/viewer/extensions/cellpack/model.ts → src/extensions/cellpack/model.ts

@@ -4,31 +4,30 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { StateAction, StateBuilder, StateTransformer, State } from '../../../../mol-state';
-import { PluginContext } from '../../../../mol-plugin/context';
-import { PluginStateObject as PSO } from '../../../../mol-plugin-state/objects';
-import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
+import { StateAction, StateBuilder, StateTransformer, State } from '../../mol-state';
+import { PluginContext } from '../../mol-plugin/context';
+import { PluginStateObject as PSO } from '../../mol-plugin-state/objects';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { Ingredient, IngredientSource, CellPacking } from './data';
 import { getFromPdb, getFromCellPackDB, IngredientFiles, parseCif, parsePDBfile } from './util';
-import { Model, Structure, StructureSymmetry, StructureSelection, QueryContext, Unit } from '../../../../mol-model/structure';
-import { trajectoryFromMmCIF, MmcifFormat } from '../../../../mol-model-formats/structure/mmcif';
-import { trajectoryFromPDB } from '../../../../mol-model-formats/structure/pdb';
-import { Mat4, Vec3, Quat } from '../../../../mol-math/linear-algebra';
-import { SymmetryOperator } from '../../../../mol-math/geometry';
-import { Task, RuntimeContext } from '../../../../mol-task';
-import { StateTransforms } from '../../../../mol-plugin-state/transforms';
+import { Model, Structure, StructureSymmetry, StructureSelection, QueryContext, Unit } from '../../mol-model/structure';
+import { trajectoryFromMmCIF, MmcifFormat } from '../../mol-model-formats/structure/mmcif';
+import { trajectoryFromPDB } from '../../mol-model-formats/structure/pdb';
+import { Mat4, Vec3, Quat } from '../../mol-math/linear-algebra';
+import { SymmetryOperator } from '../../mol-math/geometry';
+import { Task, RuntimeContext } from '../../mol-task';
+import { StateTransforms } from '../../mol-plugin-state/transforms';
 import { ParseCellPack, StructureFromCellpack, DefaultCellPackBaseUrl } from './state';
-import { MolScriptBuilder as MS } from '../../../../mol-script/language/builder';
+import { MolScriptBuilder as MS } from '../../mol-script/language/builder';
 import { getMatFromResamplePoints } from './curve';
-import { compile } from '../../../../mol-script/runtime/query/compiler';
-import { CifCategory, CifField } from '../../../../mol-io/reader/cif';
-import { mmCIF_Schema } from '../../../../mol-io/reader/cif/schema/mmcif';
-import { Column } from '../../../../mol-data/db';
-import { createModels } from '../../../../mol-model-formats/structure/basic/parser';
+import { compile } from '../../mol-script/runtime/query/compiler';
+import { CifCategory, CifField } from '../../mol-io/reader/cif';
+import { mmCIF_Schema } from '../../mol-io/reader/cif/schema/mmcif';
+import { Column } from '../../mol-data/db';
+import { createModels } from '../../mol-model-formats/structure/basic/parser';
 import { CellpackPackingPreset, CellpackMembranePreset } from './preset';
-import { AjaxTask } from '../../../../mol-util/data-source';
+import { AjaxTask } from '../../mol-util/data-source';
 import { CellPackInfoProvider } from './property';
-import { CellPackColorThemeProvider } from './color';
 
 function getCellPackModelUrl(fileName: string, baseUrl: string) {
     return `${baseUrl}/results/${fileName}`;
@@ -498,7 +497,7 @@ const LoadCellPackModelParams = {
     }, { isExpanded: true }),
     preset: PD.Group({
         traceOnly: PD.Boolean(false),
-        representation: PD.Select('gaussian-surface', PD.arrayToOptions(['spacefill', 'gaussian-surface', 'point', 'ellipsoid']))
+        representation: PD.Select('gaussian-surface', PD.arrayToOptions(['spacefill', 'gaussian-surface', 'point', 'orientation']))
     }, { isExpanded: true })
 };
 type LoadCellPackModelParams = PD.Values<typeof LoadCellPackModelParams>
@@ -508,10 +507,6 @@ export const LoadCellPackModel = StateAction.build({
     params: LoadCellPackModelParams,
     from: PSO.Root
 })(({ state, params }, ctx: PluginContext) => Task.create('CellPack Loader', async taskCtx => {
-    if (!ctx.representation.structure.themes.colorThemeRegistry.has(CellPackColorThemeProvider)) {
-        ctx.representation.structure.themes.colorThemeRegistry.add(CellPackColorThemeProvider);
-    }
-
     if (params.source.name === 'id' && params.source.params === 'hiv_lipids.bcif') {
         await loadHivMembrane(ctx, taskCtx, state, params);
     } else {

+ 4 - 4
src/apps/viewer/extensions/cellpack/preset.ts → src/extensions/cellpack/preset.ts

@@ -4,10 +4,10 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { StateObjectRef } from '../../../../mol-state';
-import { StructureRepresentationPresetProvider, presetStaticComponent } from '../../../../mol-plugin-state/builder/structure/representation-preset';
-import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
-import { ColorNames } from '../../../../mol-util/color/names';
+import { StateObjectRef } from '../../mol-state';
+import { StructureRepresentationPresetProvider, presetStaticComponent } from '../../mol-plugin-state/builder/structure/representation-preset';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
+import { ColorNames } from '../../mol-util/color/names';
 import { CellPackColorThemeProvider } from './color';
 
 export const CellpackPackingPresetParams = {

+ 4 - 4
src/apps/viewer/extensions/cellpack/property.ts → src/extensions/cellpack/property.ts

@@ -4,10 +4,10 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { CustomStructureProperty } from '../../../../mol-model-props/common/custom-structure-property';
-import { Structure, CustomPropertyDescriptor } from '../../../../mol-model/structure';
-import { CustomProperty } from '../../../../mol-model-props/common/custom-property';
-import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
+import { CustomStructureProperty } from '../../mol-model-props/common/custom-structure-property';
+import { Structure, CustomPropertyDescriptor } from '../../mol-model/structure';
+import { CustomProperty } from '../../mol-model-props/common/custom-property';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
 
 export type CellPackInfoValue = {
     packingsCount: number

+ 3 - 3
src/apps/viewer/extensions/cellpack/state.ts → src/extensions/cellpack/state.ts

@@ -4,9 +4,9 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { PluginStateObject as PSO, PluginStateTransform } from '../../../../mol-plugin-state/objects';
-import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
-import { Task } from '../../../../mol-task';
+import { PluginStateObject as PSO, PluginStateTransform } from '../../mol-plugin-state/objects';
+import { ParamDefinition as PD } from '../../mol-util/param-definition';
+import { Task } from '../../mol-task';
 import { CellPack as _CellPack, Cell, CellPacking } from './data';
 import { createStructureFromCellPack } from './model';
 import { IngredientFiles } from './util';

+ 2 - 2
src/apps/viewer/extensions/cellpack/util.ts → src/extensions/cellpack/util.ts

@@ -4,8 +4,8 @@
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { CIF } from '../../../../mol-io/reader/cif';
-import { parsePDB } from '../../../../mol-io/reader/pdb/parser';
+import { CIF } from '../../mol-io/reader/cif';
+import { parsePDB } from '../../mol-io/reader/pdb/parser';
 
 export async function parseCif(data: string|Uint8Array) {
     const comp = CIF.parse(data);