gaussian.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import { Unit, Structure } from '../../../../mol-model/structure';
  7. import { GaussianDensity } from '../../../../mol-math/geometry/gaussian-density';
  8. import { Task } from '../../../../mol-task';
  9. import { ParamDefinition as PD } from '../../../../mol-util/param-definition';
  10. import { GaussianDensityTexture, GaussianDensityTexture2d } from '../../../../mol-math/geometry/gaussian-density/gpu';
  11. import { Texture } from '../../../../mol-gl/webgl/texture';
  12. import { WebGLContext } from '../../../../mol-gl/webgl/context';
  13. import { getUnitConformationAndRadius, getStructureConformationAndRadius, CommonSurfaceParams, ensureReasonableResolution } from './common';
  14. import { BaseGeometry } from '../../../../mol-geo/geometry/base';
  15. const SharedGaussianDensityParams = {
  16. resolution: PD.Numeric(1, { min: 0.1, max: 20, step: 0.1 }, { description: 'Grid resolution/cell spacing.', ...BaseGeometry.CustomQualityParamInfo }),
  17. radiusOffset: PD.Numeric(0, { min: 0, max: 10, step: 0.1 }, { description: 'Extra/offset radius added to the atoms/coarse elements for gaussian calculation. Useful to create coarse, low resolution surfaces.' }),
  18. smoothness: PD.Numeric(1.5, { min: 0.5, max: 2.5, step: 0.1 }, { description: 'Smoothness of the gausian surface, lower is smoother.' }),
  19. ...CommonSurfaceParams
  20. };
  21. export const GaussianDensityParams = {
  22. ...SharedGaussianDensityParams,
  23. useGpu: PD.Boolean(false),
  24. };
  25. export const DefaultGaussianDensityProps = PD.getDefaultValues(GaussianDensityParams);
  26. export type GaussianDensityProps = typeof DefaultGaussianDensityProps
  27. export const GaussianDensityTextureParams = {
  28. ...SharedGaussianDensityParams
  29. };
  30. export const DefaultGaussianDensityTextureProps = PD.getDefaultValues(GaussianDensityTextureParams);
  31. export type GaussianDensityTextureProps = typeof DefaultGaussianDensityTextureProps
  32. //
  33. export function computeUnitGaussianDensity(structure: Structure, unit: Unit, props: GaussianDensityProps, webgl?: WebGLContext) {
  34. const { box } = unit.lookup3d.boundary;
  35. const p = ensureReasonableResolution(box, props);
  36. const { position, radius } = getUnitConformationAndRadius(structure, unit, p);
  37. return Task.create('Gaussian Density', async ctx => {
  38. return await GaussianDensity(ctx, position, box, radius, p, webgl);
  39. });
  40. }
  41. export function computeUnitGaussianDensityTexture(structure: Structure, unit: Unit, props: GaussianDensityTextureProps, webgl: WebGLContext, texture?: Texture) {
  42. const { box } = unit.lookup3d.boundary;
  43. const p = ensureReasonableResolution(box, props);
  44. const { position, radius } = getUnitConformationAndRadius(structure, unit, p);
  45. return Task.create('Gaussian Density', async ctx => {
  46. return GaussianDensityTexture(webgl, position, box, radius, p, texture);
  47. });
  48. }
  49. export function computeUnitGaussianDensityTexture2d(structure: Structure, unit: Unit, props: GaussianDensityTextureProps, webgl: WebGLContext, texture?: Texture) {
  50. const { box } = unit.lookup3d.boundary;
  51. const p = ensureReasonableResolution(box, props);
  52. const { position, radius } = getUnitConformationAndRadius(structure, unit, p);
  53. return Task.create('Gaussian Density', async ctx => {
  54. return GaussianDensityTexture2d(webgl, position, box, radius, p, texture);
  55. });
  56. }
  57. //
  58. export function computeStructureGaussianDensity(structure: Structure, props: GaussianDensityProps, webgl?: WebGLContext) {
  59. const { box } = structure.lookup3d.boundary;
  60. const p = ensureReasonableResolution(box, props);
  61. const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens, props.traceOnly);
  62. return Task.create('Gaussian Density', async ctx => {
  63. return await GaussianDensity(ctx, position, box, radius, p, webgl);
  64. });
  65. }
  66. export function computeStructureGaussianDensityTexture(structure: Structure, props: GaussianDensityTextureProps, webgl: WebGLContext, texture?: Texture) {
  67. const { box } = structure.lookup3d.boundary;
  68. const p = ensureReasonableResolution(box, props);
  69. const { position, radius } = getStructureConformationAndRadius(structure, props.ignoreHydrogens, props.traceOnly);
  70. return Task.create('Gaussian Density', async ctx => {
  71. return GaussianDensityTexture(webgl, position, box, radius, p, texture);
  72. });
  73. }