UNPKG

molstar

Version:

A comprehensive macromolecular library.

141 lines (140 loc) 7.17 kB
"use strict"; /** * Copyright (c) 2020-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.InterUnitBondLineVisual = exports.InterUnitBondLineParams = void 0; var tslib_1 = require("tslib"); var param_definition_1 = require("../../../mol-util/param-definition"); var structure_1 = require("../../../mol-model/structure"); var linear_algebra_1 = require("../../../mol-math/linear-algebra"); var mol_util_1 = require("../../../mol-util"); var link_1 = require("./util/link"); var complex_visual_1 = require("../complex-visual"); var types_1 = require("../../../mol-model/structure/model/types"); var bond_1 = require("./util/bond"); var lines_1 = require("../../../mol-geo/geometry/lines/lines"); var geometry_1 = require("../../../mol-math/geometry"); var tmpRefPosBondIt = new structure_1.Bond.ElementBondIterator(); function setRefPosition(pos, structure, unit, index) { tmpRefPosBondIt.setElement(structure, unit, index); while (tmpRefPosBondIt.hasNext) { var bA = tmpRefPosBondIt.move(); bA.otherUnit.conformation.position(bA.otherUnit.elements[bA.otherIndex], pos); return pos; } return null; } function createInterUnitBondLines(ctx, structure, theme, props, lines) { var bonds = structure.interUnitBonds; var edgeCount = bonds.edgeCount, edges = bonds.edges; if (!edgeCount) return lines_1.Lines.createEmpty(lines); var sizeFactor = props.sizeFactor, aromaticBonds = props.aromaticBonds, multipleBonds = props.multipleBonds; var mbOff = multipleBonds === 'off'; var mbSymmetric = multipleBonds === 'symmetric'; var ref = (0, linear_algebra_1.Vec3)(); var loc = structure_1.StructureElement.Location.create(); var builderProps = { linkCount: edgeCount, referencePosition: function (edgeIndex) { var b = edges[edgeIndex]; var unitA, unitB; var indexA, indexB; if (b.unitA < b.unitB) { unitA = structure.unitMap.get(b.unitA); unitB = structure.unitMap.get(b.unitB); indexA = b.indexA; indexB = b.indexB; } else if (b.unitA > b.unitB) { unitA = structure.unitMap.get(b.unitB); unitB = structure.unitMap.get(b.unitA); indexA = b.indexB; indexB = b.indexA; } else { throw new Error('same units in createInterUnitBondLines'); } return setRefPosition(ref, structure, unitA, indexA) || setRefPosition(ref, structure, unitB, indexB); }, position: function (posA, posB, edgeIndex) { var b = edges[edgeIndex]; var uA = structure.unitMap.get(b.unitA); var uB = structure.unitMap.get(b.unitB); uA.conformation.position(uA.elements[b.indexA], posA); uB.conformation.position(uB.elements[b.indexB], posB); }, style: function (edgeIndex) { var o = edges[edgeIndex].props.order; var f = mol_util_1.BitFlags.create(edges[edgeIndex].props.flag); if (types_1.BondType.is(f, 2 /* BondType.Flag.MetallicCoordination */) || types_1.BondType.is(f, 4 /* BondType.Flag.HydrogenBond */)) { // show metallic coordinations and hydrogen bonds with dashed cylinders return 1 /* LinkStyle.Dashed */; } else if (o === 3) { return mbOff ? 0 /* LinkStyle.Solid */ : mbSymmetric ? 4 /* LinkStyle.Triple */ : 5 /* LinkStyle.OffsetTriple */; } else if (aromaticBonds && types_1.BondType.is(f, 16 /* BondType.Flag.Aromatic */)) { return 7 /* LinkStyle.Aromatic */; } return (o !== 2 || mbOff) ? 0 /* LinkStyle.Solid */ : mbSymmetric ? 2 /* LinkStyle.Double */ : 3 /* LinkStyle.OffsetDouble */; }, radius: function (edgeIndex) { var b = edges[edgeIndex]; loc.structure = structure; loc.unit = structure.unitMap.get(b.unitA); loc.element = loc.unit.elements[b.indexA]; var sizeA = theme.size.size(loc); loc.unit = structure.unitMap.get(b.unitB); loc.element = loc.unit.elements[b.indexB]; var sizeB = theme.size.size(loc); return Math.min(sizeA, sizeB) * sizeFactor; }, ignore: (0, bond_1.makeInterBondIgnoreTest)(structure, props) }; var _a = (0, link_1.createLinkLines)(ctx, builderProps, props, lines), l = _a.lines, boundingSphere = _a.boundingSphere; if (boundingSphere) { l.setBoundingSphere(boundingSphere); } else if (l.lineCount > 0) { var child = structure.child; var sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), (child !== null && child !== void 0 ? child : structure).boundary.sphere, 1 * sizeFactor); l.setBoundingSphere(sphere); } return l; } exports.InterUnitBondLineParams = tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, complex_visual_1.ComplexLinesParams), bond_1.BondLineParams), { includeParent: param_definition_1.ParamDefinition.Boolean(false) }); function InterUnitBondLineVisual(materialId) { return (0, complex_visual_1.ComplexLinesVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.InterUnitBondLineParams), createGeometry: createInterUnitBondLines, createLocationIterator: bond_1.BondIterator.fromStructure, getLoci: bond_1.getInterBondLoci, eachLocation: bond_1.eachInterBond, setUpdateState: function (state, newProps, currentProps, newTheme, currentTheme, newStructure, currentStructure) { state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor || newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.aromaticDashCount !== currentProps.aromaticDashCount || newProps.dashCount !== currentProps.dashCount || newProps.ignoreHydrogens !== currentProps.ignoreHydrogens || !(0, mol_util_1.arrayEqual)(newProps.includeTypes, currentProps.includeTypes) || !(0, mol_util_1.arrayEqual)(newProps.excludeTypes, currentProps.excludeTypes) || newProps.multipleBonds !== currentProps.multipleBonds); if (newStructure.interUnitBonds !== currentStructure.interUnitBonds) { state.createGeometry = true; state.updateTransform = true; state.updateColor = true; state.updateSize = true; } } }, materialId); } exports.InterUnitBondLineVisual = InterUnitBondLineVisual;