diff --git a/src/apps/docking-viewer/index.ts b/src/apps/docking-viewer/index.ts index c288b158acc3927f496cb4a6fc8011857f83b519..1157b6a8efe3a601c5dab0ac37dafb78ff593884 100644 --- a/src/apps/docking-viewer/index.ts +++ b/src/apps/docking-viewer/index.ts @@ -69,9 +69,10 @@ class Viewer { viewportShowSelectionMode: false, viewportShowAnimation: false, } }; + const defaultSpec = DefaultPluginSpec(); const spec: PluginSpec = { - actions: [...DefaultPluginSpec.actions], + actions: [...defaultSpec.actions], behaviors: [ PluginSpec.Behavior(PluginBehaviors.Representation.HighlightLoci, { mark: false }), PluginSpec.Behavior(PluginBehaviors.Representation.DefaultLociLabelProvider), @@ -81,8 +82,8 @@ class Viewer { PluginSpec.Behavior(PluginBehaviors.CustomProps.Interactions), PluginSpec.Behavior(PluginBehaviors.CustomProps.SecondaryStructure), ], - animations: [...DefaultPluginSpec.animations || []], - customParamEditors: DefaultPluginSpec.customParamEditors, + animations: [...defaultSpec.animations || []], + customParamEditors: defaultSpec.customParamEditors, layout: { initial: { isExpanded: o.layoutIsExpanded, @@ -90,14 +91,14 @@ class Viewer { controlsDisplay: o.layoutControlsDisplay, }, controls: { - ...DefaultPluginSpec.layout && DefaultPluginSpec.layout.controls, + ...defaultSpec.layout && defaultSpec.layout.controls, top: o.layoutShowSequence ? undefined : 'none', bottom: o.layoutShowLog ? undefined : 'none', left: o.layoutShowLeftPanel ? undefined : 'none', } }, components: { - ...DefaultPluginSpec.components, + ...defaultSpec.components, remoteState: o.layoutShowRemoteState ? 'default' : 'none', viewport: { view: ViewportComponent diff --git a/src/apps/viewer/index.ts b/src/apps/viewer/index.ts index 4c49970a98ccaa567b4e10c32d68030c2c52fbf4..4aa38dc519b7d92bf5777dcad3e33e2259651b7a 100644 --- a/src/apps/viewer/index.ts +++ b/src/apps/viewer/index.ts @@ -89,15 +89,16 @@ export class Viewer { constructor(elementOrId: string | HTMLElement, options: Partial<ViewerOptions> = {}) { const o = { ...DefaultViewerOptions, ...options }; + const defaultSpec = DefaultPluginSpec(); const spec: PluginSpec = { - actions: [...DefaultPluginSpec.actions], + actions: [...defaultSpec.actions], behaviors: [ - ...DefaultPluginSpec.behaviors, + ...defaultSpec.behaviors, ...o.extensions.map(e => Extensions[e]), ], - animations: [...DefaultPluginSpec.animations || []], - customParamEditors: DefaultPluginSpec.customParamEditors, + animations: [...defaultSpec.animations || []], + customParamEditors: defaultSpec.customParamEditors, customFormats: o?.customFormats, layout: { initial: { @@ -106,14 +107,14 @@ export class Viewer { controlsDisplay: o.layoutControlsDisplay, }, controls: { - ...DefaultPluginSpec.layout && DefaultPluginSpec.layout.controls, + ...defaultSpec.layout && defaultSpec.layout.controls, top: o.layoutShowSequence ? undefined : 'none', bottom: o.layoutShowLog ? undefined : 'none', left: o.layoutShowLeftPanel ? undefined : 'none', } }, components: { - ...DefaultPluginSpec.components, + ...defaultSpec.components, remoteState: o.layoutShowRemoteState ? 'default' : 'none', }, config: [ diff --git a/src/examples/alpha-orbitals/index.ts b/src/examples/alpha-orbitals/index.ts index 612a835a06732b47f4d3df9257442fe0f8ab0294..efdc57abd3ac9e93168bc09b16bc1a4590e892a4 100644 --- a/src/examples/alpha-orbitals/index.ts +++ b/src/examples/alpha-orbitals/index.ts @@ -53,7 +53,7 @@ export class AlphaOrbitalsExample { async init(target: string | HTMLElement) { this.plugin = await createPluginAsync(typeof target === 'string' ? document.getElementById(target)! : target, { - ...DefaultPluginSpec, + ...DefaultPluginSpec(), layout: { initial: { isExpanded: false, diff --git a/src/examples/basic-wrapper/index.ts b/src/examples/basic-wrapper/index.ts index f2dfbcefc92c0a9057f332d261e018bc049bd809..d8d1ed030a110aa6a739e4891ce81aee0080a6af 100644 --- a/src/examples/basic-wrapper/index.ts +++ b/src/examples/basic-wrapper/index.ts @@ -28,7 +28,7 @@ class BasicWrapper { init(target: string | HTMLElement) { this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, { - ...DefaultPluginSpec, + ...DefaultPluginSpec(), layout: { initial: { isExpanded: false, diff --git a/src/examples/lighting/index.ts b/src/examples/lighting/index.ts index 95757a6215baf0d3737948d2cdf3065bb7f6a1f6..4305e6d925d69ec50b8537d291a760245265615c 100644 --- a/src/examples/lighting/index.ts +++ b/src/examples/lighting/index.ts @@ -67,7 +67,7 @@ class LightingDemo { init(target: string | HTMLElement) { this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, { - ...DefaultPluginSpec, + ...DefaultPluginSpec(), layout: { initial: { isExpanded: false, diff --git a/src/examples/proteopedia-wrapper/index.ts b/src/examples/proteopedia-wrapper/index.ts index ebd4a00e5462fd51cb571c15ce1fb1dcc33236b3..233c1878a889620b3b9a6b5fcf9e809519960697 100644 --- a/src/examples/proteopedia-wrapper/index.ts +++ b/src/examples/proteopedia-wrapper/index.ts @@ -46,7 +46,7 @@ class MolStarProteopediaWrapper { customColorList?: number[] }) { this.plugin = createPlugin(typeof target === 'string' ? document.getElementById(target)! : target, { - ...DefaultPluginSpec, + ...DefaultPluginSpec(), animations: [ AnimateModelIndex ], diff --git a/src/extensions/anvil/algorithm.ts b/src/extensions/anvil/algorithm.ts index 726adb62dbe27444442fba1142d0e7d3ccc9c20e..8dbb5c72d7d67efeeaae5e253a2da46b8f24140c 100644 --- a/src/extensions/anvil/algorithm.ts +++ b/src/extensions/anvil/algorithm.ts @@ -54,13 +54,13 @@ export function computeANVIL(structure: Structure, props: ANVILProps) { }); } -const l = StructureElement.Location.create(void 0); + const centroidHelper = new CentroidHelper(); function initialize(structure: Structure, props: ANVILProps): ANVILContext { + const l = StructureElement.Location.create(structure); const { label_atom_id, x, y, z } = StructureProperties.atom; const elementCount = structure.polymerResidueCount; centroidHelper.reset(); - l.structure = structure; let offsets = new Int32Array(elementCount); let exposed = new Array<boolean>(elementCount); @@ -328,6 +328,7 @@ namespace HphobHphil { const testPoint = Vec3(); export function filtered(ctx: ANVILContext, label_comp_id: StructureElement.Property<string>, filter?: (test: Vec3) => boolean): HphobHphil { const { offsets, exposed, structure } = ctx; + const l = StructureElement.Location.create(structure); const { x, y, z } = StructureProperties.atom; let hphob = 0; let hphil = 0; diff --git a/src/mol-math/geometry/boundary-helper.ts b/src/mol-math/geometry/boundary-helper.ts index b1cc0ec6bf5dad1e481fef4cf166e3f76db6e5ac..3d719a15e248d1dae934cd384ecf31d0affc386e 100644 --- a/src/mol-math/geometry/boundary-helper.ts +++ b/src/mol-math/geometry/boundary-helper.ts @@ -4,7 +4,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Vec3 } from '../linear-algebra/3d'; +import { Vec3 } from '../linear-algebra/3d/vec3'; import { CentroidHelper } from './centroid-helper'; import { Sphere3D } from '../geometry'; import { Box3D } from './primitives/box3d'; diff --git a/src/mol-math/geometry/centroid-helper.ts b/src/mol-math/geometry/centroid-helper.ts index 0398cfe68bb74d128f9f36eea050cc58da0baee1..32c67e8665a815898780218c2865e821195da3b2 100644 --- a/src/mol-math/geometry/centroid-helper.ts +++ b/src/mol-math/geometry/centroid-helper.ts @@ -5,7 +5,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Vec3 } from '../../mol-math/linear-algebra/3d'; +import { Vec3 } from '../../mol-math/linear-algebra/3d/vec3'; import { Sphere3D } from './primitives/sphere3d'; export { CentroidHelper }; diff --git a/src/mol-math/geometry/molecular-surface.ts b/src/mol-math/geometry/molecular-surface.ts index 5e864332182c97d3f3542a54f5ada7ad6e74cf98..c9532f808a8f11024ae54c4d1abd0b0782de430f 100644 --- a/src/mol-math/geometry/molecular-surface.ts +++ b/src/mol-math/geometry/molecular-surface.ts @@ -12,7 +12,7 @@ import { ParamDefinition as PD } from '../../mol-util/param-definition'; import { RuntimeContext } from '../../mol-task'; import { OrderedSet } from '../../mol-data/int'; import { PositionData } from './common'; -import { Mat4 } from '../../mol-math/linear-algebra/3d'; +import { Mat4 } from '../../mol-math/linear-algebra/3d/mat4'; import { Box3D, GridLookup3D, fillGridDim } from '../../mol-math/geometry'; import { BaseGeometry } from '../../mol-geo/geometry/base'; import { Boundary } from './boundary'; diff --git a/src/mol-math/geometry/symmetry-operator.ts b/src/mol-math/geometry/symmetry-operator.ts index 00c14df63a6098fa59a2b14ebd467e4b605e2f60..d1257fc923ca36c09cd2d8ef687d2b0bcbb3e3cb 100644 --- a/src/mol-math/geometry/symmetry-operator.ts +++ b/src/mol-math/geometry/symmetry-operator.ts @@ -4,9 +4,12 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Vec3, Mat4, Mat3, Quat } from '../linear-algebra/3d'; import { lerp as scalar_lerp } from '../../mol-math/interpolate'; import { defaults } from '../../mol-util'; +import { Mat3 } from '../linear-algebra/3d/mat3'; +import { Mat4 } from '../linear-algebra/3d/mat4'; +import { Quat } from '../linear-algebra/3d/quat'; +import { Vec3 } from '../linear-algebra/3d/vec3'; interface SymmetryOperator { readonly name: string, @@ -51,13 +54,13 @@ namespace SymmetryOperator { export type CreateInfo = { assembly?: SymmetryOperator['assembly'], ncsId?: number, hkl?: Vec3, spgrOp?: number } export function create(name: string, matrix: Mat4, info?: CreateInfo): SymmetryOperator { let { assembly, ncsId, hkl, spgrOp } = info || { }; - const _hkl = hkl ? Vec3.clone(hkl) : Vec3.zero(); + const _hkl = hkl ? Vec3.clone(hkl) : Vec3(); spgrOp = defaults(spgrOp, -1); ncsId = ncsId || -1; const suffix = getSuffix(info); if (Mat4.isIdentity(matrix)) return { name, assembly, matrix, inverse: Mat4.identity(), isIdentity: true, hkl: _hkl, spgrOp, ncsId, suffix }; if (!Mat4.isRotationAndTranslation(matrix, RotationTranslationEpsilon)) throw new Error(`Symmetry operator (${name}) must be a composition of rotation and translation.`); - return { name, assembly, matrix, inverse: Mat4.invert(Mat4.zero(), matrix), isIdentity: false, hkl: _hkl, spgrOp, ncsId, suffix }; + return { name, assembly, matrix, inverse: Mat4.invert(Mat4(), matrix), isIdentity: false, hkl: _hkl, spgrOp, ncsId, suffix }; } function getSuffix(info?: CreateInfo) { @@ -101,7 +104,7 @@ namespace SymmetryOperator { return create(name, t, { ncsId }); } - const _q1 = Quat.identity(), _q2 = Quat.zero(), _q3 = Quat.zero(), _axis = Vec3.zero(); + const _q1 = Quat.identity(), _q2 = Quat(), _q3 = Quat(), _axis = Vec3(); export function lerpFromIdentity(out: Mat4, op: SymmetryOperator, t: number): Mat4 { const m = op.inverse; if (op.isIdentity) return Mat4.copy(out, m); @@ -145,7 +148,7 @@ namespace SymmetryOperator { * Keep `name`, `assembly`, `ncsId`, `hkl` and `spgrOpId` properties from second. */ export function compose(first: SymmetryOperator, second: SymmetryOperator) { - const matrix = Mat4.mul(Mat4.zero(), second.matrix, first.matrix); + const matrix = Mat4.mul(Mat4(), second.matrix, first.matrix); return create(second.name, matrix, second); } diff --git a/src/mol-math/linear-algebra/3d/mat3.ts b/src/mol-math/linear-algebra/3d/mat3.ts index 6d05361fde38ef418b98692ac0ba0ebb1d441657..28072161503aef6725a13e34e1309a40081a4213 100644 --- a/src/mol-math/linear-algebra/3d/mat3.ts +++ b/src/mol-math/linear-algebra/3d/mat3.ts @@ -134,7 +134,7 @@ namespace Mat3 { * Creates a new Mat3 initialized with values from an existing matrix */ export function clone(a: Mat3) { - return Mat3.copy(Mat3.zero(), a); + return copy(zero(), a); } export function areEqual(a: Mat3, b: Mat3, eps: number) { @@ -372,7 +372,7 @@ namespace Mat3 { } const piThird = Math.PI / 3; - const tmpB = Mat3(); + const tmpB = zero(); /** * Given a real symmetric 3x3 matrix A, compute the eigenvalues * @@ -447,9 +447,9 @@ namespace Mat3 { * Get matrix to transform directions, e.g. normals */ export function directionTransform(out: Mat3, t: Mat4) { - Mat3.fromMat4(out, t); - Mat3.invert(out, out); - Mat3.transpose(out, out); + fromMat4(out, t); + invert(out, out); + transpose(out, out); return out; } diff --git a/src/mol-math/linear-algebra/3d/mat4.ts b/src/mol-math/linear-algebra/3d/mat4.ts index 1370593934e2a4bdb0bbdf487fe36e79cfc190a2..f57fc231c922fb441a10f85fed0355f40354471c 100644 --- a/src/mol-math/linear-algebra/3d/mat4.ts +++ b/src/mol-math/linear-algebra/3d/mat4.ts @@ -165,17 +165,17 @@ namespace Mat4 { } export function fromBasis(a: Mat4, x: Vec3, y: Vec3, z: Vec3) { - Mat4.setZero(a); - Mat4.setValue(a, 0, 0, x[0]); - Mat4.setValue(a, 1, 0, x[1]); - Mat4.setValue(a, 2, 0, x[2]); - Mat4.setValue(a, 0, 1, y[0]); - Mat4.setValue(a, 1, 1, y[1]); - Mat4.setValue(a, 2, 1, y[2]); - Mat4.setValue(a, 0, 2, z[0]); - Mat4.setValue(a, 1, 2, z[1]); - Mat4.setValue(a, 2, 2, z[2]); - Mat4.setValue(a, 3, 3, 1); + setZero(a); + setValue(a, 0, 0, x[0]); + setValue(a, 1, 0, x[1]); + setValue(a, 2, 0, x[2]); + setValue(a, 0, 1, y[0]); + setValue(a, 1, 1, y[1]); + setValue(a, 2, 1, y[2]); + setValue(a, 0, 2, z[0]); + setValue(a, 1, 2, z[1]); + setValue(a, 2, 2, z[2]); + setValue(a, 3, 3, 1); return a; } @@ -200,7 +200,7 @@ namespace Mat4 { } export function clone(a: Mat4) { - return Mat4.copy(Mat4.zero(), a); + return copy(zero(), a); } /** @@ -541,7 +541,7 @@ namespace Mat4 { b20, b21, b22; if (Math.abs(len) < EPSILON) { - return Mat4.identity(); + return identity(); } len = 1 / len; @@ -1075,29 +1075,29 @@ namespace Mat4 { const zAxis = Vec3.create(0, 0, 1); /** Rotation matrix for 90deg around x-axis */ - export const rotX90: ReadonlyMat4 = fromRotation(Mat4(), degToRad(90), xAxis); + export const rotX90: ReadonlyMat4 = fromRotation(zero(), degToRad(90), xAxis); /** Rotation matrix for 180deg around x-axis */ - export const rotX180: ReadonlyMat4 = fromRotation(Mat4(), degToRad(180), xAxis); + export const rotX180: ReadonlyMat4 = fromRotation(zero(), degToRad(180), xAxis); /** Rotation matrix for 90deg around y-axis */ - export const rotY90: ReadonlyMat4 = fromRotation(Mat4(), degToRad(90), yAxis); + export const rotY90: ReadonlyMat4 = fromRotation(zero(), degToRad(90), yAxis); /** Rotation matrix for 180deg around y-axis */ - export const rotY180: ReadonlyMat4 = fromRotation(Mat4(), degToRad(180), yAxis); + export const rotY180: ReadonlyMat4 = fromRotation(zero(), degToRad(180), yAxis); /** Rotation matrix for 270deg around y-axis */ - export const rotY270: ReadonlyMat4 = fromRotation(Mat4(), degToRad(270), yAxis); + export const rotY270: ReadonlyMat4 = fromRotation(zero(), degToRad(270), yAxis); /** Rotation matrix for 90deg around z-axis */ - export const rotZ90: ReadonlyMat4 = fromRotation(Mat4(), degToRad(90), zAxis); + export const rotZ90: ReadonlyMat4 = fromRotation(zero(), degToRad(90), zAxis); /** Rotation matrix for 180deg around z-axis */ - export const rotZ180: ReadonlyMat4 = fromRotation(Mat4(), degToRad(180), zAxis); + export const rotZ180: ReadonlyMat4 = fromRotation(zero(), degToRad(180), zAxis); /** Rotation matrix for 90deg around first x-axis and then y-axis */ - export const rotXY90: ReadonlyMat4 = mul(Mat4(), rotX90, rotY90); + export const rotXY90: ReadonlyMat4 = mul(zero(), rotX90, rotY90); /** Rotation matrix for 90deg around first z-axis and then y-axis */ - export const rotZY90: ReadonlyMat4 = mul(Mat4(), rotZ90, rotY90); + export const rotZY90: ReadonlyMat4 = mul(zero(), rotZ90, rotY90); /** Rotation matrix for 90deg around first z-axis and then y-axis and then z-axis */ - export const rotZYZ90: ReadonlyMat4 = mul(Mat4(), rotZY90, rotZ90); + export const rotZYZ90: ReadonlyMat4 = mul(zero(), rotZY90, rotZ90); /** Rotation matrix for 90deg around first z-axis and then 180deg around x-axis */ - export const rotZ90X180: ReadonlyMat4 = mul(Mat4(), rotZ90, rotX180); + export const rotZ90X180: ReadonlyMat4 = mul(zero(), rotZ90, rotX180); /** Rotation matrix for 90deg around first y-axis and then 180deg around z-axis */ - export const rotY90Z180: ReadonlyMat4 = mul(Mat4(), rotY90, rotZ180); + export const rotY90Z180: ReadonlyMat4 = mul(zero(), rotY90, rotZ180); /** Identity matrix */ export const id: ReadonlyMat4 = identity(); diff --git a/src/mol-math/linear-algebra/3d/quat.ts b/src/mol-math/linear-algebra/3d/quat.ts index 717052692f942b1b2c4589bff55ae8a5eab6e1ea..2f9872490cf78312a5408999668741e5e8f1c467 100644 --- a/src/mol-math/linear-algebra/3d/quat.ts +++ b/src/mol-math/linear-algebra/3d/quat.ts @@ -407,8 +407,8 @@ namespace Quat { /** * Performs a spherical linear interpolation with two control points */ - let sqlerpTemp1 = Quat(); - let sqlerpTemp2 = Quat(); + let sqlerpTemp1 = zero(); + let sqlerpTemp2 = zero(); export function sqlerp(out: Quat, a: Quat, b: Quat, c: Quat, d: Quat, t: number) { slerp(sqlerpTemp1, a, d, t); slerp(sqlerpTemp2, b, c, t); @@ -435,7 +435,7 @@ namespace Quat { axesTmpMat[5] = -view[1]; axesTmpMat[8] = -view[2]; - return normalize(out, Quat.fromMat3(out, axesTmpMat)); + return normalize(out, fromMat3(out, axesTmpMat)); } export function toString(a: Quat, precision?: number) { diff --git a/src/mol-math/linear-algebra/3d/vec3.ts b/src/mol-math/linear-algebra/3d/vec3.ts index 13a6973419f764ae2079a1b6651dc8e1b0cced01..4e0cd46cf29e8f6ae9bf3d82b14f8c1287451795 100644 --- a/src/mol-math/linear-algebra/3d/vec3.ts +++ b/src/mol-math/linear-algebra/3d/vec3.ts @@ -18,9 +18,11 @@ */ import { Mat4 } from './mat4'; -import { Quat, Mat3, EPSILON } from '../3d'; import { spline as _spline, quadraticBezier as _quadraticBezier, clamp } from '../../interpolate'; import { NumberArray } from '../../../mol-util/type-helpers'; +import { Mat3 } from './mat3'; +import { Quat } from './quat'; +import { EPSILON } from './common'; export { ReadonlyVec3 }; @@ -273,7 +275,7 @@ namespace Vec3 { } export function setMagnitude(out: Vec3, a: Vec3, l: number) { - return Vec3.scale(out, Vec3.normalize(out, a), l); + return scale(out, normalize(out, a), l); } /** @@ -339,11 +341,11 @@ namespace Vec3 { const slerpRelVec = zero(); export function slerp(out: Vec3, a: Vec3, b: Vec3, t: number) { - const dot = clamp(Vec3.dot(a, b), -1, 1); - const theta = Math.acos(dot) * t; - Vec3.scaleAndAdd(slerpRelVec, b, a, -dot); - Vec3.normalize(slerpRelVec, slerpRelVec); - return Vec3.add(out, Vec3.scale(out, a, Math.cos(theta)), Vec3.scale(slerpRelVec, slerpRelVec, Math.sin(theta))); + const d = clamp(dot(a, b), -1, 1); + const theta = Math.acos(d) * t; + scaleAndAdd(slerpRelVec, b, a, -d); + normalize(slerpRelVec, slerpRelVec); + return add(out, scale(out, a, Math.cos(theta)), scale(slerpRelVec, slerpRelVec, Math.sin(theta))); } /** @@ -562,8 +564,8 @@ namespace Vec3 { * i.e. where the dot product is > 0 */ export function matchDirection(out: Vec3, a: Vec3, b: Vec3) { - if (Vec3.dot(a, b) > 0) Vec3.copy(out, a); - else Vec3.negate(out, Vec3.copy(out, a)); + if (dot(a, b) > 0) copy(out, a); + else negate(out, copy(out, a)); return out; } @@ -580,14 +582,14 @@ namespace Vec3 { return `[${a[0].toPrecision(precision)} ${a[1].toPrecision(precision)} ${a[2].toPrecision(precision)}]`; } - export const origin: ReadonlyVec3 = Vec3.create(0, 0, 0); + export const origin: ReadonlyVec3 = create(0, 0, 0); - export const unit: ReadonlyVec3 = Vec3.create(1, 1, 1); - export const negUnit: ReadonlyVec3 = Vec3.create(-1, -1, -1); + export const unit: ReadonlyVec3 = create(1, 1, 1); + export const negUnit: ReadonlyVec3 = create(-1, -1, -1); - export const unitX: ReadonlyVec3 = Vec3.create(1, 0, 0); - export const unitY: ReadonlyVec3 = Vec3.create(0, 1, 0); - export const unitZ: ReadonlyVec3 = Vec3.create(0, 0, 1); + export const unitX: ReadonlyVec3 = create(1, 0, 0); + export const unitY: ReadonlyVec3 = create(0, 1, 0); + export const unitZ: ReadonlyVec3 = create(0, 0, 1); } export { Vec3 }; \ No newline at end of file diff --git a/src/mol-math/linear-algebra/3d/vec4.ts b/src/mol-math/linear-algebra/3d/vec4.ts index 09437726d911797c4176f94b9cb6cd0d1bb8bc33..7f724c9735cbe240612fb56987c28d052d971930 100644 --- a/src/mol-math/linear-algebra/3d/vec4.ts +++ b/src/mol-math/linear-algebra/3d/vec4.ts @@ -18,9 +18,9 @@ */ import { Mat4 } from './mat4'; -import { EPSILON } from '../3d'; import { NumberArray } from '../../../mol-util/type-helpers'; import { Sphere3D } from '../../geometry/primitives/sphere3d'; +import { EPSILON } from './common'; interface Vec4 extends Array<number> { [d: number]: number, '@type': 'vec4', length: 4 } diff --git a/src/mol-math/linear-algebra/_spec/mat3.spec.ts b/src/mol-math/linear-algebra/_spec/mat3.spec.ts index d1007d8b2e87c708eca74609b1122c177058d094..171acc1e14aa5c90e72ee08779945e233a7a3ece 100644 --- a/src/mol-math/linear-algebra/_spec/mat3.spec.ts +++ b/src/mol-math/linear-algebra/_spec/mat3.spec.ts @@ -4,7 +4,8 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Mat3, Vec3 } from '../3d'; +import { Mat3 } from '../3d/mat3'; +import { Vec3 } from '../3d/vec3'; describe('Mat3', () => { it('symmetricEigenvalues', () => { diff --git a/src/mol-math/linear-algebra/_spec/mat4.spec.ts b/src/mol-math/linear-algebra/_spec/mat4.spec.ts index df801e27bf592b513112d201a5ecd761eaa53d90..97ff10e2057d4dfd53ead65d294015e152c5b835 100644 --- a/src/mol-math/linear-algebra/_spec/mat4.spec.ts +++ b/src/mol-math/linear-algebra/_spec/mat4.spec.ts @@ -4,21 +4,22 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Mat4, Vec3 } from '../3d'; +import { Mat4 } from '../3d/mat4'; +import { Vec3 } from '../3d/vec3'; describe('Mat4', () => { it('permutation', () => { - expect(Mat4.areEqual(Mat4.fromPermutation(Mat4.zero(), [0, 1, 2, 3]), Mat4.identity(), 1e-6)).toBe(true); + expect(Mat4.areEqual(Mat4.fromPermutation(Mat4(), [0, 1, 2, 3]), Mat4.identity(), 1e-6)).toBe(true); - expect(Mat4.areEqual(Mat4.fromPermutation(Mat4.zero(), [1, 0, 2, 3]), Mat4.ofRows([ + expect(Mat4.areEqual(Mat4.fromPermutation(Mat4(), [1, 0, 2, 3]), Mat4.ofRows([ [0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1], ]), 1e-6)).toBe(true); - const perm = Mat4.fromPermutation(Mat4.zero(), [1, 2, 0, 3]); + const perm = Mat4.fromPermutation(Mat4(), [1, 2, 0, 3]); - expect(Vec3.transformMat4(Vec3.zero(), Vec3.create(1, 2, 3), perm)).toEqual(Vec3.create(2, 3, 1)); + expect(Vec3.transformMat4(Vec3(), Vec3.create(1, 2, 3), perm)).toEqual(Vec3.create(2, 3, 1)); }); }); \ No newline at end of file diff --git a/src/mol-math/linear-algebra/_spec/tensor.spec.ts b/src/mol-math/linear-algebra/_spec/tensor.spec.ts index d36522c3a8e6f2afdb7605cdc18ec46fc3288a00..923e6455e4369ad8a006563d0d052326e3924c6d 100644 --- a/src/mol-math/linear-algebra/_spec/tensor.spec.ts +++ b/src/mol-math/linear-algebra/_spec/tensor.spec.ts @@ -5,7 +5,7 @@ */ import { Tensor as T } from '../tensor'; -import { Mat4 } from '../3d'; +import { Mat4 } from '../3d/mat4'; describe('tensor', () => { it('vector', () => { diff --git a/src/mol-math/linear-algebra/_spec/vec3.spec.ts b/src/mol-math/linear-algebra/_spec/vec3.spec.ts index 38909706a44b00afc45b86bb2cb33ea273748c43..36bdd88d5a114e8ad55f31143b81d5b7814aed2d 100644 --- a/src/mol-math/linear-algebra/_spec/vec3.spec.ts +++ b/src/mol-math/linear-algebra/_spec/vec3.spec.ts @@ -1,4 +1,10 @@ -import { Vec3 } from '../3d'; +/** + * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. + * + * @author Sebastian Bittrich <sebastian.bittrich@rcsb.org> + */ + +import { Vec3 } from '../3d/vec3'; describe('vec3', () => { const vec1 = [ 1, 2, 3 ] as Vec3; diff --git a/src/mol-math/linear-algebra/matrix/principal-axes.ts b/src/mol-math/linear-algebra/matrix/principal-axes.ts index db338445538e8ec4576d8714f425a6fa7a2f112a..2f28473a06a85a72cbf6136c789c007a758a6126 100644 --- a/src/mol-math/linear-algebra/matrix/principal-axes.ts +++ b/src/mol-math/linear-algebra/matrix/principal-axes.ts @@ -5,7 +5,7 @@ */ import { Matrix } from './matrix'; -import { Vec3 } from '../3d'; +import { Vec3 } from '../3d/vec3'; import { svd } from './svd'; import { NumberArray } from '../../../mol-util/type-helpers'; import { Axes3D } from '../../geometry'; diff --git a/src/mol-math/linear-algebra/tensor.ts b/src/mol-math/linear-algebra/tensor.ts index 824b772bad1283823a5465dce37cf96c76b6c173..2632e9eb25528f9c2bcd1e4da3eec2b039e7b5d9 100644 --- a/src/mol-math/linear-algebra/tensor.ts +++ b/src/mol-math/linear-algebra/tensor.ts @@ -1,3 +1,4 @@ +import { Mat3 } from './3d/mat3'; /** * Copyright (c) 2017-2020 mol* contributors, licensed under MIT, See LICENSE file for more info. * @@ -5,7 +6,9 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { Mat4, Vec3, Vec4, Mat3 } from './3d'; +import { Mat4 } from './3d/mat4'; +import { Vec3 } from './3d/vec3'; +import { Vec4 } from './3d/vec4'; export interface Tensor { data: Tensor.Data, space: Tensor.Space } diff --git a/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/area.ts b/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/area.ts index 7c01e6f6d928a08d7d506628ce4420cb90fe599a..d2f6a7846baf942f8989db0de4da24349908130e 100644 --- a/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/area.ts +++ b/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/area.ts @@ -31,8 +31,6 @@ export async function computeArea(runtime: RuntimeContext, ctx: ShrakeRupleyCont const aPos = Vec3(); const bPos = Vec3(); const testPoint = Vec3(); -const aLoc = StructureElement.Location.create(void 0 as any); -const bLoc = StructureElement.Location.create(void 0 as any); function setLocation(l: StructureElement.Location, structure: Structure, serialIndex: number) { l.structure = structure; @@ -43,6 +41,8 @@ function setLocation(l: StructureElement.Location, structure: Structure, serialI function computeRange(ctx: ShrakeRupleyContext, begin: number, end: number) { const { structure, atomRadiusType, serialResidueIndex, area, spherePoints, scalingConstant, maxLookupRadius, probeSize } = ctx; + const aLoc = StructureElement.Location.create(structure); + const bLoc = StructureElement.Location.create(structure); const { x, y, z } = StructureProperties.atom; const { lookup3d, serialMapping, unitIndexMap } = structure; const { cumulativeUnitElementCount } = serialMapping; diff --git a/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts b/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts index 7c74846e741f7474d6d1858f214eb22f5cb7cc27..3b469df371058495ac765f06bc41f6ae032a5d03 100644 --- a/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts +++ b/src/mol-model-props/computed/accessible-surface-area/shrake-rupley/radii.ts @@ -12,12 +12,11 @@ import { VdwRadius } from '../../../../mol-model/structure/model/properties/atom import { StructureElement, StructureProperties } from '../../../../mol-model/structure/structure'; import { getElementMoleculeType } from '../../../../mol-model/structure/util'; -const l = StructureElement.Location.create(void 0); - export function assignRadiusForHeavyAtoms(ctx: ShrakeRupleyContext) { const { key } = StructureProperties.residue; const { type_symbol, label_atom_id, label_comp_id } = StructureProperties.atom; const { structure, atomRadiusType, serialResidueIndex } = ctx; + const l = StructureElement.Location.create(structure); let prevResidueIdx = 0; let residueIdx = 0; diff --git a/src/mol-model-props/computed/representations/interactions-inter-unit-cylinder.ts b/src/mol-model-props/computed/representations/interactions-inter-unit-cylinder.ts index 086b3ebd381c0926d8cc9a3de9b551ca7be6ce58..1bcf555c877bfa1b9c10dc4ca12cbeefd8864854 100644 --- a/src/mol-model-props/computed/representations/interactions-inter-unit-cylinder.ts +++ b/src/mol-model-props/computed/representations/interactions-inter-unit-cylinder.ts @@ -23,11 +23,10 @@ import { InteractionFlag } from '../interactions/common'; import { Unit } from '../../../mol-model/structure/structure'; import { Sphere3D } from '../../../mol-math/geometry'; -const tmpLoc = StructureElement.Location.create(void 0); - function createInterUnitInteractionCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<InteractionsInterUnitParams>, mesh?: Mesh) { if (!structure.hasAtomic) return Mesh.createEmpty(mesh); + const l = StructureElement.Location.create(structure); const interactions = InteractionsProvider.get(structure).value!; const { contacts, unitsFeatures } = interactions; @@ -55,14 +54,13 @@ function createInterUnitInteractionCylinderMesh(ctx: VisualContext, structure: S radius: (edgeIndex: number) => { const b = edges[edgeIndex]; const fA = unitsFeatures.get(b.unitA); - tmpLoc.structure = structure; - tmpLoc.unit = structure.unitMap.get(b.unitA); - tmpLoc.element = tmpLoc.unit.elements[fA.members[fA.offsets[b.indexA]]]; - const sizeA = theme.size.size(tmpLoc); + l.unit = structure.unitMap.get(b.unitA); + l.element = l.unit.elements[fA.members[fA.offsets[b.indexA]]]; + const sizeA = theme.size.size(l); const fB = unitsFeatures.get(b.unitB); - tmpLoc.unit = structure.unitMap.get(b.unitB); - tmpLoc.element = tmpLoc.unit.elements[fB.members[fB.offsets[b.indexB]]]; - const sizeB = theme.size.size(tmpLoc); + l.unit = structure.unitMap.get(b.unitB); + l.element = l.unit.elements[fB.members[fB.offsets[b.indexB]]]; + const sizeB = theme.size.size(l); return Math.min(sizeA, sizeB) * sizeFactor; }, ignore: (edgeIndex: number) => edges[edgeIndex].props.flag === InteractionFlag.Filtered diff --git a/src/mol-model/structure/export/categories/atom_site.ts b/src/mol-model/structure/export/categories/atom_site.ts index 98ab02958a7658f08c13d58f823cb96cbef72911..404783aef18831e7d0de8d01bd18a5152b256824 100644 --- a/src/mol-model/structure/export/categories/atom_site.ts +++ b/src/mol-model/structure/export/categories/atom_site.ts @@ -12,23 +12,21 @@ import CifField = CifWriter.Field import CifCategory = CifWriter.Category import E = CifWriter.Encodings -const _label_asym_id = P.chain.label_asym_id; function atom_site_label_asym_id(e: StructureElement.Location) { - const l = _label_asym_id(e); + const l = P.chain.label_asym_id(e); const suffix = e.unit.conformation.operator.suffix; if (!suffix) return l; return l + suffix; } -const _auth_asym_id = P.chain.auth_asym_id; function atom_site_auth_asym_id(e: StructureElement.Location) { - const l = _auth_asym_id(e); + const l = P.chain.auth_asym_id(e); const suffix = e.unit.conformation.operator.suffix; if (!suffix) return l; return l + suffix; } -const atom_site_fields = CifWriter.fields<StructureElement.Location, Structure>() +const atom_site_fields = () => CifWriter.fields<StructureElement.Location, Structure>() .str('group_PDB', P.residue.group_PDB) .index('id') .str('type_symbol', P.atom.type_symbol as any) @@ -73,7 +71,7 @@ export const _atom_site: CifCategory<CifExportContext> = { name: 'atom_site', instance({ structures }: CifExportContext) { return { - fields: atom_site_fields, + fields: atom_site_fields(), source: structures.map(s => ({ data: s, rowCount: s.elementCount, diff --git a/src/mol-model/structure/export/categories/secondary-structure.ts b/src/mol-model/structure/export/categories/secondary-structure.ts index 1f1458a4f44b299434547fbab489f3e889079d9a..a8288e4213d79945e8cfb07c0d16b2f24ab85857 100644 --- a/src/mol-model/structure/export/categories/secondary-structure.ts +++ b/src/mol-model/structure/export/categories/secondary-structure.ts @@ -20,7 +20,7 @@ export const _struct_conf: CifCategory<CifExportContext> = { instance(ctx) { const elements = findElements(ctx, 'helix'); return { - fields: struct_conf_fields, + fields: struct_conf_fields(), source: [{ data: elements, rowCount: elements.length }] }; } @@ -31,7 +31,7 @@ export const _struct_sheet_range: CifCategory<CifExportContext> = { instance(ctx) { const elements = (findElements(ctx, 'sheet') as SSElement<SecondaryStructure.Sheet>[]).sort(compare_ssr); return { - fields: struct_sheet_range_fields, + fields: struct_sheet_range_fields(), source: [{ data: elements, rowCount: elements.length }] }; } @@ -42,7 +42,7 @@ function compare_ssr(x: SSElement<SecondaryStructure.Sheet>, y: SSElement<Second return a.sheet_id < b.sheet_id ? -1 : a.sheet_id === b.sheet_id ? x.start.element - y.start.element : 1; }; -const struct_conf_fields: CifField[] = [ +const struct_conf_fields = (): CifField[] => [ CifField.str<number, SSElement<SecondaryStructure.Helix>[]>('conf_type_id', (i, data) => data[i].element.type_id), CifField.str<number, SSElement<SecondaryStructure.Helix>[]>('id', (i, data, idx) => `${data[i].element.type_id}${idx + 1}`), ...residueIdFields<number, SSElement<SecondaryStructure.Helix>[]>((i, e) => e[i].start, { prefix: 'beg' }), @@ -54,7 +54,7 @@ const struct_conf_fields: CifField[] = [ CifField.int<number, SSElement<SecondaryStructure.Helix>[]>('pdbx_PDB_helix_length', (i, data) => data[i].length) ]; -const struct_sheet_range_fields: CifField[] = [ +const struct_sheet_range_fields = (): CifField[] => [ CifField.str<number, SSElement<SecondaryStructure.Sheet>[]>('sheet_id', (i, data) => data[i].element.sheet_id), CifField.index('id'), ...residueIdFields<number, SSElement<SecondaryStructure.Sheet>[]>((i, e) => e[i].start, { prefix: 'beg' }), diff --git a/src/mol-plugin-state/animation/built-in/camera-spin.ts b/src/mol-plugin-state/animation/built-in/camera-spin.ts index bcf2c8c52151f0484fe46cdc40906c7b5ab2884e..d0e3a4a49580f52579a838acaebc8b1279408bd5 100644 --- a/src/mol-plugin-state/animation/built-in/camera-spin.ts +++ b/src/mol-plugin-state/animation/built-in/camera-spin.ts @@ -6,7 +6,8 @@ import { Camera } from '../../../mol-canvas3d/camera'; import { clamp } from '../../../mol-math/interpolate'; -import { Quat, Vec3 } from '../../../mol-math/linear-algebra/3d'; +import { Quat } from '../../../mol-math/linear-algebra/3d/quat'; +import { Vec3 } from '../../../mol-math/linear-algebra/3d/vec3'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { PluginStateAnimation } from '../model'; diff --git a/src/mol-plugin-state/helpers/structure-component.ts b/src/mol-plugin-state/helpers/structure-component.ts index 0f9dc09c9c9f5ba1377ae9af42672b7227fbd1a5..06226bafa6f4b2352e2361fdffc1d18f7df63d18 100644 --- a/src/mol-plugin-state/helpers/structure-component.ts +++ b/src/mol-plugin-state/helpers/structure-component.ts @@ -34,7 +34,7 @@ export const StaticStructureComponentTypes = [ export type StaticStructureComponentType = (typeof StaticStructureComponentTypes)[number] -export const StructureComponentParams = { +export const StructureComponentParams = () => ({ type: PD.MappedStatic('static', { static: PD.Text<StaticStructureComponentType>('polymer'), expression: PD.Value<Expression>(MolScriptBuilder.struct.generator.all), @@ -43,8 +43,8 @@ export const StructureComponentParams = { }, { isHidden: true }), nullIfEmpty: PD.Optional(PD.Boolean(true, { isHidden: true })), label: PD.Text('', { isHidden: true }) -}; -export type StructureComponentParams = PD.ValuesFor<typeof StructureComponentParams> +}); +export type StructureComponentParams = PD.ValuesFor<ReturnType<typeof StructureComponentParams>> export function createStructureComponent(a: Structure, params: StructureComponentParams, cache: { source: Structure, entry?: StructureQueryHelper.CacheEntry }) { cache.source = a; diff --git a/src/mol-plugin-state/transforms/model.ts b/src/mol-plugin-state/transforms/model.ts index 0fe48aa93cfcb1ae891f80518cf99a2d12ef5a11..c8bfcf78c90dd142729c6570fa83ef59415f9ea3 100644 --- a/src/mol-plugin-state/transforms/model.ts +++ b/src/mol-plugin-state/transforms/model.ts @@ -486,10 +486,10 @@ const StructureSelectionFromExpression = PluginStateTransform.BuiltIn({ display: { name: 'Selection', description: 'Create a molecular structure from the specified expression.' }, from: SO.Molecule.Structure, to: SO.Molecule.Structure, - params: { + params: () => ({ expression: PD.Value<Expression>(MolScriptBuilder.struct.generator.all, { isHidden: true }), label: PD.Optional(PD.Text('', { isHidden: true })) - } + }) })({ apply({ a, params, cache }) { const { selection, entry } = StructureQueryHelper.createAndRun(a.data, params.expression); @@ -526,7 +526,7 @@ const MultiStructureSelectionFromExpression = PluginStateTransform.BuiltIn({ display: { name: 'Multi-structure Measurement Selection', description: 'Create selection object from multiple structures.' }, from: SO.Root, to: SO.Molecule.Structure.Selections, - params: { + params: () => ({ selections: PD.ObjectList({ key: PD.Text(void 0, { description: 'A unique key.' }), ref: PD.Text(), @@ -535,7 +535,7 @@ const MultiStructureSelectionFromExpression = PluginStateTransform.BuiltIn({ }, e => e.ref, { isHidden: true }), isTransitive: PD.Optional(PD.Boolean(false, { isHidden: true, description: 'Remap the selections from the original structure if structurally equivalent.' })), label: PD.Optional(PD.Text('', { isHidden: true })) - } + }) })({ apply({ params, cache, dependencies }) { const entries = new Map<string, StructureQueryHelper.CacheEntry>(); @@ -651,10 +651,10 @@ const StructureSelectionFromScript = PluginStateTransform.BuiltIn({ display: { name: 'Selection', description: 'Create a molecular structure from the specified script.' }, from: SO.Molecule.Structure, to: SO.Molecule.Structure, - params: { + params: () => ({ script: PD.Script({ language: 'mol-script', expression: '(sel.atom.atom-groups :residue-test (= atom.resname ALA))' }), label: PD.Optional(PD.Text('')) - } + }) })({ apply({ a, params, cache }) { const { selection, entry } = StructureQueryHelper.createAndRun(a.data, params.script); @@ -690,10 +690,10 @@ const StructureSelectionFromBundle = PluginStateTransform.BuiltIn({ display: { name: 'Selection', description: 'Create a molecular structure from the specified structure-element bundle.' }, from: SO.Molecule.Structure, to: SO.Molecule.Structure, - params: { + params: () => ({ bundle: PD.Value<StructureElement.Bundle>(StructureElement.Bundle.Empty, { isHidden: true }), label: PD.Optional(PD.Text('', { isHidden: true })) - } + }) })({ apply({ a, params, cache }) { if (params.bundle.hash !== a.data.hashCode) { diff --git a/src/mol-plugin-state/transforms/representation.ts b/src/mol-plugin-state/transforms/representation.ts index 78b03cc56ef665f906da13bccd869dadf0d1ccd5..eb1077fea8e7747929854aef29f0f05bfd02aa3a 100644 --- a/src/mol-plugin-state/transforms/representation.ts +++ b/src/mol-plugin-state/transforms/representation.ts @@ -258,7 +258,7 @@ const OverpaintStructureRepresentation3DFromScript = PluginStateTransform.BuiltI display: 'Overpaint 3D Representation', from: SO.Molecule.Structure.Representation3D, to: SO.Molecule.Structure.Representation3DState, - params: { + params: () => ({ layers: PD.ObjectList({ script: PD.Script(Script('(sel.atom.all)', 'mol-script')), color: PD.Color(ColorNames.blueviolet), @@ -270,7 +270,7 @@ const OverpaintStructureRepresentation3DFromScript = PluginStateTransform.BuiltI clear: false }] }), - } + }) })({ canAutoUpdate() { return true; @@ -309,7 +309,7 @@ const OverpaintStructureRepresentation3DFromBundle = PluginStateTransform.BuiltI display: 'Overpaint 3D Representation', from: SO.Molecule.Structure.Representation3D, to: SO.Molecule.Structure.Representation3DState, - params: { + params: () => ({ layers: PD.ObjectList({ bundle: PD.Value<StructureElement.Bundle>(StructureElement.Bundle.Empty), color: PD.Color(ColorNames.blueviolet), @@ -322,7 +322,7 @@ const OverpaintStructureRepresentation3DFromBundle = PluginStateTransform.BuiltI }], isHidden: true }), - } + }) })({ canAutoUpdate() { return true; @@ -361,7 +361,7 @@ const TransparencyStructureRepresentation3DFromScript = PluginStateTransform.Bui display: 'Transparency 3D Representation', from: SO.Molecule.Structure.Representation3D, to: SO.Molecule.Structure.Representation3DState, - params: { + params: () => ({ layers: PD.ObjectList({ script: PD.Script(Script('(sel.atom.all)', 'mol-script')), value: PD.Numeric(0.5, { min: 0, max: 1, step: 0.01 }, { label: 'Transparency' }), @@ -371,7 +371,7 @@ const TransparencyStructureRepresentation3DFromScript = PluginStateTransform.Bui value: 0.5, }] }) - } + }) })({ canAutoUpdate() { return true; @@ -409,7 +409,7 @@ const TransparencyStructureRepresentation3DFromBundle = PluginStateTransform.Bui display: 'Transparency 3D Representation', from: SO.Molecule.Structure.Representation3D, to: SO.Molecule.Structure.Representation3DState, - params: { + params: () => ({ layers: PD.ObjectList({ bundle: PD.Value<StructureElement.Bundle>(StructureElement.Bundle.Empty), value: PD.Numeric(0.5, { min: 0, max: 1, step: 0.01 }, { label: 'Transparency' }), @@ -420,7 +420,7 @@ const TransparencyStructureRepresentation3DFromBundle = PluginStateTransform.Bui }], isHidden: true }) - } + }) })({ canAutoUpdate() { return true; @@ -458,7 +458,7 @@ const ClippingStructureRepresentation3DFromScript = PluginStateTransform.BuiltIn display: 'Clipping 3D Representation', from: SO.Molecule.Structure.Representation3D, to: SO.Molecule.Structure.Representation3DState, - params: { + params: () => ({ layers: PD.ObjectList({ script: PD.Script(Script('(sel.atom.all)', 'mol-script')), groups: PD.Converted((g: Clipping.Groups) => Clipping.Groups.toNames(g), n => Clipping.Groups.fromNames(n), PD.MultiSelect(ObjectKeys(Clipping.Groups.Names), PD.objectToOptions(Clipping.Groups.Names))), @@ -468,7 +468,7 @@ const ClippingStructureRepresentation3DFromScript = PluginStateTransform.BuiltIn groups: Clipping.Groups.Flag.None, }] }), - } + }) })({ canAutoUpdate() { return true; @@ -506,7 +506,7 @@ const ClippingStructureRepresentation3DFromBundle = PluginStateTransform.BuiltIn display: 'Clipping 3D Representation', from: SO.Molecule.Structure.Representation3D, to: SO.Molecule.Structure.Representation3DState, - params: { + params: () => ({ layers: PD.ObjectList({ bundle: PD.Value<StructureElement.Bundle>(StructureElement.Bundle.Empty), groups: PD.Converted((g: Clipping.Groups) => Clipping.Groups.toNames(g), n => Clipping.Groups.fromNames(n), PD.MultiSelect(ObjectKeys(Clipping.Groups.Names), PD.objectToOptions(Clipping.Groups.Names))), @@ -517,7 +517,7 @@ const ClippingStructureRepresentation3DFromBundle = PluginStateTransform.BuiltIn }], isHidden: true }), - } + }) })({ canAutoUpdate() { return true; @@ -705,9 +705,9 @@ const ModelUnitcell3D = PluginStateTransform.BuiltIn({ display: 'Model Unit Cell', from: SO.Molecule.Model, to: SO.Shape.Representation3D, - params: { + params: () => ({ ...UnitcellParams, - } + }) })({ isApplicable: a => !!ModelSymmetry.Provider.get(a.data), canAutoUpdate({ oldParams, newParams }) { @@ -743,9 +743,9 @@ const StructureSelectionsDistance3D = PluginStateTransform.BuiltIn({ display: '3D Distance', from: SO.Molecule.Structure.Selections, to: SO.Shape.Representation3D, - params: { + params: () => ({ ...DistanceParams, - } + }) })({ canAutoUpdate({ oldParams, newParams }) { return true; @@ -776,9 +776,9 @@ const StructureSelectionsAngle3D = PluginStateTransform.BuiltIn({ display: '3D Angle', from: SO.Molecule.Structure.Selections, to: SO.Shape.Representation3D, - params: { + params: () => ({ ...AngleParams, - } + }) })({ canAutoUpdate({ oldParams, newParams }) { return true; @@ -809,9 +809,9 @@ const StructureSelectionsDihedral3D = PluginStateTransform.BuiltIn({ display: '3D Dihedral', from: SO.Molecule.Structure.Selections, to: SO.Shape.Representation3D, - params: { + params: () => ({ ...DihedralParams, - } + }) })({ canAutoUpdate({ oldParams, newParams }) { return true; @@ -842,9 +842,9 @@ const StructureSelectionsLabel3D = PluginStateTransform.BuiltIn({ display: '3D Label', from: SO.Molecule.Structure.Selections, to: SO.Shape.Representation3D, - params: { + params: () => ({ ...LabelParams, - } + }) })({ canAutoUpdate({ oldParams, newParams }) { return true; @@ -875,9 +875,9 @@ const StructureSelectionsOrientation3D = PluginStateTransform.BuiltIn({ display: '3D Orientation', from: SO.Molecule.Structure.Selections, to: SO.Shape.Representation3D, - params: { + params: () => ({ ...OrientationParams, - } + }) })({ canAutoUpdate({ oldParams, newParams }) { return true; diff --git a/src/mol-plugin/behavior/dynamic/custom-props/structure-info.ts b/src/mol-plugin/behavior/dynamic/custom-props/structure-info.ts index 99f51da2ffdf67229840e60df68048bd02d399ca..469fca3463ec3e26164cb77ffec055deb2c0510e 100644 --- a/src/mol-plugin/behavior/dynamic/custom-props/structure-info.ts +++ b/src/mol-plugin/behavior/dynamic/custom-props/structure-info.ts @@ -4,7 +4,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import { PluginBehavior } from '../../../behavior'; +import { PluginBehavior } from '../../../behavior/behavior'; import { Structure, Model } from '../../../../mol-model/structure'; import { PluginStateObject } from '../../../../mol-plugin-state/objects'; import { StateSelection, StateObject } from '../../../../mol-state'; diff --git a/src/mol-plugin/index.ts b/src/mol-plugin/index.ts index 5556db6c76b39a5d2da480bd0f2896eb87caa8a5..019ead6aaa8e56193f4d16b662974f7ddbbb0694 100644 --- a/src/mol-plugin/index.ts +++ b/src/mol-plugin/index.ts @@ -22,7 +22,7 @@ import { AnimateAssemblyUnwind } from '../mol-plugin-state/animation/built-in/as import { AnimateCameraSpin } from '../mol-plugin-state/animation/built-in/camera-spin'; import { AnimateStateSnapshots } from '../mol-plugin-state/animation/built-in/state-snapshots'; -export const DefaultPluginSpec: PluginSpec = { +export const DefaultPluginSpec = (): PluginSpec => ({ actions: [ PluginSpec.Action(StateActions.Structure.DownloadStructure), PluginSpec.Action(StateActions.Structure.AddTrajectory), @@ -93,10 +93,10 @@ export const DefaultPluginSpec: PluginSpec = { AnimateStateSnapshots, AnimateAssemblyUnwind ] -}; +}); export function createPlugin(target: HTMLElement, spec?: PluginSpec): PluginContext { - const ctx = new PluginContext(spec || DefaultPluginSpec); + const ctx = new PluginContext(spec || DefaultPluginSpec()); ctx.init(); ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target); return ctx; @@ -104,7 +104,7 @@ export function createPlugin(target: HTMLElement, spec?: PluginSpec): PluginCont /** Returns the instance of the plugin after all behaviors have been initialized */ export async function createPluginAsync(target: HTMLElement, spec?: PluginSpec) { - const ctx = new PluginContext(spec || DefaultPluginSpec); + const ctx = new PluginContext(spec || DefaultPluginSpec()); const init = ctx.init(); ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target); await init; diff --git a/src/mol-repr/structure/visual/bond-inter-unit-line.ts b/src/mol-repr/structure/visual/bond-inter-unit-line.ts index 946714ab1a1bcbdf17e6de81d3f20efb453542ad..45135f338339e4129d5493fbf9ce821bff2e7d3a 100644 --- a/src/mol-repr/structure/visual/bond-inter-unit-line.ts +++ b/src/mol-repr/structure/visual/bond-inter-unit-line.ts @@ -29,9 +29,6 @@ function setRefPosition(pos: Vec3, structure: Structure, unit: Unit.Atomic, inde return null; } -const tmpRef = Vec3(); -const tmpLoc = StructureElement.Location.create(void 0); - function createInterUnitBondLines(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<InterUnitBondLineParams>, lines?: Lines) { const bonds = structure.interUnitBonds; const { edgeCount, edges } = bonds; @@ -39,6 +36,9 @@ function createInterUnitBondLines(ctx: VisualContext, structure: Structure, them if (!edgeCount) return Lines.createEmpty(lines); + const ref = Vec3(); + const loc = StructureElement.Location.create(); + const builderProps = { linkCount: edgeCount, referencePosition: (edgeIndex: number) => { @@ -58,7 +58,7 @@ function createInterUnitBondLines(ctx: VisualContext, structure: Structure, them } else { throw new Error('same units in createInterUnitBondLines'); } - return setRefPosition(tmpRef, structure, unitA, indexA) || setRefPosition(tmpRef, structure, unitB, indexB); + return setRefPosition(ref, structure, unitA, indexA) || setRefPosition(ref, structure, unitB, indexB); }, position: (posA: Vec3, posB: Vec3, edgeIndex: number) => { const b = edges[edgeIndex]; @@ -83,13 +83,13 @@ function createInterUnitBondLines(ctx: VisualContext, structure: Structure, them }, radius: (edgeIndex: number) => { const b = edges[edgeIndex]; - tmpLoc.structure = structure; - tmpLoc.unit = structure.unitMap.get(b.unitA); - tmpLoc.element = tmpLoc.unit.elements[b.indexA]; - const sizeA = theme.size.size(tmpLoc); - tmpLoc.unit = structure.unitMap.get(b.unitB); - tmpLoc.element = tmpLoc.unit.elements[b.indexB]; - const sizeB = theme.size.size(tmpLoc); + loc.structure = structure; + loc.unit = structure.unitMap.get(b.unitA); + loc.element = loc.unit.elements[b.indexA]; + const sizeA = theme.size.size(loc); + loc.unit = structure.unitMap.get(b.unitB); + loc.element = loc.unit.elements[b.indexB]; + const sizeB = theme.size.size(loc); return Math.min(sizeA, sizeB) * sizeFactor; }, ignore: makeInterBondIgnoreTest(structure, props)