Skip to content
Snippets Groups Projects
Commit 77f7d249 authored by Alexander Rose's avatar Alexander Rose
Browse files

added label property to Structure and Unit

parent e236db51
No related branches found
No related tags found
No related merge requests found
...@@ -18,13 +18,13 @@ interface SymmetryOperator { ...@@ -18,13 +18,13 @@ interface SymmetryOperator {
} }
namespace SymmetryOperator { namespace SymmetryOperator {
export const DefaultName = '1_555' export const DefaultName = 'identity'
export const Default: SymmetryOperator = create(DefaultName, Mat4.identity()); export const Default: SymmetryOperator = create(DefaultName, Mat4.identity());
const RotationEpsilon = 0.0001; const RotationEpsilon = 0.0001;
export function create(name: string, matrix: Mat4, hkl?: Vec3): SymmetryOperator { export function create(name: string, matrix: Mat4, hkl?: Vec3): SymmetryOperator {
const _hkl = hkl ? Vec3.copy(Vec3.zero(), hkl) : Vec3.zero(); const _hkl = hkl ? Vec3.clone(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 };
......
...@@ -144,6 +144,7 @@ function createModel(format: mmCIF_Format, bounds: Interval, previous?: Model): ...@@ -144,6 +144,7 @@ function createModel(format: mmCIF_Format, bounds: Interval, previous?: Model):
return { return {
id: UUID.create(), id: UUID.create(),
label: format.data.entry.id.value(0),
sourceData: format, sourceData: format,
modelNum: format.data.atom_site.pdbx_PDB_model_num.value(Interval.start(bounds)), modelNum: format.data.atom_site.pdbx_PDB_model_num.value(Interval.start(bounds)),
entities, entities,
......
...@@ -23,6 +23,7 @@ import from_mmCIF from './formats/mmcif' ...@@ -23,6 +23,7 @@ import from_mmCIF from './formats/mmcif'
*/ */
interface Model extends Readonly<{ interface Model extends Readonly<{
id: UUID, id: UUID,
label: string,
modelNum: number, modelNum: number,
......
...@@ -92,7 +92,8 @@ namespace Structure { ...@@ -92,7 +92,8 @@ namespace Structure {
for (let c = 0; c < chains.count; c++) { for (let c = 0; c < chains.count; c++) {
const elements = SortedArray.ofBounds(chains.segments[c], chains.segments[c + 1]); const elements = SortedArray.ofBounds(chains.segments[c], chains.segments[c + 1]);
builder.addUnit(Unit.Kind.Atomic, model, SymmetryOperator.Default, elements); const label = SymmetryOperator.Default.name
builder.addUnit(label, Unit.Kind.Atomic, model, SymmetryOperator.Default, elements);
} }
const cs = model.coarseHierarchy; const cs = model.coarseHierarchy;
...@@ -112,15 +113,16 @@ namespace Structure { ...@@ -112,15 +113,16 @@ namespace Structure {
const { chainSegments } = elements; const { chainSegments } = elements;
for (let cI = 0; cI < chainSegments.count; cI++) { for (let cI = 0; cI < chainSegments.count; cI++) {
const elements = SortedArray.ofBounds(chainSegments.segments[cI], chainSegments.segments[cI + 1]); const elements = SortedArray.ofBounds(chainSegments.segments[cI], chainSegments.segments[cI + 1]);
builder.addUnit(kind, model, SymmetryOperator.Default, elements); const label = SymmetryOperator.Default.name
builder.addUnit(label, kind, model, SymmetryOperator.Default, elements);
} }
} }
export class StructureBuilder { export class StructureBuilder {
private units: Unit[] = []; private units: Unit[] = [];
addUnit(kind: Unit.Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit { addUnit(label: string, kind: Unit.Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit {
const unit = Unit.create(this.units.length, kind, model, operator, elements); const unit = Unit.create(this.units.length, label, kind, model, operator, elements);
this.units.push(unit); this.units.push(unit);
return unit; return unit;
} }
......
...@@ -25,11 +25,11 @@ namespace Unit { ...@@ -25,11 +25,11 @@ namespace Unit {
export function isSpheres(u: Unit): u is Spheres { return u.kind === Kind.Spheres; } export function isSpheres(u: Unit): u is Spheres { return u.kind === Kind.Spheres; }
export function isGaussians(u: Unit): u is Gaussians { return u.kind === Kind.Gaussians; } export function isGaussians(u: Unit): u is Gaussians { return u.kind === Kind.Gaussians; }
export function create(id: number, kind: Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit { export function create(id: number, label: string, kind: Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit {
switch (kind) { switch (kind) {
case Kind.Atomic: return new Atomic(id, unitIdFactory(), model, elements, SymmetryOperator.createMapping(operator, model.atomicConformation), AtomicProperties()); case Kind.Atomic: return new Atomic(id, unitIdFactory(), label, model, elements, SymmetryOperator.createMapping(operator, model.atomicConformation), AtomicProperties());
case Kind.Spheres: return createCoarse(id, unitIdFactory(), model, Kind.Spheres, elements, SymmetryOperator.createMapping(operator, model.coarseConformation.spheres)); case Kind.Spheres: return createCoarse(id, unitIdFactory(), label, model, Kind.Spheres, elements, SymmetryOperator.createMapping(operator, model.coarseConformation.spheres));
case Kind.Gaussians: return createCoarse(id, unitIdFactory(), model, Kind.Gaussians, elements, SymmetryOperator.createMapping(operator, model.coarseConformation.gaussians)); case Kind.Gaussians: return createCoarse(id, unitIdFactory(), label, model, Kind.Gaussians, elements, SymmetryOperator.createMapping(operator, model.coarseConformation.gaussians));
} }
} }
...@@ -40,6 +40,7 @@ namespace Unit { ...@@ -40,6 +40,7 @@ namespace Unit {
readonly id: number, readonly id: number,
// invariant ID stays the same even if the Operator/conformation changes. // invariant ID stays the same even if the Operator/conformation changes.
readonly invariantId: number, readonly invariantId: number,
readonly label: string,
readonly elements: SortedArray, readonly elements: SortedArray,
readonly model: Model, readonly model: Model,
readonly conformation: SymmetryOperator.ArrayMapping, readonly conformation: SymmetryOperator.ArrayMapping,
...@@ -64,6 +65,7 @@ namespace Unit { ...@@ -64,6 +65,7 @@ namespace Unit {
readonly id: number; readonly id: number;
readonly invariantId: number; readonly invariantId: number;
readonly label: string;
readonly elements: SortedArray; readonly elements: SortedArray;
readonly model: Model; readonly model: Model;
readonly conformation: SymmetryOperator.ArrayMapping; readonly conformation: SymmetryOperator.ArrayMapping;
...@@ -76,12 +78,13 @@ namespace Unit { ...@@ -76,12 +78,13 @@ namespace Unit {
getChild(elements: SortedArray): Unit { getChild(elements: SortedArray): Unit {
if (elements.length === this.elements.length) return this; if (elements.length === this.elements.length) return this;
return new Atomic(this.id, this.invariantId, this.model, elements, this.conformation, AtomicProperties()); return new Atomic(this.id, this.invariantId, this.label, this.model, elements, this.conformation, AtomicProperties());
} }
applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit { applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit {
const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator); const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator);
return new Atomic(id, this.invariantId, this.model, this.elements, SymmetryOperator.createMapping(op, this.model.atomicConformation), this.props); const label = operator.name
return new Atomic(id, this.invariantId, label, this.model, this.elements, SymmetryOperator.createMapping(op, this.model.atomicConformation), this.props);
} }
get lookup3d() { get lookup3d() {
...@@ -97,9 +100,10 @@ namespace Unit { ...@@ -97,9 +100,10 @@ namespace Unit {
return this.props.bonds.ref; return this.props.bonds.ref;
} }
constructor(id: number, invariantId: number, model: Model, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping, props: AtomicProperties) { constructor(id: number, invariantId: number, label: string, model: Model, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping, props: AtomicProperties) {
this.id = id; this.id = id;
this.invariantId = invariantId; this.invariantId = invariantId;
this.label = label;
this.model = model; this.model = model;
this.elements = elements; this.elements = elements;
this.conformation = conformation; this.conformation = conformation;
...@@ -124,6 +128,7 @@ namespace Unit { ...@@ -124,6 +128,7 @@ namespace Unit {
readonly id: number; readonly id: number;
readonly invariantId: number; readonly invariantId: number;
readonly label: string;
readonly elements: SortedArray; readonly elements: SortedArray;
readonly model: Model; readonly model: Model;
readonly conformation: SymmetryOperator.ArrayMapping; readonly conformation: SymmetryOperator.ArrayMapping;
...@@ -133,12 +138,13 @@ namespace Unit { ...@@ -133,12 +138,13 @@ namespace Unit {
getChild(elements: SortedArray): Unit { getChild(elements: SortedArray): Unit {
if (elements.length === this.elements.length) return this as any as Unit /** lets call this an ugly temporary hack */; if (elements.length === this.elements.length) return this as any as Unit /** lets call this an ugly temporary hack */;
return createCoarse(this.id, this.invariantId, this.model, this.kind, elements, this.conformation); return createCoarse(this.id, this.invariantId, this.label, this.model, this.kind, elements, this.conformation);
} }
applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit { applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit {
const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator); const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator);
const ret = createCoarse(id, this.invariantId, this.model, this.kind, this.elements, SymmetryOperator.createMapping(op, this.getCoarseElements())); const label = operator.name
const ret = createCoarse(id, this.invariantId, label, this.model, this.kind, this.elements, SymmetryOperator.createMapping(op, this.getCoarseElements()));
(ret as Coarse<K, C>)._lookup3d = this._lookup3d; (ret as Coarse<K, C>)._lookup3d = this._lookup3d;
return ret; return ret;
} }
...@@ -156,10 +162,11 @@ namespace Unit { ...@@ -156,10 +162,11 @@ namespace Unit {
return this.kind === Kind.Spheres ? this.model.coarseConformation.spheres : this.model.coarseConformation.gaussians; return this.kind === Kind.Spheres ? this.model.coarseConformation.spheres : this.model.coarseConformation.gaussians;
} }
constructor(id: number, invariantId: number, model: Model, kind: K, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping) { constructor(id: number, invariantId: number, label: string, model: Model, kind: K, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping) {
this.kind = kind; this.kind = kind;
this.id = id; this.id = id;
this.invariantId = invariantId; this.invariantId = invariantId;
this.label = label;
this.model = model; this.model = model;
this.elements = elements; this.elements = elements;
this.conformation = conformation; this.conformation = conformation;
...@@ -168,8 +175,8 @@ namespace Unit { ...@@ -168,8 +175,8 @@ namespace Unit {
} }
} }
function createCoarse<K extends Kind.Gaussians | Kind.Spheres>(id: number, invariantId: number, model: Model, kind: K, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping): Unit { function createCoarse<K extends Kind.Gaussians | Kind.Spheres>(id: number, invariantId: number, label: string, model: Model, kind: K, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping): Unit {
return new Coarse(id, invariantId, model, kind, elements, conformation) as any as Unit /** lets call this an ugly temporary hack */; return new Coarse(id, invariantId, label, model, kind, elements, conformation) as any as Unit /** lets call this an ugly temporary hack */;
} }
export class Spheres extends Coarse<Kind.Spheres, CoarseSphereConformation> { } export class Spheres extends Coarse<Kind.Spheres, CoarseSphereConformation> { }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment