Browse Source

use chain-id coloring as base for illiustrative coloring

Alexander Rose 4 years ago
parent
commit
78ca5cbb43
1 changed files with 19 additions and 41 deletions
  1. 19 41
      src/mol-theme/color/illustrative.ts

+ 19 - 41
src/mol-theme/color/illustrative.ts

@@ -1,21 +1,20 @@
 /**
- * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
-import { ElementSymbol, isNucleic, isProtein, MoleculeType } from '../../mol-model/structure/model/types';
+import { ElementSymbol } from '../../mol-model/structure/model/types';
 import { Color } from '../../mol-util/color';
 import { StructureElement, Unit, Bond } from '../../mol-model/structure';
 import { Location } from '../../mol-model/location';
 import { ColorTheme } from '../color';
 import { ParamDefinition as PD } from '../../mol-util/param-definition';
 import { ThemeDataContext } from '../theme';
-import { elementSymbolColor, ElementSymbolColors } from './element-symbol';
-import { getAdjustedColorMap } from '../../mol-util/color/color';
+import { ChainIdColorTheme, getChainIdColorThemeParams } from './chain-id';
 
-const DefaultIllustrativeColor = Color(0xFFFFFF);
-const Description = `Assigns an illustrative color similar to David Goodsell's Molecule of the Month style.`;
+const DefaultIllustrativeColor = Color(0xEEEEEE);
+const Description = `Assigns an illustrative color that gives every chain a unique color with lighter carbons (inspired by David Goodsell's Molecule of the Month style).`;
 
 export const IllustrativeColorThemeParams = {};
 export type IllustrativeColorThemeParams = typeof IllustrativeColorThemeParams
@@ -23,43 +22,22 @@ export function getIllustrativeColorThemeParams(ctx: ThemeDataContext) {
     return IllustrativeColorThemeParams; // TODO return copy
 }
 
-export function illustrativeColor(colorMap: ElementSymbolColors, typeSymbol: ElementSymbol, moleculeType: MoleculeType) {
-    if (isNucleic(moleculeType)) {
-        if (typeSymbol === 'O') {
-            return Color(0xFF8C8C);
-        } else if (typeSymbol === 'P') {
-            return Color(0xFF7D7D);
-        } else {
-            return Color(0xFFA6A6);
-        }
-    } else if (isProtein(moleculeType)) {
-        if (typeSymbol === 'C') {
-            return Color(0x7FB2FF);
-        } else {
-            return Color(0x6699FF);
-        }
-    } else {
-        return elementSymbolColor(colorMap, typeSymbol);
-    }
-}
-
 export function IllustrativeColorTheme(ctx: ThemeDataContext, props: PD.Values<IllustrativeColorThemeParams>): ColorTheme<IllustrativeColorThemeParams> {
-    const colorMap = getAdjustedColorMap(ElementSymbolColors, 0, 0.7);
+    const { color: chainIdColor, legend } = ChainIdColorTheme(ctx, PD.getDefaultValues(getChainIdColorThemeParams(ctx)));
+
+    function illustrativeColor(location: Location, typeSymbol: ElementSymbol) {
+        const baseColor = chainIdColor(location, false);
+        return typeSymbol === 'C' ? Color.lighten(baseColor, 0.8) : baseColor;
+    }
 
     function color(location: Location): Color {
-        if (StructureElement.Location.is(location)) {
-            if (Unit.isAtomic(location.unit)) {
-                const moleculeType = location.unit.model.atomicHierarchy.derived.residue.moleculeType[location.unit.residueIndex[location.element]];
-                const typeSymbol = location.unit.model.atomicHierarchy.atoms.type_symbol.value(location.element);
-                return illustrativeColor(colorMap, typeSymbol, moleculeType);
-            }
-        } else if (Bond.isLocation(location)) {
-            if (Unit.isAtomic(location.aUnit)) {
-                const elementIndex = location.aUnit.elements[location.aIndex];
-                const moleculeType = location.aUnit.model.atomicHierarchy.derived.residue.moleculeType[location.aUnit.residueIndex[elementIndex]];
-                const typeSymbol = location.aUnit.model.atomicHierarchy.atoms.type_symbol.value(elementIndex);
-                return illustrativeColor(colorMap, typeSymbol, moleculeType);
-            }
+        if (StructureElement.Location.is(location) && Unit.isAtomic(location.unit)) {
+            const typeSymbol = location.unit.model.atomicHierarchy.atoms.type_symbol.value(location.element);
+            return illustrativeColor(location, typeSymbol);
+        } else if (Bond.isLocation(location) && Unit.isAtomic(location.aUnit)) {
+            const elementIndex = location.aUnit.elements[location.aIndex];
+            const typeSymbol = location.aUnit.model.atomicHierarchy.atoms.type_symbol.value(elementIndex);
+            return illustrativeColor(location, typeSymbol);
         }
         return DefaultIllustrativeColor;
     }
@@ -70,7 +48,7 @@ export function IllustrativeColorTheme(ctx: ThemeDataContext, props: PD.Values<I
         color,
         props,
         description: Description,
-        // TODO add legend
+        legend
     };
 }