UNPKG

molstar

Version:

A comprehensive macromolecular library.

47 lines (46 loc) 2.98 kB
/** * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign } from "tslib"; import { PolymerBackboneCylinderVisual, PolymerBackboneCylinderParams } from '../visual/polymer-backbone-cylinder'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { UnitsRepresentation } from '../units-representation'; import { StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation } from '../../../mol-repr/representation'; import { PolymerBackboneSphereParams, PolymerBackboneSphereVisual } from '../visual/polymer-backbone-sphere'; import { PolymerGapParams, PolymerGapVisual } from '../visual/polymer-gap-cylinder'; import { BaseGeometry } from '../../../mol-geo/geometry/base'; var BackboneVisuals = { 'polymer-backbone-cylinder': function (ctx, getParams) { return UnitsRepresentation('Polymer backbone cylinder', ctx, getParams, PolymerBackboneCylinderVisual); }, 'polymer-backbone-sphere': function (ctx, getParams) { return UnitsRepresentation('Polymer backbone sphere', ctx, getParams, PolymerBackboneSphereVisual); }, 'polymer-gap': function (ctx, getParams) { return UnitsRepresentation('Polymer gap cylinder', ctx, getParams, PolymerGapVisual); }, }; export var BackboneParams = __assign(__assign(__assign(__assign({}, PolymerBackboneSphereParams), PolymerBackboneCylinderParams), PolymerGapParams), { sizeAspectRatio: PD.Numeric(1, { min: 0.1, max: 3, step: 0.1 }), visuals: PD.MultiSelect(['polymer-backbone-cylinder', 'polymer-backbone-sphere', 'polymer-gap'], PD.objectToOptions(BackboneVisuals)), bumpFrequency: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }, BaseGeometry.ShadingCategory) }); export function getBackboneParams(ctx, structure) { var params = PD.clone(BackboneParams); var hasGaps = false; structure.units.forEach(function (u) { if (!hasGaps && u.gapElements.length) hasGaps = true; }); params.visuals.defaultValue = ['polymer-backbone-cylinder', 'polymer-backbone-sphere']; if (hasGaps) params.visuals.defaultValue.push('polymer-gap'); return params; } export function BackboneRepresentation(ctx, getParams) { return Representation.createMulti('Backbone', ctx, getParams, StructureRepresentationStateBuilder, BackboneVisuals); } export var BackboneRepresentationProvider = StructureRepresentationProvider({ name: 'backbone', label: 'Backbone', description: 'Displays polymer backbone with cylinders and spheres.', factory: BackboneRepresentation, getParams: getBackboneParams, defaultValues: PD.getDefaultValues(BackboneParams), defaultColorTheme: { name: 'chain-id' }, defaultSizeTheme: { name: 'uniform' }, isApplicable: function (structure) { return structure.polymerResidueCount > 0; }, });