Skip to content
Snippets Groups Projects
Commit db1b12d5 authored by David Sehnal's avatar David Sehnal
Browse files

removed id field from the unit interface

parent ca5dc259
No related branches found
No related tags found
No related merge requests found
...@@ -23,13 +23,19 @@ namespace SymmetryOperator { ...@@ -23,13 +23,19 @@ namespace SymmetryOperator {
const RotationEpsilon = 0.0001; const RotationEpsilon = 0.0001;
export function create(name: string, matrix: Mat4, hkl?: number[]): SymmetryOperator { export function create(name: string, matrix: Mat4, hkl?: Vec3): SymmetryOperator {
const _hkl = hkl ? Vec3.create(hkl[0], hkl[1], hkl[2]) : Vec3.zero(); const _hkl = hkl ? Vec3.copy(Vec3.zero(), hkl) : Vec3.zero();
if (Mat4.isIdentity(matrix)) return { name, matrix, inverse: Mat4.identity(), isIdentity: true, hkl: _hkl }; if (Mat4.isIdentity(matrix)) return { name, matrix, inverse: Mat4.identity(), isIdentity: true, hkl: _hkl };
if (!Mat4.isRotationAndTranslation(matrix, RotationEpsilon)) throw new Error(`Symmetry operator (${name}) must be a composition of rotation and translation.`); if (!Mat4.isRotationAndTranslation(matrix, RotationEpsilon)) throw new Error(`Symmetry operator (${name}) must be a composition of rotation and translation.`);
return { name, matrix, inverse: Mat4.invert(Mat4.zero(), matrix), isIdentity: false, hkl: _hkl }; return { name, matrix, inverse: Mat4.invert(Mat4.zero(), matrix), isIdentity: false, hkl: _hkl };
} }
// Apply the 1st and then 2nd operator. ( = second.matrix * first.matrix)
export function compose(first: SymmetryOperator, second: SymmetryOperator) {
const matrix = Mat4.mul(Mat4.zero(), second.matrix, first.matrix);
return create(second.name, matrix, second.hkl);
}
export interface CoordinateMapper { (index: number, slot: Vec3): Vec3 } export interface CoordinateMapper { (index: number, slot: Vec3): Vec3 }
export interface ArrayMapping { export interface ArrayMapping {
readonly invariantPosition: CoordinateMapper, readonly invariantPosition: CoordinateMapper,
......
...@@ -37,7 +37,7 @@ namespace Structure { ...@@ -37,7 +37,7 @@ namespace Structure {
for (let c = 0; c < chains.count; c++) { for (let c = 0; c < chains.count; c++) {
const group = AtomGroup.createNew(OrderedSet.ofBounds(chains.segments[c], chains.segments[c + 1])); const group = AtomGroup.createNew(OrderedSet.ofBounds(chains.segments[c], chains.segments[c + 1]));
const unit = Unit.create(c, model, SymmetryOperator.Default, group); const unit = Unit.create(model, SymmetryOperator.Default, group);
builder.add(unit, OrderedSet.ofBounds(chains.segments[c], chains.segments[c + 1])); builder.add(unit, OrderedSet.ofBounds(chains.segments[c], chains.segments[c + 1]));
} }
...@@ -53,12 +53,13 @@ namespace Structure { ...@@ -53,12 +53,13 @@ namespace Structure {
} }
class BuilderImpl implements Builder { class BuilderImpl implements Builder {
private _unitId = 0;
private units = IntMap.Mutable<Unit>(); private units = IntMap.Mutable<Unit>();
private atoms = AtomSet.Generator(); private atoms = AtomSet.Generator();
atomCount = 0; atomCount = 0;
add(unit: Unit, atoms: OrderedSet) { this.addUnit(unit); this.setAtoms(unit.id, atoms); } add(unit: Unit, atoms: OrderedSet) { const id = this.addUnit(unit); this.setAtoms(id, atoms); }
addUnit(unit: Unit) { this.units.set(unit.id, unit); } addUnit(unit: Unit) { const id = this._unitId++; this.units.set(id, unit); return id; }
setAtoms(unitId: number, atoms: OrderedSet) { this.atoms.add(unitId, atoms); this.atomCount += OrderedSet.size(atoms); } setAtoms(unitId: number, atoms: OrderedSet) { this.atoms.add(unitId, atoms); this.atomCount += OrderedSet.size(atoms); }
getStructure(): Structure { return this.atomCount > 0 ? Structure.create(this.units, this.atoms.getSet()) : Empty; } getStructure(): Structure { return this.atomCount > 0 ? Structure.create(this.units, this.atoms.getSet()) : Empty; }
} }
......
...@@ -25,7 +25,6 @@ function buildAssemblyImpl(structure: Structure, name: string) { ...@@ -25,7 +25,6 @@ function buildAssemblyImpl(structure: Structure, name: string) {
const assembler = Structure.Builder(); const assembler = Structure.Builder();
let unitId = 0;
for (const g of assembly.operatorGroups) { for (const g of assembly.operatorGroups) {
const selection = g.selector(structure); const selection = g.selector(structure);
if (Selection.structureCount(selection) === 0) continue; if (Selection.structureCount(selection) === 0) continue;
...@@ -36,7 +35,7 @@ function buildAssemblyImpl(structure: Structure, name: string) { ...@@ -36,7 +35,7 @@ function buildAssemblyImpl(structure: Structure, name: string) {
for (const oper of g.operators) { for (const oper of g.operators) {
for (let uI = 0, _uI = unitIds.length; uI < _uI; uI++) { for (let uI = 0, _uI = unitIds.length; uI < _uI; uI++) {
const unit = units.get(unitIds[uI]); const unit = units.get(unitIds[uI]);
assembler.add(Unit.create(unitId++, unit.model, oper, unit.naturalGroup), AtomSet.unitGetByIndex(atoms, uI)); assembler.add(Unit.withOperator(unit, oper), AtomSet.unitGetByIndex(atoms, uI));
} }
} }
} }
......
...@@ -9,9 +9,6 @@ import AtomGroup from './atom/group' ...@@ -9,9 +9,6 @@ import AtomGroup from './atom/group'
import { Model } from '../model' import { Model } from '../model'
interface Unit extends SymmetryOperator.ArrayMapping { interface Unit extends SymmetryOperator.ArrayMapping {
// Structure-level unique identifier of the unit.
readonly id: number,
// Provides access to the underlying data. // Provides access to the underlying data.
readonly model: Model, readonly model: Model,
...@@ -32,12 +29,11 @@ interface Unit extends SymmetryOperator.ArrayMapping { ...@@ -32,12 +29,11 @@ interface Unit extends SymmetryOperator.ArrayMapping {
} }
namespace Unit { namespace Unit {
export function create(id: number, model: Model, operator: SymmetryOperator, naturalGroup: AtomGroup): Unit { export function create(model: Model, operator: SymmetryOperator, naturalGroup: AtomGroup): Unit {
const h = model.hierarchy; const h = model.hierarchy;
const { invariantPosition, position, x, y, z } = SymmetryOperator.createMapping(operator, model.conformation); const { invariantPosition, position, x, y, z } = SymmetryOperator.createMapping(operator, model.conformation);
return { return {
id,
model, model,
operator, operator,
naturalGroup, naturalGroup,
...@@ -50,6 +46,10 @@ namespace Unit { ...@@ -50,6 +46,10 @@ namespace Unit {
x, y, z x, y, z
}; };
} }
export function withOperator(unit: Unit, operator: SymmetryOperator) {
return create(unit.model, SymmetryOperator.compose(unit.operator, operator), unit.naturalGroup);
}
} }
export default Unit; export default Unit;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment