Skip to content

Commit

Permalink
add dashedBonds and dashedBondConfig settings
Browse files Browse the repository at this point in the history
  • Loading branch information
dxdc committed Nov 1, 2023
1 parent c8137ac commit 5e4bd76
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/GLModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,12 @@ export class GLModel {
var doubleBondScale = style.doubleBondScaling || 0.4;
var tripleBondScale = style.tripleBondScaling || 0.25;

var bondDashLength = style.dashedBondConfig?.dashLength || 0.1;
var bondGapLength = style.dashedBondConfig?.gapLength || 0.25;

var bondR = atomBondR;
var atomSingleBond = style.singleBonds || false;
var atomDashedBonds = style.dashedBonds || false;
var fromCap = 0, toCap = 0;
var atomneedsi, atom2needsi, i, singleBond, bstyle;
var cylinder1a, cylinder1b, cylinder1c, cylinder2a, cylinder2b, cylinder2c;
Expand All @@ -787,7 +791,7 @@ export class GLModel {
fromCap = 2;

var selectCylDrawMethod = function (bondOrder) {
if (geo.imposter) return (bondOrder < 1) ? GLModel.drawDashedStickImposter : GLModel.drawStickImposter;
if (geo.imposter) return (atomDashedBonds || bondOrder < 1) ? GLModel.drawDashedStickImposter : GLModel.drawStickImposter;

return GLDraw.drawCylinder; //mesh cylinder
};
Expand Down Expand Up @@ -837,10 +841,10 @@ export class GLModel {
if (C1 != C2) {
mp = new Vector3().addVectors(p1, p2)
.multiplyScalar(0.5);
drawCyl(geo, p1, mp, bondR, C1, fromCap, 0);
drawCyl(geo, mp, p2, bondR, C2, 0, toCap);
drawCyl(geo, p1, mp, bondR, C1, fromCap, 0, bondDashLength, bondGapLength);
drawCyl(geo, mp, p2, bondR, C2, 0, toCap, bondDashLength, bondGapLength);
} else {
drawCyl(geo, p1, p2, bondR, C1, fromCap, toCap);
drawCyl(geo, p1, p2, bondR, C1, fromCap, toCap, bondDashLength, bondGapLength);
}


Expand Down Expand Up @@ -2908,6 +2912,15 @@ export interface CrossStyleSpec {
opacity?: number;
}

/** Dashed Bond style specification
*/
export interface DashedBondSpec {
/** length of dash (default 0.1) */
dashLength?: number;
/** length of gap (default 0.25) */
gapLength?: number;
}

/** Stick (cylinder) style specification
*/
export interface StickStyleSpec {
Expand All @@ -2919,6 +2932,10 @@ export interface StickStyleSpec {
doubleBondScaling?: number;
/** radius scaling factor for drawing triple bonds (default 0.25) */
tripleBondScaling?: number;
/** dashed bond properties */
dashedBondConfig?: DashedBondSpec;
/** draw all bonds as dashed bonds */
dashedBonds?: boolean;
/** draw all bonds as single bonds */
singleBonds?: boolean;
/** colorscheme to use on atoms; overrides color */
Expand Down
35 changes: 35 additions & 0 deletions tests/auto/tests/partialbonds3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

/*@div
<div style="width: 400px; height: 400px; position: relative;"
class='viewer_3Dmoljs'
data-element='moldata'
data-backgroundcolor='0xffffff'
data-style='{"stick":{"dashedBonds": true, "dashedBondConfig": { "dashLength": 0.01, "gapLength": 0.05 }}}'
data-type="sdf"></div>
*/

/*
@data
<textarea style="display: none;" id="moldata">
Molecule002
Mrv1903 01162316393D
6 5 0 0 0 0 999 V2000
0.4761 0.1839 -0.9563 H 0 0 0 0 0 0 0 0 0 0 0 0
0.1475 -0.2251 0.0075 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.8612 -0.6549 0.0499 H 0 0 0 0 0 0 0 0 0 0 0 0
0.5167 0.2726 0.9131 H 0 0 0 0 0 0 0 0 0 0 0 0
1.3194 -2.0204 0.0676 Cl 0 0 0 0 0 0 0 0 0 0 0 0
-1.5985 2.4439 -0.0818 Br 0 0 0 0 0 0 0 0 0 0 0 0
1 2 8 0 0 0 0
2 4 8 0 0 0 0
2 3 8 0 0 0 0
2 6 0.5 0 0 0 0
2 5 0.03 0 0 0 0
M END
> <anyBondsFromCoords>
true
$$$$
</textarea>
*/
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 5e4bd76

Please sign in to comment.