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

wip, coloring

parent d0b3b5ff
Branches
Tags
No related merge requests found
......@@ -49,7 +49,8 @@ export default class State {
const structPointRepr = StructureRepresentation(Point)
const pointProps: PointProps = {
colorTheme: { name: 'uniform', value: 0xFF4411 },
// colorTheme: { name: 'uniform', value: 0xFF4411 },
colorTheme: { name: 'chain-id' },
sizeTheme: { name: 'uniform', value: 0.1 }
}
await Run(structPointRepr.create(struct, pointProps), log, 100)
......@@ -59,9 +60,10 @@ export default class State {
const spacefillProps: SpacefillProps = {
detail: 1,
// colorTheme: { name: 'uniform', value: 0xFF4411 },
// colorTheme: { name: 'instance-id' },
// colorTheme: { name: 'instance-index' },
// colorTheme: { name: 'element-symbol' },
colorTheme: { name: 'atom-id' },
// colorTheme: { name: 'atom-index' },
colorTheme: { name: 'chain-id' },
}
await Run(structSpacefillRepr.create(struct, spacefillProps), log, 100)
structSpacefillRepr.renderObjects.forEach(viewer.add)
......
......@@ -19,7 +19,7 @@ import { ColorTheme, SizeTheme } from '../../theme';
import { createTransforms, createColors, createSizes } from './utils';
export const DefaultPointProps = {
colorTheme: { name: 'instance-id' } as ColorTheme,
colorTheme: { name: 'instance-index' } as ColorTheme,
sizeTheme: { name: 'vdw' } as SizeTheme
}
export type PointProps = Partial<typeof DefaultPointProps>
......
......@@ -21,7 +21,7 @@ import VertexMap from '../../shape/vertex-map';
export const DefaultSpacefillProps = {
detail: 0,
colorTheme: { name: 'instance-id' } as ColorTheme,
colorTheme: { name: 'instance-index' } as ColorTheme,
}
export type SpacefillProps = Partial<typeof DefaultSpacefillProps>
......
......@@ -7,14 +7,12 @@
import { Unit, ElementGroup } from 'mol-model/structure';
import { Mat4 } from 'mol-math/linear-algebra'
import { ColorScale } from 'mol-util/color';
import { createUniformColor, createInstanceColor, createElementInstanceColor } from '../../util/color-data';
import { createUniformColor } from '../../util/color-data';
import { createUniformSize } from '../../util/size-data';
import { vdwSizeData } from '../../theme/structure/size/vdw';
import VertexMap from '../../shape/vertex-map';
import { ColorTheme, SizeTheme } from '../../theme';
import { elementSymbolColorData } from '../../theme/structure/color/element';
import { OrderedSet } from 'mol-data/int';
import { atomIndexColorData, elementSymbolColorData, instanceIndexColorData, chainIdColorData } from '../../theme/structure/color';
export function createTransforms(units: ReadonlyArray<Unit>) {
const unitCount = units.length
......@@ -26,25 +24,17 @@ export function createTransforms(units: ReadonlyArray<Unit>) {
}
export function createColors(units: ReadonlyArray<Unit>, elementGroup: ElementGroup, vertexMap: VertexMap, props: ColorTheme) {
const instanceCount = units.length
const elementCount = OrderedSet.size(elementGroup.elements)
switch (props.name) {
case 'uniform':
return createUniformColor(props)
case 'instance-id':
const instanceDomain = props.domain ? props.domain : [ 0, instanceCount - 1 ]
const instanceScale = ColorScale.create({ domain: instanceDomain })
return createInstanceColor({ colorFn: instanceScale.color, instanceCount })
case 'atom-id':
const atomDomain = props.domain ? props.domain : [ 0, instanceCount * elementCount - 1 ]
const atomScale = ColorScale.create({ domain: atomDomain })
return createElementInstanceColor({
colorFn: (unitIdx, elementIdx) => atomScale.color(unitIdx * elementCount + elementIdx),
instanceCount,
vertexMap
})
case 'atom-index':
return atomIndexColorData({ units, elementGroup, vertexMap })
case 'chain-id':
return chainIdColorData({ units, elementGroup, vertexMap })
case 'element-symbol':
return elementSymbolColorData({ units, elementGroup, vertexMap })
case 'instance-index':
return instanceIndexColorData({ units, elementGroup, vertexMap })
case 'uniform':
return createUniformColor(props)
}
}
......
......@@ -12,7 +12,7 @@ export interface UniformColorTheme {
}
export interface ScaleColorTheme {
name: 'instance-id' | 'element-symbol' | 'atom-id'
name: 'atom-index' | 'chain-id' | 'element-symbol' | 'instance-index'
domain?: [number, number]
}
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ColorScale } from 'mol-util/color';
import { StructureColorDataProps } from '.';
import { OrderedSet } from 'mol-data/int';
import { createElementInstanceColor } from '../../../util/color-data';
export function atomIndexColorData(props: StructureColorDataProps) {
const { units, elementGroup, vertexMap } = props
const instanceCount = units.length
const elementCount = OrderedSet.size(elementGroup.elements)
const domain = [ 0, instanceCount * elementCount - 1 ]
const scale = ColorScale.create({ domain })
return createElementInstanceColor({
colorFn: (instanceIdx, elementIdx) => scale.color(instanceIdx * elementCount + elementIdx),
instanceCount,
vertexMap
})
}
\ No newline at end of file
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ElementGroup, Model } from 'mol-model/structure';
import { StructureColorDataProps } from '.';
import { createAttributeOrElementColor } from '../../../util/color-data';
import { ColorScale } from 'mol-util/color';
function createChainIdMap(model: Model) {
const { chains } = model.hierarchy
const { label_asym_id } = chains
const map = new Map<string, number>()
let index = 0
for (let i = 0, il = chains._rowCount; i < il; ++i) {
const chainId = label_asym_id.value(i)
if (map.get(chainId) === undefined) {
map.set(chainId, index)
index += 1
}
}
return { map, count: index }
}
export function chainIdColorData(props: StructureColorDataProps) {
const { units, elementGroup, vertexMap } = props
const unit = units[0]
const { chains, chainSegments } = unit.model.hierarchy
const { label_asym_id } = chains
const { map, count } = createChainIdMap(unit.model)
const domain = [ 0, count - 1 ]
const scale = ColorScale.create({ domain })
return createAttributeOrElementColor(vertexMap, {
colorFn: (elementIdx: number) => {
const aI = ElementGroup.getAt(elementGroup, elementIdx);
const cI = chainSegments.segmentMap[aI]
const chainId = label_asym_id.value(cI)
return scale.color(map.get(chainId) || 0)
},
vertexMap
})
}
\ No newline at end of file
......@@ -11,4 +11,9 @@ export interface StructureColorDataProps {
units: ReadonlyArray<Unit>,
elementGroup: ElementGroup,
vertexMap: VertexMap
}
\ No newline at end of file
}
export { atomIndexColorData } from './atom-index'
export { chainIdColorData } from './chain-id'
export { elementSymbolColorData } from './element-symbol'
export { instanceIndexColorData } from './instance-index'
\ No newline at end of file
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ColorScale } from 'mol-util/color';
import { StructureColorDataProps } from '.';
import { createInstanceColor } from '../../../util/color-data';
export function instanceIndexColorData(props: StructureColorDataProps) {
const { units } = props
const instanceCount = units.length
const domain = [ 0, instanceCount - 1 ]
const scale = ColorScale.create({ domain })
return createInstanceColor({
colorFn: scale.color,
instanceCount
})
}
\ No newline at end of file
......@@ -11,4 +11,6 @@ export interface StructureSizeDataProps {
units: ReadonlyArray<Unit>,
elementGroup: ElementGroup,
vertexMap: VertexMap
}
\ No newline at end of file
}
export { vdwSizeData } from './vdw'
\ 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