Browse Source

added PluginConfig.Structure.SizeThresholds

Alexander Rose 4 years ago
parent
commit
1448f7aeb6

+ 16 - 7
src/mol-model/structure/structure/structure.ts

@@ -1057,14 +1057,19 @@ namespace Structure {
     //
 
     export const DefaultSizeThresholds = {
+        /** Must be lower to be small */
         smallResidueCount: 10,
+        /** Must be lower to be medium */
         mediumResidueCount: 3000,
-        /** large ribosomes like 4UG0 should still be `large` */
+        /** Must be lower to be large (big ribosomes like 4UG0 should still be `large`) */
         largeResidueCount: 20000,
+        /**
+         * Structures above `largeResidueCount` are consider huge when they have
+         * a `highSymmetryUnitCount` or gigantic when not
+         */
         highSymmetryUnitCount: 10,
+        /** Fiber-like structure are consider small when below this */
         fiberResidueCount: 15,
-
-        residueCountFactor: 1
     };
     export type SizeThresholds = typeof DefaultSizeThresholds
 
@@ -1094,9 +1099,13 @@ namespace Structure {
 
     export enum Size { Small, Medium, Large, Huge, Gigantic }
 
-    export function getSize(structure: Structure, thresholds: Partial<SizeThresholds> = {}): Size {
+    /**
+     * @param residueCountFactor - modifies the threshold counts, useful when estimating
+     *                             the size of a structure comprised of multiple models
+     */
+    export function getSize(structure: Structure, thresholds: Partial<SizeThresholds> = {}, residueCountFactor = 1): Size {
         const t = { ...DefaultSizeThresholds, ...thresholds };
-        if (structure.polymerResidueCount >= t.largeResidueCount * t.residueCountFactor) {
+        if (structure.polymerResidueCount >= t.largeResidueCount * residueCountFactor) {
             if (hasHighSymmetry(structure, t)) {
                 return Size.Huge;
             } else {
@@ -1104,9 +1113,9 @@ namespace Structure {
             }
         } else if (isFiberLike(structure, t)) {
             return Size.Small;
-        } else if (structure.polymerResidueCount < t.smallResidueCount * t.residueCountFactor) {
+        } else if (structure.polymerResidueCount < t.smallResidueCount * residueCountFactor) {
             return Size.Small;
-        } else if (structure.polymerResidueCount < t.mediumResidueCount * t.residueCountFactor) {
+        } else if (structure.polymerResidueCount < t.mediumResidueCount * residueCountFactor) {
             return Size.Medium;
         } else {
             return Size.Large;

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

@@ -15,6 +15,7 @@ import { PluginContext } from '../../../mol-plugin/context';
 import { StateObjectRef, StateObjectSelector } from '../../../mol-state';
 import { StaticStructureComponentType } from '../../helpers/structure-component';
 import { StructureSelectionQueries as Q } from '../../helpers/structure-selection-query';
+import { PluginConfig } from '../../../mol-plugin/config';
 
 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; }
@@ -64,7 +65,9 @@ const auto = StructureRepresentationPresetProvider({
     apply(ref, params, plugin) {
         const structure = StateObjectRef.resolveAndCheck(plugin.state.data, ref)?.obj?.data;
         if (!structure) return { };
-        const size = Structure.getSize(structure);
+
+        const thresholds = plugin.config.get(PluginConfig.Structure.SizeThresholds) || Structure.DefaultSizeThresholds;
+        const size = Structure.getSize(structure, thresholds);
 
         switch (size) {
             case Structure.Size.Gigantic:

+ 3 - 0
src/mol-plugin/config.ts

@@ -42,6 +42,9 @@ export const PluginConfig = {
     Download: {
         DefaultPdbProvider: item<PdbDownloadProvider>('download.default-pdb-provider', 'pdbe'),
         DefaultEmdbProvider: item<EmdbDownloadProvider>('download.default-emdb-provider', 'pdbe'),
+    },
+    Structure: {
+        SizeThresholds: item('structure.size-thresholds', Structure.DefaultSizeThresholds),
     }
 };