UNPKG

molstar

Version:

A comprehensive macromolecular library.

96 lines 6.05 kB
"use strict"; /** * Copyright (c) 2019-2020 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.DistanceRepresentation = exports.DistanceParams = void 0; var tslib_1 = require("tslib"); var loci_1 = require("../../../mol-model/loci"); var lines_1 = require("../../../mol-geo/geometry/lines/lines"); var text_1 = require("../../../mol-geo/geometry/text/text"); var param_definition_1 = require("../../../mol-util/param-definition"); var names_1 = require("../../../mol-util/color/names"); var representation_1 = require("../representation"); var representation_2 = require("../../representation"); var shape_1 = require("../../../mol-model/shape"); var lines_builder_1 = require("../../../mol-geo/geometry/lines/lines-builder"); var text_builder_1 = require("../../../mol-geo/geometry/text/text-builder"); var linear_algebra_1 = require("../../../mol-math/linear-algebra"); var marker_action_1 = require("../../../mol-util/marker-action"); var label_1 = require("../../../mol-theme/label"); var common_1 = require("./common"); var geometry_1 = require("../../../mol-math/geometry"); var SharedParams = { unitLabel: param_definition_1.ParamDefinition.Text('\u212B', { isEssential: true }) }; var LineParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, lines_1.Lines.Params), SharedParams), { lineSizeAttenuation: param_definition_1.ParamDefinition.Boolean(true), linesColor: param_definition_1.ParamDefinition.Color(names_1.ColorNames.lightgreen, { isEssential: true }), linesSize: param_definition_1.ParamDefinition.Numeric(0.075, { min: 0.01, max: 5, step: 0.01 }), dashLength: param_definition_1.ParamDefinition.Numeric(0.2, { min: 0.01, max: 0.2, step: 0.01 }) }); var TextParams = (0, tslib_1.__assign)((0, tslib_1.__assign)({}, common_1.LociLabelTextParams), SharedParams); var DistanceVisuals = { 'lines': function (ctx, getParams) { return (0, representation_1.ShapeRepresentation)(getLinesShape, lines_1.Lines.Utils, { modifyState: function (s) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, s), { markerActions: marker_action_1.MarkerActions.Highlighting })); } }); }, 'text': function (ctx, getParams) { return (0, representation_1.ShapeRepresentation)(getTextShape, text_1.Text.Utils, { modifyState: function (s) { return ((0, tslib_1.__assign)((0, tslib_1.__assign)({}, s), { markerActions: marker_action_1.MarkerAction.None })); } }); }, }; exports.DistanceParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, LineParams), TextParams), { visuals: param_definition_1.ParamDefinition.MultiSelect(['lines', 'text'], param_definition_1.ParamDefinition.objectToOptions(DistanceVisuals)) }); // function getDistanceState() { return { sphereA: (0, geometry_1.Sphere3D)(), sphereB: (0, geometry_1.Sphere3D)(), center: (0, linear_algebra_1.Vec3)(), distance: 0, }; } function setDistanceState(pair, state) { var sphereA = state.sphereA, sphereB = state.sphereB, center = state.center; var _a = pair.loci, lociA = _a[0], lociB = _a[1]; loci_1.Loci.getBoundingSphere(lociA, sphereA); loci_1.Loci.getBoundingSphere(lociB, sphereB); linear_algebra_1.Vec3.add(center, sphereA.center, sphereB.center); linear_algebra_1.Vec3.scale(center, center, 0.5); state.distance = linear_algebra_1.Vec3.distance(sphereA.center, sphereB.center); return state; } var tmpState = getDistanceState(); function getDistanceName(data, unitLabel) { return data.pairs.length === 1 ? "Distance " + (0, label_1.distanceLabel)(data.pairs[0], { unitLabel: unitLabel, measureOnly: true }) : data.pairs.length + " Distances"; } // function buildLines(data, props, lines) { var builder = lines_builder_1.LinesBuilder.create(128, 64, lines); for (var i = 0, il = data.pairs.length; i < il; ++i) { setDistanceState(data.pairs[i], tmpState); builder.addFixedLengthDashes(tmpState.sphereA.center, tmpState.sphereB.center, props.dashLength, i); } return builder.getLines(); } function getLinesShape(ctx, data, props, shape) { var lines = buildLines(data, props, shape && shape.geometry); var name = getDistanceName(data, props.unitLabel); var getLabel = function (groupId) { return (0, label_1.distanceLabel)(data.pairs[groupId], props); }; return shape_1.Shape.create(name, data, lines, function () { return props.linesColor; }, function () { return props.linesSize; }, getLabel); } // function buildText(data, props, text) { var builder = text_builder_1.TextBuilder.create(props, 128, 64, text); for (var i = 0, il = data.pairs.length; i < il; ++i) { setDistanceState(data.pairs[i], tmpState); var center = tmpState.center, distance = tmpState.distance, sphereA = tmpState.sphereA, sphereB = tmpState.sphereB; var label = props.customText || distance.toFixed(2) + " " + props.unitLabel; var radius = Math.max(2, sphereA.radius, sphereB.radius); var scale = radius / 2; builder.add(label, center[0], center[1], center[2], 1, scale, i); } return builder.getText(); } function getTextShape(ctx, data, props, shape) { var text = buildText(data, props, shape && shape.geometry); var name = getDistanceName(data, props.unitLabel); var getLabel = function (groupId) { return (0, label_1.distanceLabel)(data.pairs[groupId], props); }; return shape_1.Shape.create(name, data, text, function () { return props.textColor; }, function () { return props.textSize; }, getLabel); } function DistanceRepresentation(ctx, getParams) { return representation_2.Representation.createMulti('Distance', ctx, getParams, representation_2.Representation.StateBuilder, DistanceVisuals); } exports.DistanceRepresentation = DistanceRepresentation; //# sourceMappingURL=distance.js.map