symmetry.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Copyright (c) 2017-2019 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 { StructureQuery } from '../../query'
  9. import { Model } from '../../model'
  10. import { Spacegroup } from '../../../../mol-math/geometry';
  11. import { Vec3 } from '../../../../mol-math/linear-algebra';
  12. import { ModelSymmetry } from '../../../../mol-model-formats/structure/property/symmetry';
  13. /** Determine an atom set and a list of operators that should be applied to that set */
  14. export interface OperatorGroup {
  15. readonly selector: StructureQuery,
  16. readonly operators: ReadonlyArray<SymmetryOperator>
  17. }
  18. export type OperatorGroups = ReadonlyArray<OperatorGroup>
  19. export class Assembly {
  20. readonly id: string;
  21. readonly details: string;
  22. private _operators: OperatorGroups;
  23. get operatorGroups(): OperatorGroups {
  24. if (this._operators) return this._operators;
  25. this._operators = this.operatorsProvider();
  26. return this._operators;
  27. }
  28. constructor(id: string, details: string, private operatorsProvider: () => OperatorGroups) {
  29. this.id = id;
  30. this.details = details;
  31. }
  32. }
  33. export namespace Assembly {
  34. export function create(id: string, details: string, operatorsProvider: () => OperatorGroups): Assembly {
  35. return new Assembly(id, details, operatorsProvider);
  36. }
  37. }
  38. interface Symmetry {
  39. readonly assemblies: ReadonlyArray<Assembly>,
  40. readonly spacegroup: Spacegroup,
  41. readonly isNonStandardCrytalFrame: boolean,
  42. readonly ncsOperators?: ReadonlyArray<SymmetryOperator>,
  43. /**
  44. * optionally cached operators from [-3, -3, -3] to [3, 3, 3]
  45. * around reference point `ref` in fractional coordinates
  46. */
  47. _operators_333?: {
  48. ref: Vec3,
  49. operators: SymmetryOperator[]
  50. }
  51. }
  52. namespace Symmetry {
  53. export const Default: Symmetry = { assemblies: [], spacegroup: Spacegroup.ZeroP1, isNonStandardCrytalFrame: false };
  54. export function findAssembly(model: Model, id: string): Assembly | undefined {
  55. const _id = id.toLocaleLowerCase();
  56. const symmetry = ModelSymmetry.Provider.get(model)
  57. return symmetry ? arrayFind(symmetry.assemblies, a => a.id.toLowerCase() === _id) : undefined;
  58. }
  59. }
  60. export { Symmetry }