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

wip, register ball-and-stick

parent b636bbc9
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -58,10 +58,10 @@ interface StructureViewProps { ...@@ -58,10 +58,10 @@ interface StructureViewProps {
export async function StructureView(app: App, canvas3d: Canvas3D, models: ReadonlyArray<Model>, props: StructureViewProps = {}): Promise<StructureView> { export async function StructureView(app: App, canvas3d: Canvas3D, models: ReadonlyArray<Model>, props: StructureViewProps = {}): Promise<StructureView> {
const active: { [k: string]: boolean } = { const active: { [k: string]: boolean } = {
cartoon: true, 'cartoon': true,
'ball-and-stick': true,
// point: false, // point: false,
// surface: false, // surface: false,
// ballAndStick: false,
// carbohydrate: false, // carbohydrate: false,
// spacefill: false, // spacefill: false,
// distanceRestraint: false, // distanceRestraint: false,
...@@ -197,7 +197,7 @@ export async function StructureView(app: App, canvas3d: Canvas3D, models: Readon ...@@ -197,7 +197,7 @@ export async function StructureView(app: App, canvas3d: Canvas3D, models: Readon
if (structureRepresentations[k]) { if (structureRepresentations[k]) {
repr = structureRepresentations[k] repr = structureRepresentations[k]
} else { } else {
repr = app.structureRepresentationRegistry.create('cartoon', app.reprCtx, structure) repr = app.structureRepresentationRegistry.create(k, app.reprCtx, structure)
structureRepresentations[k] = repr structureRepresentations[k] = repr
} }
await app.runTask(repr.createOrUpdate(app.reprCtx, {}, {}, structure).run( await app.runTask(repr.createOrUpdate(app.reprCtx, {}, {}, structure).run(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import { Structure } from 'mol-model/structure'; import { Structure } from 'mol-model/structure';
import { RepresentationProvider, RepresentationRegistry } from '../representation'; import { RepresentationProvider, RepresentationRegistry } from '../representation';
import { CartoonRepresentationProvider } from './representation/cartoon'; import { CartoonRepresentationProvider } from './representation/cartoon';
import { BallAndStickRepresentationProvider } from './representation/ball-and-stick';
export class StructureRepresentationRegistry extends RepresentationRegistry<Structure> { export class StructureRepresentationRegistry extends RepresentationRegistry<Structure> {
constructor() { constructor() {
...@@ -20,6 +21,7 @@ export class StructureRepresentationRegistry extends RepresentationRegistry<Stru ...@@ -20,6 +21,7 @@ export class StructureRepresentationRegistry extends RepresentationRegistry<Stru
export const BuiltInStructureRepresentations = { export const BuiltInStructureRepresentations = {
'cartoon': CartoonRepresentationProvider, 'cartoon': CartoonRepresentationProvider,
'ball-and-stick': BallAndStickRepresentationProvider,
} }
export type BuiltInStructureRepresentationsName = keyof typeof BuiltInStructureRepresentations export type BuiltInStructureRepresentationsName = keyof typeof BuiltInStructureRepresentations
export const BuiltInStructureRepresentationsNames = Object.keys(BuiltInStructureRepresentations) export const BuiltInStructureRepresentationsNames = Object.keys(BuiltInStructureRepresentations)
......
// /** /**
// * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
// * *
// * @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
// */ */
// import { ElementSphereVisual, ElementSphereParams } from '../visual/element-sphere'; import { ElementSphereVisual, ElementSphereParams, ElementSphereProps } from '../visual/element-sphere';
// import { IntraUnitLinkVisual, IntraUnitLinkParams } from '../visual/intra-unit-link-cylinder'; import { IntraUnitLinkVisual, IntraUnitLinkParams } from '../visual/intra-unit-link-cylinder';
// import { InterUnitLinkVisual, InterUnitLinkParams } from '../visual/inter-unit-link-cylinder'; import { InterUnitLinkVisual, InterUnitLinkParams, InterUnitLinkProps } from '../visual/inter-unit-link-cylinder';
// import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
// import { UnitsRepresentation } from '../units-representation'; import { UnitsRepresentation } from '../units-representation';
// import { ComplexRepresentation } from '../complex-representation'; import { ComplexRepresentation } from '../complex-representation';
// import { StructureRepresentation } from '../representation'; import { StructureRepresentation, StructureRepresentationProvider } from '../representation';
// import { Representation } from 'mol-repr/representation'; import { Representation } from 'mol-repr/representation';
// import { ThemeRegistryContext } from 'mol-theme/theme'; import { ThemeRegistryContext } from 'mol-theme/theme';
// import { Structure } from 'mol-model/structure'; import { Structure } from 'mol-model/structure';
import { IntraUnitLinkProps } from '../visual/polymer-gap-cylinder';
import { BuiltInSizeThemeName, BuiltInSizeThemeOptions } from 'mol-theme/size';
import { BuiltInColorThemeName, BuiltInColorThemeOptions } from 'mol-theme/color';
import { UnitKind, UnitKindOptions } from '../visual/util/common';
// export const BallAndStickParams = { const BallAndStickVisuals = {
// ...ElementSphereParams, 'element-sphere': (defaultProps: ElementSphereProps) => UnitsRepresentation('Element sphere mesh', defaultProps, ElementSphereVisual),
// ...IntraUnitLinkParams, 'intra-link': (defaultProps: IntraUnitLinkProps) => UnitsRepresentation('Intra-unit link cylinder', defaultProps, IntraUnitLinkVisual),
// ...InterUnitLinkParams, 'inter-link': (defaultProps: InterUnitLinkProps) => ComplexRepresentation('Inter-unit link cylinder', defaultProps, InterUnitLinkVisual),
// // TODO }
// // unitKinds: PD.MultiSelect<UnitKind>('Unit Kind', '', ['atomic'], UnitKindOptions), type BallAndStickVisualName = keyof typeof BallAndStickVisuals
// } const BallAndStickVisualOptions = Object.keys(BallAndStickVisuals).map(name => [name, name] as [BallAndStickVisualName, string])
// export function getBallAndStickParams(ctx: ThemeRegistryContext, structure: Structure) {
// return BallAndStickParams // TODO return copy
// }
// export type BallAndStickProps = PD.DefaultValues<typeof BallAndStickParams>
// export type BallAndStickRepresentation = StructureRepresentation<BallAndStickProps> export const BallAndStickParams = {
...ElementSphereParams,
...IntraUnitLinkParams,
...InterUnitLinkParams,
unitKinds: PD.MultiSelect<UnitKind>('Unit Kind', '', ['atomic'], UnitKindOptions),
sizeFactor: PD.Numeric('Size Factor', '', 0.2, 0.01, 10, 0.01),
sizeTheme: PD.Select<BuiltInSizeThemeName>('Size Theme', '', 'uniform', BuiltInSizeThemeOptions),
colorTheme: PD.Select<BuiltInColorThemeName>('Color Theme', '', 'polymer-index', BuiltInColorThemeOptions),
visuals: PD.MultiSelect<BallAndStickVisualName>('Visuals', '', ['element-sphere', 'intra-link', 'inter-link'], BallAndStickVisualOptions),
}
export function getBallAndStickParams(ctx: ThemeRegistryContext, structure: Structure) {
return BallAndStickParams // TODO return copy
}
export type BallAndStickProps = PD.DefaultValues<typeof BallAndStickParams>
// export function BallAndStickRepresentation(defaultProps: BallAndStickProps): BallAndStickRepresentation { export type BallAndStickRepresentation = StructureRepresentation<BallAndStickProps>
// return Representation.createMulti('Ball & Stick', defaultProps, [
// UnitsRepresentation('Element sphere mesh', defaultProps, ElementSphereVisual), export function BallAndStickRepresentation(defaultProps: BallAndStickProps): BallAndStickRepresentation {
// UnitsRepresentation('Intra-unit link cylinder', defaultProps, IntraUnitLinkVisual), return Representation.createMulti('Ball & Stick', defaultProps, BallAndStickVisuals as unknown as Representation.Def<BallAndStickProps>)
// ComplexRepresentation('Inter-unit link cylinder', defaultProps, InterUnitLinkVisual) }
// ])
// } export const BallAndStickRepresentationProvider: StructureRepresentationProvider<typeof BallAndStickParams> = {
\ No newline at end of file factory: BallAndStickRepresentation, params: getBallAndStickParams
}
\ No newline at end of file
...@@ -10,13 +10,12 @@ import { VisualUpdateState } from '../../util'; ...@@ -10,13 +10,12 @@ import { VisualUpdateState } from '../../util';
import { createElementSphereMesh, markElement, getElementLoci, StructureElementIterator } from './util/element'; import { createElementSphereMesh, markElement, getElementLoci, StructureElementIterator } from './util/element';
import { UnitsMeshVisual, UnitsMeshParams } from '../units-visual'; import { UnitsMeshVisual, UnitsMeshParams } from '../units-visual';
import { ParamDefinition as PD } from 'mol-util/param-definition'; import { ParamDefinition as PD } from 'mol-util/param-definition';
import { BuiltInSizeThemeName, BuiltInSizeThemeOptions } from 'mol-theme/size';
export const ElementSphereParams = { export const ElementSphereParams = {
...UnitsMeshParams, ...UnitsMeshParams,
// TODO sizeTheme: PD.Select<BuiltInSizeThemeName>('Size Theme', '', 'physical', BuiltInSizeThemeOptions),
// sizeTheme: PD.Select<SizeThemeName>('Size Theme', '', 'physical', SizeThemeOptions), sizeFactor: PD.Numeric('Size Factor', '', 1, 0, 10, 0.1),
// sizeValue: PD.Numeric('Size Value', '', 0.2, 0, 10, 0.1),
// sizeFactor: PD.Numeric('Size Factor', '', 1, 0, 10, 0.1),
detail: PD.Numeric('Sphere Detail', '', 0, 0, 3, 1), detail: PD.Numeric('Sphere Detail', '', 0, 0, 3, 1),
} }
export const DefaultElementSphereProps = PD.getDefaultValues(ElementSphereParams) export const DefaultElementSphereProps = PD.getDefaultValues(ElementSphereParams)
......
...@@ -20,7 +20,7 @@ import { PickingId } from 'mol-geo/geometry/picking'; ...@@ -20,7 +20,7 @@ import { PickingId } from 'mol-geo/geometry/picking';
import { VisualContext } from 'mol-repr/representation'; import { VisualContext } from 'mol-repr/representation';
import { Theme } from 'mol-theme/theme'; import { Theme } from 'mol-theme/theme';
async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: LinkCylinderProps, mesh?: Mesh) { async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: IntraUnitLinkProps, mesh?: Mesh) {
if (!Unit.isAtomic(unit)) return Mesh.createEmpty(mesh) if (!Unit.isAtomic(unit)) return Mesh.createEmpty(mesh)
const location = StructureElement.create(unit) const location = StructureElement.create(unit)
...@@ -29,6 +29,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s ...@@ -29,6 +29,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s
const links = unit.links const links = unit.links
const { edgeCount, a, b, edgeProps, offset } = links const { edgeCount, a, b, edgeProps, offset } = links
const { order: _order, flags: _flags } = edgeProps const { order: _order, flags: _flags } = edgeProps
const { sizeFactor } = props
if (!edgeCount) return Mesh.createEmpty(mesh) if (!edgeCount) return Mesh.createEmpty(mesh)
...@@ -56,7 +57,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s ...@@ -56,7 +57,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s
flags: (edgeIndex: number) => BitFlags.create(_flags[edgeIndex]), flags: (edgeIndex: number) => BitFlags.create(_flags[edgeIndex]),
radius: (edgeIndex: number) => { radius: (edgeIndex: number) => {
location.element = elements[a[edgeIndex]] location.element = elements[a[edgeIndex]]
return theme.size.size(location) return theme.size.size(location) * sizeFactor
} }
} }
...@@ -66,10 +67,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s ...@@ -66,10 +67,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s
export const IntraUnitLinkParams = { export const IntraUnitLinkParams = {
...UnitsMeshParams, ...UnitsMeshParams,
...LinkCylinderParams, ...LinkCylinderParams,
// TODO sizeFactor: PD.Numeric('Size Factor', '', 0.2, 0, 10, 0.01),
// sizeTheme: PD.Select<SizeThemeName>('Size Theme', '', 'physical', SizeThemeOptions),
// sizeValue: PD.Numeric('Size Value', '', 0.2, 0, 10, 0.1),
// sizeFactor: PD.Numeric('Size Factor', '', 1, 0, 10, 0.1),
} }
export const DefaultIntraUnitLinkProps = PD.getDefaultValues(IntraUnitLinkParams) export const DefaultIntraUnitLinkProps = PD.getDefaultValues(IntraUnitLinkParams)
export type IntraUnitLinkProps = typeof DefaultIntraUnitLinkProps export type IntraUnitLinkProps = typeof DefaultIntraUnitLinkProps
......
...@@ -20,10 +20,11 @@ import { StructureGroup } from 'mol-repr/structure/units-visual'; ...@@ -20,10 +20,11 @@ import { StructureGroup } from 'mol-repr/structure/units-visual';
export interface ElementSphereMeshProps { export interface ElementSphereMeshProps {
detail: number, detail: number,
sizeFactor: number
} }
export async function createElementSphereMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: ElementSphereMeshProps, mesh?: Mesh) { export async function createElementSphereMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: ElementSphereMeshProps, mesh?: Mesh) {
const { detail } = props const { detail, sizeFactor } = props
const { elements } = unit; const { elements } = unit;
const elementCount = elements.length; const elementCount = elements.length;
...@@ -40,7 +41,7 @@ export async function createElementSphereMesh(ctx: VisualContext, unit: Unit, st ...@@ -40,7 +41,7 @@ export async function createElementSphereMesh(ctx: VisualContext, unit: Unit, st
pos(elements[i], v) pos(elements[i], v)
meshBuilder.setGroup(i) meshBuilder.setGroup(i)
addSphere(meshBuilder, v, theme.size.size(l), detail) addSphere(meshBuilder, v, theme.size.size(l) * sizeFactor, detail)
if (i % 10000 === 0 && ctx.runtime.shouldUpdate) { if (i % 10000 === 0 && ctx.runtime.shouldUpdate) {
await ctx.runtime.update({ message: 'Sphere mesh', current: i, max: elementCount }); await ctx.runtime.update({ message: 'Sphere mesh', current: i, max: elementCount });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment