Browse Source

added assemblyName to structure

Alexander Rose 6 years ago
parent
commit
f22e9815e4

+ 1 - 1
src/mol-model/structure/query/queries/generators.ts

@@ -171,7 +171,7 @@ function atomGroupsGrouped({ entityTest, chainTest, residueTest, atomTest, group
 function getRingStructure(unit: Unit.Atomic, ring: UnitRing) {
     const elements = new Int32Array(ring.length) as any as ElementIndex[];
     for (let i = 0, _i = ring.length; i < _i; i++) elements[i] = unit.elements[ring[i]];
-    return Structure.create([unit.getChild(SortedArray.ofSortedArray(elements))])
+    return Structure.create([unit.getChild(SortedArray.ofSortedArray(elements))], '')
 }
 
 export function rings(fingerprints?: ArrayLike<UnitRing.Fingerprint>): StructureQuery {

+ 4 - 4
src/mol-model/structure/query/queries/internal.ts

@@ -35,7 +35,7 @@ export function atomicSequence(): StructureQuery {
 
             units.push(unit);
         }
-        return StructureSelection.Singletons(inputStructure, new Structure(units));
+        return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure.assemblyName));
     };
 }
 
@@ -54,7 +54,7 @@ export function water(): StructureQuery {
             if (P.entity.type(l) !== 'water') continue;
             units.push(unit);
         }
-        return StructureSelection.Singletons(inputStructure, new Structure(units));
+        return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure.assemblyName));
     };
 }
 
@@ -84,7 +84,7 @@ export function atomicHet(): StructureQuery {
 
             units.push(unit);
         }
-        return StructureSelection.Singletons(inputStructure, new Structure(units));
+        return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure.assemblyName));
     };
 }
 
@@ -97,6 +97,6 @@ export function spheres(): StructureQuery {
             if (unit.kind !== Unit.Kind.Spheres) continue;
             units.push(unit);
         }
-        return StructureSelection.Singletons(inputStructure, new Structure(units));
+        return StructureSelection.Singletons(inputStructure, new Structure(units, inputStructure.assemblyName));
     };
 }

+ 1 - 1
src/mol-model/structure/query/selection.ts

@@ -109,7 +109,7 @@ namespace StructureSelection {
                 const { elements } = unit;
                 for (let i = 0, _i = elements.length; i < _i; i++) {
                     // TODO: optimize this somehow???
-                    const s = Structure.create([unit.getChild(SortedArray.ofSingleton(elements[i]))]);
+                    const s = Structure.create([unit.getChild(SortedArray.ofSingleton(elements[i]))], sel.structure.assemblyName);
                     fn(s, idx++);
                 }
             }

+ 2 - 2
src/mol-model/structure/query/utils/structure-set.ts

@@ -80,7 +80,7 @@ export function structureIntersect(sA: Structure, sB: Structure): Structure {
         }
     }
 
-    return Structure.create(units);
+    return Structure.create(units, sA.assemblyName === sB.assemblyName ? sA.assemblyName : '');
 }
 
 export function structureSubtract(a: Structure, b: Structure): Structure {
@@ -100,5 +100,5 @@ export function structureSubtract(a: Structure, b: Structure): Structure {
         }
     }
 
-    return Structure.create(units);
+    return Structure.create(units, a.assemblyName === b.assemblyName ? a.assemblyName : '');
 }

+ 16 - 8
src/mol-model/structure/structure/structure.ts

@@ -2,6 +2,7 @@
  * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author David Sehnal <david.sehnal@gmail.com>
+ * @author Alexander Rose <alexander.rose@weirdbyte.de>
  */
 
 import { IntMap, SortedArray, Iterator, Segmentation } from 'mol-data/int'
