molstar
Version:
A comprehensive macromolecular library.
187 lines • 10.8 kB
JavaScript
"use strict";
/**
* Copyright (c) 2019-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.InteractionsIntraUnitVisual = exports.InteractionsIntraUnitParams = void 0;
var tslib_1 = require("tslib");
var structure_1 = require("../../../mol-model/structure");
var linear_algebra_1 = require("../../../mol-math/linear-algebra");
var loci_1 = require("../../../mol-model/loci");
var int_1 = require("../../../mol-data/int");
var param_definition_1 = require("../../../mol-util/param-definition");
var mesh_1 = require("../../../mol-geo/geometry/mesh/mesh");
var interactions_1 = require("../interactions");
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 interactions_2 = require("../interactions/interactions");
var geometry_1 = require("../../../mol-math/geometry");
function createIntraUnitInteractionsCylinderMesh(ctx, unit, structure, theme, props, mesh) {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
var child, childUnit, location, interactions, features, contacts, x, y, z, members, offsets, edgeCount, a, b, flag, sizeFactor, builderProps, m, sphere;
return (0, tslib_1.__generator)(this, function (_a) {
if (!structure_1.Unit.isAtomic(unit))
return [2 /*return*/, mesh_1.Mesh.createEmpty(mesh)];
child = structure.child;
childUnit = child === null || child === void 0 ? void 0 : child.unitMap.get(unit.id);
if (child && !childUnit)
return [2 /*return*/, mesh_1.Mesh.createEmpty(mesh)];
location = structure_1.StructureElement.Location.create(structure, unit);
interactions = interactions_1.InteractionsProvider.get(structure).value;
features = interactions.unitsFeatures.get(unit.id);
contacts = interactions.unitsContacts.get(unit.id);
x = features.x, y = features.y, z = features.z, members = features.members, offsets = features.offsets;
edgeCount = contacts.edgeCount, a = contacts.a, b = contacts.b, flag = contacts.edgeProps.flag;
sizeFactor = props.sizeFactor;
if (!edgeCount)
return [2 /*return*/, mesh_1.Mesh.createEmpty(mesh)];
builderProps = {
linkCount: edgeCount * 2,
position: function (posA, posB, edgeIndex) {
linear_algebra_1.Vec3.set(posA, x[a[edgeIndex]], y[a[edgeIndex]], z[a[edgeIndex]]);
linear_algebra_1.Vec3.set(posB, x[b[edgeIndex]], y[b[edgeIndex]], z[b[edgeIndex]]);
},
style: function (edgeIndex) { return 1 /* Dashed */; },
radius: function (edgeIndex) {
location.element = unit.elements[members[offsets[a[edgeIndex]]]];
var sizeA = theme.size.size(location);
location.element = unit.elements[members[offsets[b[edgeIndex]]]];
var sizeB = theme.size.size(location);
return Math.min(sizeA, sizeB) * sizeFactor;
},
ignore: function (edgeIndex) { return (flag[edgeIndex] === 1 /* Filtered */ ||
// TODO: check all members
(!!childUnit && !int_1.SortedArray.has(childUnit.elements, unit.elements[members[offsets[a[edgeIndex]]]]))); }
};
m = (0, link_1.createLinkCylinderMesh)(ctx, builderProps, props, mesh);
sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), (childUnit !== null && childUnit !== void 0 ? childUnit : unit).boundary.sphere, 1 * sizeFactor);
m.setBoundingSphere(sphere);
return [2 /*return*/, m];
});
});
}
exports.InteractionsIntraUnitParams = (0, tslib_1.__assign)((0, tslib_1.__assign)((0, tslib_1.__assign)({}, units_visual_1.UnitsMeshParams), link_1.LinkCylinderParams), { sizeFactor: param_definition_1.ParamDefinition.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), dashCount: param_definition_1.ParamDefinition.Numeric(6, { min: 2, max: 10, step: 2 }), dashScale: param_definition_1.ParamDefinition.Numeric(0.4, { min: 0, max: 2, step: 0.1 }), includeParent: param_definition_1.ParamDefinition.Boolean(false) });
function InteractionsIntraUnitVisual(materialId) {
return (0, units_visual_1.UnitsMeshVisual)({
defaultProps: param_definition_1.ParamDefinition.getDefaultValues(exports.InteractionsIntraUnitParams),
createGeometry: createIntraUnitInteractionsCylinderMesh,
createLocationIterator: createInteractionsIterator,
getLoci: getInteractionLoci,
eachLocation: eachInteraction,
setUpdateState: function (state, newProps, currentProps, newTheme, currentTheme, newStructureGroup, currentStructureGroup) {
state.createGeometry = (newProps.sizeFactor !== currentProps.sizeFactor ||
newProps.dashCount !== currentProps.dashCount ||
newProps.dashScale !== currentProps.dashScale ||
newProps.dashCap !== currentProps.dashCap ||
newProps.radialSegments !== currentProps.radialSegments);
var interactionsHash = interactions_1.InteractionsProvider.get(newStructureGroup.structure).version;
if (state.info.interactionsHash !== interactionsHash) {
state.createGeometry = true;
state.updateTransform = true;
state.updateColor = true;
state.info.interactionsHash = interactionsHash;
}
}
}, materialId);
}
exports.InteractionsIntraUnitVisual = InteractionsIntraUnitVisual;
function getInteractionLoci(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 = structure.unitMap.get(group.units[instanceId].id);
var interactions = interactions_1.InteractionsProvider.get(structure).value;
var _a = interactions.unitsContacts.get(unit.id), a = _a.a, b = _a.b;
return interactions_2.Interactions.Loci(structure, interactions, [
{ unitA: unit, indexA: a[groupId], unitB: unit, indexB: b[groupId] },
{ unitA: unit, indexA: b[groupId], unitB: unit, indexB: a[groupId] },
]);
}
return loci_1.EmptyLoci;
}
function eachInteraction(loci, structureGroup, apply, isMarking) {
var changed = false;
if (interactions_2.Interactions.isLoci(loci)) {
var structure = structureGroup.structure, group = structureGroup.group;
if (!structure_1.Structure.areEquivalent(loci.data.structure, structure))
return false;
var interactions = interactions_1.InteractionsProvider.get(structure).value;
if (loci.data.interactions !== interactions)
return false;
var unit = group.units[0];
var contacts = interactions.unitsContacts.get(unit.id);
var groupCount = contacts.edgeCount * 2;
for (var _i = 0, _a = loci.elements; _i < _a.length; _i++) {
var e = _a[_i];
if (e.unitA !== e.unitB)
continue;
var unitIdx = group.unitIndexMap.get(e.unitA.id);
if (unitIdx !== undefined) {
var idx = contacts.getDirectedEdgeIndex(e.indexA, e.indexB);
if (idx !== -1) {
if (apply(int_1.Interval.ofSingleton(unitIdx * groupCount + idx)))
changed = true;
}
}
}
}
else if (structure_1.StructureElement.Loci.is(loci)) {
var structure = structureGroup.structure, group = structureGroup.group;
if (!structure_1.Structure.areEquivalent(loci.structure, structure))
return false;
var interactions = interactions_1.InteractionsProvider.get(structure).value;
if (!interactions)
return false;
var unit = group.units[0];
var contacts = interactions.unitsContacts.get(unit.id);
var features = interactions.unitsFeatures.get(unit.id);
var groupCount_1 = contacts.edgeCount * 2;
var offset_1 = contacts.offset;
var _b = features.elementsIndex, fOffsets_1 = _b.offsets, fIndices_1 = _b.indices;
var _loop_1 = function (e) {
var unitIdx = group.unitIndexMap.get(e.unit.id);
if (unitIdx !== undefined)
return "continue";
if (isMarking && int_1.OrderedSet.size(e.indices) === 1)
return "continue";
int_1.OrderedSet.forEach(e.indices, function (v) {
for (var i = fOffsets_1[v], il = fOffsets_1[v + 1]; i < il; ++i) {
var fI = fIndices_1[i];
for (var j = offset_1[fI], jl = offset_1[fI + 1]; j < jl; ++j) {
if (apply(int_1.Interval.ofSingleton(unitIdx * groupCount_1 + j)))
changed = true;
}
}
});
};
// TODO: when isMarking, all elements of contact features need to be in the loci
for (var _c = 0, _d = loci.elements; _c < _d.length; _c++) {
var e = _d[_c];
_loop_1(e);
}
}
return changed;
}
function createInteractionsIterator(structureGroup) {
var structure = structureGroup.structure, group = structureGroup.group;
var unit = group.units[0];
var interactions = interactions_1.InteractionsProvider.get(structure).value;
var contacts = interactions.unitsContacts.get(unit.id);
var groupCount = contacts.edgeCount * 2;
var instanceCount = group.units.length;
var location = interactions_2.Interactions.Location(interactions, structure);
var element = location.element;
var getLocation = function (groupIndex, instanceIndex) {
var instanceUnit = group.units[instanceIndex];
element.unitA = instanceUnit;
element.indexA = contacts.a[groupIndex];
element.unitB = instanceUnit;
element.indexB = contacts.b[groupIndex];
return location;
};
return (0, location_iterator_1.LocationIterator)(groupCount, instanceCount, 1, getLocation);
}
//# sourceMappingURL=interactions-intra-unit-cylinder.js.map