symmetry.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. */
  6. import { SymmetryOperator } from 'mol-math/geometry/symmetry-operator'
  7. import { arrayFind } from 'mol-data/util'
  8. import { Query } from '../../query'
  9. import { Model } from '../../model'
  10. /** Determine an atom set and a list of operators that should be applied to that set */
  11. export interface OperatorGroup {
  12. readonly selector: Query,
  13. readonly operators: ReadonlyArray<SymmetryOperator>
  14. }
  15. export type OperatorGroups = ReadonlyArray<OperatorGroup>
  16. export class Assembly {
  17. readonly id: string;
  18. readonly details: string;
  19. private _operators: OperatorGroups;
  20. get operatorGroups(): OperatorGroups {
  21. if (this._operators) return this._operators;
  22. this._operators = this.operatorsProvider();
  23. return this._operators;
  24. }
  25. constructor(id: string, details: string, private operatorsProvider: () => OperatorGroups) {
  26. this.id = id;
  27. this.details = details;
  28. }
  29. }
  30. export namespace Assembly {
  31. export function create(id: string, details: string, operatorsProvider: () => OperatorGroups): Assembly {
  32. return new Assembly(id, details, operatorsProvider);
  33. }
  34. }
  35. interface Symmetry {
  36. readonly assemblies: ReadonlyArray<Assembly>,
  37. }
  38. namespace Symmetry {
  39. export const Empty: Symmetry = { assemblies: [] };
  40. export function findAssembly(model: Model, id: string): Assembly | undefined {
  41. const _id = id.toLocaleLowerCase();
  42. return arrayFind(model.symmetry.assemblies, a => a.id.toLowerCase() === _id);
  43. }
  44. }
  45. export default Symmetry