Select Git revision
bond-inter-unit-line.ts
bond-inter-unit-line.ts 7.09 KiB
/**
* Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
import { VisualContext } from '../../visual';
import { Structure, StructureElement, Bond, Unit } from '../../../mol-model/structure';
import { Theme } from '../../../mol-theme/theme';
import { Vec3 } from '../../../mol-math/linear-algebra';
import { BitFlags, arrayEqual } from '../../../mol-util';
import { LinkStyle, createLinkLines, LinkBuilderProps } from './util/link';
import { ComplexVisual, ComplexLinesVisual, ComplexLinesParams } from '../complex-visual';
import { VisualUpdateState } from '../../util';
import { BondType } from '../../../mol-model/structure/model/types';
import { BondIterator, getInterBondLoci, eachInterBond, BondLineParams, makeInterBondIgnoreTest } from './util/bond';
import { Lines } from '../../../mol-geo/geometry/lines/lines';
import { Sphere3D } from '../../../mol-math/geometry';
const tmpRefPosBondIt = new Bond.ElementBondIterator();
function setRefPosition(pos: Vec3, structure: Structure, unit: Unit.Atomic, index: StructureElement.UnitIndex) {
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 createInterUnitBondLines(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<InterUnitBondLineParams>, lines?: Lines) {
const bonds = structure.interUnitBonds;
const { edgeCount, edges } = bonds;
if (!edgeCount) return Lines.createEmpty(lines);
const { sizeFactor, aromaticBonds, multipleBonds } = props;
const mbOff = multipleBonds === 'off';
const mbSymmetric = multipleBonds === 'symmetric';
const ref = Vec3();
const loc = StructureElement.Location.create();
const builderProps: LinkBuilderProps = {
linkCount: edgeCount,
referencePosition: (edgeIndex: number) => {
const b = edges[edgeIndex];
let unitA: Unit.Atomic, unitB: Unit.Atomic;
let indexA: StructureElement.UnitIndex, indexB: StructureElement.UnitIndex;
if (b.unitA < b.unitB) {
unitA = structure.unitMap.get(b.unitA) as Unit.Atomic;
unitB = structure.unitMap.get(b.unitB) as Unit.Atomic;
indexA = b.indexA;
indexB = b.indexB;
} else if (b.unitA > b.unitB) {
unitA = structure.unitMap.get(b.unitB) as Unit.Atomic;
unitB = structure.unitMap.get(b.unitA) as Unit.Atomic;
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: Vec3, posB: Vec3, edgeIndex: number) => {
const b = edges[edgeIndex];
const uA = structure.unitMap.get(b.unitA);
const uB = structure.unitMap.get(b.unitB);