JonStargaryen 4 years ago
parent
commit
30ded76111

+ 3 - 3
src/viewer/helpers/model.ts

@@ -14,11 +14,11 @@ import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/tr
 
 export class ModelLoader {
     async load(load: LoadParams, props?: PresetProps, matrix?: Mat4) {
-        const { fileOrUrl, format, isBinary } = load
+        const { fileOrUrl, format, isBinary } = load;
 
         const data = fileOrUrl instanceof File
             ? (await this.plugin.builders.data.readFile({ file: Asset.File(fileOrUrl), isBinary })).data
-            : await this.plugin.builders.data.download({ url: fileOrUrl, isBinary })
+            : await this.plugin.builders.data.download({ url: fileOrUrl, isBinary });
         await this.handleTrajectory(data, format, props, matrix);
     }
 
@@ -29,7 +29,7 @@ export class ModelLoader {
     }
 
     async handleTrajectory(data: any, format: BuiltInTrajectoryFormat, props?: PresetProps, matrix?: Mat4) {
-        const trajectory = await this.plugin.builders.structure.parseTrajectory(data, format)
+        const trajectory = await this.plugin.builders.structure.parseTrajectory(data, format);
 
         const selector = await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, RcsbPreset, {
             preset: props || { kind: 'standard', assemblyId: '' }

+ 28 - 28
src/viewer/helpers/preset.ts

@@ -31,41 +31,41 @@ type Target = {
 }
 
 function targetToExpression(target: Target): Expression {
-    const residueTests: Expression[] = []
-    const tests = Object.create(null)
+    const residueTests: Expression[] = [];
+    const tests = Object.create(null);
 
     if (target.auth_seq_id) {
-        residueTests.push(MS.core.rel.eq([target.auth_seq_id, MS.ammp('auth_seq_id')]))
+        residueTests.push(MS.core.rel.eq([target.auth_seq_id, MS.ammp('auth_seq_id')]));
     } else if (target.label_seq_id) {
-        residueTests.push(MS.core.rel.eq([target.label_seq_id, MS.ammp('label_seq_id')]))
+        residueTests.push(MS.core.rel.eq([target.label_seq_id, MS.ammp('label_seq_id')]));
     }
     if (target.label_comp_id) {
-        residueTests.push(MS.core.rel.eq([target.label_comp_id, MS.ammp('label_comp_id')]))
+        residueTests.push(MS.core.rel.eq([target.label_comp_id, MS.ammp('label_comp_id')]));
     }
     if (residueTests.length === 1) {
-        tests['residue-test'] = residueTests[0]
+        tests['residue-test'] = residueTests[0];
     } else if (residueTests.length > 1) {
-        tests['residue-test'] = MS.core.logic.and(residueTests)
+        tests['residue-test'] = MS.core.logic.and(residueTests);
     }
 
     if (target.label_asym_id) {
-        tests['chain-test'] = MS.core.rel.eq([target.label_asym_id, MS.ammp('label_asym_id')])
+        tests['chain-test'] = MS.core.rel.eq([target.label_asym_id, MS.ammp('label_asym_id')]);
     }
 
     if (Object.keys(tests).length > 0) {
         return MS.struct.modifier.union([
             MS.struct.generator.atomGroups(tests)
-        ])
+        ]);
     } else {
-        return MS.struct.generator.empty
+        return MS.struct.generator.empty;
     }
 }
 
 function targetToLoci(target: Target, structure: Structure): StructureElement.Loci {
-    const expression = targetToExpression(target)
-    const query = compile<StructureSelection>(expression)
+    const expression = targetToExpression(target);
+    const query = compile<StructureSelection>(expression);
     const selection = query(new QueryContext(structure));
-    return StructureSelection.toLociWithSourceUnits(selection)
+    return StructureSelection.toLociWithSourceUnits(selection);
 }
 
 type BaseProps = {
@@ -107,21 +107,21 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
     id: 'preset-trajectory-rcsb',
     display: { name: 'RCSB' },
     isApplicable: o => {
-        return true
+        return true;
     },
     params: RcsbParams,
     async apply(trajectory, params, plugin) {
         const builder = plugin.builders.structure;
-        const p = params.preset
+        const p = params.preset;
 
-        const modelParams = { modelIndex: p.modelIndex || 0 }
+        const modelParams = { modelIndex: p.modelIndex || 0 };
 
-        const structureParams: RootStructureDefinition.Params = { name: 'model', params: {} }
+        const structureParams: RootStructureDefinition.Params = { name: 'model', params: {} };
         if (p.assemblyId && p.assemblyId !== '' && p.assemblyId !== '0') {
             Object.assign(structureParams, {
                 name: 'assembly',
                 params: { id: p.assemblyId }
-            } as RootStructureDefinition.Params)
+            } as RootStructureDefinition.Params);
         }
 
         const model = await builder.createModel(trajectory, modelParams);
@@ -132,7 +132,7 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
 
         const unitcell = await builder.tryCreateUnitcell(modelProperties, undefined, { isHidden: true });
 
-        let representation: StructureRepresentationPresetProvider.Result | undefined = undefined
+        let representation: StructureRepresentationPresetProvider.Result | undefined = undefined;
 
         if (p.kind === 'validation') {
             representation = await plugin.builders.structure.representation.applyPreset(structureProperties, ValidationReportGeometryQualityPreset);
@@ -142,25 +142,25 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
             ViewerState(plugin).collapsed.next({
                 ...ViewerState(plugin).collapsed.value,
                 custom: false
-            })
+            });
         } else {
             representation = await plugin.builders.structure.representation.applyPreset(structureProperties, 'auto');
         }
 
         if (p.kind === 'feature' && structure.obj) {
-            const loci = targetToLoci(p.target, structure.obj.data)
+            const loci = targetToLoci(p.target, structure.obj.data);
             // if target is only defined by chain: then don't force first residue
             const chainMode = p.target.label_asym_id && !p.target.auth_seq_id && !p.target.label_seq_id && !p.target.label_comp_id;
-            const target = chainMode ? loci : StructureElement.Loci.firstResidue(loci)
-            plugin.managers.structure.focus.setFromLoci(target)
-            plugin.managers.camera.focusLoci(target)
+            const target = chainMode ? loci : StructureElement.Loci.firstResidue(loci);
+            plugin.managers.structure.focus.setFromLoci(target);
+            plugin.managers.camera.focusLoci(target);
         }
 
         if (p.kind === 'density' && structure.cell?.parent) {
             const volumeRoot = StateSelection.findTagInSubtree(structure.cell.parent.tree, structure.cell.transform.ref, VolumeStreaming.RootTag);
             if (!volumeRoot) {
-                const params = PD.getDefaultValues(InitVolumeStreaming.definition.params!(structure.obj!, plugin))
-                await plugin.runTask(plugin.state.data.applyAction(InitVolumeStreaming, params, structure.ref))
+                const params = PD.getDefaultValues(InitVolumeStreaming.definition.params!(structure.obj!, plugin));
+                await plugin.runTask(plugin.state.data.applyAction(InitVolumeStreaming, params, structure.ref));
             }
 
             await PluginCommands.Toast.Show(plugin, {
@@ -168,7 +168,7 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
                 message: 'Click on a residue to display electron density, click background to reset.',
                 key: 'toast-density',
                 timeoutMs: 60000
-            })
+            });
 
             plugin.behaviors.interaction.click.subscribe(async (e: InteractivityManager.ClickEvent) => {
                 if (e.current && e.current.loci && e.current.loci.kind !== 'empty-loci') {
@@ -179,7 +179,7 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
             ViewerState(plugin).collapsed.next({
                 ...ViewerState(plugin).collapsed.value,
                 volume: false
-            })
+            });
         }
 
         return {

+ 18 - 18
src/viewer/index.ts

@@ -6,9 +6,9 @@
 
 import { BehaviorSubject } from 'rxjs';
 import { DefaultPluginSpec } from 'molstar/lib/mol-plugin';
-import { Plugin } from 'molstar/lib/mol-plugin-ui/plugin'
-import './index.html'
-import './favicon.ico'
+import { Plugin } from 'molstar/lib/mol-plugin-ui/plugin';
+import './index.html';
+import './favicon.ico';
 import { PluginContext } from 'molstar/lib/mol-plugin/context';
 import { PluginCommands } from 'molstar/lib/mol-plugin/commands';
 import { ViewerState as ViewerState, CollapsedState, ModelUrlProvider } from './types';
@@ -28,14 +28,14 @@ import { PluginState } from 'molstar/lib/mol-plugin/state';
 import { BuiltInTrajectoryFormat } from 'molstar/lib/mol-plugin-state/formats/trajectory';
 import { ObjectKeys } from 'molstar/lib/mol-util/type-helpers';
 import { PluginLayoutControlsDisplay } from 'molstar/lib/mol-plugin/layout';
-require('./skin/rcsb.scss')
+require('./skin/rcsb.scss');
 
 /** package version, filled in at bundle build time */
-declare const __RCSB_MOLSTAR_VERSION__: string
+declare const __RCSB_MOLSTAR_VERSION__: string;
 export const RCSB_MOLSTAR_VERSION = __RCSB_MOLSTAR_VERSION__;
 
 /** unix time stamp, to be filled in at bundle build time */
-declare const __BUILD_TIMESTAMP__: number
+declare const __BUILD_TIMESTAMP__: number;
 export const BUILD_TIMESTAMP = __BUILD_TIMESTAMP__;
 export const BUILD_DATE = new Date(BUILD_TIMESTAMP);
 
@@ -81,13 +81,13 @@ export class Viewer {
     private readonly modelUrlProviders: ModelUrlProvider[];
 
     private get customState() {
-        return this.plugin.customState as ViewerState
+        return this.plugin.customState as ViewerState;
     }
 
     constructor(target: string | HTMLElement, props: Partial<ViewerProps> = {}) {
-        target = typeof target === 'string' ? document.getElementById(target)! : target
+        target = typeof target === 'string' ? document.getElementById(target)! : target;
 
-        const o = { ...DefaultViewerProps, ...props }
+        const o = { ...DefaultViewerProps, ...props };
 
         const spec: PluginSpec = {
             actions: [...DefaultPluginSpec.actions],
@@ -140,10 +140,10 @@ export class Viewer {
                 volume: true,
                 custom: true,
             }),
-        }
+        };
 
         this.plugin.init();
-        ReactDOM.render(React.createElement(Plugin, { plugin: this.plugin }), target)
+        ReactDOM.render(React.createElement(Plugin, { plugin: this.plugin }), target);
 
         const renderer = this.plugin.canvas3d!.props.renderer;
         PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: { ...renderer, backgroundColor: o.backgroundColor } } });
