Browse Source

more general structure for subset preset

Yana Rose 4 years ago
parent
commit
7c6fae37f4
2 changed files with 65 additions and 33 deletions
  1. 54 23
      src/viewer/helpers/preset.ts
  2. 11 10
      src/viewer/helpers/superpose/color.ts

+ 54 - 23
src/viewer/helpers/preset.ts

@@ -73,28 +73,39 @@ type BaseProps = {
     modelIndex?: number
 }
 
+type ColorProp = {
+    name: 'color',
+    value: number
+};
+
+type PropSet = {
+    args: ColorProp,
+    location: {
+        beg: number
+        end: number
+    }
+};
+
 type SubsetProps = {
     kind: 'subset'
     blocks: {
         asymId: string
-        matrix: Mat4
-        seqIdRange?: {
-            beg: number
-            end: number
-        },
-        color?: number
+        matrix: Mat4,
+        selection?: {
+            location: {
+                beg: number
+                end: number
+            }
+        }[],
+        propset: PropSet[]
     }[]
 } & BaseProps
 
-type ColorRangesProps = {
-    kind: 'color-ranges'
-    colorRanges: {
-        asymId: string
-        seqIdRange?: {
-            beg: number
-            end: number
-        },
-        color: number
+type PropsetProps = {
+    kind: 'prop-set'
+    blocks: {
+        asymId: string,
+        propset: PropSet[]
     }[]
 } & BaseProps
 
@@ -122,7 +133,7 @@ type DensityProps = {
     kind: 'density'
 } & BaseProps
 
-export type PresetProps = ValidationProps | StandardProps | SymmetryProps | FeatureProps | DensityProps | SubsetProps | ColorRangesProps
+export type PresetProps = ValidationProps | StandardProps | SymmetryProps | FeatureProps | DensityProps | SubsetProps | PropsetProps
 
 const RcsbParams = (a: PluginStateObject.Molecule.Trajectory | undefined, plugin: PluginContext) => ({
     preset: PD.Value<PresetProps>({ kind: 'standard', assemblyId: '' }, { isHidden: true })
@@ -159,19 +170,33 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
 
         let representation: StructureRepresentationPresetProvider.Result | undefined = undefined
 
-        if (p.kind === 'color-ranges') {
+        if (p.kind === 'prop-set') {
 
             const entryId = model.data?.entryId;
 
             const selections = new Array();
             const _sele = plugin.state.data.build().to(structureProperties).apply(StructureSelectionFromExpression, {
-                expression: MS.struct.generator.all,
+                expression: MS.struct.generator.all(),
                 label: `${entryId}`
             });
             const sele = await _sele.commit();
             selections.push(sele);
 
+            sele.data!.inheritedPropertyData.colors = {};
+
             const representations = new Array();
+            p.blocks.forEach( async block => {
+                let colorLookup = new Map();
+                block.propset.forEach(prop => {
+                    if (prop.args.name === 'color') {
+                        for (let i=prop.location.beg; i<=prop.location.end; i++) {
+                            colorLookup.set(i, prop.args.value);
+                        }
+                    }
+                });
+                sele.data!.inheritedPropertyData.colors[block.asymId] = colorLookup;
+            });
+
             const repr = await plugin.builders.structure.representation.applyPreset(sele, 'polymer-cartoon', {
                 theme: { globalName: 'superpose' }
             });
@@ -186,11 +211,7 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
 
             p.blocks.forEach( async block => {
 
-                structureProperties.data!.inheritedPropertyData.subset = {
-                    beg: block.seqIdRange!.beg,
-                    end: block.seqIdRange!.end,
-                    color: block!.color
-                }
+                structureProperties.data!.inheritedPropertyData.colors = {};
 
                 const _sele = plugin.state.data.build().to(structureProperties).apply(StructureSelectionFromExpression, {
                     expression: MS.struct.generator.atomGroups({
@@ -203,6 +224,16 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
                 const sele = await _sele.commit();
                 selections.push(sele);
 
+                let colorLookup = new Map();
+                block.propset.forEach(prop => {
+                    if (prop.args.name === 'color') {
+                        for (let i=prop.location.beg; i<=prop.location.end; i++){
+                            colorLookup.set(i, prop.args.value);
+                        }
+                    }
+                });
+                sele.data!.inheritedPropertyData.colors[block.asymId] = colorLookup;
+
                 const repr = await plugin.builders.structure.representation.applyPreset(sele, 'polymer-cartoon', {
                     theme: { globalName: 'superpose' }
                 });

+ 11 - 10
src/viewer/helpers/superpose/color.ts

@@ -16,19 +16,20 @@ const DefaultColor = Color(0xCCCCCC);
 
 export function SuperposeColorTheme(ctx: ThemeDataContext, props: {}): ColorTheme<{}> {
 
-    let colorCode = ctx.structure?.inheritedPropertyData.subset.color
-    if (colorCode === undefined) {
-        const index = Structure.Index.get(ctx.structure!).value || 0;
-        const { list } = ColorLists['many-distinct']
-        colorCode = list[index % list.length];
-    }
-
-    const beg = ctx.structure?.inheritedPropertyData.subset.beg;
-    const end = ctx.structure?.inheritedPropertyData.subset.end;
+    let colorLookup = ctx.structure?.inheritedPropertyData.colors;
+
+    const index = Structure.Index.get(ctx.structure!).value || 0;
+    const { list } = ColorLists['many-distinct']
+    let colorCode = list[index % list.length];
+
     const color = (location: Location): Color => {
         if (StructureElement.Location.is(location)) {
+            const asymId = StructureProperties.chain.label_asym_id(location);
             const seqId = StructureProperties.residue.label_seq_id(location);
-            if ( beg<=seqId && seqId<=end ) {
+            if (colorLookup[asymId]?.has(seqId) ) {
+                if (colorLookup[asymId]?.get(seqId) !== undefined) {
+                    colorCode = colorLookup[asymId]?.get(seqId);
+                }
                 return colorCode;
             }
         }