Browse Source

structure size and quality threshold improvements

Alexander Rose 5 years ago
parent
commit
8833474a43

+ 12 - 9
src/mol-model/structure/structure/structure.ts

@@ -1014,14 +1014,17 @@ namespace Structure {
 
     //
 
-    const DefaultSizeThresholds = {
+    export const DefaultSizeThresholds = {
         smallResidueCount: 10,
-        mediumResidueCount: 1500,
-        largeResidueCount: 12000,
+        mediumResidueCount: 3000,
+        /** large ribosomes like 4UG0 should still be `large` */
+        largeResidueCount: 20000,
         highSymmetryUnitCount: 10,
-        fiberResidueCount: 15
+        fiberResidueCount: 15,
+
+        residueCountFactor: 1
     }
-    type SizeThresholds = typeof DefaultSizeThresholds
+    export type SizeThresholds = typeof DefaultSizeThresholds
 
     function getPolymerSymmetryGroups(structure: Structure) {
         return structure.unitSymmetryGroups.filter(ug => ug.units[0].polymerElements.length > 0)
@@ -1050,8 +1053,8 @@ namespace Structure {
     export enum Size { Small, Medium, Large, Huge, Gigantic }
 
     export function getSize(structure: Structure, thresholds: Partial<SizeThresholds> = {}): Size {
-        const t = { ...DefaultSizeThresholds, thresholds }
-        if (structure.polymerResidueCount >= t.largeResidueCount) {
+        const t = { ...DefaultSizeThresholds, ...thresholds }
+        if (structure.polymerResidueCount >= t.largeResidueCount * t.residueCountFactor) {
             if (hasHighSymmetry(structure, t)) {
                 return Size.Huge
             } else {
@@ -1059,9 +1062,9 @@ namespace Structure {
             }
         } else if (isFiberLike(structure, t)) {
             return Size.Small
-        } else if (structure.polymerResidueCount < t.smallResidueCount) {
+        } else if (structure.polymerResidueCount < t.smallResidueCount * t.residueCountFactor) {
             return Size.Small
-        } else if (structure.polymerResidueCount < t.mediumResidueCount) {
+        } else if (structure.polymerResidueCount < t.mediumResidueCount * t.residueCountFactor) {
             return Size.Medium
         } else {
             return Size.Large

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

@@ -15,6 +15,7 @@ import { PresetStructureRepresentations } from './representation-preset';
 import { PluginContext } from '../../../mol-plugin/context';
 import { Vec3 } from '../../../mol-math/linear-algebra';
 import { Model } from '../../../mol-model/structure';
+import { getStructureQuality } from '../../../mol-repr/util';
 
 export interface TrajectoryHierarchyPresetProvider<P = any, S = {}> extends PresetProvider<PluginStateObject.Molecule.Trajectory, P, S> { }
 export function TrajectoryHierarchyPresetProvider<P, S>(preset: TrajectoryHierarchyPresetProvider<P, S>) { return preset; }
@@ -91,7 +92,9 @@ const allModels = TrajectoryHierarchyPresetProvider({
 
             models.push(model);
             structures.push(structure);
-            await builder.representation.applyPreset(structureProperties, params.representationPreset || 'auto', { globalThemeName: 'model-index', quality: 'medium' });
+
+            const quality = structure.obj ? getStructureQuality(structure.obj.data, { elementCountFactor: tr.length }) : 'medium'
+            await builder.representation.applyPreset(structureProperties, params.representationPreset || 'auto', { globalThemeName: 'model-index', quality });
         }
 
         return { models, structures };

+ 21 - 8
src/mol-repr/util.ts

@@ -53,18 +53,31 @@ export interface QualityProps {
     doubleSided: boolean
 }
 
-export function getStructureQuality(structure: Structure): VisualQuality {
-    let score = structure.elementCount
-    if (structure.isCoarseGrained) score *= 10
-    if (score > 500_000) {
+export const DefaultQualityThresholds = {
+    lowestElementCount: 500_000,
+    lowerElementCount: 200_000,
+    lowElementCount: 60_000,
+    mediumElementCount: 20_000,
+    highElementCount: 2_000,
+    coarseGrainedFactor: 10,
+
+    elementCountFactor: 1
+}
+export type QualityThresholds = typeof DefaultQualityThresholds
+
+export function getStructureQuality(structure: Structure, tresholds: Partial<QualityThresholds> = {}): VisualQuality {
+    const t = { ...DefaultQualityThresholds, ...tresholds }
+    let score = structure.elementCount * t.elementCountFactor
+    if (structure.isCoarseGrained) score *= t.coarseGrainedFactor
+    if (score > t.lowestElementCount) {
         return 'lowest'
-    } else if (score > 200_000) {
+    } else if (score > t.lowerElementCount) {
         return 'lower'
-    } else if (score > 60_000) {
+    } else if (score > t.lowElementCount) {
         return 'low'
-    } else if (score > 20_000) {
+    } else if (score > t.mediumElementCount) {
         return 'medium'
-    } else if (score > 2_000) {
+    } else if (score > t.highElementCount) {
         return 'high'
     } else {
         return 'higher'