From 0237bfde3bcc9275eb36e5d09e0c7de21cbe0d99 Mon Sep 17 00:00:00 2001
From: Alexander Rose <alex.rose@rcsb.org>
Date: Thu, 15 Nov 2018 17:40:14 -0800
Subject: [PATCH] registered carbohydrate representation

---
 src/mol-repr/structure/registry.ts            |  2 +
 .../structure/representation/carbohydrate.ts  | 71 +++++++++++--------
 2 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/src/mol-repr/structure/registry.ts b/src/mol-repr/structure/registry.ts
index 912e353e8..058a9c178 100644
--- a/src/mol-repr/structure/registry.ts
+++ b/src/mol-repr/structure/registry.ts
@@ -9,6 +9,7 @@ import { RepresentationProvider, RepresentationRegistry } from '../representatio
 import { CartoonRepresentationProvider } from './representation/cartoon';
 import { BallAndStickRepresentationProvider } from './representation/ball-and-stick';
 import { MolecularSurfaceRepresentationProvider } from './representation/molecular-surface';
+import { CarbohydrateRepresentationProvider } from './representation/carbohydrate';
 
 export class StructureRepresentationRegistry extends RepresentationRegistry<Structure> {
     constructor() {
@@ -24,6 +25,7 @@ export const BuiltInStructureRepresentations = {
     'cartoon': CartoonRepresentationProvider,
     'ball-and-stick': BallAndStickRepresentationProvider,
     'molecular-surface': MolecularSurfaceRepresentationProvider,
+    'carbohydrate': CarbohydrateRepresentationProvider,
 }
 export type BuiltInStructureRepresentationsName = keyof typeof BuiltInStructureRepresentations
 export const BuiltInStructureRepresentationsNames = Object.keys(BuiltInStructureRepresentations)
diff --git a/src/mol-repr/structure/representation/carbohydrate.ts b/src/mol-repr/structure/representation/carbohydrate.ts
index 6493be0ae..82660da3f 100644
--- a/src/mol-repr/structure/representation/carbohydrate.ts
+++ b/src/mol-repr/structure/representation/carbohydrate.ts
@@ -1,32 +1,47 @@
-// /**
-//  * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
-//  *
-//  * @author Alexander Rose <alexander.rose@weirdbyte.de>
-//  */
+/**
+ * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
+ */
 
-// import { CarbohydrateSymbolVisual, CarbohydrateSymbolParams } from '../visual/carbohydrate-symbol-mesh';
-// import { CarbohydrateLinkVisual, CarbohydrateLinkParams } from '../visual/carbohydrate-link-cylinder';
-// import { ParamDefinition as PD } from 'mol-util/param-definition';
-// import { ComplexRepresentation } from '../complex-representation';
-// import { StructureRepresentation } from '../representation';
-// import { Representation } from 'mol-repr/representation';
-// import { ThemeRegistryContext } from 'mol-theme/theme';
-// import { Structure } from 'mol-model/structure';
+import { CarbohydrateSymbolVisual, CarbohydrateSymbolParams } from '../visual/carbohydrate-symbol-mesh';
+import { CarbohydrateLinkVisual, CarbohydrateLinkParams } from '../visual/carbohydrate-link-cylinder';
+import { ParamDefinition as PD } from 'mol-util/param-definition';
+import { ComplexRepresentation } from '../complex-representation';
+import { StructureRepresentation, StructureRepresentationProvider } from '../representation';
+import { Representation, RepresentationParamsGetter } from 'mol-repr/representation';
+import { ThemeRegistryContext } from 'mol-theme/theme';
+import { Structure } from 'mol-model/structure';
+import { BuiltInColorThemeOptions, getBuiltInColorThemeParams } from 'mol-theme/color';
 
-// export const CarbohydrateParams = {
-//     ...CarbohydrateSymbolParams,
-//     ...CarbohydrateLinkParams,
-// }
-// export function getCarbohydrateParams(ctx: ThemeRegistryContext, structure: Structure) {
-//     return CarbohydrateParams // TODO return copy
-// }
-// export type CarbohydrateProps = PD.DefaultValues<typeof CarbohydrateParams>
+const CarbohydrateVisuals = {
+    'carbohydrate-symbol': (getParams: RepresentationParamsGetter<Structure, CarbohydrateSymbolParams>) => ComplexRepresentation('Carbohydrate symbol mesh', getParams, CarbohydrateSymbolVisual),
+    'carbohydrate-link': (getParams: RepresentationParamsGetter<Structure, CarbohydrateLinkParams>) => ComplexRepresentation('Carbohydrate link cylinder', getParams, CarbohydrateLinkVisual),
+}
+type CarbohydrateVisualName = keyof typeof CarbohydrateVisuals
+const CarbohydrateVisualOptions = Object.keys(CarbohydrateVisuals).map(name => [name, name] as [CarbohydrateVisualName, string])
 
-// export type CarbohydrateRepresentation = StructureRepresentation<CarbohydrateProps>
+export const CarbohydrateParams = {
+    ...CarbohydrateSymbolParams,
+    ...CarbohydrateLinkParams,
+    colorTheme: PD.Mapped('carbohydrate-symbol', BuiltInColorThemeOptions, getBuiltInColorThemeParams),
+    visuals: PD.MultiSelect<CarbohydrateVisualName>(['carbohydrate-symbol', 'carbohydrate-link'], CarbohydrateVisualOptions),
+}
+PD.getDefaultValues(CarbohydrateParams).colorTheme.name
+export type CarbohydrateParams = typeof CarbohydrateParams
+export function getCarbohydrateParams(ctx: ThemeRegistryContext, structure: Structure) {
+    return PD.clone(CarbohydrateParams)
+}
 
-// export function CarbohydrateRepresentation(defaultProps: CarbohydrateProps): CarbohydrateRepresentation {
-//     return Representation.createMulti('Carbohydrate', defaultProps, [
-//         ComplexRepresentation('Carbohydrate symbol mesh', defaultProps, CarbohydrateSymbolVisual),
-//         ComplexRepresentation('Carbohydrate link cylinder', defaultProps, CarbohydrateLinkVisual)
-//     ])
-// }
\ No newline at end of file
+export type CarbohydrateRepresentation = StructureRepresentation<CarbohydrateParams>
+export function CarbohydrateRepresentation(getParams: RepresentationParamsGetter<Structure, CarbohydrateParams>): CarbohydrateRepresentation {
+    return Representation.createMulti('Carbohydrate', getParams, CarbohydrateVisuals as unknown as Representation.Def<Structure, CarbohydrateParams>)
+}
+
+export const CarbohydrateRepresentationProvider: StructureRepresentationProvider<CarbohydrateParams> = {
+    label: 'Carbohydrate',
+    description: 'Displays carbohydrate symbols (3D SNFG).',
+    factory: CarbohydrateRepresentation,
+    getParams: getCarbohydrateParams,
+    defaultValues: PD.getDefaultValues(CarbohydrateParams)
+}
\ No newline at end of file
-- 
GitLab