From b95e47ce6bd32b9438f5f638e98ce5067b8a2456 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alexander.rose@weirdbyte.de>
Date: Fri, 9 Nov 2018 22:21:13 -0800
Subject: [PATCH] wip, register ball-and-stick

---
 package-lock.json                             | Bin 422244 -> 422636 bytes
 src/apps/canvas/structure-view.ts             |   6 +-
 src/mol-repr/structure/registry.ts            |   2 +
 .../representation/ball-and-stick.ts          |  83 +++++++++++-------
 .../structure/visual/element-sphere.ts        |   7 +-
 .../visual/intra-unit-link-cylinder.ts        |  10 +--
 src/mol-repr/structure/visual/util/element.ts |   5 +-
 7 files changed, 64 insertions(+), 49 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 539aec393ef4a81fe88c46bb79781f76eeceaac4..edafd4d1f9c93c4ded380346f45198682ee709a0 100644
GIT binary patch
delta 319
zcmaFzNb=27$%ZYAo1aWy@P*NE`iUou1=A1wVC0|f@R3n{a@a}b=>aEL*tS<cWt3xt
zC|UQ6F&4s7c+QvwW^JGUoY9dRBKY+a<3EH6)8!<YET`M6vMNm$*epDK!)wN{>HS|B
zS*Ne+W9FY8Z_Ow$y?~F2W$I}buIax%Fy?|BAT&MgD`N}DG}GyI0!-}FxxN8ygga{b
z`jgBe(>?Q9c%}>NV`bgG>>Fb?BV1Z%yTK2}>+BG>$g8okPnUbk$T?Mq=_y=^`gUzb
zrn%e*{&dS{KzC$FF*QvWh+?ytZt#-P5$u1ERs7QvqS<8I9r&1lm>Gy!fS7f=10S18
FG5~Q%eklL|

delta 228
zcmaF!RPxCq$%ZYAo1aWSkjx}H{lE@Z*69HgnR%ywd%_sEz2GThA|qI4a@9%R>HN<b
z10d=qJZH=Tv$ku$V07e$2+sY?_;1oisp<O;vsg}^y-#Vfz-Hm;_FozIPY0SKJ>B#h
z<5Y;k-`^NBrhR0To4$abiF;ZRGwb%X-x+Hdrza#a$xQF5VCLMO^^@@;J4A5~Bhy!q
zsRweIm8M=`;+|f`!o)j$X*8SE^oA`gf*=dRwg)jYJ>qH);9~+}W*}w(V%F^ed~9=4
E0N8X|;{X5v

diff --git a/src/apps/canvas/structure-view.ts b/src/apps/canvas/structure-view.ts
index 5f80091c0..7e24cf4b1 100644
--- a/src/apps/canvas/structure-view.ts
+++ b/src/apps/canvas/structure-view.ts
@@ -58,10 +58,10 @@ interface StructureViewProps {
 
 export async function StructureView(app: App, canvas3d: Canvas3D, models: ReadonlyArray<Model>, props: StructureViewProps = {}): Promise<StructureView> {
     const active: { [k: string]: boolean } = {
-        cartoon: true,
+        'cartoon': true,
+        'ball-and-stick': true,
         // point: false,
         // surface: false,
-        // ballAndStick: false,
         // carbohydrate: false,
         // spacefill: false,
         // distanceRestraint: false,
@@ -197,7 +197,7 @@ export async function StructureView(app: App, canvas3d: Canvas3D, models: Readon
                     if (structureRepresentations[k]) {
                         repr = structureRepresentations[k]
                     } else {
-                        repr = app.structureRepresentationRegistry.create('cartoon', app.reprCtx, structure)
+                        repr = app.structureRepresentationRegistry.create(k, app.reprCtx, structure)
                         structureRepresentations[k] = repr
                     }
                     await app.runTask(repr.createOrUpdate(app.reprCtx, {}, {}, structure).run(
diff --git a/src/mol-repr/structure/registry.ts b/src/mol-repr/structure/registry.ts
index 90822d785..c6fce5ebf 100644
--- a/src/mol-repr/structure/registry.ts
+++ b/src/mol-repr/structure/registry.ts
@@ -7,6 +7,7 @@
 import { Structure } from 'mol-model/structure';
 import { RepresentationProvider, RepresentationRegistry } from '../representation';
 import { CartoonRepresentationProvider } from './representation/cartoon';
+import { BallAndStickRepresentationProvider } from './representation/ball-and-stick';
 
 export class StructureRepresentationRegistry extends RepresentationRegistry<Structure> {
     constructor() {
@@ -20,6 +21,7 @@ export class StructureRepresentationRegistry extends RepresentationRegistry<Stru
 
 export const BuiltInStructureRepresentations = {
     'cartoon': CartoonRepresentationProvider,
+    'ball-and-stick': BallAndStickRepresentationProvider,
 }
 export type BuiltInStructureRepresentationsName = keyof typeof BuiltInStructureRepresentations
 export const BuiltInStructureRepresentationsNames = Object.keys(BuiltInStructureRepresentations)
diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts
index e8efe0971..a6e3d51ce 100644
--- a/src/mol-repr/structure/representation/ball-and-stick.ts
+++ b/src/mol-repr/structure/representation/ball-and-stick.ts
@@ -1,38 +1,53 @@
-// /**
-//  * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
-//  *
-//  * @author Alexander Rose <alexander.rose@weirdbyte.de>
-//  */
+/**
+ * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
 
-// import { ElementSphereVisual, ElementSphereParams } from '../visual/element-sphere';
-// import { IntraUnitLinkVisual, IntraUnitLinkParams } from '../visual/intra-unit-link-cylinder';
-// import { InterUnitLinkVisual, InterUnitLinkParams } from '../visual/inter-unit-link-cylinder';
-// import { ParamDefinition as PD } from 'mol-util/param-definition';
-// import { UnitsRepresentation } from '../units-representation';
-// import { ComplexRepresentation } from '../complex-representation';
-// import { StructureRepresentation } from '../representation';
-// import { Representation } from 'mol-repr/representation';
-// import { ThemeRegistryContext } from 'mol-theme/theme';
-// import { Structure } from 'mol-model/structure';
+import { ElementSphereVisual, ElementSphereParams, ElementSphereProps } from '../visual/element-sphere';
+import { IntraUnitLinkVisual, IntraUnitLinkParams } from '../visual/intra-unit-link-cylinder';
+import { InterUnitLinkVisual, InterUnitLinkParams, InterUnitLinkProps } from '../visual/inter-unit-link-cylinder';
+import { ParamDefinition as PD } from 'mol-util/param-definition';
+import { UnitsRepresentation } from '../units-representation';
+import { ComplexRepresentation } from '../complex-representation';
+import { StructureRepresentation, StructureRepresentationProvider } from '../representation';
+import { Representation } from 'mol-repr/representation';
+import { ThemeRegistryContext } from 'mol-theme/theme';
+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 = {
-//     ...ElementSphereParams,
-//     ...IntraUnitLinkParams,
-//     ...InterUnitLinkParams,
-//     // TODO
-//     // unitKinds: PD.MultiSelect<UnitKind>('Unit Kind', '', ['atomic'], UnitKindOptions),
-// }
-// export function getBallAndStickParams(ctx: ThemeRegistryContext, structure: Structure) {
-//     return BallAndStickParams // TODO return copy
-// }
-// export type BallAndStickProps = PD.DefaultValues<typeof BallAndStickParams>
+const BallAndStickVisuals = {
+    'element-sphere': (defaultProps: ElementSphereProps) => UnitsRepresentation('Element sphere mesh', defaultProps, ElementSphereVisual),
+    'intra-link': (defaultProps: IntraUnitLinkProps) => UnitsRepresentation('Intra-unit link cylinder', defaultProps, IntraUnitLinkVisual),
+    'inter-link': (defaultProps: InterUnitLinkProps) => ComplexRepresentation('Inter-unit link cylinder', defaultProps, InterUnitLinkVisual),
+}
+type BallAndStickVisualName = keyof typeof BallAndStickVisuals
+const BallAndStickVisualOptions = Object.keys(BallAndStickVisuals).map(name => [name, name] as [BallAndStickVisualName, string])
 
-// 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 {
-//     return Representation.createMulti('Ball & Stick', defaultProps, [
-//         UnitsRepresentation('Element sphere mesh', defaultProps, ElementSphereVisual),
-//         UnitsRepresentation('Intra-unit link cylinder', defaultProps, IntraUnitLinkVisual),
-//         ComplexRepresentation('Inter-unit link cylinder', defaultProps, InterUnitLinkVisual)
-//     ])
-// }
\ No newline at end of file
+export type BallAndStickRepresentation = StructureRepresentation<BallAndStickProps>
+
+export function BallAndStickRepresentation(defaultProps: BallAndStickProps): BallAndStickRepresentation {
+    return Representation.createMulti('Ball & Stick', defaultProps, BallAndStickVisuals as unknown as Representation.Def<BallAndStickProps>)
+}
+
+export const BallAndStickRepresentationProvider: StructureRepresentationProvider<typeof BallAndStickParams> = {
+    factory: BallAndStickRepresentation, params: getBallAndStickParams
+}
\ No newline at end of file
diff --git a/src/mol-repr/structure/visual/element-sphere.ts b/src/mol-repr/structure/visual/element-sphere.ts
index 29feb54d3..2b4a7c0d1 100644
--- a/src/mol-repr/structure/visual/element-sphere.ts
+++ b/src/mol-repr/structure/visual/element-sphere.ts
@@ -10,13 +10,12 @@ import { VisualUpdateState } from '../../util';
 import { createElementSphereMesh, markElement, getElementLoci, StructureElementIterator } from './util/element';
 import { UnitsMeshVisual, UnitsMeshParams } from '../units-visual';
 import { ParamDefinition as PD } from 'mol-util/param-definition';
+import { BuiltInSizeThemeName, BuiltInSizeThemeOptions } from 'mol-theme/size';
 
 export const ElementSphereParams = {
     ...UnitsMeshParams,
-    // TODO
-    // 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),
+    sizeTheme: PD.Select<BuiltInSizeThemeName>('Size Theme', '', 'physical', BuiltInSizeThemeOptions),
+    sizeFactor: PD.Numeric('Size Factor', '', 1, 0, 10, 0.1),
     detail: PD.Numeric('Sphere Detail', '', 0, 0, 3, 1),
 }
 export const DefaultElementSphereProps = PD.getDefaultValues(ElementSphereParams)
diff --git a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts
index e177c362d..e305dcf0d 100644
--- a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts
+++ b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts
@@ -20,7 +20,7 @@ import { PickingId } from 'mol-geo/geometry/picking';
 import { VisualContext } from 'mol-repr/representation';
 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)
 
     const location = StructureElement.create(unit)
@@ -29,6 +29,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s
     const links = unit.links
     const { edgeCount, a, b, edgeProps, offset } = links
     const { order: _order, flags: _flags } = edgeProps
+    const { sizeFactor } = props
 
     if (!edgeCount) return Mesh.createEmpty(mesh)
 
@@ -56,7 +57,7 @@ async function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, s
         flags: (edgeIndex: number) => BitFlags.create(_flags[edgeIndex]),
         radius: (edgeIndex: number) => {
             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
 export const IntraUnitLinkParams = {
     ...UnitsMeshParams,
     ...LinkCylinderParams,
-    // TODO
-    // 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),
+    sizeFactor: PD.Numeric('Size Factor', '', 0.2, 0, 10, 0.01),
 }
 export const DefaultIntraUnitLinkProps = PD.getDefaultValues(IntraUnitLinkParams)
 export type IntraUnitLinkProps = typeof DefaultIntraUnitLinkProps
diff --git a/src/mol-repr/structure/visual/util/element.ts b/src/mol-repr/structure/visual/util/element.ts
index 9f5841714..38188c438 100644
--- a/src/mol-repr/structure/visual/util/element.ts
+++ b/src/mol-repr/structure/visual/util/element.ts
@@ -20,10 +20,11 @@ import { StructureGroup } from 'mol-repr/structure/units-visual';
 
 export interface ElementSphereMeshProps {
     detail: number,
+    sizeFactor: number
 }
 
 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 elementCount = elements.length;
@@ -40,7 +41,7 @@ export async function createElementSphereMesh(ctx: VisualContext, unit: Unit, st
         pos(elements[i], v)
 
         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) {
             await ctx.runtime.update({ message: 'Sphere mesh', current: i, max: elementCount });
-- 
GitLab