molstar
Version:
A comprehensive macromolecular library.
52 lines (51 loc) • 2.58 kB
JavaScript
/**
* Copyright (c) 2018-2024 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { ElementSphereVisual, ElementSphereParams, StructureElementSphereVisual } from '../visual/element-sphere';
import { UnitsRepresentation } from '../units-representation';
import { ParamDefinition as PD } from '../../../mol-util/param-definition';
import { ComplexRepresentation, StructureRepresentationProvider, StructureRepresentationStateBuilder } from '../representation';
import { Representation } from '../../../mol-repr/representation';
import { BaseGeometry } from '../../../mol-geo/geometry/base';
const SpacefillVisuals = {
'element-sphere': (ctx, getParams) => UnitsRepresentation('Sphere mesh/impostor', ctx, getParams, ElementSphereVisual),
'structure-element-sphere': (ctx, getParams) => ComplexRepresentation('Structure sphere mesh/impostor', ctx, getParams, StructureElementSphereVisual),
};
export const SpacefillParams = {
...ElementSphereParams,
bumpFrequency: PD.Numeric(1, { min: 0, max: 10, step: 0.1 }, BaseGeometry.ShadingCategory),
density: PD.Numeric(0.5, { min: 0, max: 1, step: 0.01 }, BaseGeometry.ShadingCategory),
visuals: PD.MultiSelect(['element-sphere'], PD.objectToOptions(SpacefillVisuals)),
};
let CoarseGrainedSpacefillParams;
export function getSpacefillParams(ctx, structure) {
let params = SpacefillParams;
if (structure.isCoarseGrained) {
if (!CoarseGrainedSpacefillParams) {
CoarseGrainedSpacefillParams = PD.clone(SpacefillParams);
CoarseGrainedSpacefillParams.sizeFactor.defaultValue = 2;
}
params = CoarseGrainedSpacefillParams;
}
if (structure.unitSymmetryGroups.length > 5000) {
params = PD.clone(params);
params.visuals.defaultValue = ['structure-element-sphere'];
}
return params;
}
export function SpacefillRepresentation(ctx, getParams) {
return Representation.createMulti('Spacefill', ctx, getParams, StructureRepresentationStateBuilder, SpacefillVisuals);
}
export const SpacefillRepresentationProvider = StructureRepresentationProvider({
name: 'spacefill',
label: 'Spacefill',
description: 'Displays atomic/coarse elements as spheres.',
factory: SpacefillRepresentation,
getParams: getSpacefillParams,
defaultValues: PD.getDefaultValues(SpacefillParams),
defaultColorTheme: { name: 'element-symbol' },
defaultSizeTheme: { name: 'physical' },
isApplicable: (structure) => structure.elementCount > 0
});