From a61f3c401df03584fc85ce6b5518fc5ce50953e6 Mon Sep 17 00:00:00 2001 From: Michele Ceriotti Date: Wed, 20 Sep 2023 14:06:54 -0700 Subject: [PATCH] Few tweaks - mostly scale as a global parameter --- src/structure/shapes.ts | 20 ++++++++++++-------- src/structure/viewer.ts | 22 ---------------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/structure/shapes.ts b/src/structure/shapes.ts index 91e9b8adf..31357b931 100644 --- a/src/structure/shapes.ts +++ b/src/structure/shapes.ts @@ -27,6 +27,7 @@ export interface XYZ { export interface BaseShapeData { position: [number, number, number]; orientation?: [number, number, number, number]; + scale?: number; color?: ColorSpec; } @@ -158,6 +159,8 @@ export class Shape { public position: XYZ; /// orientation of the particle public orientation: Quaternion; + /// scaling factor + public scale: number; // orientation is passed to 3dmol in the (x, y, z, w) convention constructor(data: Partial) { @@ -165,6 +168,7 @@ export class Shape { this.orientation = new Quaternion(qx, qy, qz, qw); const [x, y, z] = data.position || [0, 0, 0]; this.position = { x, y, z }; + this.scale = data.scale || 1.0; } // disabling eslint because it complains parameters is never used @@ -265,8 +269,8 @@ export class Sphere extends Shape { public radius: number; constructor(data: Partial) { - super({ position: data.position }); - this.radius = data.radius || 1.0; + super(data); + this.radius = (data.radius || 1.0) * this.scale; } public static validateParameters(parameters: Record): string { @@ -321,7 +325,7 @@ export class Ellipsoid extends Shape { constructor(data: Partial) { super(data); assert(data.semiaxes); - this.semiaxes = data.semiaxes; + this.semiaxes = [ this.scale * data.semiaxes[0], this.scale * data.semiaxes[1], this.scale * data.semiaxes[2] ]; } public static validateParameters(parameters: Record): string { @@ -481,10 +485,10 @@ export class Arrow extends Shape { constructor(data: Partial) { super(data); assert(data.vector); - this.vector = data.vector; - this.base_radius = data.base_radius || 0.1; - this.head_radius = data.head_radius || 0.15; - this.head_length = data.head_length || 0.2; + this.vector = [this.scale*data.vector[0], this.scale*data.vector[1], this.scale*data.vector[2] ]; + this.base_radius = this.scale*(data.base_radius || 0.1); + this.head_radius = this.scale*(data.head_radius || 0.15); + this.head_length = this.scale*(data.head_length || 0.2); } public static validateParameters(parameters: Record): string { @@ -548,7 +552,7 @@ export class CustomShape extends Shape { this.vertices = []; for (const v of data.vertices) { - this.vertices.push({ x: v[0], y: v[1], z: v[2] }); + this.vertices.push({ x: v[0]*this.scale, y: v[1]*this.scale, z: v[2]*this.scale }); } this.simplices = data.simplices; } diff --git a/src/structure/viewer.ts b/src/structure/viewer.ts index 6accf4987..a6d3f70e8 100644 --- a/src/structure/viewer.ts +++ b/src/structure/viewer.ts @@ -1003,28 +1003,6 @@ export class MoleculeViewer { shape.outputTo3Dmol(shape_data.color || 0xffffff) ); } - /* - if (current_shape[i].kind === 'ellipsoid') { - const data = current_shape[i] as unknown as EllipsoidData; - const shape = new Ellipsoid(position, data); - this._viewer.addCustom( - shape.outputTo3Dmol($3Dmol.elementColors.Jmol[name] || 0x000000) - ); - } else if (current_shape[i].kind === 'custom') { - const data = current_shape[i] as unknown as CustomShapeData; - const shape = new CustomShape(position, data); - this._viewer.addCustom( - shape.outputTo3Dmol($3Dmol.elementColors.Jmol[name] || 0x000000) - ); - } else { - assert(current_shape[i].kind === 'sphere'); - const data = current_shape[i] as unknown as SphereData; - const shape = new Sphere(position, data); - this._viewer.addCustom( - shape.outputTo3Dmol($3Dmol.elementColors.Jmol[name] || 0x000000) - ); - } - */ } } else { // the shape is defined only at the structure level