UNPKG

molstar

Version:

A comprehensive macromolecular library.

243 lines 13.6 kB
"use strict"; /** * Copyright (c) 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.ClashesRepresentationProvider = exports.ClashesRepresentation = exports.getClashesParams = exports.ClashesParams = exports.InterUnitClashVisual = exports.InterUnitClashParams = exports.IntraUnitClashVisual = exports.IntraUnitClashParams = 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 loci_1 = require("../../../mol-model/loci"); var representation_1 = require("../../../mol-repr/representation"); var representation_2 = require("../../../mol-repr/structure/representation"); var link_1 = require("../../../mol-repr/structure/visual/util/link"); var units_visual_1 = require("../../../mol-repr/structure/units-visual"); var location_iterator_1 = require("../../../mol-geo/util/location-iterator"); var prop_1 = require("./prop"); var complex_visual_1 = require("../../../mol-repr/structure/complex-visual"); var color_1 = require("../../../mol-util/color"); var marker_action_1 = require("../../../mol-util/marker-action"); var centroid_helper_1 = require("../../../mol-math/geometry/centroid-helper"); var label_1 = require("../../../mol-theme/label"); var params_1 = require("../../../mol-repr/structure/params"); // function createIntraUnitClashCylinderMesh(ctx, unit, structure, theme, props, mesh) { if (!structure_1.Unit.isAtomic(unit)) return mesh_1.Mesh.createEmpty(mesh); var clashes = prop_1.ClashesProvider.get(structure).value.intraUnit.get(unit.id); var edgeCount = clashes.edgeCount, a = clashes.a, b = clashes.b, edgeProps = clashes.edgeProps; var magnitude = edgeProps.magnitude; var sizeFactor = props.sizeFactor; if (!edgeCount) return mesh_1.Mesh.createEmpty(mesh); var elements = unit.elements; var pos = unit.conformation.invariantPosition; var builderProps = { linkCount: edgeCount * 2, position: function (posA, posB, edgeIndex) { pos(elements[a[edgeIndex]], posA); pos(elements[b[edgeIndex]], posB); }, style: function (edgeIndex) { return 6 /* Disk */; }, radius: function (edgeIndex) { return magnitude[edgeIndex] * sizeFactor; }, }; return (0, link_1.createLinkCylinderMesh)(ctx, builderProps, props, mesh); } exports.IntraUnitClashParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, units_visual_1.UnitsMeshParams), link_1.LinkCylinderParams), { linkCap: param_definition_1.ParamDefinition.Boolean(true), sizeFactor: param_definition_1.ParamDefinition.Numeric(1, { min: 0, max: 10, step: 0.01 }) }); function IntraUnitClashVisual(materialId) { return (0, units_visual_1.UnitsMeshVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.IntraUnitClashParams), createGeometry: createIntraUnitClashCylinderMesh, createLocationIterator: createIntraClashIterator, getLoci: getIntraClashLoci, eachLocation: eachIntraClash, setUpdateState: function (state, newProps, currentProps) { state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor || newProps.radialSegments !== currentProps.radialSegments || newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.linkCap !== currentProps.linkCap); } }, materialId); } exports.IntraUnitClashVisual = IntraUnitClashVisual; function getIntraClashBoundingSphere(unit, clashes, elements, boundingSphere) { return centroid_helper_1.CentroidHelper.fromPairProvider(elements.length, function (i, pA, pB) { unit.conformation.position(unit.elements[clashes.a[elements[i]]], pA); unit.conformation.position(unit.elements[clashes.b[elements[i]]], pB); }, boundingSphere); } function getIntraClashLabel(structure, unit, clashes, elements) { var idx = elements[0]; if (idx === undefined) return ''; var _a = clashes.edgeProps, id = _a.id, magnitude = _a.magnitude, distance = _a.distance; var mag = magnitude[idx].toFixed(2); var dist = distance[idx].toFixed(2); return [ "Clash id: " + id[idx] + " | Magnitude: " + mag + " \u212B | Distance: " + dist + " \u212B", (0, label_1.bondLabel)(structure_1.Bond.Location(structure, unit, clashes.a[idx], structure, unit, clashes.b[idx])) ].join('</br>'); } function IntraClashLoci(structure, unit, clashes, elements) { return (0, loci_1.DataLoci)('intra-clashes', { unit: unit, clashes: clashes }, elements, function (boundingSphere) { return getIntraClashBoundingSphere(unit, clashes, elements, boundingSphere); }, function () { return getIntraClashLabel(structure, unit, clashes, elements); }); } function getIntraClashLoci(pickingId, structureGroup, id) { var objectId = pickingId.objectId, instanceId = pickingId.instanceId, groupId = pickingId.groupId; if (id === objectId) { var structure = structureGroup.structure, group = structureGroup.group; var unit = group.units[instanceId]; if (structure_1.Unit.isAtomic(unit)) { var clashes = prop_1.ClashesProvider.get(structure).value.intraUnit.get(unit.id); return IntraClashLoci(structure, unit, clashes, [groupId]); } } return loci_1.EmptyLoci; } function eachIntraClash(loci, structureGroup, apply) { var changed = false; // TODO return changed; } function createIntraClashIterator(structureGroup) { var structure = structureGroup.structure, group = structureGroup.group; var unit = group.units[0]; var clashes = prop_1.ClashesProvider.get(structure).value.intraUnit.get(unit.id); var a = clashes.a; var groupCount = clashes.edgeCount * 2; var instanceCount = group.units.length; var location = structure_1.StructureElement.Location.create(structure); var getLocation = function (groupIndex, instanceIndex) { var unit = group.units[instanceIndex]; location.unit = unit; location.element = unit.elements[a[groupIndex]]; return location; }; return (0, location_iterator_1.LocationIterator)(groupCount, instanceCount, 1, getLocation); } // function createInterUnitClashCylinderMesh(ctx, structure, theme, props, mesh) { var clashes = prop_1.ClashesProvider.get(structure).value.interUnit; var edges = clashes.edges, edgeCount = clashes.edgeCount; var sizeFactor = props.sizeFactor; if (!edgeCount) return mesh_1.Mesh.createEmpty(mesh); var builderProps = { linkCount: edgeCount, 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) { return 6 /* Disk */; }, radius: function (edgeIndex) { return edges[edgeIndex].props.magnitude * sizeFactor; } }; return (0, link_1.createLinkCylinderMesh)(ctx, builderProps, props, mesh); } exports.InterUnitClashParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, complex_visual_1.ComplexMeshParams), link_1.LinkCylinderParams), { linkCap: param_definition_1.ParamDefinition.Boolean(true), sizeFactor: param_definition_1.ParamDefinition.Numeric(1, { min: 0, max: 10, step: 0.01 }) }); function InterUnitClashVisual(materialId) { return (0, complex_visual_1.ComplexMeshVisual)({ defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.InterUnitClashParams), createGeometry: createInterUnitClashCylinderMesh, createLocationIterator: createInterClashIterator, getLoci: getInterClashLoci, eachLocation: eachInterClash, setUpdateState: function (state, newProps, currentProps) { state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor || newProps.radialSegments !== currentProps.radialSegments || newProps.linkScale !== currentProps.linkScale || newProps.linkSpacing !== currentProps.linkSpacing || newProps.linkCap !== currentProps.linkCap); } }, materialId); } exports.InterUnitClashVisual = InterUnitClashVisual; function getInterClashBoundingSphere(structure, clashes, elements, boundingSphere) { return centroid_helper_1.CentroidHelper.fromPairProvider(elements.length, function (i, pA, pB) { var c = clashes.edges[elements[i]]; var uA = structure.unitMap.get(c.unitA); var uB = structure.unitMap.get(c.unitB); uA.conformation.position(uA.elements[c.indexA], pA); uB.conformation.position(uB.elements[c.indexB], pB); }, boundingSphere); } function getInterClashLabel(structure, clashes, elements) { var idx = elements[0]; if (idx === undefined) return ''; var c = clashes.edges[idx]; var uA = structure.unitMap.get(c.unitA); var uB = structure.unitMap.get(c.unitB); var mag = c.props.magnitude.toFixed(2); var dist = c.props.distance.toFixed(2); return [ "Clash id: " + c.props.id + " | Magnitude: " + mag + " \u212B | Distance: " + dist + " \u212B", (0, label_1.bondLabel)(structure_1.Bond.Location(structure, uA, c.indexA, structure, uB, c.indexB)) ].join('</br>'); } function InterClashLoci(structure, clashes, elements) { return (0, loci_1.DataLoci)('inter-clashes', clashes, elements, function (boundingSphere) { return getInterClashBoundingSphere(structure, clashes, elements, boundingSphere); }, function () { return getInterClashLabel(structure, clashes, elements); }); } function getInterClashLoci(pickingId, structure, id) { var objectId = pickingId.objectId, groupId = pickingId.groupId; if (id === objectId) { var clashes = prop_1.ClashesProvider.get(structure).value.interUnit; return InterClashLoci(structure, clashes, [groupId]); } return loci_1.EmptyLoci; } function eachInterClash(loci, structure, apply) { var changed = false; // TODO return changed; } function createInterClashIterator(structure) { var clashes = prop_1.ClashesProvider.get(structure).value.interUnit; var groupCount = clashes.edgeCount; var instanceCount = 1; var location = structure_1.StructureElement.Location.create(structure); var getLocation = function (groupIndex) { var clash = clashes.edges[groupIndex]; location.unit = structure.unitMap.get(clash.unitA); location.element = location.unit.elements[clash.indexA]; return location; }; return (0, location_iterator_1.LocationIterator)(groupCount, instanceCount, 1, getLocation, true); } // var ClashesVisuals = { 'intra-clash': function (ctx, getParams) { return (0, representation_2.UnitsRepresentation)('Intra-unit clash cylinder', ctx, getParams, IntraUnitClashVisual); }, 'inter-clash': function (ctx, getParams) { return (0, representation_2.ComplexRepresentation)('Inter-unit clash cylinder', ctx, getParams, InterUnitClashVisual); }, }; exports.ClashesParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, exports.IntraUnitClashParams), exports.InterUnitClashParams), { unitKinds: (0, params_1.getUnitKindsParam)(['atomic']), visuals: param_definition_1.ParamDefinition.MultiSelect(['intra-clash', 'inter-clash'], param_definition_1.ParamDefinition.objectToOptions(ClashesVisuals)) }); function getClashesParams(ctx, structure) { return param_definition_1.ParamDefinition.clone(exports.ClashesParams); } exports.getClashesParams = getClashesParams; function ClashesRepresentation(ctx, getParams) { var repr = representation_1.Representation.createMulti('Clashes', ctx, getParams, representation_2.StructureRepresentationStateBuilder, ClashesVisuals); repr.setState({ markerActions: marker_action_1.MarkerActions.Highlighting }); return repr; } exports.ClashesRepresentation = ClashesRepresentation; exports.ClashesRepresentationProvider = (0, representation_2.StructureRepresentationProvider)({ name: prop_1.ValidationReport.Tag.Clashes, label: 'Validation Clashes', description: 'Displays clashes between atoms as disks. Data from wwPDB Validation Report, obtained via RCSB PDB.', factory: ClashesRepresentation, getParams: getClashesParams, defaultValues: param_definition_1.ParamDefinition.getDefaultValues(exports.ClashesParams), defaultColorTheme: { name: 'uniform', props: { value: (0, color_1.Color)(0xFA28FF) } }, defaultSizeTheme: { name: 'physical' }, isApplicable: function (structure) { return structure.elementCount > 0; }, ensureCustomProperties: { attach: function (ctx, structure) { return prop_1.ClashesProvider.attach(ctx, structure, void 0, true); }, detach: function (data) { return prop_1.ClashesProvider.ref(data, false); } } }); //# sourceMappingURL=representation.js.map