UNPKG

molstar

Version:

A comprehensive macromolecular library.

49 lines (48 loc) 3.16 kB
/** * Copyright (c) 2020-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose <alexander.rose@weirdbyte.de> */ import { __assign } from "tslib"; import { IntraUnitBondLineVisual, IntraUnitBondLineParams } from '../visual/bond-intra-unit-line'; import { InterUnitBondLineVisual, InterUnitBondLineParams } from '../visual/bond-inter-unit-line'; import { ParamDefinition as PD } from '../../../mol-util/param-definition'; import { UnitsRepresentation } from '../units-representation'; import { ComplexRepresentation } from '../complex-representation'; import { StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation'; import { Representation } from '../../../mol-repr/representation'; import { getUnitKindsParam } from '../params'; import { ElementPointParams, ElementPointVisual } from '../visual/element-point'; import { ElementCrossParams, ElementCrossVisual } from '../visual/element-cross'; var LineVisuals = { 'intra-bond': function (ctx, getParams) { return UnitsRepresentation('Intra-unit bond line', ctx, getParams, IntraUnitBondLineVisual); }, 'inter-bond': function (ctx, getParams) { return ComplexRepresentation('Inter-unit bond line', ctx, getParams, InterUnitBondLineVisual); }, 'element-point': function (ctx, getParams) { return UnitsRepresentation('Points', ctx, getParams, ElementPointVisual); }, 'element-cross': function (ctx, getParams) { return UnitsRepresentation('Crosses', ctx, getParams, ElementCrossVisual); }, }; export var LineParams = __assign(__assign(__assign(__assign(__assign({}, IntraUnitBondLineParams), InterUnitBondLineParams), ElementPointParams), ElementCrossParams), { multipleBonds: PD.Select('offset', PD.arrayToOptions(['off', 'symmetric', 'offset'])), includeParent: PD.Boolean(false), sizeFactor: PD.Numeric(2, { min: 0.01, max: 10, step: 0.01 }), unitKinds: getUnitKindsParam(['atomic']), visuals: PD.MultiSelect(['intra-bond', 'inter-bond', 'element-point', 'element-cross'], PD.objectToOptions(LineVisuals)) }); export function getLineParams(ctx, structure) { var params = PD.clone(LineParams); params.pointStyle.defaultValue = 'circle'; return params; } export function LineRepresentation(ctx, getParams) { return Representation.createMulti('Line', ctx, getParams, StructureRepresentationStateBuilder, LineVisuals); } export var LineRepresentationProvider = StructureRepresentationProvider({ name: 'line', label: 'Line', description: 'Displays bonds as lines and atoms as points or croses.', factory: LineRepresentation, getParams: getLineParams, defaultValues: PD.getDefaultValues(LineParams), defaultColorTheme: { name: 'element-symbol' }, defaultSizeTheme: { name: 'uniform' }, isApplicable: function (structure) { return structure.elementCount > 0; }, getData: function (structure, props) { return props.includeParent ? structure.asParent() : structure; }, mustRecreate: function (oldProps, newProps) { return oldProps.includeParent !== newProps.includeParent; } });