Skip to content
Snippets Groups Projects
Commit d121a11e authored by Alexander Rose's avatar Alexander Rose
Browse files

tweaked structure-element export

- got rid of index.ts for better compatibility
parent 5484a2a7
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import * as StructureElement from './element/index'; import * as StructureElement from './element/element';
export { StructureElement }; export { StructureElement };
\ No newline at end of file
...@@ -5,50 +5,8 @@ ...@@ -5,50 +5,8 @@
* @author Alexander Rose <alexander.rose@weirdbyte.de> * @author Alexander Rose <alexander.rose@weirdbyte.de>
*/ */
import { SortedArray } from '../../../../mol-data/int'; export * from './location';
import { ElementIndex, ResidueIndex, ChainIndex } from '../../model'; export * from './loci';
import { Unit } from '../unit'; export * from './bundle';
import { Location } from './location'; export * from './stats';
import { StructureProperties } from '../properties'; export * from './util';
\ No newline at end of file
// TODO: when nominal types are available, make this indexed by UnitIndex
export type Set = SortedArray<ElementIndex>
/** Index into Unit.elements */
export type UnitIndex = { readonly '@type': 'unit-element-index' } & number
export interface Property<T> { (location: Location): T }
export interface Predicate extends Property<boolean> { }
export function property<T>(p: Property<T>) { return p; }
function _wrongUnitKind(kind: string) { throw new Error(`Property only available for ${kind} models.`); }
export function atomicProperty<T>(p: (location: Location<Unit.Atomic>) => T) {
return property(l => Unit.isAtomic(l.unit) ? p(l as Location<Unit.Atomic>) : _wrongUnitKind('atomic'));
}
export function coarseProperty<T>(p: (location: Location<Unit.Spheres | Unit.Gaussians>) => T) {
return property(l => Unit.isCoarse(l.unit) ? p(l as Location<Unit.Spheres | Unit.Gaussians>) : _wrongUnitKind('coarse'));
}
export function residueIndex(e: Location) {
if (Unit.isAtomic(e.unit)) {
return e.unit.residueIndex[e.element];
} else {
// TODO: throw error instead?
return -1 as ResidueIndex;
}
}
export function chainIndex(e: Location) {
if (Unit.isAtomic(e.unit)) {
return e.unit.chainIndex[e.element];
} else {
// TODO: throw error instead?
return -1 as ChainIndex;
}
}
export function entityIndex(l: Location) {
return StructureProperties.entity.key(l);
}
\ No newline at end of file
/**
* Copyright (c) 2017-2019 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>
*/
export * from './location';
export * from './loci';
export * from './bundle';
export * from './stats';
export * from './element';
\ No newline at end of file
/**
* Copyright (c) 2017-2019 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 { SortedArray } from '../../../../mol-data/int';
import { ElementIndex, ResidueIndex, ChainIndex } from '../../model';
import { Unit } from '../unit';
import { Location } from './location';
import { StructureProperties } from '../properties';
// TODO: when nominal types are available, make this indexed by UnitIndex
export type Set = SortedArray<ElementIndex>
/** Index into Unit.elements */
export type UnitIndex = { readonly '@type': 'unit-element-index' } & number
export interface Property<T> { (location: Location): T }
export interface Predicate extends Property<boolean> { }
export function property<T>(p: Property<T>) { return p; }
function _wrongUnitKind(kind: string) { throw new Error(`Property only available for ${kind} models.`); }
export function atomicProperty<T>(p: (location: Location<Unit.Atomic>) => T) {
return property(l => Unit.isAtomic(l.unit) ? p(l as Location<Unit.Atomic>) : _wrongUnitKind('atomic'));
}
export function coarseProperty<T>(p: (location: Location<Unit.Spheres | Unit.Gaussians>) => T) {
return property(l => Unit.isCoarse(l.unit) ? p(l as Location<Unit.Spheres | Unit.Gaussians>) : _wrongUnitKind('coarse'));
}
export function residueIndex(e: Location) {
if (Unit.isAtomic(e.unit)) {
return e.unit.residueIndex[e.element];
} else {
// TODO: throw error instead?
return -1 as ResidueIndex;
}
}
export function chainIndex(e: Location) {
if (Unit.isAtomic(e.unit)) {
return e.unit.chainIndex[e.element];
} else {
// TODO: throw error instead?
return -1 as ChainIndex;
}
}
export function entityIndex(l: Location) {
return StructureProperties.entity.key(l);
}
\ 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