Jelajahi Sumber

added FormatRegistry.isApplicable and properly check AtomSiteAnisotrop

Alexander Rose 5 tahun lalu
induk
melakukan
ac45500e35

+ 14 - 2
src/mol-model-formats/structure/common/property.ts

@@ -8,19 +8,27 @@ import { CustomPropertyDescriptor, Model } from '../../../mol-model/structure';
 import { ModelFormat } from '../format';
 
 class FormatRegistry<T> {
-    map = new Map<ModelFormat['kind'], (model: Model) => T | undefined>()
+    private map = new Map<ModelFormat['kind'], (model: Model) => T | undefined>()
+    private applicable = new Map<ModelFormat['kind'], (model: Model) => boolean>()
 
-    add(kind: ModelFormat['kind'], obtain: (model: Model) => T | undefined) {
+    add(kind: ModelFormat['kind'], obtain: (model: Model) => T | undefined, applicable?: (model: Model) => boolean) {
         this.map.set(kind, obtain)
+        if (applicable) this.applicable.set(kind, applicable)
     }
 
     remove(kind: ModelFormat['kind']) {
         this.map.delete(kind)
+        this.applicable.delete(kind)
     }
 
     get(kind: ModelFormat['kind']) {
         return this.map.get(kind)
     }
+
+    isApplicable(model: Model) {
+        const isApplicable = this.applicable.get(model.sourceData.kind)
+        return isApplicable ? isApplicable(model) : true
+    }
 }
 
 export { FormatPropertyProvider as FormatPropertyProvider }
@@ -28,6 +36,7 @@ export { FormatPropertyProvider as FormatPropertyProvider }
 interface FormatPropertyProvider<T> {
     readonly descriptor: CustomPropertyDescriptor
     readonly formatRegistry: FormatRegistry<T>
+    isApplicable(model: Model): boolean
     get(model: Model): T | undefined
     set(model: Model, value: T): void
 }
@@ -40,6 +49,9 @@ namespace FormatPropertyProvider {
         return {
             descriptor,
             formatRegistry,
+            isApplicable(model: Model) {
+                return formatRegistry.isApplicable(model)
+            },
             get(model: Model): T | undefined {
                 if (model._staticPropertyData[name]) return model._staticPropertyData[name]
                 if (model.customProperties.has(descriptor)) return

+ 1 - 1
src/mol-repr/structure/representation/ellipsoid.ts

@@ -50,5 +50,5 @@ export const EllipsoidRepresentationProvider = StructureRepresentationProvider({
     defaultValues: PD.getDefaultValues(EllipsoidParams),
     defaultColorTheme: { name: 'element-symbol' },
     defaultSizeTheme: { name: 'uniform' },
-    isApplicable: (structure: Structure) => structure.elementCount > 0 && structure.models.some(m => m.customProperties.has(AtomSiteAnisotrop.Descriptor))
+    isApplicable: (structure: Structure) => structure.elementCount > 0 && structure.models.some(m => AtomSiteAnisotrop.Provider.isApplicable(m))
 })