Skip to content

Commit

Permalink
Few tweaks - mostly scale as a global parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ceriottm committed Sep 20, 2023
1 parent e4c38c7 commit a61f3c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
20 changes: 12 additions & 8 deletions src/structure/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface XYZ {
export interface BaseShapeData {
position: [number, number, number];
orientation?: [number, number, number, number];
scale?: number;
color?: ColorSpec;
}

Expand Down Expand Up @@ -158,13 +159,16 @@ 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<SphereData>) {
const [qx, qy, qz, qw] = data.orientation || [0, 0, 0, 1];
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
Expand Down Expand Up @@ -265,8 +269,8 @@ export class Sphere extends Shape {
public radius: number;

constructor(data: Partial<SphereData>) {
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, unknown>): string {
Expand Down Expand Up @@ -321,7 +325,7 @@ export class Ellipsoid extends Shape {
constructor(data: Partial<EllipsoidData>) {
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, unknown>): string {
Expand Down Expand Up @@ -481,10 +485,10 @@ export class Arrow extends Shape {
constructor(data: Partial<ArrowData>) {
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, unknown>): string {
Expand Down Expand Up @@ -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;
}
Expand Down
22 changes: 0 additions & 22 deletions src/structure/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a61f3c4

Please sign in to comment.