Skip to content

Commit

Permalink
Add support for custom scaling of double/triple bonds
Browse files Browse the repository at this point in the history
Addresses Issue #732
  • Loading branch information
dkoes committed Oct 20, 2023
1 parent 5d58638 commit ea353d2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/GLModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@ export class GLModel {
return;

var atomBondR = style.radius || this.defaultStickRadius;
var doubleBondScale = style.doubleBondScaling || 0.4;
var tripleBondScale = style.tripleBondScaling || 0.25;

var bondR = atomBondR;
var atomSingleBond = style.singleBonds || false;
var fromCap = 0, toCap = 0;
Expand Down Expand Up @@ -839,7 +842,7 @@ export class GLModel {
v = this.getSideBondV(atom, atom2, i);

if (atom.bondOrder[i] == 2) {
r = bondR / 2.5;
r = bondR * doubleBondScale;

v.multiplyScalar(r * 1.5);
p1a = p1.clone();
Expand Down Expand Up @@ -889,7 +892,7 @@ export class GLModel {
}
}
else if (atom.bondOrder[i] == 3) {
r = bondR / 4;
r = bondR * tripleBondScale;
v.cross(dir);
v.normalize();
v.multiplyScalar(r * 3);
Expand Down Expand Up @@ -2872,6 +2875,10 @@ export interface StickStyleSpec {
hidden?: boolean;
/** radius of stick */
radius?: number;
/** radius scaling factor for drawing double bonds (default 0.4) */
doubleBondScaling?: number;
/** radius scaling factor for drawing triple bonds (default 0.25) */
tripleBondScaling?: number;
/** draw all bonds as single bonds */
singleBonds?: boolean;
/** colorscheme to use on atoms; overrides color */
Expand Down
2 changes: 1 addition & 1 deletion src/GLShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ export class GLShape {

boundingSphere: Sphere;
intersectionShape: any;
color: any;
color: any = 0xffffff;
hidden = false;
wireframe = false;
opacity = 1;
Expand Down
6 changes: 6 additions & 0 deletions tests/auto/tests/bondscaling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$3Dmol.download("cid:10321", viewer, {}, function () {
viewer.setStyle({stick:{doubleBondScaling: 1, tripleBondScaling: 0.5}});

viewer.zoomTo();
viewer.render();
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ea353d2

Please sign in to comment.