element-point.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2018 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 { RuntimeContext } from 'mol-task'
  8. import { UnitsVisual, VisualUpdateState } from '..';
  9. import { getElementLoci, StructureElementIterator, markElement } from './util/element';
  10. import { Vec3 } from 'mol-math/linear-algebra';
  11. import { SizeThemeProps } from 'mol-view/theme/size';
  12. import { UnitsPointVisual, DefaultUnitsPointProps } from '../units-visual';
  13. import { Point } from '../../../geometry/point/point';
  14. import { PointBuilder } from '../../../geometry/point/point-builder';
  15. export const DefaultElementPointProps = {
  16. ...DefaultUnitsPointProps,
  17. sizeTheme: { name: 'uniform', value: 0.2 } as SizeThemeProps,
  18. pointSizeAttenuation: true,
  19. }
  20. export type ElementPointProps = typeof DefaultElementPointProps
  21. // TODO size
  22. export async function createElementPoint(ctx: RuntimeContext, unit: Unit, structure: Structure, props: ElementPointProps, point: Point) {
  23. const elements = unit.elements
  24. const n = elements.length
  25. const builder = PointBuilder.create(n, n / 10, point)
  26. const pos = unit.conformation.invariantPosition
  27. const p = Vec3.zero()
  28. for (let i = 0; i < n; ++i) {
  29. pos(elements[i], p)
  30. builder.add(p[0], p[1], p[2], i)
  31. if (i % 10000 === 0 && ctx.shouldUpdate) {
  32. await ctx.update({ message: 'Creating points', current: i, max: n });
  33. }
  34. }
  35. return builder.getPoint()
  36. }
  37. export function ElementPointVisual(): UnitsVisual<ElementPointProps> {
  38. return UnitsPointVisual<ElementPointProps>({
  39. defaultProps: DefaultElementPointProps,
  40. createPoint: createElementPoint,
  41. createLocationIterator: StructureElementIterator.fromGroup,
  42. getLoci: getElementLoci,
  43. mark: markElement,
  44. setUpdateState: (state: VisualUpdateState, newProps: ElementPointProps, currentProps: ElementPointProps) => {
  45. }
  46. })
  47. }