UNPKG

molstar

Version:

A comprehensive macromolecular library.

124 lines (123 loc) 7.56 kB
"use strict"; /** * Copyright (c) 2018-2021 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.PolymerBackboneCylinderMeshVisual = exports.PolymerBackboneCylinderImpostorVisual = exports.PolymerBackboneCylinderVisual = exports.PolymerBackboneCylinderParams = void 0; var tslib_1 = require("tslib"); var param_definition_1 = require("../../../mol-util/param-definition"); var structure_1 = require("../../../mol-model/structure"); var mesh_1 = require("../../../mol-geo/geometry/mesh/mesh"); var mesh_builder_1 = require("../../../mol-geo/geometry/mesh/mesh-builder"); var linear_algebra_1 = require("../../../mol-math/linear-algebra"); var polymer_1 = require("./util/polymer"); var cylinder_1 = require("../../../mol-geo/geometry/mesh/builder/cylinder"); var units_visual_1 = require("../units-visual"); var base_1 = require("../../../mol-geo/geometry/base"); var geometry_1 = require("../../../mol-math/geometry"); var types_1 = require("../../../mol-model/structure/model/types"); var cylinders_1 = require("../../../mol-geo/geometry/cylinders/cylinders"); var cylinders_builder_1 = require("../../../mol-geo/geometry/cylinders/cylinders-builder"); var backbone_1 = require("./util/polymer/backbone"); // avoiding namespace lookup improved performance in Chrome (Aug 2020) var v3scale = linear_algebra_1.Vec3.scale; var v3add = linear_algebra_1.Vec3.add; var v3sub = linear_algebra_1.Vec3.sub; exports.PolymerBackboneCylinderParams = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, units_visual_1.UnitsMeshParams), units_visual_1.UnitsCylindersParams), { sizeFactor: param_definition_1.ParamDefinition.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), radialSegments: param_definition_1.ParamDefinition.Numeric(16, { min: 2, max: 56, step: 2 }, base_1.BaseGeometry.CustomQualityParamInfo), tryUseImpostor: param_definition_1.ParamDefinition.Boolean(true) }); function PolymerBackboneCylinderVisual(materialId, structure, props, webgl) { return props.tryUseImpostor && webgl && webgl.extensions.fragDepth ? PolymerBackboneCylinderImpostorVisual(materialId) : PolymerBackboneCylinderMeshVisual(materialId); } exports.PolymerBackboneCylinderVisual = PolymerBackboneCylinderVisual; function createPolymerBackboneCylinderImpostor(ctx, unit, structure, theme, props, cylinders) { var polymerElementCount = unit.polymerElements.length; if (!polymerElementCount) return cylinders_1.Cylinders.createEmpty(cylinders); var cylindersCountEstimate = polymerElementCount * 2; var builder = cylinders_builder_1.CylindersBuilder.create(cylindersCountEstimate, cylindersCountEstimate / 4, cylinders); var pos = unit.conformation.invariantPosition; var pA = (0, linear_algebra_1.Vec3)(); var pB = (0, linear_algebra_1.Vec3)(); var pM = (0, linear_algebra_1.Vec3)(); var add = function (indexA, indexB, groupA, groupB, moleculeType) { pos(indexA, pA); pos(indexB, pB); var isNucleicType = (0, types_1.isNucleic)(moleculeType); var shift = isNucleicType ? polymer_1.NucleicShift : polymer_1.StandardShift; v3add(pM, pA, v3scale(pM, v3sub(pM, pB, pA), shift)); builder.add(pA[0], pA[1], pA[2], pM[0], pM[1], pM[2], 1, false, false, groupA); builder.add(pM[0], pM[1], pM[2], pB[0], pB[1], pB[2], 1, false, false, groupB); }; (0, backbone_1.eachPolymerBackboneLink)(unit, add); var c = builder.getCylinders(); var sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, 1 * props.sizeFactor); c.setBoundingSphere(sphere); return c; } function PolymerBackboneCylinderImpostorVisual(materialId) { return (0, units_visual_1.UnitsCylindersVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.PolymerBackboneCylinderParams), createGeometry: createPolymerBackboneCylinderImpostor, createLocationIterator: polymer_1.PolymerLocationIterator.fromGroup, getLoci: polymer_1.getPolymerElementLoci, eachLocation: polymer_1.eachPolymerElement, setUpdateState: function (state, newProps, currentProps) { }, mustRecreate: function (structureGroup, props, webgl) { return !props.tryUseImpostor || !webgl; } }, materialId); } exports.PolymerBackboneCylinderImpostorVisual = PolymerBackboneCylinderImpostorVisual; function createPolymerBackboneCylinderMesh(ctx, unit, structure, theme, props, mesh) { var polymerElementCount = unit.polymerElements.length; if (!polymerElementCount) return mesh_1.Mesh.createEmpty(mesh); var radialSegments = props.radialSegments, sizeFactor = props.sizeFactor; var vertexCountEstimate = radialSegments * 2 * polymerElementCount * 2; var builderState = mesh_builder_1.MeshBuilder.createState(vertexCountEstimate, vertexCountEstimate / 10, mesh); var pos = unit.conformation.invariantPosition; var pA = (0, linear_algebra_1.Vec3)(); var pB = (0, linear_algebra_1.Vec3)(); var cylinderProps = { radiusTop: 1, radiusBottom: 1, radialSegments: radialSegments }; var centerA = structure_1.StructureElement.Location.create(structure, unit); var centerB = structure_1.StructureElement.Location.create(structure, unit); var add = function (indexA, indexB, groupA, groupB, moleculeType) { centerA.element = indexA; centerB.element = indexB; pos(centerA.element, pA); pos(centerB.element, pB); var isNucleicType = (0, types_1.isNucleic)(moleculeType); var shift = isNucleicType ? polymer_1.NucleicShift : polymer_1.StandardShift; cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerA) * sizeFactor; builderState.currentGroup = groupA; (0, cylinder_1.addCylinder)(builderState, pA, pB, shift, cylinderProps); cylinderProps.radiusTop = cylinderProps.radiusBottom = theme.size.size(centerB) * sizeFactor; builderState.currentGroup = groupB; (0, cylinder_1.addCylinder)(builderState, pB, pA, 1 - shift, cylinderProps); }; (0, backbone_1.eachPolymerBackboneLink)(unit, add); var m = mesh_builder_1.MeshBuilder.getMesh(builderState); var sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), unit.boundary.sphere, 1 * props.sizeFactor); m.setBoundingSphere(sphere); return m; } function PolymerBackboneCylinderMeshVisual(materialId) { return (0, units_visual_1.UnitsMeshVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.PolymerBackboneCylinderParams), createGeometry: createPolymerBackboneCylinderMesh, createLocationIterator: polymer_1.PolymerLocationIterator.fromGroup, getLoci: polymer_1.getPolymerElementLoci, eachLocation: polymer_1.eachPolymerElement, setUpdateState: function (state, newProps, currentProps) { state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor || newProps.radialSegments !== currentProps.radialSegments); }, mustRecreate: function (structureGroup, props, webgl) { return props.tryUseImpostor && !!webgl; } }, materialId); } exports.PolymerBackboneCylinderMeshVisual = PolymerBackboneCylinderMeshVisual;