diff --git a/src/apps/canvas/component/structure-representation.tsx b/src/apps/canvas/component/structure-representation.tsx index d282e8e41fd53d705dd00990bd519263f80daf8a..4249ddea2d2a3c4c0ba727884ebc5a9ed4ebc57a 100644 --- a/src/apps/canvas/component/structure-representation.tsx +++ b/src/apps/canvas/component/structure-representation.tsx @@ -26,8 +26,8 @@ export interface StructureRepresentationComponentState { flatShaded?: boolean resolutionFactor?: number - probeRadius?: number - isoValue?: number + radiusOffset?: number + smoothness?: number } export class StructureRepresentationComponent extends React.Component<StructureRepresentationComponentProps, StructureRepresentationComponentState> { @@ -40,8 +40,8 @@ export class StructureRepresentationComponent extends React.Component<StructureR flatShaded: (this.props.representation.props as any).flatShaded, resolutionFactor: (this.props.representation.props as any).resolutionFactor, - probeRadius: (this.props.representation.props as any).probeRadius, - isoValue: (this.props.representation.props as any).isoValue, + radiusOffset: (this.props.representation.props as any).radiusOffset, + smoothness: (this.props.representation.props as any).smoothness, } componentWillMount() { @@ -57,8 +57,8 @@ export class StructureRepresentationComponent extends React.Component<StructureR flatShaded: (repr.props as any).flatShaded, resolutionFactor: (repr.props as any).resolutionFactor, - probeRadius: (repr.props as any).probeRadius, - isoValue: (repr.props as any).isoValue, + radiusOffset: (repr.props as any).probeRadius, + smoothness: (repr.props as any).smoothness, }) } @@ -73,8 +73,8 @@ export class StructureRepresentationComponent extends React.Component<StructureR if (state.flatShaded !== undefined) (props as any).flatShaded = state.flatShaded if (state.resolutionFactor !== undefined) (props as any).resolutionFactor = state.resolutionFactor - if (state.probeRadius !== undefined) (props as any).probeRadius = state.probeRadius - if (state.isoValue !== undefined) (props as any).isoValue = state.isoValue + if (state.radiusOffset !== undefined) (props as any).probeRadius = state.radiusOffset + if (state.smoothness !== undefined) (props as any).smoothness = state.smoothness await repr.createOrUpdate(props).run( progress => console.log(Progress.format(progress)) @@ -161,25 +161,25 @@ export class StructureRepresentationComponent extends React.Component<StructureR > </input> </div> : '' } - { this.state.isoValue !== undefined ? <div> - <span>Iso Value </span> + { this.state.smoothness !== undefined ? <div> + <span>Smoothness </span> <input type='range' - defaultValue={this.state.isoValue.toString()} + defaultValue={this.state.smoothness.toString()} min='1' max='3' step='0.1' - onInput={(e) => this.update({ isoValue: parseFloat(e.currentTarget.value) })} + onInput={(e) => this.update({ smoothness: parseFloat(e.currentTarget.value) })} > </input> </div> : '' } - { this.state.probeRadius !== undefined ? <div> - <span>Probe Radius </span> + { this.state.radiusOffset !== undefined ? <div> + <span>Radius Offset </span> <input type='range' - defaultValue={this.state.probeRadius.toString()} + defaultValue={this.state.radiusOffset.toString()} min='0' max='10' step='0.1' - onInput={(e) => this.update({ probeRadius: parseFloat(e.currentTarget.value) })} + onInput={(e) => this.update({ radiusOffset: parseFloat(e.currentTarget.value) })} > </input> </div> : '' } diff --git a/src/apps/canvas/structure-view.ts b/src/apps/canvas/structure-view.ts index 62ef041ddfb753af90e335284ec85e431ae03c3e..e4acd4e8e3deea2217ac17b790f826bd74becdcb 100644 --- a/src/apps/canvas/structure-view.ts +++ b/src/apps/canvas/structure-view.ts @@ -68,10 +68,10 @@ export async function StructureView(viewer: Viewer, models: ReadonlyArray<Model> const active: { [k: string]: boolean } = { cartoon: true, point: false, - surface: true, + surface: false, ballAndStick: false, carbohydrate: false, - spacefill: true, + spacefill: false, distanceRestraint: false, symmetryAxes: false, // polymerSphere: false, diff --git a/src/mol-geo/representation/structure/index.ts b/src/mol-geo/representation/structure/index.ts index 13dfc293a317d10d8ba4e7f38d788f111efc3090..a29ab4fdaac7f9505b15f8adf3fbe996f2e3c6fc 100644 --- a/src/mol-geo/representation/structure/index.ts +++ b/src/mol-geo/representation/structure/index.ts @@ -29,8 +29,8 @@ export const DefaultStructureMeshProps = { export type StructureMeshProps = typeof DefaultStructureMeshProps export const DefaultStructurePointProps = { + ...Point.DefaultProps, ...DefaultStructureProps, - ...Point.DefaultProps } export type StructurePointProps = typeof DefaultStructurePointProps diff --git a/src/mol-geo/representation/structure/representation/surface.ts b/src/mol-geo/representation/structure/representation/surface.ts index 5d8c77e678ae58ae8db45558eed608f4576f8f16..d9237e575d449c7215b937ae1ec7c8390af0780d 100644 --- a/src/mol-geo/representation/structure/representation/surface.ts +++ b/src/mol-geo/representation/structure/representation/surface.ts @@ -38,7 +38,7 @@ export function SurfaceRepresentation(): SurfaceRepresentation { currentProps = Object.assign({}, DefaultSurfaceProps, currentProps, props) return Task.create('Creating SurfaceRepresentation', async ctx => { await gaussianSurfaceRepr.createOrUpdate(currentProps, structure).runInContext(ctx) - await gaussianPointRepr.createOrUpdate(currentProps, structure).runInContext(ctx) + // await gaussianPointRepr.createOrUpdate(currentProps, structure).runInContext(ctx) }) }, getLoci: (pickingId: PickingId) => { diff --git a/src/mol-geo/representation/structure/visual/gaussian-density-point.ts b/src/mol-geo/representation/structure/visual/gaussian-density-point.ts index 7bc2d1c9d671bad4c69321708b4b25ea99af4621..b6c3efd2ea2b92c48de6f4d520dcf695f644d9f0 100644 --- a/src/mol-geo/representation/structure/visual/gaussian-density-point.ts +++ b/src/mol-geo/representation/structure/visual/gaussian-density-point.ts @@ -10,36 +10,22 @@ import { UnitsVisual, VisualUpdateState } from '..'; import { StructureElementIterator } from './util/element'; import { EmptyLoci } from 'mol-model/loci'; import { Vec3 } from 'mol-math/linear-algebra'; -import { SizeThemeProps } from 'mol-view/theme/size'; import { UnitsPointVisual, DefaultUnitsPointProps } from '../units-visual'; -import { computeGaussianDensity } from './util/gaussian'; -import { Color } from 'mol-util/color'; -import { ColorThemeProps } from 'mol-view/theme/color'; +import { computeGaussianDensity, DefaultGaussianDensityProps } from './util/gaussian'; import { Point } from '../../../geometry/point/point'; import { PointBuilder } from '../../../geometry/point/point-builder'; +import { SizeThemeProps } from 'mol-view/theme/size'; export const DefaultGaussianDensityPointProps = { ...DefaultUnitsPointProps, + ...DefaultGaussianDensityProps, - sizeTheme: { name: 'uniform', value: 1.5 } as SizeThemeProps, - colorTheme: { name: 'uniform', value: Color(0xAAAAAA) } as ColorThemeProps, + sizeTheme: { name: 'uniform', value: 1 } as SizeThemeProps, pointSizeAttenuation: false, - - resolutionFactor: 7, - probeRadius: 0, - isoValue: 1.5, } export type GaussianDensityPointProps = typeof DefaultGaussianDensityPointProps -export interface GaussianDensityProps { - sizeTheme: SizeThemeProps - - resolutionFactor: number - probeRadius: number - isoValue: number -} - -export async function createGaussianDensityPoint(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianDensityProps, point?: Point) { +export async function createGaussianDensityPoint(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianDensityPointProps, point?: Point) { const { transform, field: { space, data } } = await computeGaussianDensity(unit, structure, props).runAsChild(ctx) const { dimensions, get } = space @@ -77,7 +63,9 @@ export function GaussianDensityPointVisual(): UnitsVisual<GaussianDensityPointPr getLoci: () => EmptyLoci, mark: () => false, setUpdateState: (state: VisualUpdateState, newProps: GaussianDensityPointProps, currentProps: GaussianDensityPointProps) => { - + if (newProps.resolutionFactor !== currentProps.resolutionFactor) state.createGeometry = true + if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true + if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true } }) } \ No newline at end of file diff --git a/src/mol-geo/representation/structure/visual/gaussian-surface-mesh.ts b/src/mol-geo/representation/structure/visual/gaussian-surface-mesh.ts index 8966ca864a445e4ae546d338d66a73f151c231af..59485b6727f1f20830516cdd34265b523ef608ae 100644 --- a/src/mol-geo/representation/structure/visual/gaussian-surface-mesh.ts +++ b/src/mol-geo/representation/structure/visual/gaussian-surface-mesh.ts @@ -11,33 +11,17 @@ import { Mesh } from '../../../geometry/mesh/mesh'; import { UnitsMeshVisual, DefaultUnitsMeshProps } from '../units-visual'; import { StructureElementIterator, getElementLoci, markElement } from './util/element'; import { computeMarchingCubes } from '../../../util/marching-cubes/algorithm'; -import { SizeThemeProps } from 'mol-view/theme/size'; -import { Color } from 'mol-util/color'; -import { computeGaussianDensity } from './util/gaussian'; -import { ColorThemeProps } from 'mol-view/theme/color'; +import { computeGaussianDensity, DefaultGaussianDensityProps } from './util/gaussian'; -export interface GaussianSurfaceMeshProps { - sizeTheme: SizeThemeProps - - resolutionFactor: number - probeRadius: number - isoValue: number -} - -async function createGaussianSurfaceMesh(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianSurfaceMeshProps, mesh?: Mesh): Promise<Mesh> { - const { isoValue } = props - - console.time('surface density') +async function createGaussianSurfaceMesh(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianSurfaceProps, mesh?: Mesh): Promise<Mesh> { + const { smoothness } = props const { transform, field } = await computeGaussianDensity(unit, structure, props).runAsChild(ctx) - console.timeEnd('surface density') - console.time('surface mc') const surface = await computeMarchingCubes({ - isoLevel: Math.exp(-isoValue), + isoLevel: Math.exp(-smoothness), scalarField: field, oldSurface: mesh }).runAsChild(ctx) - console.timeEnd('surface mc') Mesh.transformImmediate(surface, transform) Mesh.computeNormalsImmediate(surface) @@ -47,19 +31,9 @@ async function createGaussianSurfaceMesh(ctx: RuntimeContext, unit: Unit, struct export const DefaultGaussianSurfaceProps = { ...DefaultUnitsMeshProps, - linearSegments: 8, - radialSegments: 12, - aspectRatio: 5, - arrowFactor: 1.5, - - flipSided: true, - // flatShaded: true, - alpha: 0.7, - colorTheme: { name: 'uniform' as 'uniform', value: Color(0xDDDDDD) } as ColorThemeProps, + ...DefaultGaussianDensityProps, - resolutionFactor: 7, - probeRadius: 0, - isoValue: 1.5, + flipSided: true, // TODO should not be required } export type GaussianSurfaceProps = typeof DefaultGaussianSurfaceProps @@ -72,8 +46,8 @@ export function GaussianSurfaceVisual(): UnitsVisual<GaussianSurfaceProps> { mark: markElement, setUpdateState: (state: VisualUpdateState, newProps: GaussianSurfaceProps, currentProps: GaussianSurfaceProps) => { if (newProps.resolutionFactor !== currentProps.resolutionFactor) state.createGeometry = true - if (newProps.probeRadius !== currentProps.probeRadius) state.createGeometry = true - if (newProps.isoValue !== currentProps.isoValue) state.createGeometry = true + if (newProps.radiusOffset !== currentProps.radiusOffset) state.createGeometry = true + if (newProps.smoothness !== currentProps.smoothness) state.createGeometry = true } }) } \ No newline at end of file diff --git a/src/mol-geo/representation/structure/visual/util/gaussian.ts b/src/mol-geo/representation/structure/visual/util/gaussian.ts index 1607bbb7fb3f71ce0a4e5d0998da9fa1c05289de..20505c1f1573567723ed0b1ef8b5813e82a3ee4f 100644 --- a/src/mol-geo/representation/structure/visual/util/gaussian.ts +++ b/src/mol-geo/representation/structure/visual/util/gaussian.ts @@ -8,24 +8,21 @@ import { Unit, Structure, StructureElement } from 'mol-model/structure'; import { RuntimeContext, Task } from 'mol-task' import { Tensor, Vec3, Mat4 } from 'mol-math/linear-algebra'; import { Box3D } from 'mol-math/geometry'; -import { SizeThemeProps, SizeTheme } from 'mol-view/theme/size'; +import { SizeTheme } from 'mol-view/theme/size'; -export interface GaussianDensityProps { - sizeTheme: SizeThemeProps - - resolutionFactor: number - probeRadius: number - isoValue: number +export const DefaultGaussianDensityProps = { + resolutionFactor: 7, + radiusOffset: 0, + smoothness: 1.5, } +export type GaussianDensityProps = typeof DefaultGaussianDensityProps function getDelta(box: Box3D, resolutionFactor: number) { const extent = Vec3.sub(Vec3.zero(), box.max, box.min) - const n = Math.pow(Math.pow(2, resolutionFactor), 3) const f = (extent[0] * extent[1] * extent[2]) / n const s = Math.pow(f, 1 / 3) const size = Vec3.zero() - // Vec3.scale(size, extent, s) Vec3.ceil(size, Vec3.scale(size, extent, s)) const delta = Vec3.div(Vec3.zero(), extent, size) return delta @@ -40,18 +37,18 @@ export function computeGaussianDensity(unit: Unit, structure: Structure, props: } export async function GaussianDensity(ctx: RuntimeContext, unit: Unit, structure: Structure, props: GaussianDensityProps): Promise<Density> { - const { resolutionFactor, probeRadius, isoValue } = props + const { resolutionFactor, radiusOffset, smoothness } = props const { elements } = unit; const elementCount = elements.length; - const sizeTheme = SizeTheme(props.sizeTheme) + const sizeTheme = SizeTheme({ name: 'physical' }) const v = Vec3.zero() const p = Vec3.zero() const pos = unit.conformation.invariantPosition const l = StructureElement.create(unit) - const pad = (probeRadius + 3) * 3 // TODO calculate max radius + const pad = (radiusOffset + 3) * 3 // TODO calculate max radius const box = unit.lookup3d.boundary.box const expandedBox = Box3D.expand(Box3D.empty(), box, Vec3.create(pad, pad, pad)); const extent = Vec3.sub(Vec3.zero(), expandedBox.max, expandedBox.min) @@ -67,9 +64,9 @@ export async function GaussianDensity(ctx: RuntimeContext, unit: Unit, structure const c = Vec3.zero() - const alpha = isoValue // smoothness + const alpha = smoothness - const _r2 = (probeRadius + 1.4 * 2) + const _r2 = (radiusOffset + 1.4 * 2) const _radius2 = Vec3.create(_r2, _r2, _r2) Vec3.mul(_radius2, _radius2, delta) const updateChunk = Math.ceil(10000 / (_radius2[0] * _radius2[1] * _radius2[2])) @@ -84,10 +81,10 @@ export async function GaussianDensity(ctx: RuntimeContext, unit: Unit, structure Vec3.sub(v, v, min) Vec3.mul(c, v, delta) - const radius = sizeTheme.size(l) + probeRadius + const radius = sizeTheme.size(l) + radiusOffset const rSq = radius * radius - const r2 = (probeRadius + radius * 2) + const r2 = (radiusOffset + radius * 2) const radius2 = Vec3.create(r2, r2, r2) Vec3.mul(radius2, radius2, delta) const r2sq = r2 * r2