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

polymer-trace-mesh.ts

Blame
  • inter-unit-link-cylinder.ts 5.54 KiB
    /**
     * Copyright (c) 2018 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, Link } from '../../../mol-model/structure';
    import { Theme } from '../../../mol-theme/theme';
    import { Mesh } from '../../../mol-geo/geometry/mesh/mesh';
    import { Vec3 } from '../../../mol-math/linear-algebra';
    import { BitFlags } from '../../../mol-util';
    import { createLinkCylinderMesh, LinkCylinderParams, LinkIterator } from './util/link';
    import { ComplexMeshParams, ComplexVisual, ComplexMeshVisual } from '../complex-visual';
    import { VisualUpdateState } from '../../util';
    import { PickingId } from '../../../mol-geo/geometry/picking';
    import { EmptyLoci, Loci } from '../../../mol-model/loci';
    import { Interval, OrderedSet } from '../../../mol-data/int';
    import { isHydrogen } from './util/common';
    
    function createInterUnitLinkCylinderMesh(ctx: VisualContext, structure: Structure, theme: Theme, props: PD.Values<InterUnitLinkParams>, mesh?: Mesh) {
        const links = structure.links
        const { bondCount, bonds } = links
        const { sizeFactor, sizeAspectRatio, ignoreHydrogens } = props
    
        if (!bondCount) return Mesh.createEmpty(mesh)
    
        const location = StructureElement.create()
    
        const builderProps = {
            linkCount: bondCount,
            referencePosition: (edgeIndex: number) => null, // TODO
            position: (posA: Vec3, posB: Vec3, edgeIndex: number) => {
                const b = bonds[edgeIndex]
                const uA = b.unitA, uB = b.unitB
                uA.conformation.position(uA.elements[b.indexA], posA)
                uB.conformation.position(uB.elements[b.indexB], posB)
            },
            order: (edgeIndex: number) => bonds[edgeIndex].order,
            flags: (edgeIndex: number) => BitFlags.create(bonds[edgeIndex].flag),
            radius: (edgeIndex: number) => {
                const b = bonds[edgeIndex]
                location.unit = b.unitA
                location.element = b.unitA.elements[b.indexA]
                return theme.size.size(location) * sizeFactor * sizeAspectRatio
            },
            ignore: ignoreHydrogens ? (edgeIndex: number) => {
                const b = bonds[edgeIndex]
                const uA = b.unitA, uB = b.unitB
                return isHydrogen(uA, uA.elements[b.indexA]) || isHydrogen(uB, uB.elements[b.indexB])
            } : () => false
        }
    
        return createLinkCylinderMesh(ctx, builderProps, props, mesh)
    }
    
    export const InterUnitLinkParams = {
        ...ComplexMeshParams,
        ...LinkCylinderParams,
        sizeFactor: PD.Numeric(0.3, { min: 0, max: 10, step: 0.01 }),
        sizeAspectRatio: PD.Numeric(2/3, { min: 0, max: 3, step: 0.01 }),
        ignoreHydrogens: PD.Boolean(false),
    }
    export type InterUnitLinkParams = typeof InterUnitLinkParams
    
    export function InterUnitLinkVisual(materialId: number): ComplexVisual<InterUnitLinkParams> {
        return ComplexMeshVisual<InterUnitLinkParams>({
            defaultProps: PD.getDefaultValues(InterUnitLinkParams),
            createGeometry: createInterUnitLinkCylinderMesh,