From 1e9e41754a7f1f58571aa4e372d78d894a0e7bce Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Mon, 12 Aug 2019 16:46:48 -0700
Subject: [PATCH] added isApplicable support to representation provider &
 registry

---
 .../representations/assembly-symmetry-axes.ts   |  3 ++-
 src/mol-repr/representation.ts                  | 17 ++++++++++++++---
 .../structure/representation/ball-and-stick.ts  |  3 ++-
 .../structure/representation/carbohydrate.ts    |  3 ++-
 .../structure/representation/cartoon.ts         |  3 ++-
 .../representation/distance-restraint.ts        |  3 ++-
 .../representation/gaussian-surface.ts          |  3 ++-
 .../structure/representation/gaussian-volume.ts |  3 ++-
 .../representation/molecular-surface.ts         |  3 ++-
 src/mol-repr/structure/representation/point.ts  |  3 ++-
 src/mol-repr/structure/representation/putty.ts  |  3 ++-
 .../structure/representation/spacefill.ts       |  3 ++-
 src/mol-repr/volume/direct-volume.ts            |  3 ++-
 src/mol-repr/volume/isosurface.ts               |  3 ++-
 14 files changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts b/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts
index d3f8c3816..88b7fa39b 100644
--- a/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts
+++ b/src/mol-model-props/rcsb/representations/assembly-symmetry-axes.ts
@@ -54,7 +54,8 @@ export const AssemblySymmetryAxesRepresentationProvider: StructureRepresentation
     getParams: getAssemblySymmetryAxesParams,
     defaultValues: PD.getDefaultValues(AssemblySymmetryAxesParams),
     defaultColorTheme: 'uniform',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => AssemblySymmetry.get(structure.models[0]) !== undefined
 }
 
 //
diff --git a/src/mol-repr/representation.ts b/src/mol-repr/representation.ts
index 2926beefd..638d6f913 100644
--- a/src/mol-repr/representation.ts
+++ b/src/mol-repr/representation.ts
@@ -46,6 +46,7 @@ export interface RepresentationProvider<D, P extends PD.Params, S extends Repres
     readonly defaultValues: PD.Values<P>
     readonly defaultColorTheme: string
     readonly defaultSizeTheme: string
