From a1288e83658dbb1a6434c9df6127cfe8dad0d801 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Tue, 5 Jun 2018 11:10:54 +0200 Subject: [PATCH] Removed Unit.label, fixed Model.label from mmCIF --- src/mol-geo/representation/structure/index.ts | 2 +- .../structure/model/formats/mmcif.ts | 6 +++- .../structure/structure/structure.ts | 20 +++--------- src/mol-model/structure/structure/unit.ts | 31 +++++++------------ src/perf-tests/lookup3d.ts | 4 +-- src/servers/model/server/api.ts | 5 ++- src/servers/model/server/query.ts | 2 +- 7 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/mol-geo/representation/structure/index.ts b/src/mol-geo/representation/structure/index.ts index b9716cef4..fdddec8de 100644 --- a/src/mol-geo/representation/structure/index.ts +++ b/src/mol-geo/representation/structure/index.ts @@ -34,7 +34,7 @@ interface GroupRepresentation<T> { function label(loc: Element.Location) { const model = loc.unit.model.label - const instance = loc.unit.label + const instance = loc.unit.conformation.operator.name let element = '' if (Unit.isAtomic(loc.unit)) { diff --git a/src/mol-model/structure/model/formats/mmcif.ts b/src/mol-model/structure/model/formats/mmcif.ts index 33c5897d3..a50d29311 100644 --- a/src/mol-model/structure/model/formats/mmcif.ts +++ b/src/mol-model/structure/model/formats/mmcif.ts @@ -142,9 +142,13 @@ function createModel(format: mmCIF_Format, bounds: Interval, previous?: Model): const coarse = getIHMCoarse(format.data, entities); + const label = format.data.entry.id.valueKind(0) === Column.ValueKind.Present + ? format.data.entry.id.value(0) + : format.data._name; + return { id: UUID.create(), - label: format.data.entry.id.value(0), + label, sourceData: format, modelNum: format.data.atom_site.pdbx_PDB_model_num.value(Interval.start(bounds)), entities, diff --git a/src/mol-model/structure/structure/structure.ts b/src/mol-model/structure/structure/structure.ts index 88abc9949..cac54e0b5 100644 --- a/src/mol-model/structure/structure/structure.ts +++ b/src/mol-model/structure/structure/structure.ts @@ -1,5 +1,5 @@ /** - * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. + * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ @@ -92,8 +92,7 @@ namespace Structure { for (let c = 0; c < chains.count; c++) { const elements = SortedArray.ofBounds(chains.segments[c], chains.segments[c + 1]); - const label = SymmetryOperator.Default.name - builder.addUnit(label, Unit.Kind.Atomic, model, SymmetryOperator.Default, elements); + builder.addUnit(Unit.Kind.Atomic, model, SymmetryOperator.Default, elements); } const cs = model.coarseHierarchy; @@ -113,16 +112,15 @@ namespace Structure { const { chainSegments } = elements; for (let cI = 0; cI < chainSegments.count; cI++) { const elements = SortedArray.ofBounds(chainSegments.segments[cI], chainSegments.segments[cI + 1]); - const label = SymmetryOperator.Default.name - builder.addUnit(label, kind, model, SymmetryOperator.Default, elements); + builder.addUnit(kind, model, SymmetryOperator.Default, elements); } } export class StructureBuilder { private units: Unit[] = []; - addUnit(label: string, kind: Unit.Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit { - const unit = Unit.create(this.units.length, label, kind, model, operator, elements); + addUnit(kind: Unit.Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit { + const unit = Unit.create(this.units.length, kind, model, operator, elements); this.units.push(unit); return unit; } @@ -153,14 +151,6 @@ namespace Structure { return arr.array; } - export function getLookup3d(s: Structure): StructureLookup3D { - return 0 as any; - } - - export function getBoundary(s: Structure) { - return getLookup3d(s).boundary; - } - export function hashCode(s: Structure) { return s.hashCode; } diff --git a/src/mol-model/structure/structure/unit.ts b/src/mol-model/structure/structure/unit.ts index 8c6e715ea..5c34fd555 100644 --- a/src/mol-model/structure/structure/unit.ts +++ b/src/mol-model/structure/structure/unit.ts @@ -25,11 +25,11 @@ namespace Unit { 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 create(id: number, label: string, kind: Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit { + export function create(id: number, kind: Kind, model: Model, operator: SymmetryOperator, elements: SortedArray): Unit { switch (kind) { - case Kind.Atomic: return new Atomic(id, unitIdFactory(), label, model, elements, SymmetryOperator.createMapping(operator, model.atomicConformation), AtomicProperties()); - 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(), label, model, Kind.Gaussians, elements, SymmetryOperator.createMapping(operator, model.coarseConformation.gaussians)); + case Kind.Atomic: return new Atomic(id, unitIdFactory(), 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.Gaussians: return createCoarse(id, unitIdFactory(), model, Kind.Gaussians, elements, SymmetryOperator.createMapping(operator, model.coarseConformation.gaussians)); } } @@ -40,7 +40,6 @@ namespace Unit { readonly id: number, // invariant ID stays the same even if the Operator/conformation changes. readonly invariantId: number, - readonly label: string, readonly elements: SortedArray, readonly model: Model, readonly conformation: SymmetryOperator.ArrayMapping, @@ -65,7 +64,6 @@ namespace Unit { readonly id: number; readonly invariantId: number; - readonly label: string; readonly elements: SortedArray; readonly model: Model; readonly conformation: SymmetryOperator.ArrayMapping; @@ -78,13 +76,12 @@ namespace Unit { getChild(elements: SortedArray): Unit { if (elements.length === this.elements.length) return this; - return new Atomic(this.id, this.invariantId, this.label, this.model, elements, this.conformation, AtomicProperties()); + return new Atomic(this.id, this.invariantId, this.model, elements, this.conformation, AtomicProperties()); } applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit { const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator); - const label = operator.name - return new Atomic(id, this.invariantId, label, this.model, this.elements, SymmetryOperator.createMapping(op, this.model.atomicConformation), this.props); + return new Atomic(id, this.invariantId, this.model, this.elements, SymmetryOperator.createMapping(op, this.model.atomicConformation), this.props); } get lookup3d() { @@ -100,10 +97,9 @@ namespace Unit { return this.props.bonds.ref; } - constructor(id: number, invariantId: number, label: string, model: Model, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping, props: AtomicProperties) { + constructor(id: number, invariantId: number, model: Model, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping, props: AtomicProperties) { this.id = id; this.invariantId = invariantId; - this.label = label; this.model = model; this.elements = elements; this.conformation = conformation; @@ -128,7 +124,6 @@ namespace Unit { readonly id: number; readonly invariantId: number; - readonly label: string; readonly elements: SortedArray; readonly model: Model; readonly conformation: SymmetryOperator.ArrayMapping; @@ -138,13 +133,12 @@ namespace Unit { getChild(elements: SortedArray): Unit { 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.label, this.model, this.kind, elements, this.conformation); + return createCoarse(this.id, this.invariantId, this.model, this.kind, elements, this.conformation); } applyOperator(id: number, operator: SymmetryOperator, dontCompose = false): Unit { const op = dontCompose ? operator : SymmetryOperator.compose(this.conformation.operator, operator); - const label = operator.name - const ret = createCoarse(id, this.invariantId, label, this.model, this.kind, this.elements, SymmetryOperator.createMapping(op, this.getCoarseElements())); + const ret = createCoarse(id, this.invariantId, this.model, this.kind, this.elements, SymmetryOperator.createMapping(op, this.getCoarseElements())); (ret as Coarse<K, C>)._lookup3d = this._lookup3d; return ret; } @@ -162,11 +156,10 @@ namespace Unit { return this.kind === Kind.Spheres ? this.model.coarseConformation.spheres : this.model.coarseConformation.gaussians; } - constructor(id: number, invariantId: number, label: string, model: Model, kind: K, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping) { + constructor(id: number, invariantId: number, model: Model, kind: K, elements: SortedArray, conformation: SymmetryOperator.ArrayMapping) { this.kind = kind; this.id = id; this.invariantId = invariantId; - this.label = label; this.model = model; this.elements = elements; this.conformation = conformation; @@ -175,8 +168,8 @@ namespace 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, label, model, kind, elements, conformation) as any as Unit /** lets call this an ugly temporary hack */; + function createCoarse<K extends Kind.Gaussians | Kind.Spheres>(id: number, invariantId: number, 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 */; } export class Spheres extends Coarse<Kind.Spheres, CoarseSphereConformation> { } diff --git a/src/perf-tests/lookup3d.ts b/src/perf-tests/lookup3d.ts index 3b52eee9f..957ce7c01 100644 --- a/src/perf-tests/lookup3d.ts +++ b/src/perf-tests/lookup3d.ts @@ -52,11 +52,11 @@ export async function test() { const result = lookup.find(-30.07, 8.178, -13.897, 10); console.log(result.count)//, sortArray(result.indices)); - const sl = Structure.getLookup3d(structures[0]); + const sl = structures[0].lookup3d; const result1 = sl.find(-30.07, 8.178, -13.897, 10); console.log(result1.count);//, result1.indices); - console.log(Structure.getBoundary(structures[0])); + console.log(structures[0].boundary); console.log(lookup.boundary); } diff --git a/src/servers/model/server/api.ts b/src/servers/model/server/api.ts index a482fcf98..96820b82d 100644 --- a/src/servers/model/server/api.ts +++ b/src/servers/model/server/api.ts @@ -52,10 +52,9 @@ const AtomSiteParameters = { // } function entityTest1_555(params: any): Element.Predicate | undefined { - const oper = Queries.props.unit.operator_name; - if (typeof params.entity_id === 'undefined') return Element.property(l => oper(l) === '1_555'); + if (typeof params.entity_id === 'undefined') return Element.property(l => l.unit.conformation.operator.isIdentity); const p = Queries.props.entity.id, id = '' + params.entityId; - return Element.property(l => p(l) === id && oper(l) === '1_555'); + return Element.property(l => l.unit.conformation.operator.isIdentity && p(l) === id); } function chainTest(params: any): Element.Predicate | undefined { diff --git a/src/servers/model/server/query.ts b/src/servers/model/server/query.ts index 01f3325d8..ed9ebedf8 100644 --- a/src/servers/model/server/query.ts +++ b/src/servers/model/server/query.ts @@ -77,7 +77,7 @@ export async function resolveRequest(req: Request, writer: Writer) { const encoder = CifWriter.createEncoder({ binary: req.responseFormat.isBinary, encoderName: `ModelServer ${Version}` }); perf.start('encode'); - encoder.startDataBlock('result'); + encoder.startDataBlock(structure.units[0].model.label.toUpperCase()); encoder.writeCategory(_model_server_result, [req]); encoder.writeCategory(_model_server_params, [req]); -- GitLab