molstar
Version:
A comprehensive macromolecular library.
156 lines (155 loc) • 7.67 kB
JavaScript
/**
* Copyright (c) 2020-2024 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.InterUnitBondLineParams = void 0;
exports.getInterUnitBondLineBuilderProps = getInterUnitBondLineBuilderProps;
exports.InterUnitBondLineVisual = InterUnitBondLineVisual;
const param_definition_1 = require("../../../mol-util/param-definition");
const structure_1 = require("../../../mol-model/structure");
const linear_algebra_1 = require("../../../mol-math/linear-algebra");
const mol_util_1 = require("../../../mol-util");
const link_1 = require("./util/link");
const complex_visual_1 = require("../complex-visual");
const types_1 = require("../../../mol-model/structure/model/types");
const bond_1 = require("./util/bond");
const lines_1 = require("../../../mol-geo/geometry/lines/lines");
const geometry_1 = require("../../../mol-math/geometry");
const location_iterator_1 = require("../../../mol-geo/util/location-iterator");
const tmpRefPosBondIt = new structure_1.Bond.ElementBondIterator();
function setRefPosition(pos, structure, unit, index) {
tmpRefPosBondIt.setElement(structure, unit, index);
while (tmpRefPosBondIt.hasNext) {
const bA = tmpRefPosBondIt.move();
bA.otherUnit.conformation.position(bA.otherUnit.elements[bA.otherIndex], pos);
return pos;
}
return null;
}
function getInterUnitBondLineBuilderProps(structure, theme, props) {
const bonds = structure.interUnitBonds;
const { edgeCount, edges } = bonds;
const { sizeFactor, aromaticBonds, multipleBonds } = props;
const mbOff = multipleBonds === 'off';
const mbSymmetric = multipleBonds === 'symmetric';
const ref = (0, linear_algebra_1.Vec3)();
const loc = structure_1.StructureElement.Location.create();
return {
linkCount: edgeCount,
referencePosition: (edgeIndex) => {
const b = edges[edgeIndex];
let unitA, unitB;
let 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: (posA, posB, edgeIndex, _adjust) => {
const b = edges[edgeIndex];
const uA = structure.unitMap.get(b.unitA);
const uB = structure.unitMap.get(b.unitB);
uA.conformation.position(uA.elements[b.indexA], posA);
uB.conformation.position(uB.elements[b.indexB], posB);
},
style: (edgeIndex) => {
const o = edges[edgeIndex].props.order;
const 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: (edgeIndex) => {
const b = edges[edgeIndex];
loc.structure = structure;
loc.unit = structure.unitMap.get(b.unitA);
loc.element = loc.unit.elements[b.indexA];
const sizeA = theme.size.size(loc);
loc.unit = structure.unitMap.get(b.unitB);
loc.element = loc.unit.elements[b.indexB];
const sizeB = theme.size.size(loc);
return Math.min(sizeA, sizeB) * sizeFactor;
},
ignore: (0, bond_1.makeInterBondIgnoreTest)(structure, props)
};
}
function createInterUnitBondLines(ctx, structure, theme, props, lines) {
if (!(0, bond_1.hasStructureVisibleBonds)(structure, props))
return lines_1.Lines.createEmpty(lines);
if (!structure.interUnitBonds.edgeCount)
return lines_1.Lines.createEmpty(lines);
const builderProps = getInterUnitBondLineBuilderProps(structure, theme, props);
const { lines: l, boundingSphere } = (0, link_1.createLinkLines)(ctx, builderProps, props, lines);
if (boundingSphere) {
l.setBoundingSphere(boundingSphere);
}
else if (l.lineCount > 0) {
const { child } = structure;
const sphere = geometry_1.Sphere3D.expand((0, geometry_1.Sphere3D)(), (child !== null && child !== void 0 ? child : structure).boundary.sphere, 1 * props.sizeFactor);
l.setBoundingSphere(sphere);
}
return l;
}
exports.InterUnitBondLineParams = {
...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: (structure, props) => {
return !(0, bond_1.hasStructureVisibleBonds)(structure, props)
? location_iterator_1.EmptyLocationIterator
: bond_1.BondIterator.fromStructure(structure);
},
getLoci: bond_1.getInterBondLoci,
eachLocation: bond_1.eachInterBond,
setUpdateState: (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 ||
newProps.ignoreHydrogensVariant !== currentProps.ignoreHydrogensVariant ||
!(0, mol_util_1.arrayEqual)(newProps.includeTypes, currentProps.includeTypes) ||
!(0, mol_util_1.arrayEqual)(newProps.excludeTypes, currentProps.excludeTypes) ||
newProps.multipleBonds !== currentProps.multipleBonds);
if ((0, bond_1.hasStructureVisibleBonds)(newStructure, newProps) && newStructure.interUnitBonds !== currentStructure.interUnitBonds) {
state.createGeometry = true;
state.updateTransform = true;
state.updateColor = true;
state.updateSize = true;
}
}
}, materialId);
}
;