UNPKG

molstar

Version:

A comprehensive macromolecular library.

127 lines 6.98 kB
"use strict"; /** * Copyright (c) 2018-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.CrossLinkRestraintRepresentationProvider = exports.CrossLinkRestraintRepresentation = exports.getCrossLinkRestraintParams = exports.CrossLinkRestraintParams = exports.CrossLinkRestraintVisual = exports.CrossLinkRestraintCylinderParams = void 0; var tslib_1 = require("tslib"); var representation_1 = require("../../../mol-repr/representation"); var mesh_1 = require("../../../mol-geo/geometry/mesh/mesh"); var location_iterator_1 = require("../../../mol-geo/util/location-iterator"); var loci_1 = require("../../../mol-model/loci"); var int_1 = require("../../../mol-data/int"); var param_definition_1 = require("../../../mol-util/param-definition"); var structure_1 = require("../../../mol-model/structure"); var link_1 = require("../../../mol-repr/structure/visual/util/link"); var complex_visual_1 = require("../../../mol-repr/structure/complex-visual"); var representation_2 = require("../../../mol-repr/structure/representation"); var property_1 = require("./property"); function createCrossLinkRestraintCylinderMesh(ctx, structure, theme, props, mesh) { var crossLinks = property_1.CrossLinkRestraintProvider.get(structure).value; if (!crossLinks.count) return mesh_1.Mesh.createEmpty(mesh); var sizeFactor = props.sizeFactor; var location = structure_1.StructureElement.Location.create(structure); var builderProps = { linkCount: crossLinks.count, position: function (posA, posB, edgeIndex) { var b = crossLinks.pairs[edgeIndex]; var uA = b.unitA, uB = b.unitB; uA.conformation.position(uA.elements[b.indexA], posA); uB.conformation.position(uB.elements[b.indexB], posB); }, radius: function (edgeIndex) { var b = crossLinks.pairs[edgeIndex]; location.unit = b.unitA; location.element = b.unitA.elements[b.indexA]; return theme.size.size(location) * sizeFactor; }, }; return (0, link_1.createLinkCylinderMesh)(ctx, builderProps, props, mesh); } exports.CrossLinkRestraintCylinderParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, complex_visual_1.ComplexMeshParams), link_1.LinkCylinderParams), { sizeFactor: param_definition_1.ParamDefinition.Numeric(0.5, { min: 0, max: 10, step: 0.1 }) }); function CrossLinkRestraintVisual(materialId) { return (0, complex_visual_1.ComplexMeshVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.CrossLinkRestraintCylinderParams), createGeometry: createCrossLinkRestraintCylinderMesh, createLocationIterator: createCrossLinkRestraintIterator, getLoci: getLinkLoci, eachLocation: eachCrossLink, setUpdateState: function (state, newProps, currentProps) { state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor || newProps.radialSegments !== currentProps.radialSegments || newProps.linkCap !== currentProps.linkCap); } }, materialId); } exports.CrossLinkRestraintVisual = CrossLinkRestraintVisual; function createCrossLinkRestraintIterator(structure) { var crossLinkRestraints = property_1.CrossLinkRestraintProvider.get(structure).value; var pairs = crossLinkRestraints.pairs; var groupCount = pairs.length; var instanceCount = 1; var location = property_1.CrossLinkRestraint.Location(crossLinkRestraints, structure); var getLocation = function (groupIndex) { location.element = groupIndex; return location; }; return (0, location_iterator_1.LocationIterator)(groupCount, instanceCount, 1, getLocation, true); } function getLinkLoci(pickingId, structure, id) { var objectId = pickingId.objectId, groupId = pickingId.groupId; if (id === objectId) { var crossLinkRestraints = property_1.CrossLinkRestraintProvider.get(structure).value; var pair = crossLinkRestraints.pairs[groupId]; if (pair) { return property_1.CrossLinkRestraint.Loci(structure, crossLinkRestraints, [groupId]); } } return loci_1.EmptyLoci; } function eachCrossLink(loci, structure, apply) { var changed = false; if (property_1.CrossLinkRestraint.isLoci(loci)) { if (!structure_1.Structure.areEquivalent(loci.data.structure, structure)) return false; var crossLinkRestraints = property_1.CrossLinkRestraintProvider.get(structure).value; if (loci.data.crossLinkRestraints !== crossLinkRestraints) return false; for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) { var e = _a[_i]; if (apply(int_1.Interval.ofSingleton(e))) changed = true; } } return changed; } // var CrossLinkRestraintVisuals = { 'cross-link-restraint': function (ctx, getParams) { return (0, representation_2.ComplexRepresentation)('Cross-link restraint', ctx, getParams, CrossLinkRestraintVisual); }, }; exports.CrossLinkRestraintParams = (0, tslib_1.__assign)({}, exports.CrossLinkRestraintCylinderParams); function getCrossLinkRestraintParams(ctx, structure) { return param_definition_1.ParamDefinition.clone(exports.CrossLinkRestraintParams); } exports.getCrossLinkRestraintParams = getCrossLinkRestraintParams; function CrossLinkRestraintRepresentation(ctx, getParams) { return representation_1.Representation.createMulti('CrossLinkRestraint', ctx, getParams, representation_2.StructureRepresentationStateBuilder, CrossLinkRestraintVisuals); } exports.CrossLinkRestraintRepresentation = CrossLinkRestraintRepresentation; exports.CrossLinkRestraintRepresentationProvider = (0, representation_2.StructureRepresentationProvider)({ name: property_1.CrossLinkRestraint.Tag.CrossLinkRestraint, label: 'Cross Link Restraint', description: 'Displays cross-link restraints.', factory: CrossLinkRestraintRepresentation, getParams: getCrossLinkRestraintParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.CrossLinkRestraintParams), defaultColorTheme: { name: property_1.CrossLinkRestraint.Tag.CrossLinkRestraint }, defaultSizeTheme: { name: 'uniform' }, isApplicable: function (structure) { return property_1.CrossLinkRestraint.isApplicable(structure); }, ensureCustomProperties: { attach: function (ctx, structure) { return property_1.CrossLinkRestraintProvider.attach(ctx, structure, void 0, true); }, detach: function (data) { return property_1.CrossLinkRestraintProvider.ref(data, false); } } }); //# sourceMappingURL=representation.js.map