+    readonly isApplicable: (data: D) => boolean
 }
 
 export namespace RepresentationProvider {
@@ -66,15 +67,17 @@ export const EmptyRepresentationProvider = {
     defaultValues: {}
 }
 
+function getTypes(list: { name: string, provider: RepresentationProvider<any, any, any> }[]) {
+    return list.map(e => [e.name, e.provider.label] as [string, string]);
+}
+
 export class RepresentationRegistry<D, S extends Representation.State> {
     private _list: { name: string, provider: RepresentationProvider<D, any, any> }[] = []
     private _map = new Map<string, RepresentationProvider<D, any, any>>()
     private _name = new Map<RepresentationProvider<D, any, any>, string>()
 
     get default() { return this._list[0]; }
-    get types(): [string, string][] {
-        return this._list.map(e => [e.name, e.provider.label] as [string, string]);
-    }
+    get types(): [string, string][] { return getTypes(this._list) }
 
     constructor() {};
 
@@ -105,6 +108,14 @@ export class RepresentationRegistry<D, S extends Representation.State> {
     get list() {
         return this._list
     }
+
+    getApplicableList(data: D) {
+        return this._list.filter(e => e.provider.isApplicable(data));
+    }
+
+    getApplicableTypes(data: D) {
+        return getTypes(this.getApplicableList(data))
+    }
 }
 
 //
diff --git a/src/mol-repr/structure/representation/ball-and-stick.ts b/src/mol-repr/structure/representation/ball-and-stick.ts
index 324fb6eff..570973184 100644
--- a/src/mol-repr/structure/representation/ball-and-stick.ts
+++ b/src/mol-repr/structure/representation/ball-and-stick.ts
@@ -50,5 +50,6 @@ export const BallAndStickRepresentationProvider: StructureRepresentationProvider
     getParams: getBallAndStickParams,
     defaultValues: PD.getDefaultValues(BallAndStickParams),
     defaultColorTheme: 'element-symbol',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/carbohydrate.ts b/src/mol-repr/structure/representation/carbohydrate.ts
index a36b8e7ec..ad1af619a 100644
--- a/src/mol-repr/structure/representation/carbohydrate.ts
+++ b/src/mol-repr/structure/representation/carbohydrate.ts
@@ -45,5 +45,6 @@ export const CarbohydrateRepresentationProvider: StructureRepresentationProvider
     getParams: getCarbohydrateParams,
     defaultValues: PD.getDefaultValues(CarbohydrateParams),
     defaultColorTheme: 'carbohydrate-symbol',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.carbohydrates.elements.length > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/cartoon.ts b/src/mol-repr/structure/representation/cartoon.ts
index e315ea78a..66df27a1f 100644
--- a/src/mol-repr/structure/representation/cartoon.ts
+++ b/src/mol-repr/structure/representation/cartoon.ts
@@ -62,5 +62,6 @@ export const CartoonRepresentationProvider: StructureRepresentationProvider<Cart
     getParams: getCartoonParams,
     defaultValues: PD.getDefaultValues(CartoonParams),
     defaultColorTheme: 'polymer-id',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.polymerResidueCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/distance-restraint.ts b/src/mol-repr/structure/representation/distance-restraint.ts
index 40788e2c9..045d5ae9d 100644
--- a/src/mol-repr/structure/representation/distance-restraint.ts
+++ b/src/mol-repr/structure/representation/distance-restraint.ts
@@ -38,5 +38,6 @@ export const DistanceRestraintRepresentationProvider: StructureRepresentationPro
     getParams: getDistanceRestraintParams,
     defaultValues: PD.getDefaultValues(DistanceRestraintParams),
     defaultColorTheme: 'cross-link',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.crossLinkRestraints.count > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/gaussian-surface.ts b/src/mol-repr/structure/representation/gaussian-surface.ts
index 41711eeb7..556ec3271 100644
--- a/src/mol-repr/structure/representation/gaussian-surface.ts
+++ b/src/mol-repr/structure/representation/gaussian-surface.ts
@@ -43,5 +43,6 @@ export const GaussianSurfaceRepresentationProvider: StructureRepresentationProvi
     getParams: getGaussianSurfaceParams,
     defaultValues: PD.getDefaultValues(GaussianSurfaceParams),
     defaultColorTheme: 'polymer-id',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/gaussian-volume.ts b/src/mol-repr/structure/representation/gaussian-volume.ts
index caf0913b4..ef661a587 100644
--- a/src/mol-repr/structure/representation/gaussian-volume.ts
+++ b/src/mol-repr/structure/representation/gaussian-volume.ts
@@ -35,5 +35,6 @@ export const GaussianVolumeRepresentationProvider: StructureRepresentationProvid
     getParams: getGaussianVolumeParams,
     defaultValues: PD.getDefaultValues(GaussianVolumeParams),
     defaultColorTheme: 'polymer-id',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/molecular-surface.ts b/src/mol-repr/structure/representation/molecular-surface.ts
index 2a0c6ecc4..6bac83915 100644
--- a/src/mol-repr/structure/representation/molecular-surface.ts
+++ b/src/mol-repr/structure/representation/molecular-surface.ts
@@ -39,5 +39,6 @@ export const MolecularSurfaceRepresentationProvider: StructureRepresentationProv
     getParams: getMolecularSurfaceParams,
     defaultValues: PD.getDefaultValues(MolecularSurfaceParams),
     defaultColorTheme: 'polymer-id',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/point.ts b/src/mol-repr/structure/representation/point.ts
index 64157d4c9..c9aec2913 100644
--- a/src/mol-repr/structure/representation/point.ts
+++ b/src/mol-repr/structure/representation/point.ts
@@ -38,5 +38,6 @@ export const PointRepresentationProvider: StructureRepresentationProvider<PointP
     getParams: getPointParams,
     defaultValues: PD.getDefaultValues(PointParams),
     defaultColorTheme: 'element-symbol',
-    defaultSizeTheme: 'physical'
+    defaultSizeTheme: 'physical',
+    isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/putty.ts b/src/mol-repr/structure/representation/putty.ts
index 4623077e4..1c5c2106b 100644
--- a/src/mol-repr/structure/representation/putty.ts
+++ b/src/mol-repr/structure/representation/putty.ts
@@ -52,5 +52,6 @@ export const PuttyRepresentationProvider: StructureRepresentationProvider<PuttyP
     getParams: getPuttyParams,
     defaultValues: PD.getDefaultValues(PuttyParams),
     defaultColorTheme: 'polymer-id',
-    defaultSizeTheme: 'uncertainty'
+    defaultSizeTheme: 'uncertainty',
+    isApplicable: (structure: Structure) => structure.polymerResidueCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/structure/representation/spacefill.ts b/src/mol-repr/structure/representation/spacefill.ts
index 91223e3a7..e1fbcc162 100644
--- a/src/mol-repr/structure/representation/spacefill.ts
+++ b/src/mol-repr/structure/representation/spacefill.ts
@@ -38,5 +38,6 @@ export const SpacefillRepresentationProvider: StructureRepresentationProvider<Sp
     getParams: getSpacefillParams,
     defaultValues: PD.getDefaultValues(SpacefillParams),
     defaultColorTheme: 'element-symbol',
-    defaultSizeTheme: 'physical'
+    defaultSizeTheme: 'physical',
+    isApplicable: (structure: Structure) => structure.elementCount > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/volume/direct-volume.ts b/src/mol-repr/volume/direct-volume.ts
index 6d223ada5..8aa809c6b 100644
--- a/src/mol-repr/volume/direct-volume.ts
+++ b/src/mol-repr/volume/direct-volume.ts
@@ -187,5 +187,6 @@ export const DirectVolumeRepresentationProvider: VolumeRepresentationProvider<Di
     getParams: getDirectVolumeParams,
     defaultValues: PD.getDefaultValues(DirectVolumeParams),
     defaultColorTheme: 'uniform',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (volume: VolumeData) => volume.data.data.length > 0
 }
\ No newline at end of file
diff --git a/src/mol-repr/volume/isosurface.ts b/src/mol-repr/volume/isosurface.ts
index ce877d67d..46d9aabed 100644
--- a/src/mol-repr/volume/isosurface.ts
+++ b/src/mol-repr/volume/isosurface.ts
@@ -171,5 +171,6 @@ export const IsosurfaceRepresentationProvider: VolumeRepresentationProvider<Isos
     getParams: getIsosurfaceParams,
     defaultValues: PD.getDefaultValues(IsosurfaceParams),
     defaultColorTheme: 'uniform',
-    defaultSizeTheme: 'uniform'
+    defaultSizeTheme: 'uniform',
+    isApplicable: (volume: VolumeData) => volume.data.data.length > 0
 }
\ No newline at end of file
-- 
GitLab