UNPKG

molstar

Version:

A comprehensive macromolecular library.

96 lines (95 loc) 6.18 kB
"use strict"; /** * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CartoonRepresentationProvider = exports.CartoonRepresentation = exports.getCartoonParams = exports.CartoonParams = void 0; var tslib_1 = require("tslib"); var structure_1 = require("../../../mol-model/structure"); var representation_1 = require("../../../mol-repr/representation"); var param_definition_1 = require("../../../mol-util/param-definition"); var representation_2 = require("../representation"); var units_representation_1 = require("../units-representation"); var nucleotide_block_mesh_1 = require("../visual/nucleotide-block-mesh"); var nucleotide_ring_mesh_1 = require("../visual/nucleotide-ring-mesh"); var polymer_direction_wedge_1 = require("../visual/polymer-direction-wedge"); var polymer_gap_cylinder_1 = require("../visual/polymer-gap-cylinder"); var polymer_trace_mesh_1 = require("../visual/polymer-trace-mesh"); var secondary_structure_1 = require("../../../mol-model-props/computed/secondary-structure"); var helix_orientation_1 = require("../../../mol-model-props/computed/helix-orientation"); var base_1 = require("../../../mol-geo/geometry/base"); var CartoonVisuals = { 'polymer-trace': function (ctx, getParams) { return (0, units_representation_1.UnitsRepresentation)('Polymer trace mesh', ctx, getParams, polymer_trace_mesh_1.PolymerTraceVisual); }, 'polymer-gap': function (ctx, getParams) { return (0, units_representation_1.UnitsRepresentation)('Polymer gap cylinder', ctx, getParams, polymer_gap_cylinder_1.PolymerGapVisual); }, 'nucleotide-block': function (ctx, getParams) { return (0, units_representation_1.UnitsRepresentation)('Nucleotide block mesh', ctx, getParams, nucleotide_block_mesh_1.NucleotideBlockVisual); }, 'nucleotide-ring': function (ctx, getParams) { return (0, units_representation_1.UnitsRepresentation)('Nucleotide ring mesh', ctx, getParams, nucleotide_ring_mesh_1.NucleotideRingVisual); }, 'direction-wedge': function (ctx, getParams) { return (0, units_representation_1.UnitsRepresentation)('Polymer direction wedge', ctx, getParams, polymer_direction_wedge_1.PolymerDirectionVisual); } }; exports.CartoonParams = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, polymer_trace_mesh_1.PolymerTraceParams), polymer_gap_cylinder_1.PolymerGapParams), nucleotide_block_mesh_1.NucleotideBlockParams), nucleotide_ring_mesh_1.NucleotideRingParams), polymer_direction_wedge_1.PolymerDirectionParams), { sizeFactor: param_definition_1.ParamDefinition.Numeric(0.2, { min: 0, max: 10, step: 0.01 }), visuals: param_definition_1.ParamDefinition.MultiSelect(['polymer-trace', 'polymer-gap', 'nucleotide-ring'], param_definition_1.ParamDefinition.objectToOptions(CartoonVisuals)), bumpFrequency: param_definition_1.ParamDefinition.Numeric(2, { min: 0, max: 10, step: 0.1 }, base_1.BaseGeometry.ShadingCategory) }); function getCartoonParams(ctx, structure) { var params = param_definition_1.ParamDefinition.clone(exports.CartoonParams); var hasNucleotides = false; var hasGaps = false; structure.units.forEach(function (u) { if (!hasNucleotides && structure_1.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; } exports.getCartoonParams = getCartoonParams; function CartoonRepresentation(ctx, getParams) { return representation_1.Representation.createMulti('Cartoon', ctx, getParams, representation_2.StructureRepresentationStateBuilder, CartoonVisuals); } exports.CartoonRepresentation = CartoonRepresentation; exports.CartoonRepresentationProvider = (0, representation_2.StructureRepresentationProvider)({ name: 'cartoon', label: 'Cartoon', description: 'Displays ribbons, planks, tubes smoothly following the trace atoms of polymers.', factory: CartoonRepresentation, getParams: getCartoonParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.CartoonParams), defaultColorTheme: { name: 'chain-id' }, defaultSizeTheme: { name: 'uniform' }, isApplicable: function (structure) { return structure.polymerResidueCount > 0; }, ensureCustomProperties: { attach: function (ctx, structure) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { var _i, _a, m; return tslib_1.__generator(this, function (_b) { switch (_b.label) { case 0: return [4 /*yield*/, secondary_structure_1.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*/, helix_orientation_1.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) { secondary_structure_1.SecondaryStructureProvider.ref(data, false); for (var _i = 0, _a = data.models; _i < _a.length; _i++) { var m = _a[_i]; helix_orientation_1.HelixOrientationProvider.ref(m, false); } } } });