瀏覽代碼

basic coloring support

JonStargaryen 3 年之前
父節點
當前提交
5f04906a13
共有 4 個文件被更改,包括 31 次插入17 次删除
  1. 10 7
      src/viewer/helpers/preset.ts
  2. 3 2
      src/viewer/helpers/selection.ts
  3. 14 6
      src/viewer/helpers/superpose/preset.ts
  4. 4 2
      src/viewer/index.html

+ 10 - 7
src/viewer/helpers/preset.ts

@@ -89,7 +89,7 @@ type FeatureDensityProps = {
 
 export type MotifProps = {
     kind: 'motif',
-    label: string,
+    label?: string,
     targets: Target[],
     color?: number
 } & BaseProps
@@ -188,22 +188,25 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
             const params = {
                 ignoreHydrogens: CommonParams.ignoreHydrogens.defaultValue,
                 quality: CommonParams.quality.defaultValue,
-                theme: { globalName: 'superpose' as any, focus: { name: 'superpose' } },
+                theme: { globalName: 'superpose', focus: { name: 'superpose' } },
                 selectionExpressions: selectionExpressions
             };
-            representation = await plugin.builders.structure.representation.applyPreset(structureProperties!, RcsbSuperpositionRepresentationPreset, params);
+            representation = await plugin.builders.structure.representation.applyPreset<any>(structureProperties!, RcsbSuperpositionRepresentationPreset, params);
         } else if (p.kind === 'motif') {
-            let selectionExpressions = createSelectionExpression(p.label, p.targets);
-            const globalExpressions = createSelectionExpression(p.label); // global reps, to be hidden
+            let selectionExpressions = createSelectionExpression(p.label || model.data!.entryId, p.targets);
+            const globalExpressions = createSelectionExpression(p.label || model.data!.entryId); // global reps, to be hidden
             selectionExpressions = selectionExpressions.concat(globalExpressions.map(e => { return { ...e, isHidden: true }; }));
 
+            if (p.color) {
+                selectionExpressions = selectionExpressions.map(e => { return { ...e, color: p.color }; });
+            }
+
             const params = {
                 ignoreHydrogens: true,
                 quality: CommonParams.quality.defaultValue,
-                theme: { globalName: 'superpose' as any, focus: { name: 'superpose' } },
                 selectionExpressions: selectionExpressions
             };
-            representation = await plugin.builders.structure.representation.applyPreset(structureProperties!, RcsbSuperpositionRepresentationPreset, params);
+            representation = await plugin.builders.structure.representation.applyPreset<any>(structureProperties!, RcsbSuperpositionRepresentationPreset, params);
         } else if (p.kind === 'validation') {
             representation = await plugin.builders.structure.representation.applyPreset(structureProperties!, ValidationReportGeometryQualityPreset);
         } else if (p.kind === 'symmetry') {

+ 3 - 2
src/viewer/helpers/selection.ts

@@ -30,7 +30,8 @@ export type SelectionExpression = {
     type: StructureRepresentationRegistry.BuiltIn
     label: string
     expression: Expression
-    isHidden?: boolean
+    isHidden?: boolean,
+    color?: number
 };
 
 /**
@@ -40,7 +41,7 @@ export type SelectionExpression = {
  */
 export function createSelectionExpression(labelBase: string, selection?: Range | Target[]): SelectionExpression[] {
     if (selection) {
-        if (selection.hasOwnProperty('label_asym_id') && selection.hasOwnProperty('label_seq_id')) {
+        if ('label_asym_id' in selection && 'label_seq_id' in selection) {
             const range = selection as Range;
             const residues: number[] = (range.label_seq_id) ? toRange(range.label_seq_id.beg, range.label_seq_id.end) : [];
             const test = rangeToTest(range.label_asym_id, residues);

+ 14 - 6
src/viewer/helpers/superpose/preset.ts

@@ -39,17 +39,25 @@ export const RcsbSuperpositionRepresentationPreset = StructureRepresentationPres
 
             const { update, builder, typeParams, color } = reprBuilder(plugin, params);
 
-            let typeProps = { ...typeParams };
+            const typeProps = { ...typeParams };
             if (expr.type === 'cartoon') {
                 Object.assign(typeProps, { ...cartoonProps });
             }
 
+            const reprProps = {
+                type: expr.type,
+                typeParams: typeProps,
+                color: color as any
+            };
+            if (expr.color) {
+                Object.assign(reprProps, {
+                    color: 'uniform',
+                    colorParams: { value: expr.color }
+                });
+            }
+
             Object.assign(representations, {
-                [expr.label]: builder.buildRepresentation(update, comp, {
-                    type: expr.type,
-                    typeParams: typeProps,
-                    color: color as any
-                }, {
+                [expr.label]: builder.buildRepresentation(update, comp, reprProps, {
                     tag: expr.tag,
                     // this only hides the visuals but the state UI will still indicate them as visible
                     initialState: { isHidden: expr.isHidden || false }

+ 4 - 2
src/viewer/index.html

@@ -379,7 +379,8 @@
                                     { label_asym_id: 'B', label_seq_id: 42 },
                                     { label_asym_id: 'B', label_seq_id: 87 },
                                     { label_asym_id: 'C', label_seq_id: 47 }
-                                ]
+                                ],
+                                // color: 13203230
                             }
                         }, {
                             pdbId: '6yiw',
@@ -391,7 +392,8 @@
                                     { label_asym_id: 'A', label_seq_id: 40 },
                                     { label_asym_id: 'A', label_seq_id: 84 },
                                     { label_asym_id: 'A', label_seq_id: 177 }
-                                ]
+                                ],
+                                // color: 4947916
                             },
                             matrix: [
                                 0.1651637134205112, 0.7020365618749254, 0.6927233311791812, 0,