Browse Source

improve preset for many polymer gaps

- show all atom instead
- for medium sized structures
- fixes #57
Alexander Rose 4 years ago
parent
commit
c57b9b9214

+ 19 - 0
src/mol-model/structure/structure/structure.ts

@@ -69,6 +69,7 @@ class Structure {
         uniqueElementCount: number,
         atomicResidueCount: number,
         polymerResidueCount: number,
+        polymerGapCount: number,
         polymerUnitCount: number,
         coordinateSystem: SymmetryOperator,
         label: string,
@@ -82,6 +83,7 @@ class Structure {
         uniqueElementCount: -1,
         atomicResidueCount: -1,
         polymerResidueCount: -1,
+        polymerGapCount: -1,
         polymerUnitCount: -1,
         coordinateSystem: SymmetryOperator.Default,
         label: ''
@@ -136,6 +138,14 @@ class Structure {
         return this._props.polymerResidueCount;
     }
 
+    /** Count of all polymer gaps in the structure */
+    get polymerGapCount() {
+        if (this._props.polymerGapCount === -1) {
+            this._props.polymerGapCount = getPolymerGapCount(this);
+        }
+        return this._props.polymerGapCount;
+    }
+
     get polymerUnitCount() {
         if (this._props.polymerUnitCount === -1) {
             this._props.polymerUnitCount = getPolymerUnitCount(this);
@@ -568,6 +578,15 @@ function getPolymerResidueCount(structure: Structure): number {
     return polymerResidueCount;
 }
 
+function getPolymerGapCount(structure: Structure): number {
+    const { units } = structure;
+    let polymerGapCount = 0;
+    for (let i = 0, _i = units.length; i < _i; i++) {
+        polymerGapCount += units[i].gapElements.length / 2;
+    }
+    return polymerGapCount;
+}
+
 function getPolymerUnitCount(structure: Structure): number {
     const { units } = structure;
     let polymerUnitCount = 0;

+ 9 - 2
src/mol-plugin-state/builder/structure/representation-preset.ts

@@ -23,6 +23,7 @@ import { OperatorNameColorThemeProvider } from '../../../mol-theme/color/operato
 import { IndexPairBonds } from '../../../mol-model-formats/structure/property/bonds/index-pair';
 import { StructConn } from '../../../mol-model-formats/structure/property/bonds/struct_conn';
 import { StructureRepresentationRegistry } from '../../../mol-repr/structure/registry';
+import { assertUnreachable } from '../../../mol-util/type-helpers';
 
 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; }
@@ -111,6 +112,8 @@ const auto = StructureRepresentationPresetProvider({
         const thresholds = plugin.config.get(PluginConfig.Structure.SizeThresholds) || Structure.DefaultSizeThresholds;
         const size = Structure.getSize(structure, thresholds);
 
+        const gapFraction = structure.polymerResidueCount / structure.polymerGapCount;
+
         switch (size) {
             case Structure.Size.Gigantic:
             case Structure.Size.Huge:
@@ -118,10 +121,14 @@ const auto = StructureRepresentationPresetProvider({
             case Structure.Size.Large:
                 return polymerCartoon.apply(ref, params, plugin);
             case Structure.Size.Medium:
-                return polymerAndLigand.apply(ref, params, plugin);
+                if (gapFraction > 3) {
+                    return polymerAndLigand.apply(ref, params, plugin);
+                } // else fall through
             case Structure.Size.Small:
-                // `showCarbohydrateSymbol: true` is nice e.g. for PDB 1aga
+                // `showCarbohydrateSymbol: true` is nice, e.g., for PDB 1aga
                 return atomicDetail.apply(ref, { ...params, showCarbohydrateSymbol: true }, plugin);
+            default:
+                assertUnreachable(size);
         }
     }
 });