Ver Fonte

Started "AtomUnits"

David Sehnal há 7 anos atrás
pai
commit
0328282d52

+ 9 - 0
src/mol-model/structure/query/selection.ts

@@ -13,11 +13,20 @@ type Selection =
     | Structure // each atom is interpreted as a singleton structure
     | Structure[]
 
+// TODO: Do not allow to change unit set in the middle of a query, create a differnt language to control assemblies etc.
+/*
+type Selection =
+  | { kind: 'sequence', units: UnitCollection, sets: AtomSet[] }
+  | { kind: 'atom-set', units: UnitCollection, set: AtomSet }
+*/
+
 namespace Selection {
     export const Empty: Selection = [];
 
     function isStructure(x: Selection): x is Structure { return !!(x as Structure).units && !!(x as Structure).atoms; }
 
+    export const isOfSingletons = isStructure
+
     export function structureCount(sel: Selection) {
         if (isStructure(sel)) return AtomSet.atomCount(sel.atoms);
         return sel.length;

+ 0 - 0
src/mol-model/structure/structure/atom/set/builder.ts → src/mol-model/structure/structure/atom/impl/builder.ts


+ 0 - 0
src/mol-model/structure/structure/atom/set/properties.ts → src/mol-model/structure/structure/atom/impl/properties.ts


+ 1 - 5
src/mol-model/structure/structure/atom/set/impl.ts → src/mol-model/structure/structure/atom/impl/set.ts

@@ -17,14 +17,10 @@ export type AtomSetImpl = Atom | AtomSetElements
 export const Empty: AtomSetImpl = { sets: IntMap.Empty, offsets: new Int32Array(1), hashCode: 0, keys: SortedArray.Empty };
 
 export function create(data: Atom | ArrayLike<Atom>): AtomSetImpl {
-    if (typeof data === 'number' || Atom.is(data)) return data;
+    if (Atom.is(data)) return data;
     return ofAtoms(data);
 }
 
-export function isSingleton(set: AtomSetImpl) {
-    return typeof set === 'number';
-}
-
 export function getKeys(set: AtomSetImpl): SortedArray {
     if (typeof set === 'number') return SortedArray.ofSingleton(set);
     return (set as AtomSetElements).keys;

+ 2 - 2
src/mol-model/structure/structure/atom/set.ts

@@ -6,8 +6,8 @@
 
 import { OrderedSet, SortedArray, Iterator } from 'mol-data/int'
 import Atom from '../atom'
-import * as Impl from './set/impl'
-import * as Builders from './set/builder'
+import * as Impl from './impl/set'
+import * as Builders from './impl/builder'
 
 /** A map-like representation of grouped atom set */
 namespace AtomSet {

+ 34 - 0
src/mol-model/structure/structure/atom/unit.ts

@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ *
+ * @author David Sehnal <david.sehnal@gmail.com>
+ */
+
+// TODO : wrap OrderedSet with and include "id" to identify unique (sub)sets in AtomSet and the ability to cache data (also include "ancestor" field for effictient subsets).
+
+import { OrderedSet } from 'mol-data/int'
+
+interface AtomUnit {
+    set: OrderedSet,
+    id: number,
+    ancestor?: AtomUnit
+}
+
+namespace AtomUnit {
+    export function create(set: OrderedSet, ancestor?: AtomUnit): AtomUnit {
+        if (!ancestor) {
+            return { id: nextId(), set };
+        }
+        if (OrderedSet.areEqual(set, ancestor.set)) return ancestor;
+        return { id: nextId(), set, ancestor: ancestor.ancestor || ancestor };
+    }
+
+    let _id = 0;
+    function nextId() {
+        const ret = _id;
+        _id = (_id + 1) % 0x3fffffff;
+        return ret;
+    }
+}
+
+export default AtomUnit

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

@@ -35,7 +35,7 @@ namespace Structure {
         const builder = Builder();
 
         for (let c = 0; c < chains.count; c++) {
-            const unit = Unit.create(model, SymmetryOperator.Default);
+            const unit = Unit.create(c, model, SymmetryOperator.Default);
             builder.add(unit, OrderedSet.ofBounds(chains.segments[c], chains.segments[c + 1]));
         }
 

+ 2 - 1
src/mol-model/structure/structure/symmetry.ts

@@ -25,6 +25,7 @@ function buildAssemblyImpl(structure: Structure, name: string) {
 
     const assembler = Structure.Builder();
 
+    let unitId = 0;
     for (const g of assembly.operatorGroups) {
         const selection = g.selector(structure);
         if (Selection.structureCount(selection) === 0) continue;
@@ -35,7 +36,7 @@ function buildAssemblyImpl(structure: Structure, name: string) {
         for (const oper of g.operators) {
             for (let uI = 0, _uI = unitIds.length; uI < _uI; uI++) {
                 const unit = units.get(unitIds[uI]);
-                assembler.add(Unit.create(unit.model, oper), AtomSet.unitGetByIndex(atoms, uI));
+                assembler.add(Unit.create(unitId++, unit.model, oper), AtomSet.unitGetByIndex(atoms, uI));
             }
         }
     }

+ 3 - 10
src/mol-model/structure/structure/unit.ts

@@ -28,12 +28,12 @@ interface Unit extends SymmetryOperator.ArrayMapping {
 }
 
 namespace Unit {
-    export function create(model: Model, operator: SymmetryOperator): Unit {
+    export function create(id: number, model: Model, operator: SymmetryOperator): Unit {
         const h = model.hierarchy;
         const { invariantPosition, position, x, y, z } = SymmetryOperator.createMapping(operator, model.conformation);
 
         return {
-            id: nextUnitId(),
+            id,
             model,
             operator,
             residueIndex: h.residueSegments.segmentMap,
@@ -47,11 +47,4 @@ namespace Unit {
     }
 }
 
-export default Unit;
-
-let _id = 0;
-function nextUnitId() {
-    const ret = _id;
-    _id = (_id + 1) % 0x3fffffff;
-    return ret;
-}
+export default Unit;