ソースを参照

color superimposed regions

Yana Rose 4 年 前
コミット
64fc68dfb3
3 ファイル変更74 行追加6 行削除
  1. 16 6
      src/viewer/helpers/preset.ts
  2. 55 0
      src/viewer/helpers/superpose/color.ts
  3. 3 0
      src/viewer/index.ts

+ 16 - 6
src/viewer/helpers/preset.ts

@@ -75,6 +75,7 @@ type BaseProps = {
 
 type SubsetProps = {
     kind: 'subset'
+    index: number,
     blocks: {
         asymId: string
         matrix: Mat4
@@ -148,25 +149,34 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
 
         if (p.kind === 'subset') {
 
-            var selections = new Array();
-            var representations = new Array();
+            const selections = new Array();
+            const representations = new Array();
+
             p.blocks.forEach( async block => {
+
+                structureProperties.data!.inheritedPropertyData.subset = {
+                    beg: block.seqIdRange!.beg,
+                    end: block.seqIdRange!.end,
+                    index: p.index
+                }
+
                 const _sele = plugin.state.data.build().to(structureProperties).apply(StructureSelectionFromExpression, {
                     expression: MS.struct.generator.atomGroups({
                         'chain-test': MS.core.rel.eq([MS.ammp('label_asym_id'), block.asymId]),
                     }),
                     label: `Chain ${block.asymId}`
-                })
-                .apply(TransformStructureConformation, { 
+                }).apply(TransformStructureConformation, {
                     transform: { name: 'matrix', params: { data: block.matrix, transpose: false } }
                 });
                 const sele = await _sele.commit();
                 selections.push(sele);
 
-                const repr = await plugin.builders.structure.representation.applyPreset(sele, 'polymer-cartoon');
+                const repr = await plugin.builders.structure.representation.applyPreset(sele, 'polymer-cartoon', {
+                    theme: { globalName: 'superpose' }
+                });
                 representations.push(repr);
             });
-            
+
         } else if (p.kind === 'validation') {
             representation = await plugin.builders.structure.representation.applyPreset(structureProperties, ValidationReportGeometryQualityPreset);
         } else if (p.kind === 'symmetry') {

+ 55 - 0
src/viewer/helpers/superpose/color.ts

@@ -0,0 +1,55 @@
+/**
+ * Copyright (c) 2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Yana Rose
+ */
+
+import { ThemeDataContext } from 'molstar/lib/mol-theme/theme';
+import { ColorTheme } from 'molstar/lib/mol-theme/color';
+import { ParamDefinition as PD } from 'molstar/lib/mol-util/param-definition';
+import { Color } from 'molstar/lib/mol-util/color';
+import { StructureElement, StructureProperties } from 'molstar/lib/mol-model/structure';
+import { Location } from 'molstar/lib/mol-model/location';
+import { ColorNames } from 'molstar/lib/mol-util/color/names';
+
+const DefaultColor = Color(0xCCCCCC);
+
+const colorMap = new Map();
+colorMap.set(0, ColorNames.green);
+colorMap.set(1, ColorNames.blue);
+
+export function SuperposeColorTheme(ctx: ThemeDataContext, props: {}): ColorTheme<{}> {
+
+    console.log(ctx.structure?.inheritedPropertyData.subset);
+
+    const index = ctx.structure?.inheritedPropertyData.subset.index;
+    const beg = ctx.structure?.inheritedPropertyData.subset.beg;
+    const end = ctx.structure?.inheritedPropertyData.subset.end;
+    const color = (location: Location): Color => {
+        if (StructureElement.Location.is(location)) {
+            const seqId = StructureProperties.residue.label_seq_id(location);
+            if ( beg>=seqId && seqId<=end ) {
+                return colorMap.get(index);
+            }
+        }
+        return DefaultColor;
+    };
+
+    return {
+        factory: SuperposeColorTheme,
+        granularity: 'group',
+        color,
+        props,
+        description: 'Superpose coloring',
+    };
+}
+
+export const SuperposeColorThemeProvider: ColorTheme.Provider<{}, 'superpose'> = {
+    name: 'superpose',
+    label: 'Superpose',
+    category: ColorTheme.Category.Misc,
+    factory: SuperposeColorTheme,
+    getParams: () => ({}),
+    defaultValues: PD.getDefaultValues({}),
+    isApplicable: (ctx: ThemeDataContext) => !!ctx.structure && !!ctx.structure.inheritedPropertyData.subset,
+};

+ 3 - 0
src/viewer/index.ts

@@ -28,6 +28,7 @@ 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';
+import { SuperposeColorThemeProvider } from './helpers/superpose/color';
 require('./skin/rcsb.scss')
 
 /** package version, filled in at bundle build time */
@@ -158,6 +159,8 @@ export class Viewer {
         const renderer = this.plugin.canvas3d!.props.renderer;
         PluginCommands.Canvas3D.SetSettings(this.plugin, { settings: { renderer: { ...renderer, backgroundColor: o.backgroundColor } } });
 
+        this.plugin.representation.structure.themes.colorThemeRegistry.add(SuperposeColorThemeProvider);
+
         if (o.showWelcomeToast) {
             PluginCommands.Toast.Show(this.plugin, {
                 title: 'Welcome',