Skip to content
Snippets Groups Projects
Commit 32e2552c authored by Alexander Rose's avatar Alexander Rose
Browse files

rudimentary cross-link color scheme

parent c71c1b0f
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ const ballAndStickProps: Partial<BallAndStickProps> = {
const distanceRestraintProps: Partial<DistanceRestraintProps> = {
doubleSided: true,
colorTheme: { name: 'chain-id' },
colorTheme: { name: 'cross-link' },
sizeTheme: { name: 'uniform', value: 0.6 },
quality: 'auto',
useFog: false
......
......@@ -14,6 +14,7 @@ import { ChainIdColorTheme } from './color/chain-id';
import { ElementSymbolColorTheme } from './color/element-symbol';
import { UnitIndexColorTheme } from './color/unit-index';
import { UniformColorTheme } from './color/uniform';
import { CrossLinkColorTheme } from './color/cross-link';
export interface ColorTheme {
kind: ColorType
......@@ -24,6 +25,7 @@ export function ColorTheme(props: ColorThemeProps): ColorTheme {
switch (props.name) {
case 'element-index': return ElementIndexColorTheme(props)
case 'carbohydrate-symbol': return CarbohydrateSymbolColorTheme(props)
case 'cross-link': return CrossLinkColorTheme(props)
case 'chain-id': return ChainIdColorTheme(props)
case 'element-symbol': return ElementSymbolColorTheme(props)
case 'unit-index': return UnitIndexColorTheme(props)
......@@ -32,7 +34,7 @@ export function ColorTheme(props: ColorThemeProps): ColorTheme {
}
export interface ColorThemeProps {
name: 'element-index' | 'chain-id'| 'unit-index' | 'uniform' | 'carbohydrate-symbol' | 'element-symbol'
name: ColorThemeName
domain?: [number, number]
value?: Color
structure?: Structure
......@@ -41,6 +43,7 @@ export interface ColorThemeProps {
export const ColorThemeInfo = {
'element-index': {},
'carbohydrate-symbol': {},
'cross-link': {},
'chain-id': {},
'element-symbol': {},
'unit-index': {},
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Link } from 'mol-model/structure';
import { Color, ColorScale, ColorBrewer } from 'mol-util/color';
import { Location } from 'mol-model/location';
import { ColorThemeProps, ColorTheme } from '../color';
import { LocationColor } from 'mol-geo/util/color-data';
import { Vec3 } from 'mol-math/linear-algebra';
const DefaultColor = 0xCCCCCC;
const distVecA = Vec3.zero(), distVecB = Vec3.zero()
function linkDistance(link: Link.Location) {
link.aUnit.conformation.position(link.aIndex, distVecA)
link.bUnit.conformation.position(link.bIndex, distVecB)
return Vec3.distance(distVecA, distVecB)
}
export function CrossLinkColorTheme(props: ColorThemeProps): ColorTheme {
let colorFn: LocationColor
if (props.structure) {
const crosslinks = props.structure.crossLinkRestraints
const scale = ColorScale.create({ domain: [ -10, 10 ], colors: ColorBrewer.RdYlBu })
colorFn = (location: Location): Color => {
if (Link.isLocation(location)) {
const pairs = crosslinks.getPairs(location.aIndex, location.aUnit, location.bIndex, location.bUnit)
if (pairs) {
return scale.color(linkDistance(location) - pairs[0].distanceThreshold)
}
}
return DefaultColor
}
} else {
colorFn = () => DefaultColor
}
return {
kind: 'element',
color: colorFn
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment