UNPKG

molstar

Version:

A comprehensive macromolecular library.

91 lines (90 loc) 5.27 kB
/** * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign, __awaiter, __generator } from "tslib"; import { Unit } from '../../../mol-model/structure'; import { Representation } from '../../../mol-repr/representation'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { UnitsRepresentation } from '../units-representation'; import { NucleotideBlockParams, NucleotideBlockVisual } from '../visual/nucleotide-block-mesh'; import { NucleotideRingParams, NucleotideRingVisual } from '../visual/nucleotide-ring-mesh'; import { PolymerDirectionParams, PolymerDirectionVisual } from '../visual/polymer-direction-wedge'; import { PolymerGapParams, PolymerGapVisual } from '../visual/polymer-gap-cylinder'; import { PolymerTraceParams, PolymerTraceVisual } from '../visual/polymer-trace-mesh'; import { SecondaryStructureProvider } from '../../../mol-model-props/computed/secondary-structure'; import { HelixOrientationProvider } from '../../../mol-model-props/computed/helix-orientation'; import { BaseGeometry } from '../../../mol-geo/geometry/base'; var CartoonVisuals = { 'polymer-trace': function (ctx, getParams) { return UnitsRepresentation('Polymer trace mesh', ctx, getParams, PolymerTraceVisual); }, 'polymer-gap': function (ctx, getParams) { return UnitsRepresentation('Polymer gap cylinder', ctx, getParams, PolymerGapVisual); }, 'nucleotide-block': function (ctx, getParams) { return UnitsRepresentation('Nucleotide block mesh', ctx, getParams, NucleotideBlockVisual); }, 'nucleotide-ring': function (ctx, getParams) { return UnitsRepresentation('Nucleotide ring mesh', ctx, getParams, NucleotideRingVisual); }, 'direction-wedge': function (ctx, getParams) { return UnitsRepresentation('Polymer direction wedge', ctx, getParams, PolymerDirectionVisual); } }; export var CartoonParams = __assign(__assign(__assign(__assign(__assign(__assign({}, PolymerTraceParams), PolymerGapParams), NucleotideBlockParams), NucleotideRingParams), PolymerDirectionParams), { sizeFactor: PD.Numeric(0.2, { min: 0, max: 10, step: 0.01 }), visuals: PD.MultiSelect(['polymer-trace', 'polymer-gap', 'nucleotide-ring'], PD.objectToOptions(CartoonVisuals)), bumpFrequency: PD.Numeric(2, { min: 0, max: 10, step: 0.1 }, BaseGeometry.ShadingCategory) }); export function getCartoonParams(ctx, structure) { var params = PD.clone(CartoonParams); var hasNucleotides = false; var hasGaps = false; structure.units.forEach(function (u) { if (!hasNucleotides && Unit.isAtomic(u) && u.nucleotideElements.length) hasNucleotides = true; if (!hasGaps && u.gapElements.length) hasGaps = true; }); params.visuals.defaultValue = ['polymer-trace']; if (hasNucleotides) params.visuals.defaultValue.push('nucleotide-ring'); if (hasGaps) params.visuals.defaultValue.push('polymer-gap'); return params; } export function CartoonRepresentation(ctx, getParams) { return Representation.createMulti('Cartoon', ctx, getParams, StructureRepresentationStateBuilder, CartoonVisuals); } export var CartoonRepresentationProvider = StructureRepresentationProvider({ name: 'cartoon', label: 'Cartoon', description: 'Displays ribbons, planks, tubes smoothly following the trace atoms of polymers.', factory: CartoonRepresentation, getParams: getCartoonParams, defaultValues: PD.getDefaultValues(CartoonParams), defaultColorTheme: { name: 'chain-id' }, defaultSizeTheme: { name: 'uniform' }, isApplicable: function (structure) { return structure.polymerResidueCount > 0; }, ensureCustomProperties: { attach: function (ctx, structure) { return __awaiter(void 0, void 0, void 0, function () { var _i, _a, m; return __generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, SecondaryStructureProvider.attach(ctx, structure, void 0, true)]; case 1: _b.sent(); _i = 0, _a = structure.models; _b.label = 2; case 2: if (!(_i < _a.length)) return [3 /*break*/, 5]; m = _a[_i]; return [4 /*yield*/, HelixOrientationProvider.attach(ctx, m, void 0, true)]; case 3: _b.sent(); _b.label = 4; case 4: _i++; return [3 /*break*/, 2]; case 5: return [2 /*return*/]; } }); }); }, detach: function (data) { SecondaryStructureProvider.ref(data, false); for (var _i = 0, _a = data.models; _i < _a.length; _i++) { var m = _a[_i]; HelixOrientationProvider.ref(m, false); } } } });