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