Select Git revision
polymer-trace-mesh.ts
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,