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

Started "AtomUnits"

parent 1f07aee5
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
......
......@@ -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 {
......
/**
* 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
\ No newline at end of file
......@@ -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]));
}
......
......@@ -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));
}
}
}
......
......@@ -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,
......@@ -48,10 +48,3 @@ namespace Unit {
}
export default Unit;
\ No newline at end of file
let _id = 0;
function nextUnitId() {
const ret = _id;
_id = (_id + 1) % 0x3fffffff;
return ret;
}
\ 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