molstar
Version:
A comprehensive macromolecular library.
183 lines • 10.1 kB
JavaScript
/**
* Copyright (c) 2019-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { __assign, __awaiter, __generator } from "tslib";
import { Unit, Structure, StructureElement } from '../../../mol-model/structure';
import { Vec3 } from '../../../mol-math/linear-algebra';
import { EmptyLoci } from '../../../mol-model/loci';
import { Interval, OrderedSet, SortedArray } from '../../../mol-data/int';
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
import { Mesh } from '../../../mol-geo/geometry/mesh/mesh';
import { InteractionsProvider } from '../interactions';
import { createLinkCylinderMesh, LinkCylinderParams } from '../../../mol-repr/structure/visual/util/link';
import { UnitsMeshParams, UnitsMeshVisual } from '../../../mol-repr/structure/units-visual';
import { LocationIterator } from '../../../mol-geo/util/location-iterator';
import { Interactions } from '../interactions/interactions';
import { Sphere3D } from '../../../mol-math/geometry';
function createIntraUnitInteractionsCylinderMesh(ctx, unit, structure, theme, props, mesh) {
return __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 __generator(this, function (_a) {
if (!Unit.isAtomic(unit))
return [2 /*return*/, 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.createEmpty(mesh)];
location = StructureElement.Location.create(structure, unit);
interactions = 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.createEmpty(mesh)];
builderProps = {
linkCount: edgeCount * 2,
position: function (posA, posB, edgeIndex) {
Vec3.set(posA, x[a[edgeIndex]], y[a[edgeIndex]], z[a[edgeIndex]]);
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 && !SortedArray.has(childUnit.elements, unit.elements[members[offsets[a[edgeIndex]]]]))); }
};
m = createLinkCylinderMesh(ctx, builderProps, props, mesh);
sphere = Sphere3D.expand(Sphere3D(), (childUnit !== null && childUnit !== void 0 ? childUnit : unit).boundary.sphere, 1 * sizeFactor);
m.setBoundingSphere(sphere);
return [2 /*return*/, m];
});
});
}
export var InteractionsIntraUnitParams = __assign(__assign(__assign({}, UnitsMeshParams), LinkCylinderParams), { sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }), dashCount: PD.Numeric(6, { min: 2, max: 10, step: 2 }), dashScale: PD.Numeric(0.4, { min: 0, max: 2, step: 0.1 }), includeParent: PD.Boolean(false) });
export function InteractionsIntraUnitVisual(materialId) {
return UnitsMeshVisual({
defaultProps: PD.getDefaultValues(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 = InteractionsProvider.get(newStructureGroup.structure).version;
if (state.info.interactionsHash !== interactionsHash) {
state.createGeometry = true;
state.updateTransform = true;
state.updateColor = true;
state.info.interactionsHash = interactionsHash;
}
}
}, materialId);
}
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 = InteractionsProvider.get(structure).value;
var _a = interactions.unitsContacts.get(unit.id), a = _a.a, b = _a.b;
return 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 EmptyLoci;
}
function eachInteraction(loci, structureGroup, apply, isMarking) {
var changed = false;
if (Interactions.isLoci(loci)) {
var structure = structureGroup.structure, group = structureGroup.group;
if (!Structure.areEquivalent(loci.data.structure, structure))
return false;
var interactions = 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(Interval.ofSingleton(unitIdx * groupCount + idx)))
changed = true;
}
}
}
}
else if (StructureElement.Loci.is(loci)) {
var structure = structureGroup.structure, group = structureGroup.group;
if (!Structure.areEquivalent(loci.structure, structure))
return false;
var interactions = 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 && OrderedSet.size(e.indices) === 1)
return "continue";
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(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 = InteractionsProvider.get(structure).value;
var contacts = interactions.unitsContacts.get(unit.id);
var groupCount = contacts.edgeCount * 2;
var instanceCount = group.units.length;
var location = 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 LocationIterator(groupCount, instanceCount, 1, getLocation);
}
//# sourceMappingURL=interactions-intra-unit-cylinder.js.map