Skip to content
Snippets Groups Projects
Select Git revision
  • c28dd8135cd61db9047967bcc1ab74bb6d67aad4
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

bond-inter-unit-line.ts

Blame
  • 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);