From a61ba71f1e137f755d3bbfa6614adb2407150aba Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Mon, 30 Sep 2019 12:11:07 -0700
Subject: [PATCH] handle mixed sizes in link visuals

---
 src/mol-repr/structure/representation/ball-and-stick.ts   | 4 ++--
 src/mol-repr/structure/visual/inter-unit-link-cylinder.ts | 6 +++++-
 src/mol-repr/structure/visual/intra-unit-link-cylinder.ts | 5 ++++-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts
index 570973184..7a081a09a 100644
--- a/src/mol-repr/structure/representation/ball-and-stick.ts
+++ b/src/mol-repr/structure/representation/ball-and-stick.ts
@@ -29,7 +29,7 @@ export const BallAndStickParams = {
     ...IntraUnitLinkParams,
     ...InterUnitLinkParams,
     unitKinds: PD.MultiSelect<UnitKind>(['atomic'], UnitKindOptions),
-    sizeFactor: PD.Numeric(0.3, { min: 0.01, max: 10, step: 0.01 }),
+    sizeFactor: PD.Numeric(0.2, { min: 0.01, max: 10, step: 0.01 }),
     sizeAspectRatio: PD.Numeric(2/3, { min: 0.01, max: 3, step: 0.01 }),
     visuals: PD.MultiSelect<BallAndStickVisualName>(['element-sphere', 'intra-link', 'inter-link'], BallAndStickVisualOptions),
 }
@@ -50,6 +50,6 @@ export const BallAndStickRepresentationProvider: StructureRepresentationProvider
     getParams: getBallAndStickParams,
     defaultValues: PD.getDefaultValues(BallAndStickParams),
     defaultColorTheme: 'element-symbol',
-    defaultSizeTheme: 'uniform',
+    defaultSizeTheme: 'physical',
     isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts
index 2ca73dfc0..fdfdfbde2 100644
--- a/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts
+++ b/src/mol-repr/structure/visual/inter-unit-link-cylinder.ts
@@ -43,7 +43,11 @@ function createInterUnitLinkCylinderMesh(ctx: VisualContext, structure: Structur
             const b = bonds[edgeIndex]
             location.unit = b.unitA
             location.element = b.unitA.elements[b.indexA]
-            return theme.size.size(location) * sizeFactor * sizeAspectRatio
+            const sizeA = theme.size.size(location)
+            location.unit = b.unitB
+            location.element = b.unitB.elements[b.indexB]
+            const sizeB = theme.size.size(location)
+            return Math.min(sizeA, sizeB) * sizeFactor * sizeAspectRatio
         },
         ignore: ignoreHydrogens ? (edgeIndex: number) => {
             const b = bonds[edgeIndex]
diff --git a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts
index 611ea6858..fb8b8ec43 100644
--- a/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts
+++ b/src/mol-repr/structure/visual/intra-unit-link-cylinder.ts
@@ -63,7 +63,10 @@ function createIntraUnitLinkCylinderMesh(ctx: VisualContext, unit: Unit, structu
         flags: (edgeIndex: number) => BitFlags.create(_flags[edgeIndex]),
         radius: (edgeIndex: number) => {
             location.element = elements[a[edgeIndex]]
-            return theme.size.size(location) * sizeFactor * sizeAspectRatio
+            const sizeA = theme.size.size(location)
+            location.element = elements[b[edgeIndex]]
+            const sizeB = theme.size.size(location)
+            return Math.min(sizeA, sizeB) * sizeFactor * sizeAspectRatio
         },
         ignore: ignoreHydrogens ? (edgeIndex: number) => {
             return isHydrogen(unit, elements[a[edgeIndex]]) || isHydrogen(unit, elements[b[edgeIndex]])
-- 
GitLab