Skip to content
Snippets Groups Projects
Select Git revision
  • ea08b46ff289f4c265b260773557c7df7796bf6a
  • 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

util.ts

Blame
  • polymer-trace-mesh.ts 7.55 KiB
    /**
     * Copyright (c) 2018-2019 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 { Unit, Structure } from '../../../mol-model/structure';
    import { Theme } from '../../../mol-theme/theme';
    import { Mesh } from '../../../mol-geo/geometry/mesh/mesh';
    import { MeshBuilder } from '../../../mol-geo/geometry/mesh/mesh-builder';
    import { createCurveSegmentState, PolymerTraceIterator, interpolateCurveSegment, interpolateSizes, PolymerLocationIterator, getPolymerElementLoci, eachPolymerElement } from './util/polymer';
    import { isNucleic, SecondaryStructureType } from '../../../mol-model/structure/model/types';
    import { addSheet } from '../../../mol-geo/geometry/mesh/builder/sheet';
    import { addTube } from '../../../mol-geo/geometry/mesh/builder/tube';
    import { UnitsMeshParams, UnitsVisual, UnitsMeshVisual, StructureGroup } from '../units-visual';
    import { VisualUpdateState } from '../../util';
    import { ComputedSecondaryStructure } from '../../../mol-model-props/computed/secondary-structure';
    import { addRibbon } from '../../../mol-geo/geometry/mesh/builder/ribbon';
    
    export const PolymerTraceMeshParams = {
        sizeFactor: PD.Numeric(0.2, { min: 0, max: 10, step: 0.01 }),
        linearSegments: PD.Numeric(8, { min: 1, max: 48, step: 1 }),
        radialSegments: PD.Numeric(16, { min: 2, max: 56, step: 2 }),
        aspectRatio: PD.Numeric(5, { min: 0.1, max: 10, step: 0.1 }),
        arrowFactor: PD.Numeric(1.5, { min: 0, max: 3, step: 0.1 }),
    }
    export const DefaultPolymerTraceMeshProps = PD.getDefaultValues(PolymerTraceMeshParams)
    export type PolymerTraceMeshProps = typeof DefaultPolymerTraceMeshProps
    
    // TODO handle polymer ends properly
    
    function createPolymerTraceMesh(ctx: VisualContext, unit: Unit, structure: Structure, theme: Theme, props: PolymerTraceMeshProps, mesh?: Mesh) {
        const polymerElementCount = unit.polymerElements.length
    
        if (!polymerElementCount) return Mesh.createEmpty(mesh)
        const { sizeFactor, linearSegments, radialSegments, aspectRatio, arrowFactor } = props
    
        const vertexCount = linearSegments * radialSegments * polymerElementCount + (radialSegments + 1) * polymerElementCount * 2
        const builderState = MeshBuilder.createState(vertexCount, vertexCount / 10, mesh)
    
        const isCoarse = Unit.isCoarse(unit)
        const state = createCurveSegmentState(linearSegments)
        const { curvePoints, normalVectors, binormalVectors, widthValues, heightValues } = state
    
        let i = 0
        const polymerTraceIt = PolymerTraceIterator(unit, structure)
        while (polymerTraceIt.hasNext) {
            const v = polymerTraceIt.move()
            builderState.currentGroup = i
    
            const isNucleicType = isNucleic(v.moleculeType)
            const isSheet = SecondaryStructureType.is(v.secStrucType, SecondaryStructureType.Flag.Beta)
            const isHelix = SecondaryStructureType.is(v.secStrucType, SecondaryStructureType.Flag.Helix)
            const tension = isHelix ? 0.9 : 0.5
            const shift = isNucleicType ? 0.3 : 0.5
    
            interpolateCurveSegment(state, v, tension, shift)
    
            let w0 = theme.size.size(v.centerPrev) * sizeFactor
            let w1 = theme.size.size(v.center) * sizeFactor
            let w2 = theme.size.size(v.centerNext) * sizeFactor
            if (isCoarse) {
                w0 *= aspectRatio / 2
                w1 *= aspectRatio / 2
                w2 *= aspectRatio / 2
            }
    
            if (isSheet) {