Browse Source

improved atomicDetail preset

Alexander Rose 4 years ago
parent
commit
e1b830a59d

+ 2 - 2
src/mol-model-formats/structure/property/bonds/struct_conn.ts

@@ -56,9 +56,9 @@ export namespace StructConn {
      * Heuristic to test if StructConn likely provides all atomic bonds by
      * checking if the fraction of bonds and atoms is high (> 0.95).
      */
-    export function isExhaustive(model: Model) {
+    export function isExhaustive(model: Model): boolean {
         const structConn = StructConn.Provider.get(model);
-        return structConn && (structConn.data.id.rowCount / model.atomicConformation.atomId.rowCount) > 0.95;
+        return !!structConn && (structConn.data.id.rowCount / model.atomicConformation.atomId.rowCount) > 0.95;
     }
 
     function hasAtom({ units }: Structure, element: ElementIndex) {

+ 10 - 4
src/mol-plugin-state/builder/structure/representation-preset.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
@@ -20,6 +20,8 @@ import { StructureFocusRepresentation } from '../../../mol-plugin/behavior/dynam
 import { createStructureColorThemeParams } from '../../helpers/structure-representation-params';
 import { ChainIdColorThemeProvider } from '../../../mol-theme/color/chain-id';
 import { OperatorNameColorThemeProvider } from '../../../mol-theme/color/operator-name';
+import { IndexPairBonds } from '../../../mol-model-formats/structure/property/bonds/index-pair';
+import { StructConn } from '../../../mol-model-formats/structure/property/bonds/struct_conn';
 
 export interface StructureRepresentationPresetProvider<P = any, S extends _Result = _Result> extends PresetProvider<PluginStateObject.Molecule.Structure, P, S> { }
 export function StructureRepresentationPresetProvider<P, S extends _Result>(repr: StructureRepresentationPresetProvider<P, S>) { return repr; }
@@ -332,8 +334,12 @@ const atomicDetail = StructureRepresentationPresetProvider({
             structure.elementCount > 1000 &&
             structure.atomicResidueCount / structure.elementCount < 3;
 
-        const atomicType = lowResidueElementRatio ? 'spacefill' :
-            highElementCount ? 'line' : 'ball-and-stick';
+        const m = structure.models[0];
+        const bondsGiven = !!IndexPairBonds.Provider.get(m) || StructConn.isExhaustive(m);
+
+        const atomicType = lowResidueElementRatio && !bondsGiven
+            ? 'spacefill' : highElementCount
+                ? 'line' : 'ball-and-stick';
         const showCarbohydrateSymbol = params.showCarbohydrateSymbol && !highElementCount && !lowResidueElementRatio;
 
         if (showCarbohydrateSymbol) {
@@ -343,7 +349,7 @@ const atomicDetail = StructureRepresentationPresetProvider({
         }
 
         const { update, builder, typeParams, color, ballAndStickColor } = reprBuilder(plugin, params, structure);
-        const colorParams = lowResidueElementRatio
+        const colorParams = lowResidueElementRatio && !bondsGiven
             ? { carbonColor: { name: 'element-symbol', params: {} } }
             : ballAndStickColor;