@@ -154,7 +154,7 @@ export class Viewer {
                 message: `RCSB PDB Mol* Viewer ${RCSB_MOLSTAR_VERSION} [${BUILD_DATE.toLocaleString()}]`,
                 key: 'toast-welcome',
                 timeoutMs: 5000
-            })
+            });
         }
     }
 
@@ -166,17 +166,17 @@ export class Viewer {
 
     clear() {
         const state = this.plugin.state.data;
-        return PluginCommands.State.RemoveObject(this.plugin, { state, ref: state.tree.root.ref })
+        return PluginCommands.State.RemoveObject(this.plugin, { state, ref: state.tree.root.ref });
     }
 
     async loadPdbId(pdbId: string, props?: PresetProps, matrix?: Mat4) {
         for (const provider of this.modelUrlProviders) {
             try {
-                const p = provider(pdbId)
-                await this.customState.modelLoader.load({ fileOrUrl: p.url, format: p.format, isBinary: p.isBinary }, props, matrix)
-                break
+                const p = provider(pdbId);
+                await this.customState.modelLoader.load({ fileOrUrl: p.url, format: p.format, isBinary: p.isBinary }, props, matrix);
+                break;
             } catch (e) {
-                console.warn(`loading '${pdbId}' failed with '${e}', trying next model-loader-provider`)
+                console.warn(`loading '${pdbId}' failed with '${e}', trying next model-loader-provider`);
             }
         }
     }
@@ -189,7 +189,7 @@ export class Viewer {
     }
 
     loadStructureFromUrl(url: string, format: BuiltInTrajectoryFormat, isBinary: boolean, props?: PresetProps, matrix?: Mat4) {
-        return this.customState.modelLoader.load({ fileOrUrl: url, format, isBinary }, props, matrix)
+        return this.customState.modelLoader.load({ fileOrUrl: url, format, isBinary }, props, matrix);
     }
 
     loadSnapshotFromUrl(url: string, type: PluginState.SnapshotType) {

+ 1 - 1
src/viewer/types.ts

@@ -47,5 +47,5 @@ export interface ViewerState {
     collapsed: BehaviorSubject<CollapsedState>
 }
 export function ViewerState(plugin: PluginContext) {
-    return plugin.customState as ViewerState
+    return plugin.customState as ViewerState;
 }

+ 3 - 3
src/viewer/ui/controls.tsx

@@ -18,15 +18,15 @@ import { SessionControls } from './session';
 
 export class StructureTools extends PluginUIComponent {
     get customState() {
-        return ViewerState(this.plugin)
+        return ViewerState(this.plugin);
     }
 
     componentDidMount() {
-        this.subscribe(this.customState.collapsed, () => this.forceUpdate())
+        this.subscribe(this.customState.collapsed, () => this.forceUpdate());
     }
 
     render() {
-        const collapsed = this.customState.collapsed.value
+        const collapsed = this.customState.collapsed.value;
         return <>
             <StructureSourceControls />
             <StructureMeasurementsControls initiallyCollapsed={collapsed.measurements} />

+ 2 - 2
src/viewer/ui/import.tsx

@@ -18,13 +18,13 @@ export class ImportControls extends CollapsableControls {
             header: 'Import',
             isCollapsed: false,
             brand: { accent:  'gray' as const, svg: FileOutlineSvg }
-        }
+        };
     }
 
     renderControls() {
         return <div className={'msp-control-offset'} style={{ paddingTop: '1px' }}>
             <ApplyActionControl key={`${OpenFiles.id}`} state={this.plugin.state.data} action={OpenFiles} nodeRef={StateTransform.RootRef} initiallyCollapsed={true} />
             <ApplyActionControl key={`${DownloadStructure.id}`} state={this.plugin.state.data} action={DownloadStructure} nodeRef={StateTransform.RootRef} initiallyCollapsed={true} />
-        </div>
+        </div>;
     }
 }

+ 6 - 6
src/viewer/ui/session.tsx

@@ -14,14 +14,14 @@ class LocalStateControls extends CollapsableControls {
         return {
             header: 'Views',
             isCollapsed: true,
-        }
+        };
     }
 
     renderControls() {
         return <div>
             <LocalStateSnapshots />
             <LocalStateSnapshotList />
-        </div>
+        </div>;
     }
 }
 
@@ -30,13 +30,13 @@ class StateControls extends CollapsableControls {
         return {
             header: 'Download / Open',
             isCollapsed: true,
-        }
+        };
     }
 
     renderControls() {
         return <div>
             <StateExportImportControls />
-        </div>
+        </div>;
     }
 }
 
@@ -46,13 +46,13 @@ export class SessionControls extends CollapsableControls {
             header: 'Session',
             isCollapsed: true,
             brand: { accent:  'gray' as const, svg: SaveOutlinedSvg }
-        }
+        };
     }
 
     renderControls() {
         return <div className={'msp-control-offset'} style={{ paddingTop: '1px' }}>
             <LocalStateControls />
             <StateControls />
-        </div>
+        </div>;
     }
 }