Browse Source

setting the default color to lighter version of primary color

Yana Rose 4 years ago
parent
commit
a1bede2a96
2 changed files with 17 additions and 11 deletions
  1. 1 1
      src/viewer/helpers/preset.ts
  2. 16 10
      src/viewer/helpers/superpose/color.ts

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

@@ -245,7 +245,7 @@ export const RcsbPreset = TrajectoryHierarchyPresetProvider({
             // adding coloring lookup scheme
             structure.data!.inheritedPropertyData.colors = {};
             for (const reprProp of p.representation) {
-                let colorLookup = structure.data!.inheritedPropertyData.colors[reprProp.asymId] || new Map();
+                const colorLookup = structure.data!.inheritedPropertyData.colors[reprProp.asymId] || new Map();
                 reprProp.propset.forEach(prop => {
                     if (prop.args.name === 'color') {
                         for (let i = 0; i < prop.positions.length; i++) {

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

@@ -8,19 +8,24 @@ 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, Structure } from 'molstar/lib/mol-model/structure';
+import { StructureElement, StructureProperties } from 'molstar/lib/mol-model/structure';
 import { Location } from 'molstar/lib/mol-model/location';
-import { ColorLists } from 'molstar/lib/mol-util/color/lists';
-
-const DefaultColor = Color(0xCCCCCC);
 
 export function SuperposeColorTheme(ctx: ThemeDataContext, props: {}): ColorTheme<{}> {
+    const colorLookup = ctx.structure?.inheritedPropertyData.colors;
 
-    let colorLookup = ctx.structure?.inheritedPropertyData.colors;
+    const defaultColorLookup: Map<string, Color> = new Map();
+    for (let [asymId, seqIds] of Object.entries(colorLookup)) {
+        const colorValue = Array.from((seqIds as Map<number, Color>).values())[0];
+        const defaultColor = Color.desaturate(Color.lighten(colorValue, 1.7), 1.2);
+        defaultColorLookup.set(asymId, defaultColor);
+    }
 
-    const index = Structure.Index.get(ctx.structure!).value || 0;
-    const { list } = ColorLists['many-distinct']
-    let colorCode = list[index % list.length];
+    let DefaultColor = Color(0xCCCCCC);
+    const colorValues: Color[] = Array.from(defaultColorLookup.values());
+    if (colorValues.every( (val, i, arr) => val === arr[0] )) {
+        DefaultColor = colorValues[0];
+    }
 
     const color = (location: Location): Color => {
         if (StructureElement.Location.is(location)) {
@@ -28,9 +33,10 @@ export function SuperposeColorTheme(ctx: ThemeDataContext, props: {}): ColorThem
             const seqId = StructureProperties.residue.label_seq_id(location);
             if (colorLookup?.[asymId]?.has(seqId)) {
                 if (colorLookup[asymId]?.get(seqId) !== undefined) {
-                    colorCode = colorLookup[asymId]?.get(seqId);
+                    return colorLookup[asymId]?.get(seqId);
                 }
-                return Array.isArray(colorCode) ? colorCode[0] : colorCode;
+            } else if (colorLookup?.[asymId]) {
+                return defaultColorLookup.get(asymId)!;
             }
         }
         return DefaultColor;