From f636ff44e5453d46acb978c93eae389caa08756a Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Mon, 25 Jun 2018 21:17:58 +0200 Subject: [PATCH] Refactor symmetryGroups to a structure level property --- src/mol-geo/representation/structure/index.ts | 4 ++-- src/mol-model/structure/structure/structure.ts | 8 ++++++++ src/mol-model/structure/structure/symmetry.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mol-geo/representation/structure/index.ts b/src/mol-geo/representation/structure/index.ts index ecb466cea..9d46deebc 100644 --- a/src/mol-geo/representation/structure/index.ts +++ b/src/mol-geo/representation/structure/index.ts @@ -43,7 +43,7 @@ export function StructureRepresentation<P extends StructureProps>(unitsVisualCto return Task.create('Creating StructureRepresentation', async ctx => { if (!_structure) { - _groups = StructureSymmetry.getTransformGroups(structure); + _groups = structure.symmetryGroups; for (let i = 0; i < _groups.length; i++) { const group = _groups[i]; const visual = unitsVisualCtor() @@ -59,7 +59,7 @@ export function StructureRepresentation<P extends StructureProps>(unitsVisualCto if (_structure.hashCode === structure.hashCode) { await update(_props) } else { - _groups = StructureSymmetry.getTransformGroups(structure); + _groups = structure.symmetryGroups; const newGroups: Unit.SymmetryGroup[] = [] const oldUnitsVisuals = unitsVisuals unitsVisuals = new Map() diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts index 09a9db336..d36ea0a2b 100644 --- a/src/mol-model/structure/structure/structure.ts +++ b/src/mol-model/structure/structure/structure.ts @@ -16,6 +16,7 @@ import { CoarseElements } from '../model/properties/coarse'; import { StructureSubsetBuilder } from './util/subset-builder'; import { Queries } from '../query'; import { InterUnitBonds, computeInterUnitBonds } from './unit/links'; +import StructureSymmetry from './symmetry'; class Structure { readonly unitMap: IntMap<Unit>; @@ -68,6 +69,13 @@ class Structure { return this._links; } + private _symmetryGroups?: ReadonlyArray<Unit.SymmetryGroup> = void 0; + get symmetryGroups(): ReadonlyArray<Unit.SymmetryGroup> { + if (this._symmetryGroups) return this._symmetryGroups; + this._symmetryGroups = StructureSymmetry.computeTransformGroups(this); + return this._symmetryGroups; + } + constructor(units: ArrayLike<Unit>) { const map = IntMap.Mutable<Unit>(); let elementCount = 0; diff --git a/src/mol-model/structure/structure/symmetry.ts b/src/mol-model/structure/structure/symmetry.ts index a7836b792..5c71b1114 100644 --- a/src/mol-model/structure/structure/symmetry.ts +++ b/src/mol-model/structure/structure/symmetry.ts @@ -68,7 +68,7 @@ namespace StructureSymmetry { return EquivalenceClasses<number, Unit>(hashUnit, areUnitsEquivalent); } - export function getTransformGroups(s: Structure): ReadonlyArray<Unit.SymmetryGroup> { + export function computeTransformGroups(s: Structure): ReadonlyArray<Unit.SymmetryGroup> { const groups = UnitEquivalenceBuilder(); for (const u of s.units) groups.add(u.id, u); -- GitLab