@@ -48,7 +49,8 @@ class Structure {
         transformHash: number,
         elementCount: number,
         polymerResidueCount: number,
-    } = { hashCode: -1, transformHash: -1, elementCount: 0, polymerResidueCount: 0 };
+        assemblyName: string
+    } = { hashCode: -1, transformHash: -1, elementCount: 0, polymerResidueCount: 0, assemblyName: '' };
 
     subsetBuilder(isSorted: boolean) {
         return new StructureSubsetBuilder(this, isSorted);
@@ -64,6 +66,11 @@ class Structure {
         return this._props.polymerResidueCount;
     }
 
+    /** Name of the assembly given by `_pdbx_struct_assembly.id` when applicable */
+    get assemblyName() {
+        return this._props.assemblyName;
+    }
+
     /** Coarse structure, defined as Containing less than twice as many elements as polymer residues */
     get isCoarse() {
         const ec = this.elementCount
@@ -169,7 +176,7 @@ class Structure {
         return SortedArray.has(this.unitMap.get(e.unit.id).elements, e.element);
     }
 
-    constructor(units: ArrayLike<Unit>) {
+    constructor(units: ArrayLike<Unit>, assemblyName: string) {
         const map = IntMap.Mutable<Unit>();
         let elementCount = 0;
         let polymerResidueCount = 0;
@@ -188,6 +195,7 @@ class Structure {
         this.units = units as ReadonlyArray<Unit>;
         this._props.elementCount = elementCount;
         this._props.polymerResidueCount = polymerResidueCount;
+        this._props.assemblyName = assemblyName
     }
 }
 
@@ -278,7 +286,7 @@ function getUniqueAtomicResidueIndices(structure: Structure): ReadonlyMap<UUID,
 }
 
 namespace Structure {
-    export const Empty = new Structure([]);
+    export const Empty = new Structure([], '');
 
     /** Represents a single structure */
     export interface Loci {
@@ -297,7 +305,7 @@ namespace Structure {
         return a.structure === b.structure
     }
 
-    export function create(units: ReadonlyArray<Unit>): Structure { return new Structure(units); }
+    export function create(units: ReadonlyArray<Unit>, assemblyName: string): Structure { return new Structure(units, assemblyName); }
 
     /**
      * Construct a Structure from a model.
@@ -338,7 +346,7 @@ namespace Structure {
             }
         }
 
-        return builder.getStructure();
+        return builder.getStructure('deposited');
     }
 
     function isWaterChain(model: Model, chainIndex: ChainIndex, indices: SortedArray) {
@@ -380,7 +388,7 @@ namespace Structure {
             units.push(u.applyOperator(u.id, op));
         }
 
-        return new Structure(units);
+        return new Structure(units, s.assemblyName);
     }
 
     export class StructureBuilder {
@@ -399,8 +407,8 @@ namespace Structure {
             return newUnit;
         }
 
-        getStructure(): Structure {
-            return create(this.units);
+        getStructure(assemblyName: string): Structure {
+            return create(this.units, assemblyName);
         }
 
         get isEmpty() {

+ 3 - 3
src/mol-model/structure/structure/symmetry.ts

@@ -42,7 +42,7 @@ namespace StructureSymmetry {
                 }
             }
 
-            return assembler.getStructure();
+            return assembler.getStructure(asmName);
         });
     }
 
@@ -118,7 +118,7 @@ function assembleOperators(structure: Structure, operators: ReadonlyArray<Symmet
             assembler.addWithOperator(unit, oper);
         }
     }
-    return assembler.getStructure();
+    return assembler.getStructure(structure.assemblyName);
 }
 
 async function _buildNCS(ctx: RuntimeContext, structure: Structure) {
@@ -173,7 +173,7 @@ async function findMatesRadius(ctx: RuntimeContext, structure: Structure, radius
     }
 
 
-    return assembler.getStructure();
+    return assembler.getStructure(structure.assemblyName);
 }
 
 export default StructureSymmetry;

+ 1 - 1
src/mol-model/structure/structure/util/subset-builder.ts

@@ -90,7 +90,7 @@ export class StructureSubsetBuilder {
             newUnits[newUnits.length] = child;
         }
 
-        return Structure.create(newUnits);
+        return Structure.create(newUnits, this.parent.assemblyName);
     }
 
     getStructure() {

+ 1 - 1
src/mol-model/structure/structure/util/unique-subset-builder.ts

@@ -85,7 +85,7 @@ export class StructureUniqueSubsetBuilder {
             newUnits[newUnits.length] = child;
         }
 
-        return Structure.create(newUnits);
+        return Structure.create(newUnits, this.parent.assemblyName);
     }
 
     get isEmpty() {