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

tweaks

parent 3ae9803b
No related branches found
No related tags found
No related merge requests found
...@@ -35,9 +35,8 @@ namespace OrderedSet { ...@@ -35,9 +35,8 @@ namespace OrderedSet {
export const subtract: (a: OrderedSet, b: OrderedSet) => OrderedSet = Base.subtract as any; export const subtract: (a: OrderedSet, b: OrderedSet) => OrderedSet = Base.subtract as any;
export const getPredIndex: (set: OrderedSet, x: number) => number = Base.getPredIndex as any; export const getPredIndex: (set: OrderedSet, x: number) => number = Base.getPredIndex as any;
export const getPredIndex1: (set: OrderedSet, x: number, start: number, end: number) => number = Base.getPredIndex1 as any; export const getPredIndexInRange: (set: OrderedSet, x: number, range: IndexRange) => number = Base.getPredIndexInRange as any;
export const getIntervalRange: (set: OrderedSet, min: number, max: number) => IndexRange = (set, min, max) => Base.getIntervalRange(set as any, min, max, IndexRange()); export const getIntervalRange: (set: OrderedSet, min: number, max: number) => IndexRange = Base.getIntervalRange as any;
export const getIntervalRange1: (set: OrderedSet, min: number, max: number, target: IndexRange) => IndexRange = Base.getIntervalRange as any;
export const segments = SegmentIterator export const segments = SegmentIterator
} }
......
...@@ -70,15 +70,16 @@ export function getPredIndex(set: OrderedSetImpl, x: number) { ...@@ -70,15 +70,16 @@ export function getPredIndex(set: OrderedSetImpl, x: number) {
return typeof set === 'number' ? rangeSearchIndex(set, x) : binarySearchPredIndex(set as SortedArray, x); return typeof set === 'number' ? rangeSearchIndex(set, x) : binarySearchPredIndex(set as SortedArray, x);
} }
export function getPredIndex1(set: OrderedSetImpl, x: number, start: number, end: number) { export function getPredIndexInRange(set: OrderedSetImpl, x: number, { start, end }: { start: number, end: number }) {
return typeof set === 'number' ? rangeSearchIndex(set, x) : binarySearchPredIndexRange(set as SortedArray, x, start, end); if (typeof set === 'number') {
const ret = rangeSearchIndex(set, x);
return ret <= start ? start : ret >= end ? end : ret;
} else return binarySearchPredIndexRange(set as SortedArray, x, start, end);
} }
export function getIntervalRange(set: OrderedSetImpl, min: number, max: number, range: { start: number, end: number }) { export function getIntervalRange(set: OrderedSetImpl, min: number, max: number) {
const { start, end } = getStartEnd(set, min, max); const { start, end } = getStartEnd(set, min, max);
range.start = start; return { start, end };
range.end = end;
return range;
} }
export function union(a: OrderedSetImpl, b: OrderedSetImpl) { export function union(a: OrderedSetImpl, b: OrderedSetImpl) {
......
...@@ -41,7 +41,7 @@ class SegmentIterator implements Iterator<{ segmentIndex: number } & OrderedSet. ...@@ -41,7 +41,7 @@ class SegmentIterator implements Iterator<{ segmentIndex: number } & OrderedSet.
private updateValue() { private updateValue() {
const segmentEnd = OrderedSet.getAt(this.segments, this.segmentRange.start + 1); const segmentEnd = OrderedSet.getAt(this.segments, this.segmentRange.start + 1);
const end = OrderedSet.getPredIndex1(this.set, segmentEnd, this.setRange.start, this.setRange.end); const end = OrderedSet.getPredIndexInRange(this.set, segmentEnd, this.setRange);
this.value.start = this.setRange.start; this.value.start = this.setRange.start;
this.value.end = end; this.value.end = end;
this.setRange.start = end; this.setRange.start = end;
......
/** // /**
* Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. // * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info.
* // *
* @author David Sehnal <david.sehnal@gmail.com> // * @author David Sehnal <david.sehnal@gmail.com>
*/ // */
import * as Data from './data' // import * as Data from './data'
import { Selectors } from './selectors' // import { Selectors } from './selectors'
import { Vec3, Mat4 } from '../../mol-base/math/linear-algebra' // import { Vec3, Mat4 } from '../../mol-base/math/linear-algebra'
let _uid = 0; // let _uid = 0;
/** Model-related unique identifiers */ // /** Model-related unique identifiers */
export function getUid() { return _uid++; } // export function getUid() { return _uid++; }
/** Unit = essentially a list of residues (usually a chain) */ // /** Unit = essentially a list of residues (usually a chain) */
export interface Unit extends Readonly<{ // export interface Unit extends Readonly<{
operator: Unit.Operator, // operator: Unit.Operator,
/** The static part (essentially residue annotations) */ // /** The static part (essentially residue annotations) */
structure: Unit.Structure, // structure: Unit.Structure,
/** 3D arrangement that often changes with time. */ // /** 3D arrangement that often changes with time. */
conformation: Unit.Conformation, // conformation: Unit.Conformation,
/** Position of i-th atom. Special function for this because it's the only one that depends on "operator" */ // /** Position of i-th atom. Special function for this because it's the only one that depends on "operator" */
atomPosition(i: number, p: Vec3): Vec3, // atomPosition(i: number, p: Vec3): Vec3,
/** Property access */ // /** Property access */
selectors: Selectors // selectors: Selectors
}> { } // }> { }
export namespace Unit { // export namespace Unit {
export interface Structure extends Readonly<{ // export interface Structure extends Readonly<{
/** A globally unique identifier for this instance (to easily determine unique structures within a model) */ // /** A globally unique identifier for this instance (to easily determine unique structures within a model) */
id: number, // id: number,
/** Source data for this structure */ // /** Source data for this structure */
data: Data.Structure, // data: Data.Structure,
/** Reference to the data.entities table */ // /** Reference to the data.entities table */
entity: number, // entity: number,
/** Reference to the data.chains table */ // /** Reference to the data.chains table */
chain: number, // chain: number,
/** Indices into the data.residues table. */ // /** Indices into the data.residues table. */
residues: ArrayLike<number>, // residues: ArrayLike<number>,
/** Offsets of atoms in the residue layer. start = offsets[i], endExclusive = offsets[i + 1] */ // /** Offsets of atoms in the residue layer. start = offsets[i], endExclusive = offsets[i + 1] */
atomOffsets: ArrayLike<number>, // atomOffsets: ArrayLike<number>,
/** Indices into data.atoms table */ // /** Indices into data.atoms table */
atoms: ArrayLike<number> // atoms: ArrayLike<number>
/** Index of a residue in the corresponding residues array. */ // /** Index of a residue in the corresponding residues array. */
atomResidue: ArrayLike<number> // atomResidue: ArrayLike<number>
}> { } // }> { }
export interface Conformation extends Readonly<{ // export interface Conformation extends Readonly<{
/** A globally unique identifier for this instance (to easily determine unique structures within a model) */ // /** A globally unique identifier for this instance (to easily determine unique structures within a model) */
id: number, // id: number,
positions: Data.Positions, // positions: Data.Positions,
/** Per residue secondary structure assignment. */ // /** Per residue secondary structure assignment. */
secondaryStructure: Data.SecondaryStructures // secondaryStructure: Data.SecondaryStructures
}> { // }> {
'@spatialLookup': any, // TODO // '@spatialLookup': any, // TODO
'@boundingSphere': Readonly<{ center: Vec3, radius: number }>, // '@boundingSphere': Readonly<{ center: Vec3, radius: number }>,
'@bonds': Data.Bonds // '@bonds': Data.Bonds
} // }
export namespace Conformation { // export namespace Conformation {
export function spatialLookup(conformation: Conformation): any { // export function spatialLookup(conformation: Conformation): any {
throw 'not implemented' // throw 'not implemented'
} // }
export function boundingSphere(conformation: Conformation): any { // export function boundingSphere(conformation: Conformation): any {
throw 'not implemented' // throw 'not implemented'
} // }
export function bonds(conformation: Conformation): any { // export function bonds(conformation: Conformation): any {
throw 'not implemented' // throw 'not implemented'
} // }
} // }
export type OperatorKind = // export type OperatorKind =
| { kind: 'identity' } // | { kind: 'identity' }
| { kind: 'symmetry', id: string, hkl: Vec3 } // | { kind: 'symmetry', id: string, hkl: Vec3 }
| { kind: 'assembly', index: number } // | { kind: 'assembly', index: number }
| { kind: 'custom' } // | { kind: 'custom' }
export interface Operator extends Readonly<{ // export interface Operator extends Readonly<{
kind: OperatorKind, // kind: OperatorKind,
transform: Mat4, // transform: Mat4,
inverse: Mat4 // inverse: Mat4
}> { } // }> { }
export interface SpatialLookup { // export interface SpatialLookup {
// TODO // // TODO
} // }
} // }
export interface Model extends Readonly<{ // export interface Model extends Readonly<{
units: Unit[], // units: Unit[],
structure: { [id: number]: Unit.Structure }, // structure: { [id: number]: Unit.Structure },
conformation: { [id: number]: Unit.Conformation } // conformation: { [id: number]: Unit.Conformation }
}> { // }> {
'@unitLookup'?: Unit.SpatialLookup, // '@unitLookup'?: Unit.SpatialLookup,
/** bonds between units */ // /** bonds between units */
'@unitBonds'?: Data.Bonds // '@unitBonds'?: Data.Bonds
} // }
export namespace Model { // export namespace Model {
export function unitLookup(model: Model): Unit.SpatialLookup { // export function unitLookup(model: Model): Unit.SpatialLookup {
throw 'not implemented'; // throw 'not implemented';
} // }
export function unitBonds(model: Model): Data.Bonds { // export function unitBonds(model: Model): Data.Bonds {
throw 'not implemented'; // throw 'not implemented';
} // }
export function join(a: Model, b: Model): Model { // export function join(a: Model, b: Model): Model {
return { // return {
units: [...a.units, ...b.units], // units: [...a.units, ...b.units],
structure: { ...a.structure, ...b.structure }, // structure: { ...a.structure, ...b.structure },
conformation: { ...a.conformation, ...b.conformation } // conformation: { ...a.conformation, ...b.conformation }
} // }
} // }
} // }
export namespace Atom { // export namespace Atom {
/** // /**
* Represents a "packed reference" to an atom. // * Represents a "packed reference" to an atom.
* This is because selections can then be represented // * This is because selections can then be represented
* a both number[] and Float64Array(), making it much // * a both number[] and Float64Array(), making it much
* more efficient than storing an array of objects. // * more efficient than storing an array of objects.
*/ // */
export type PackedReference = number // export type PackedReference = number
export interface Reference { unit: number, atom: number } // export interface Reference { unit: number, atom: number }
export type Selection = ArrayLike<PackedReference> // export type Selection = ArrayLike<PackedReference>
const { _uint32, _float64 } = (function() { // const { _uint32, _float64 } = (function() {
const data = new ArrayBuffer(8); // const data = new ArrayBuffer(8);
return { _uint32: new Uint32Array(data), _float64: new Float64Array(data) }; // return { _uint32: new Uint32Array(data), _float64: new Float64Array(data) };
}()); // }());
export function emptyRef(): Reference { return { unit: 0, atom: 0 }; } // export function emptyRef(): Reference { return { unit: 0, atom: 0 }; }
export function packRef(location: Reference) { // export function packRef(location: Reference) {
_uint32[0] = location.unit; // _uint32[0] = location.unit;
_uint32[1] = location.atom; // _uint32[1] = location.atom;
return _float64[0]; // return _float64[0];
} // }
export function unpackRef(ref: PackedReference) { // export function unpackRef(ref: PackedReference) {
return updateRef(ref, emptyRef()); // return updateRef(ref, emptyRef());
} // }
export function updateRef(ref: PackedReference, location: Reference): Reference { // export function updateRef(ref: PackedReference, location: Reference): Reference {
_float64[0] = ref; // _float64[0] = ref;
location.unit = _uint32[0]; // location.unit = _uint32[0];
location.atom = _uint32[1]; // location.atom = _uint32[1];
return location; // return location;
} // }
} // }
export interface Selector<T> { // export interface Selector<T> {
'@type': T, // '@type': T,
create(m: Model, u: number): Selector.Field<T> // create(m: Model, u: number): Selector.Field<T>
} // }
export function Selector<T>(create: (m: Model, u: number) => (a: number, v?: T) => T): Selector<T> { // export function Selector<T>(create: (m: Model, u: number) => (a: number, v?: T) => T): Selector<T> {
return { create } as Selector<T>; // return { create } as Selector<T>;
} // }
export namespace Selector { // export namespace Selector {
export type Field<T> = (a: number, v?: T) => T; // export type Field<T> = (a: number, v?: T) => T;
export type Category = { [s: string]: Selector<any> }; // export type Category = { [s: string]: Selector<any> };
export type Unit<C extends Category> = { [F in keyof C]: Field<C[F]['@type']> } // export type Unit<C extends Category> = { [F in keyof C]: Field<C[F]['@type']> }
export type Set<S extends { [n: string]: Category }> = { [C in keyof S]: Unit<S[C]> } // export type Set<S extends { [n: string]: Category }> = { [C in keyof S]: Unit<S[C]> }
} // }
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment