From 2a87a9d1311fa5788eed9406626647db48178c87 Mon Sep 17 00:00:00 2001 From: David Sehnal <david.sehnal@gmail.com> Date: Tue, 24 Oct 2017 21:46:27 +0200 Subject: [PATCH] Refactored project structure --- .../spec => common/_spec}/collections.spec.ts | 147 ------------- .../collections}/chunked-array.ts | 0 .../collections/hash-functions.ts | 0 .../collections/hash-set.ts | 0 .../collections/int-tuple.ts | 0 .../collections/iterator.ts | 0 .../collections/linked-index.ts | 0 .../collections/ordered-set.ts | 0 src/{structure => common}/collections/sort.ts | 0 src/{utils => common}/computation.ts | 0 src/{utils => common/math}/linear-algebra.ts | 0 src/{utils => common}/scheduler.ts | 0 src/index.d.ts | 7 - src/mol-data/_spec/atom-set.spec.ts | 154 +++++++++++++ .../multi-set.ts => mol-data/atom-set.ts} | 204 +++++++++--------- src/{ => mol-data}/structure/data.ts | 0 src/{ => mol-data}/structure/model.ts | 2 +- src/{ => mol-data}/structure/selectors.ts | 0 .../structure/selectors/common.ts | 0 .../structure/selectors/mmcif.ts | 0 .../structure/structure.ts} | 3 +- src/{ => mol-data}/structure/symmetry.ts | 0 .../topology/connected-components.ts | 0 .../structure/topology/secondary-structure.ts | 0 .../spec => mol-io/reader/_spec}/cif.spec.ts | 0 .../reader/_spec}/column.spec.ts | 0 .../spec => mol-io/reader/_spec}/gro.spec.ts | 0 src/{ => mol-io}/reader/cif/binary/decoder.ts | 0 .../reader/cif/binary/encoding.ts | 0 src/{ => mol-io}/reader/cif/binary/field.ts | 0 src/{ => mol-io}/reader/cif/binary/parser.ts | 2 +- src/{ => mol-io}/reader/cif/data-model.ts | 0 src/{ => mol-io}/reader/cif/index.ts | 0 src/{ => mol-io}/reader/cif/schema.ts | 0 src/{ => mol-io}/reader/cif/schema/ccd.ts | 0 src/{ => mol-io}/reader/cif/schema/ddl.ts | 0 src/{ => mol-io}/reader/cif/schema/density.ts | 0 src/{ => mol-io}/reader/cif/schema/dic.ts | 0 src/{ => mol-io}/reader/cif/schema/mmcif.ts | 0 src/{ => mol-io}/reader/cif/schema/utils.ts | 0 src/{ => mol-io}/reader/cif/text/field.ts | 0 src/{ => mol-io}/reader/cif/text/parser.ts | 2 +- .../reader/common/binary/column.ts | 0 src/{ => mol-io}/reader/common/column.ts | 0 .../reader/common/text/column/fixed.ts | 0 .../reader/common/text/column/token.ts | 0 .../reader/common/text/number-parser.ts | 0 .../reader/common/text/tokenizer.ts | 2 +- src/{ => mol-io}/reader/gro/parser.ts | 2 +- src/{ => mol-io}/reader/gro/schema.d.ts | 0 src/{ => mol-io}/reader/mol2/schema.d.ts | 0 src/{ => mol-io}/reader/result.ts | 0 src/{ => mol-io}/utils/msgpack/decode.ts | 0 src/{ => mol-io}/utils/msgpack/encode.ts | 0 src/{ => mol-io}/utils/short-string-pool.ts | 0 src/{ => mol-io}/utils/utf8.ts | 0 src/perf-tests/chunked-array-vs-native.ts | 2 +- src/perf-tests/sets.ts | 20 +- src/perf-tests/sort.ts | 2 +- src/script.ts | 9 +- tsconfig.json | 5 +- 61 files changed, 282 insertions(+), 281 deletions(-) rename src/{structure/spec => common/_spec}/collections.spec.ts (68%) rename src/{utils => common/collections}/chunked-array.ts (100%) rename src/{structure => common}/collections/hash-functions.ts (100%) rename src/{structure => common}/collections/hash-set.ts (100%) rename src/{structure => common}/collections/int-tuple.ts (100%) rename src/{structure => common}/collections/iterator.ts (100%) rename src/{structure => common}/collections/linked-index.ts (100%) rename src/{structure => common}/collections/ordered-set.ts (100%) rename src/{structure => common}/collections/sort.ts (100%) rename src/{utils => common}/computation.ts (100%) rename src/{utils => common/math}/linear-algebra.ts (100%) rename src/{utils => common}/scheduler.ts (100%) delete mode 100644 src/index.d.ts create mode 100644 src/mol-data/_spec/atom-set.spec.ts rename src/{structure/collections/multi-set.ts => mol-data/atom-set.ts} (66%) rename src/{ => mol-data}/structure/data.ts (100%) rename src/{ => mol-data}/structure/model.ts (98%) rename src/{ => mol-data}/structure/selectors.ts (100%) rename src/{ => mol-data}/structure/selectors/common.ts (100%) rename src/{ => mol-data}/structure/selectors/mmcif.ts (100%) rename src/{index.ts => mol-data/structure/structure.ts} (59%) rename src/{ => mol-data}/structure/symmetry.ts (100%) rename src/{ => mol-data}/structure/topology/connected-components.ts (100%) rename src/{ => mol-data}/structure/topology/secondary-structure.ts (100%) rename src/{reader/spec => mol-io/reader/_spec}/cif.spec.ts (100%) rename src/{reader/spec => mol-io/reader/_spec}/column.spec.ts (100%) rename src/{reader/spec => mol-io/reader/_spec}/gro.spec.ts (100%) rename src/{ => mol-io}/reader/cif/binary/decoder.ts (100%) rename src/{ => mol-io}/reader/cif/binary/encoding.ts (100%) rename src/{ => mol-io}/reader/cif/binary/field.ts (100%) rename src/{ => mol-io}/reader/cif/binary/parser.ts (96%) rename src/{ => mol-io}/reader/cif/data-model.ts (100%) rename src/{ => mol-io}/reader/cif/index.ts (100%) rename src/{ => mol-io}/reader/cif/schema.ts (100%) rename src/{ => mol-io}/reader/cif/schema/ccd.ts (100%) rename src/{ => mol-io}/reader/cif/schema/ddl.ts (100%) rename src/{ => mol-io}/reader/cif/schema/density.ts (100%) rename src/{ => mol-io}/reader/cif/schema/dic.ts (100%) rename src/{ => mol-io}/reader/cif/schema/mmcif.ts (100%) rename src/{ => mol-io}/reader/cif/schema/utils.ts (100%) rename src/{ => mol-io}/reader/cif/text/field.ts (100%) rename src/{ => mol-io}/reader/cif/text/parser.ts (99%) rename src/{ => mol-io}/reader/common/binary/column.ts (100%) rename src/{ => mol-io}/reader/common/column.ts (100%) rename src/{ => mol-io}/reader/common/text/column/fixed.ts (100%) rename src/{ => mol-io}/reader/common/text/column/token.ts (100%) rename src/{ => mol-io}/reader/common/text/number-parser.ts (100%) rename src/{ => mol-io}/reader/common/text/tokenizer.ts (99%) rename src/{ => mol-io}/reader/gro/parser.ts (99%) rename src/{ => mol-io}/reader/gro/schema.d.ts (100%) rename src/{ => mol-io}/reader/mol2/schema.d.ts (100%) rename src/{ => mol-io}/reader/result.ts (100%) rename src/{ => mol-io}/utils/msgpack/decode.ts (100%) rename src/{ => mol-io}/utils/msgpack/encode.ts (100%) rename src/{ => mol-io}/utils/short-string-pool.ts (100%) rename src/{ => mol-io}/utils/utf8.ts (100%) diff --git a/src/structure/spec/collections.spec.ts b/src/common/_spec/collections.spec.ts similarity index 68% rename from src/structure/spec/collections.spec.ts rename to src/common/_spec/collections.spec.ts index 13ad53905..07f31810d 100644 --- a/src/structure/spec/collections.spec.ts +++ b/src/common/_spec/collections.spec.ts @@ -9,8 +9,6 @@ import IntTuple from '../collections/int-tuple' import * as Sort from '../collections/sort' import OrderedSet from '../collections/ordered-set' import LinkedIndex from '../collections/linked-index' -import MultiSet from '../collections/multi-set' - function iteratorToArray<T>(it: Iterator<T>): T[] { const ret = []; @@ -314,149 +312,4 @@ describe('linked-index', () => { expect(index.has(0)).toBe(false); expect(index.has(1)).toBe(false); }); -}); - -describe('multiset', () => { - const p = (i: number, j: number) => IntTuple.create(i, j); - const r = (i: number, j: number) => IntTuple.pack(i, j); - - function setToPairs(set: MultiSet): ArrayLike<IntTuple.Unpacked> { - const ret = []; - const it = MultiSet.values(set); - for (let v = it.move(); !it.done; v = it.move()) ret[ret.length] = IntTuple.create(v.fst, v.snd); - return ret; - } - - it('singleton pair', () => { - const set = MultiSet.create(p(10, 11)); - expect(setToPairs(set)).toEqual([p(10, 11)]); - expect(MultiSet.has(set, r(10, 11))).toBe(true); - expect(MultiSet.has(set, r(11, 11))).toBe(false); - expect(MultiSet.getAt(set, 0)).toBe(r(10, 11)); - expect(MultiSet.size(set)).toBe(1); - }); - - it('singleton number', () => { - const set = MultiSet.create(r(10, 11)); - expect(setToPairs(set)).toEqual([p(10, 11)]); - }); - - it('multi', () => { - const set = MultiSet.create({ - 1: OrderedSet.ofSortedArray([4, 6, 7]), - 3: OrderedSet.ofRange(0, 1), - }); - const ret = [p(1, 4), p(1, 6), p(1, 7), p(3, 0), p(3, 1)]; - expect(MultiSet.size(set)).toBe(ret.length); - expect(setToPairs(set)).toEqual([p(1, 4), p(1, 6), p(1, 7), p(3, 0), p(3, 1)]); - expect(MultiSet.has(set, r(10, 11))).toBe(false); - expect(MultiSet.has(set, r(3, 0))).toBe(true); - expect(MultiSet.has(set, r(1, 7))).toBe(true); - for (let i = 0; i < MultiSet.size(set); i++) { - expect(MultiSet.getAt(set, i)).toBe(IntTuple.pack1(ret[i])); - } - }); - - it('element at / index of', () => { - const control: IntTuple[] = []; - const sets = Object.create(null); - for (let i = 1; i < 10; i++) { - const set = []; - for (let j = 1; j < 7; j++) { - control[control.length] = r(i * i, j * j + 1); - set[set.length] = j * j + 1; - } - sets[i * i] = OrderedSet.ofSortedArray(set); - } - const ms = MultiSet.create(sets); - for (let i = 0; i < control.length; i++) { - expect(IntTuple.areEqual(MultiSet.getAt(ms, i), control[i])).toBe(true); - } - - for (let i = 0; i < control.length; i++) { - expect(MultiSet.indexOf(ms, control[i])).toBe(i); - } - }); - - it('packed pairs', () => { - const set = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - expect(setToPairs(set)).toEqual([p(0, 1), p(0, 2), p(0, 6), p(1, 3)]); - }); - - it('equality', () => { - const a = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const b = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const c = MultiSet.create([r(1, 3), r(0, 4), r(0, 6), r(0, 2)]); - const d = MultiSet.create([r(1, 3)]); - const e = MultiSet.create([r(1, 3)]); - const f = MultiSet.create([r(3, 3)]); - - expect(MultiSet.areEqual(a, a)).toBe(true); - expect(MultiSet.areEqual(a, b)).toBe(true); - expect(MultiSet.areEqual(a, c)).toBe(false); - expect(MultiSet.areEqual(a, d)).toBe(false); - expect(MultiSet.areEqual(d, d)).toBe(true); - expect(MultiSet.areEqual(d, e)).toBe(true); - expect(MultiSet.areEqual(d, f)).toBe(false); - }); - - it('are intersecting', () => { - const a = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const b = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const c = MultiSet.create([r(1, 3), r(0, 4), r(0, 6), r(0, 2)]); - const d = MultiSet.create([r(1, 3)]); - const e = MultiSet.create([r(1, 3)]); - const f = MultiSet.create([r(3, 3)]); - const g = MultiSet.create([r(10, 3), r(8, 1), r(7, 6), r(3, 2)]); - - expect(MultiSet.areIntersecting(a, a)).toBe(true); - expect(MultiSet.areIntersecting(a, b)).toBe(true); - expect(MultiSet.areIntersecting(a, c)).toBe(true); - expect(MultiSet.areIntersecting(a, d)).toBe(true); - expect(MultiSet.areIntersecting(a, g)).toBe(false); - expect(MultiSet.areIntersecting(d, d)).toBe(true); - expect(MultiSet.areIntersecting(d, e)).toBe(true); - expect(MultiSet.areIntersecting(d, f)).toBe(false); - }); - - it('intersection', () => { - const a = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const b = MultiSet.create([r(10, 3), r(0, 1), r(0, 6), r(4, 2)]); - const c = MultiSet.create([r(1, 3)]); - const d = MultiSet.create([r(2, 3)]); - expect(MultiSet.intersect(a, a)).toBe(a); - expect(setToPairs(MultiSet.intersect(a, b))).toEqual([p(0, 1), p(0, 6)]); - expect(setToPairs(MultiSet.intersect(a, c))).toEqual([p(1, 3)]); - expect(setToPairs(MultiSet.intersect(c, d))).toEqual([]); - }); - - it('subtract', () => { - const a = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const a1 = MultiSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); - const b = MultiSet.create([r(10, 3), r(0, 1), r(0, 6), r(4, 2)]); - const c = MultiSet.create([r(1, 3)]); - const d = MultiSet.create([r(2, 3)]); - expect(setToPairs(MultiSet.subtract(a, a))).toEqual([]); - expect(setToPairs(MultiSet.subtract(a, a1))).toEqual([]); - expect(setToPairs(MultiSet.subtract(a, b))).toEqual([p(0, 2), p(1, 3)]); - expect(setToPairs(MultiSet.subtract(c, d))).toEqual([p(1, 3)]); - expect(setToPairs(MultiSet.subtract(a, c))).toEqual([p(0, 1), p(0, 2), p(0, 6)]); - expect(setToPairs(MultiSet.subtract(c, a))).toEqual([]); - expect(setToPairs(MultiSet.subtract(d, a))).toEqual([p(2, 3)]); - }); - - it('union', () => { - const a = MultiSet.create([r(1, 3), r(0, 1)]); - const a1 = MultiSet.create([r(1, 3), r(0, 1)]); - const b = MultiSet.create([r(10, 3), r(0, 1)]); - const c = MultiSet.create([r(1, 3)]); - const d = MultiSet.create([r(2, 3)]); - expect(MultiSet.unionMany([a])).toBe(a); - expect(MultiSet.union(a, a)).toBe(a); - expect(setToPairs(MultiSet.union(a, a))).toEqual([p(0, 1), p(1, 3)]); - expect(setToPairs(MultiSet.union(a, a1))).toEqual([p(0, 1), p(1, 3)]); - expect(setToPairs(MultiSet.union(a, b))).toEqual([p(0, 1), p(1, 3), p(10, 3)]); - expect(setToPairs(MultiSet.union(c, d))).toEqual([p(1, 3), p(2, 3)]); - expect(setToPairs(MultiSet.unionMany([a, b, c, d]))).toEqual([p(0, 1), p(1, 3), p(2, 3), p(10, 3)]); - }); }); \ No newline at end of file diff --git a/src/utils/chunked-array.ts b/src/common/collections/chunked-array.ts similarity index 100% rename from src/utils/chunked-array.ts rename to src/common/collections/chunked-array.ts diff --git a/src/structure/collections/hash-functions.ts b/src/common/collections/hash-functions.ts similarity index 100% rename from src/structure/collections/hash-functions.ts rename to src/common/collections/hash-functions.ts diff --git a/src/structure/collections/hash-set.ts b/src/common/collections/hash-set.ts similarity index 100% rename from src/structure/collections/hash-set.ts rename to src/common/collections/hash-set.ts diff --git a/src/structure/collections/int-tuple.ts b/src/common/collections/int-tuple.ts similarity index 100% rename from src/structure/collections/int-tuple.ts rename to src/common/collections/int-tuple.ts diff --git a/src/structure/collections/iterator.ts b/src/common/collections/iterator.ts similarity index 100% rename from src/structure/collections/iterator.ts rename to src/common/collections/iterator.ts diff --git a/src/structure/collections/linked-index.ts b/src/common/collections/linked-index.ts similarity index 100% rename from src/structure/collections/linked-index.ts rename to src/common/collections/linked-index.ts diff --git a/src/structure/collections/ordered-set.ts b/src/common/collections/ordered-set.ts similarity index 100% rename from src/structure/collections/ordered-set.ts rename to src/common/collections/ordered-set.ts diff --git a/src/structure/collections/sort.ts b/src/common/collections/sort.ts similarity index 100% rename from src/structure/collections/sort.ts rename to src/common/collections/sort.ts diff --git a/src/utils/computation.ts b/src/common/computation.ts similarity index 100% rename from src/utils/computation.ts rename to src/common/computation.ts diff --git a/src/utils/linear-algebra.ts b/src/common/math/linear-algebra.ts similarity index 100% rename from src/utils/linear-algebra.ts rename to src/common/math/linear-algebra.ts diff --git a/src/utils/scheduler.ts b/src/common/scheduler.ts similarity index 100% rename from src/utils/scheduler.ts rename to src/common/scheduler.ts diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index 8b4489030..000000000 --- a/src/index.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. - * - * @author Alexander Rose <alexander.rose@weirdbyte.de> - */ - -// TODO: fix me \ No newline at end of file diff --git a/src/mol-data/_spec/atom-set.spec.ts b/src/mol-data/_spec/atom-set.spec.ts new file mode 100644 index 000000000..5e8a607c1 --- /dev/null +++ b/src/mol-data/_spec/atom-set.spec.ts @@ -0,0 +1,154 @@ +/** + * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +import IntTuple from '../../common/collections/int-tuple' +import OrderedSet from '../../common/collections/ordered-set' +import AtomSet from '../atom-set' + +describe('atom set', () => { + const p = (i: number, j: number) => IntTuple.create(i, j); + const r = (i: number, j: number) => IntTuple.pack(i, j); + + function setToPairs(set: AtomSet): ArrayLike<IntTuple.Unpacked> { + const ret = []; + const it = AtomSet.values(set); + for (let v = it.move(); !it.done; v = it.move()) ret[ret.length] = IntTuple.create(v.fst, v.snd); + return ret; + } + + it('singleton pair', () => { + const set = AtomSet.create(p(10, 11)); + expect(setToPairs(set)).toEqual([p(10, 11)]); + expect(AtomSet.has(set, r(10, 11))).toBe(true); + expect(AtomSet.has(set, r(11, 11))).toBe(false); + expect(AtomSet.getAt(set, 0)).toBe(r(10, 11)); + expect(AtomSet.size(set)).toBe(1); + }); + + it('singleton number', () => { + const set = AtomSet.create(r(10, 11)); + expect(setToPairs(set)).toEqual([p(10, 11)]); + }); + + it('multi', () => { + const set = AtomSet.create({ + 1: OrderedSet.ofSortedArray([4, 6, 7]), + 3: OrderedSet.ofRange(0, 1), + }); + const ret = [p(1, 4), p(1, 6), p(1, 7), p(3, 0), p(3, 1)]; + expect(AtomSet.size(set)).toBe(ret.length); + expect(setToPairs(set)).toEqual([p(1, 4), p(1, 6), p(1, 7), p(3, 0), p(3, 1)]); + expect(AtomSet.has(set, r(10, 11))).toBe(false); + expect(AtomSet.has(set, r(3, 0))).toBe(true); + expect(AtomSet.has(set, r(1, 7))).toBe(true); + for (let i = 0; i < AtomSet.size(set); i++) { + expect(AtomSet.getAt(set, i)).toBe(IntTuple.pack1(ret[i])); + } + }); + + it('element at / index of', () => { + const control: IntTuple[] = []; + const sets = Object.create(null); + for (let i = 1; i < 10; i++) { + const set = []; + for (let j = 1; j < 7; j++) { + control[control.length] = r(i * i, j * j + 1); + set[set.length] = j * j + 1; + } + sets[i * i] = OrderedSet.ofSortedArray(set); + } + const ms = AtomSet.create(sets); + for (let i = 0; i < control.length; i++) { + expect(IntTuple.areEqual(AtomSet.getAt(ms, i), control[i])).toBe(true); + } + + for (let i = 0; i < control.length; i++) { + expect(AtomSet.indexOf(ms, control[i])).toBe(i); + } + }); + + it('packed pairs', () => { + const set = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + expect(setToPairs(set)).toEqual([p(0, 1), p(0, 2), p(0, 6), p(1, 3)]); + }); + + it('equality', () => { + const a = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const b = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const c = AtomSet.create([r(1, 3), r(0, 4), r(0, 6), r(0, 2)]); + const d = AtomSet.create([r(1, 3)]); + const e = AtomSet.create([r(1, 3)]); + const f = AtomSet.create([r(3, 3)]); + + expect(AtomSet.areEqual(a, a)).toBe(true); + expect(AtomSet.areEqual(a, b)).toBe(true); + expect(AtomSet.areEqual(a, c)).toBe(false); + expect(AtomSet.areEqual(a, d)).toBe(false); + expect(AtomSet.areEqual(d, d)).toBe(true); + expect(AtomSet.areEqual(d, e)).toBe(true); + expect(AtomSet.areEqual(d, f)).toBe(false); + }); + + it('are intersecting', () => { + const a = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const b = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const c = AtomSet.create([r(1, 3), r(0, 4), r(0, 6), r(0, 2)]); + const d = AtomSet.create([r(1, 3)]); + const e = AtomSet.create([r(1, 3)]); + const f = AtomSet.create([r(3, 3)]); + const g = AtomSet.create([r(10, 3), r(8, 1), r(7, 6), r(3, 2)]); + + expect(AtomSet.areIntersecting(a, a)).toBe(true); + expect(AtomSet.areIntersecting(a, b)).toBe(true); + expect(AtomSet.areIntersecting(a, c)).toBe(true); + expect(AtomSet.areIntersecting(a, d)).toBe(true); + expect(AtomSet.areIntersecting(a, g)).toBe(false); + expect(AtomSet.areIntersecting(d, d)).toBe(true); + expect(AtomSet.areIntersecting(d, e)).toBe(true); + expect(AtomSet.areIntersecting(d, f)).toBe(false); + }); + + it('intersection', () => { + const a = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const b = AtomSet.create([r(10, 3), r(0, 1), r(0, 6), r(4, 2)]); + const c = AtomSet.create([r(1, 3)]); + const d = AtomSet.create([r(2, 3)]); + expect(AtomSet.intersect(a, a)).toBe(a); + expect(setToPairs(AtomSet.intersect(a, b))).toEqual([p(0, 1), p(0, 6)]); + expect(setToPairs(AtomSet.intersect(a, c))).toEqual([p(1, 3)]); + expect(setToPairs(AtomSet.intersect(c, d))).toEqual([]); + }); + + it('subtract', () => { + const a = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const a1 = AtomSet.create([r(1, 3), r(0, 1), r(0, 6), r(0, 2)]); + const b = AtomSet.create([r(10, 3), r(0, 1), r(0, 6), r(4, 2)]); + const c = AtomSet.create([r(1, 3)]); + const d = AtomSet.create([r(2, 3)]); + expect(setToPairs(AtomSet.subtract(a, a))).toEqual([]); + expect(setToPairs(AtomSet.subtract(a, a1))).toEqual([]); + expect(setToPairs(AtomSet.subtract(a, b))).toEqual([p(0, 2), p(1, 3)]); + expect(setToPairs(AtomSet.subtract(c, d))).toEqual([p(1, 3)]); + expect(setToPairs(AtomSet.subtract(a, c))).toEqual([p(0, 1), p(0, 2), p(0, 6)]); + expect(setToPairs(AtomSet.subtract(c, a))).toEqual([]); + expect(setToPairs(AtomSet.subtract(d, a))).toEqual([p(2, 3)]); + }); + + it('union', () => { + const a = AtomSet.create([r(1, 3), r(0, 1)]); + const a1 = AtomSet.create([r(1, 3), r(0, 1)]); + const b = AtomSet.create([r(10, 3), r(0, 1)]); + const c = AtomSet.create([r(1, 3)]); + const d = AtomSet.create([r(2, 3)]); + expect(AtomSet.unionMany([a])).toBe(a); + expect(AtomSet.union(a, a)).toBe(a); + expect(setToPairs(AtomSet.union(a, a))).toEqual([p(0, 1), p(1, 3)]); + expect(setToPairs(AtomSet.union(a, a1))).toEqual([p(0, 1), p(1, 3)]); + expect(setToPairs(AtomSet.union(a, b))).toEqual([p(0, 1), p(1, 3), p(10, 3)]); + expect(setToPairs(AtomSet.union(c, d))).toEqual([p(1, 3), p(2, 3)]); + expect(setToPairs(AtomSet.unionMany([a, b, c, d]))).toEqual([p(0, 1), p(1, 3), p(2, 3), p(10, 3)]); + }); +}); \ No newline at end of file diff --git a/src/structure/collections/multi-set.ts b/src/mol-data/atom-set.ts similarity index 66% rename from src/structure/collections/multi-set.ts rename to src/mol-data/atom-set.ts index 4cc7f2717..41c65c4e0 100644 --- a/src/structure/collections/multi-set.ts +++ b/src/mol-data/atom-set.ts @@ -4,160 +4,160 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import OrderedSet from './ordered-set' -import Iterator from './iterator' -import IntTuple from './int-tuple' -import { sortArray } from './sort' -import { hash1 } from './hash-functions' +import OrderedSet from '../common/collections/ordered-set' +import Iterator from '../common/collections/iterator' +import IntTuple from '../common/collections/int-tuple' +import { sortArray } from '../common/collections/sort' +import { hash1 } from '../common/collections/hash-functions' /** A map-like representation of integer set */ -interface MultiSet { '@type': 'int-multi-set' } +interface AtomSet { '@type': 'atom-set' } -namespace MultiSet { - export const Empty: MultiSet = { offsets: [0], hashCode: 0, keys: OrderedSet.Empty } as MultiSetElements as any; +namespace AtomSet { + export const Empty: AtomSet = { offsets: [0], hashCode: 0, keys: OrderedSet.Empty } as AtomSetElements as any; - export function create(data: IntTuple | ArrayLike<IntTuple> | IntTuple | { [id: number]: OrderedSet }): MultiSet { + export function create(data: IntTuple | ArrayLike<IntTuple> | IntTuple | { [id: number]: OrderedSet }): AtomSet { if (typeof data === 'number') return data; if (IntTuple.is(data)) return IntTuple.pack1(data) as any; if (isArrayLike(data)) return ofTuples(data) as any; return ofObject(data as { [id: number]: OrderedSet }) as any; } - export const keys: (set: MultiSet) => OrderedSet = keysI as any; - export const keyCount: (set: MultiSet) => number = keyCountI as any; - export const hasKey: (set: MultiSet, key: number) => boolean = hasKeyI as any; - export const geyKey: (set: MultiSet, i: number) => number = getKeyI as any; - export const getByKey: (set: MultiSet, key: number) => OrderedSet = getByKeyI as any; - export const getByIndex: (set: MultiSet, i: number) => OrderedSet = getByIndexI as any; - export const has: (set: MultiSet, x: IntTuple) => boolean = hasI as any; - export const indexOf: (set: MultiSet, x: IntTuple) => number = indexOfI as any; - export const getAt: (set: MultiSet, i: number) => IntTuple = getAtI as any; - export const values: (set: MultiSet) => Iterator<IntTuple.Unpacked> = valuesI as any; + export const keys: (set: AtomSet) => OrderedSet = keysI as any; + export const keyCount: (set: AtomSet) => number = keyCountI as any; + export const hasKey: (set: AtomSet, key: number) => boolean = hasKeyI as any; + export const geyKey: (set: AtomSet, i: number) => number = getKeyI as any; + export const getByKey: (set: AtomSet, key: number) => OrderedSet = getByKeyI as any; + export const getByIndex: (set: AtomSet, i: number) => OrderedSet = getByIndexI as any; + export const has: (set: AtomSet, x: IntTuple) => boolean = hasI as any; + export const indexOf: (set: AtomSet, x: IntTuple) => number = indexOfI as any; + export const getAt: (set: AtomSet, i: number) => IntTuple = getAtI as any; + export const values: (set: AtomSet) => Iterator<IntTuple.Unpacked> = valuesI as any; - export const size: (set: MultiSet) => number = sizeI as any; - export const hashCode: (set: MultiSet) => number = hashCodeI as any; + export const size: (set: AtomSet) => number = sizeI as any; + export const hashCode: (set: AtomSet) => number = hashCodeI as any; - export const areEqual: (a: MultiSet, b: MultiSet) => boolean = areEqualI as any; - export const areIntersecting: (a: MultiSet, b: MultiSet) => boolean = areIntersectingI as any; + export const areEqual: (a: AtomSet, b: AtomSet) => boolean = areEqualI as any; + export const areIntersecting: (a: AtomSet, b: AtomSet) => boolean = areIntersectingI as any; - export const union: (a: MultiSet, b: MultiSet) => MultiSet = unionI as any; - export const unionMany: (sets: MultiSet[]) => MultiSet = unionManyI as any; - export const intersect: (a: MultiSet, b: MultiSet) => MultiSet = intersectI as any; - export const subtract: (a: MultiSet, b: MultiSet) => MultiSet = subtractI as any; + export const union: (a: AtomSet, b: AtomSet) => AtomSet = unionI as any; + export const unionMany: (sets: AtomSet[]) => AtomSet = unionManyI as any; + export const intersect: (a: AtomSet, b: AtomSet) => AtomSet = intersectI as any; + export const subtract: (a: AtomSet, b: AtomSet) => AtomSet = subtractI as any; } -export default MultiSet +export default AtomSet /** Long and painful implementation starts here */ -interface MultiSetElements { [id: number]: OrderedSet, offsets: number[], hashCode: number, keys: OrderedSet } -type MultiSetImpl = IntTuple | MultiSetElements +interface AtomSetElements { [id: number]: OrderedSet, offsets: number[], hashCode: number, keys: OrderedSet } +type AtomSetImpl = IntTuple | AtomSetElements -function keysI(set: MultiSetImpl): OrderedSet { +function keysI(set: AtomSetImpl): OrderedSet { if (typeof set === 'number') return OrderedSet.ofSingleton(set); - return (set as MultiSetElements).keys; + return (set as AtomSetElements).keys; } -function keyCountI(set: MultiSetImpl): number { +function keyCountI(set: AtomSetImpl): number { if (typeof set === 'number') return 1; - return OrderedSet.size((set as MultiSetElements).keys); + return OrderedSet.size((set as AtomSetElements).keys); } -function hasKeyI(set: MultiSetImpl, key: number): boolean { +function hasKeyI(set: AtomSetImpl, key: number): boolean { if (typeof set === 'number') return IntTuple.fst(set) === key; - return OrderedSet.has((set as MultiSetElements).keys, key); + return OrderedSet.has((set as AtomSetElements).keys, key); } -function getKeyI(set: MultiSetImpl, index: number): number { +function getKeyI(set: AtomSetImpl, index: number): number { if (typeof set === 'number') return IntTuple.fst(set); - return OrderedSet.getAt((set as MultiSetElements).keys, index); + return OrderedSet.getAt((set as AtomSetElements).keys, index); } -function hasI(set: MultiSetImpl, t: IntTuple): boolean { +function hasI(set: AtomSetImpl, t: IntTuple): boolean { if (typeof set === 'number') return IntTuple.areEqual(t, set); IntTuple.unpack(t, _hasP); - return OrderedSet.has((set as MultiSetElements).keys, _hasP.fst) ? OrderedSet.has((set as MultiSetElements)[_hasP.fst], _hasP.snd) : false; + return OrderedSet.has((set as AtomSetElements).keys, _hasP.fst) ? OrderedSet.has((set as AtomSetElements)[_hasP.fst], _hasP.snd) : false; } const _hasP = IntTuple.zero(); -function getByKeyI(set: MultiSetImpl, key: number): OrderedSet { +function getByKeyI(set: AtomSetImpl, key: number): OrderedSet { if (typeof set === 'number') { IntTuple.unpack(set, _gS); return _gS.fst === key ? OrderedSet.ofSingleton(_gS.snd) : OrderedSet.Empty; } - return OrderedSet.has((set as MultiSetElements).keys, key) ? (set as MultiSetElements)[key] : OrderedSet.Empty; + return OrderedSet.has((set as AtomSetElements).keys, key) ? (set as AtomSetElements)[key] : OrderedSet.Empty; } const _gS = IntTuple.zero(); -function getByIndexI(set: MultiSetImpl, index: number): OrderedSet { +function getByIndexI(set: AtomSetImpl, index: number): OrderedSet { if (typeof set === 'number') return index === 0 ? OrderedSet.ofSingleton(IntTuple.snd(set)) : OrderedSet.Empty; - const key = OrderedSet.getAt((set as MultiSetElements).keys, index); - return (set as MultiSetElements)[key] || OrderedSet.Empty; + const key = OrderedSet.getAt((set as AtomSetElements).keys, index); + return (set as AtomSetElements)[key] || OrderedSet.Empty; } -function getAtI(set: MultiSetImpl, i: number): IntTuple { +function getAtI(set: AtomSetImpl, i: number): IntTuple { if (typeof set === 'number') return set; - return getAtE(set as MultiSetElements, i); + return getAtE(set as AtomSetElements, i); } -function indexOfI(set: MultiSetImpl, t: IntTuple) { +function indexOfI(set: AtomSetImpl, t: IntTuple) { if (typeof set === 'number') return IntTuple.areEqual(set, t) ? 0 : -1; - return indexOfE(set as MultiSetElements, t); + return indexOfE(set as AtomSetElements, t); } /** Number elements in the "child" sets */ -function sizeI(set: MultiSetImpl) { +function sizeI(set: AtomSetImpl) { if (typeof set === 'number') return 1; - return (set as MultiSetElements).offsets[(set as MultiSetElements).offsets.length - 1]; + return (set as AtomSetElements).offsets[(set as AtomSetElements).offsets.length - 1]; } -function hashCodeI(set: MultiSetImpl) { +function hashCodeI(set: AtomSetImpl) { if (typeof set === 'number') return IntTuple.hashCode(set); - if ((set as MultiSetElements).hashCode !== -1) return (set as MultiSetElements).hashCode; - return computeHash((set as MultiSetElements)); + if ((set as AtomSetElements).hashCode !== -1) return (set as AtomSetElements).hashCode; + return computeHash((set as AtomSetElements)); } -function areEqualI(a: MultiSetImpl, b: MultiSetImpl) { +function areEqualI(a: AtomSetImpl, b: AtomSetImpl) { if (typeof a === 'number') { if (typeof b === 'number') return IntTuple.areEqual(a, b); return false; } if (typeof b === 'number') return false; - return areEqualEE(a as MultiSetElements, b as MultiSetElements); + return areEqualEE(a as AtomSetElements, b as AtomSetElements); } -function areIntersectingI(a: MultiSetImpl, b: MultiSetImpl) { +function areIntersectingI(a: AtomSetImpl, b: AtomSetImpl) { if (typeof a === 'number') { if (typeof b === 'number') return IntTuple.areEqual(a, b); - return areIntersectingNE(a, b as MultiSetElements); + return areIntersectingNE(a, b as AtomSetElements); } - if (typeof b === 'number') return areIntersectingNE(b, a as MultiSetElements); - return areIntersectingEE(a as MultiSetElements, b as MultiSetElements); + if (typeof b === 'number') return areIntersectingNE(b, a as AtomSetElements); + return areIntersectingEE(a as AtomSetElements, b as AtomSetElements); } -function intersectI(a: MultiSetImpl, b: MultiSetImpl) { +function intersectI(a: AtomSetImpl, b: AtomSetImpl) { if (typeof a === 'number') { - if (typeof b === 'number') return IntTuple.areEqual(a, b) ? a : MultiSet.Empty; - return intersectNE(a, b as MultiSetElements); + if (typeof b === 'number') return IntTuple.areEqual(a, b) ? a : AtomSet.Empty; + return intersectNE(a, b as AtomSetElements); } - if (typeof b === 'number') return intersectNE(b, a as MultiSetElements); - return intersectEE(a as MultiSetElements, b as MultiSetElements); + if (typeof b === 'number') return intersectNE(b, a as AtomSetElements); + return intersectEE(a as AtomSetElements, b as AtomSetElements); } -function subtractI(a: MultiSetImpl, b: MultiSetImpl) { +function subtractI(a: AtomSetImpl, b: AtomSetImpl) { if (typeof a === 'number') { - if (typeof b === 'number') return IntTuple.areEqual(a, b) ? MultiSet.Empty : a; - return subtractNE(a, b as MultiSetElements); + if (typeof b === 'number') return IntTuple.areEqual(a, b) ? AtomSet.Empty : a; + return subtractNE(a, b as AtomSetElements); } - if (typeof b === 'number') return subtractEN(a as MultiSetElements, b); - return subtractEE(a as MultiSetElements, b as MultiSetElements); + if (typeof b === 'number') return subtractEN(a as AtomSetElements, b); + return subtractEE(a as AtomSetElements, b as AtomSetElements); } -function unionI(a: MultiSetImpl, b: MultiSetImpl) { +function unionI(a: AtomSetImpl, b: AtomSetImpl) { return findUnion([a, b]); } -function unionManyI(sets: ArrayLike<MultiSetImpl>) { +function unionManyI(sets: ArrayLike<AtomSetImpl>) { return findUnion(sets); } @@ -198,16 +198,16 @@ class ElementsIterator implements Iterator<IntTuple.Unpacked> { return true; } - constructor(private elements: MultiSetElements) { + constructor(private elements: AtomSetElements) { this.keyCount = OrderedSet.size(elements.keys); this.done = this.keyCount === 0; this.advance(); } } -function valuesI(set: MultiSetImpl): Iterator<IntTuple.Unpacked> { +function valuesI(set: AtomSetImpl): Iterator<IntTuple.Unpacked> { if (typeof set === 'number') return Iterator.Value(IntTuple.unpack1(set)); - return new ElementsIterator(set as MultiSetElements); + return new ElementsIterator(set as AtomSetElements); } function isArrayLike(x: any): x is ArrayLike<IntTuple> { @@ -220,7 +220,7 @@ function ofObject(data: { [id: number]: OrderedSet }) { const k = +_k; if (OrderedSet.size(data[k]) > 0) keys[keys.length] = k; } - if (!keys.length) return MultiSet.Empty; + if (!keys.length) return AtomSet.Empty; if (keys.length === 1) { const set = data[keys[0]]; if (OrderedSet.size(set) === 1) return IntTuple.pack(keys[0], OrderedSet.getAt(set, 0)); @@ -248,7 +248,7 @@ function ofObjectOrdered(keys: OrderedSet, data: { [id: number]: OrderedSet }) { } function _createObjectOrdered(keys: OrderedSet, data: { [id: number]: OrderedSet }) { - const ret: MultiSetElements = Object.create(null); + const ret: AtomSetElements = Object.create(null); ret.keys = keys; const offsets = [0]; let size = 0; @@ -287,7 +287,7 @@ function normalizeArray(xs: number[]) { } function ofTuples(xs: ArrayLike<IntTuple>) { - if (xs.length === 0) return MultiSet.Empty; + if (xs.length === 0) return AtomSet.Empty; const sets: { [key: number]: number[] } = Object.create(null); const p = IntTuple.zero(); for (let i = 0, _i = xs.length; i < _i; i++) { @@ -321,7 +321,7 @@ function getOffsetIndex(xs: ArrayLike<number>, value: number) { return value < xs[min] ? min - 1 : min; } -function getAtE(set: MultiSetElements, i: number): IntTuple { +function getAtE(set: AtomSetElements, i: number): IntTuple { const { offsets, keys } = set; const o = getOffsetIndex(offsets, i); if (o >= offsets.length - 1) return 0 as any; @@ -331,7 +331,7 @@ function getAtE(set: MultiSetElements, i: number): IntTuple { } const _iOE = IntTuple.zero(); -function indexOfE(set: MultiSetElements, t: IntTuple) { +function indexOfE(set: AtomSetElements, t: IntTuple) { IntTuple.unpack(t, _iOE); const { keys } = set; const setIdx = OrderedSet.indexOf(keys, _iOE.fst); @@ -341,7 +341,7 @@ function indexOfE(set: MultiSetElements, t: IntTuple) { return set.offsets[setIdx] + o; } -function computeHash(set: MultiSetElements) { +function computeHash(set: AtomSetElements) { const { keys } = set; let hash = 23; for (let i = 0, _i = OrderedSet.size(keys); i < _i; i++) { @@ -355,7 +355,7 @@ function computeHash(set: MultiSetElements) { return hash; } -function areEqualEE(a: MultiSetElements, b: MultiSetElements) { +function areEqualEE(a: AtomSetElements, b: AtomSetElements) { if (a === b) return true; if (sizeI(a) !== sizeI(a)) return false; @@ -369,12 +369,12 @@ function areEqualEE(a: MultiSetElements, b: MultiSetElements) { } const _aeP = IntTuple.zero(); -function areIntersectingNE(a: IntTuple, b: MultiSetElements) { +function areIntersectingNE(a: IntTuple, b: AtomSetElements) { IntTuple.unpack(a, _aeP); return OrderedSet.has(b.keys, _aeP.fst) && OrderedSet.has(b[_aeP.fst], _aeP.snd); } -function areIntersectingEE(a: MultiSetElements, b: MultiSetElements) { +function areIntersectingEE(a: AtomSetElements, b: AtomSetElements) { if (a === b) return true; const keysA = a.keys, keysB = b.keys; if (!OrderedSet.areIntersecting(a.keys, b.keys)) return false; @@ -387,16 +387,16 @@ function areIntersectingEE(a: MultiSetElements, b: MultiSetElements) { } const _nP = IntTuple.zero(); -function intersectNE(a: IntTuple, b: MultiSetElements) { +function intersectNE(a: IntTuple, b: AtomSetElements) { IntTuple.unpack(a, _nP); - return OrderedSet.has(b.keys, _nP.fst) && OrderedSet.has(b[_nP.fst], _nP.snd) ? a : MultiSet.Empty; + return OrderedSet.has(b.keys, _nP.fst) && OrderedSet.has(b[_nP.fst], _nP.snd) ? a : AtomSet.Empty; } -function intersectEE(a: MultiSetElements, b: MultiSetElements) { +function intersectEE(a: AtomSetElements, b: AtomSetElements) { if (a === b) return a; const keysA = a.keys, keysB = b.keys; - if (!OrderedSet.areIntersecting(a.keys, b.keys)) return MultiSet.Empty; + if (!OrderedSet.areIntersecting(a.keys, b.keys)) return AtomSet.Empty; const { start, end } = OrderedSet.getIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); const keys = [], ret = Object.create(null); @@ -414,13 +414,13 @@ function intersectEE(a: MultiSetElements, b: MultiSetElements) { } const _sNE = IntTuple.zero(); -function subtractNE(a: IntTuple, b: MultiSetElements) { +function subtractNE(a: IntTuple, b: AtomSetElements) { IntTuple.unpack(a, _sNE); - return OrderedSet.has(b.keys, _sNE.fst) && OrderedSet.has(b[_sNE.fst], _sNE.snd) ? MultiSet.Empty : a; + return OrderedSet.has(b.keys, _sNE.fst) && OrderedSet.has(b[_sNE.fst], _sNE.snd) ? AtomSet.Empty : a; } const _sEN = IntTuple.zero(); -function subtractEN(a: MultiSetElements, b: IntTuple): MultiSetImpl { +function subtractEN(a: AtomSetElements, b: IntTuple): AtomSetImpl { const aKeys = a.keys; IntTuple.unpack(b, _sEN); if (!OrderedSet.has(aKeys, _sEN.fst) || !OrderedSet.has(a[_sEN.fst], _sEN.snd)) return a; @@ -432,11 +432,11 @@ function subtractEN(a: MultiSetElements, b: IntTuple): MultiSetImpl { } } -function subtractEE(a: MultiSetElements, b: MultiSetElements) { - if (a === b) return MultiSet.Empty; +function subtractEE(a: AtomSetElements, b: AtomSetElements) { + if (a === b) return AtomSet.Empty; const keysA = a.keys, keysB = b.keys; - if (!OrderedSet.areIntersecting(a.keys, b.keys)) return MultiSet.Empty; + if (!OrderedSet.areIntersecting(a.keys, b.keys)) return AtomSet.Empty; const { start, end } = OrderedSet.getIntervalRange(keysA, OrderedSet.min(keysB), OrderedSet.max(keysB)); const keys = [], ret = Object.create(null); @@ -466,8 +466,8 @@ function subtractEE(a: MultiSetElements, b: MultiSetElements) { return ofObjectOrdered(OrderedSet.ofSortedArray(keys), ret); } -function findUnion(sets: ArrayLike<MultiSetImpl>) { - if (!sets.length) return MultiSet.Empty; +function findUnion(sets: ArrayLike<AtomSetImpl>) { + if (!sets.length) return AtomSet.Empty; if (sets.length === 1) return sets[0]; if (sets.length === 2 && areEqualI(sets[0], sets[1])) return sets[0]; @@ -477,23 +477,23 @@ function findUnion(sets: ArrayLike<MultiSetImpl>) { const ret = Object.create(null); for (let i = 0, _i = sets.length; i < _i; i++) { const s = sets[i]; - if (typeof s !== 'number') unionInto(ret, s as MultiSetElements); + if (typeof s !== 'number') unionInto(ret, s as AtomSetElements); } - if (sizeI(ns as MultiSetImpl) > 0) { + if (sizeI(ns as AtomSetImpl) > 0) { if (typeof ns === 'number') unionIntoN(ret, ns as any); - else unionInto(ret, ns as MultiSetElements); + else unionInto(ret, ns as AtomSetElements); } return ofObject(ret); } -function unionN(sets: ArrayLike<MultiSetImpl>, eCount: { count: number }) { +function unionN(sets: ArrayLike<AtomSetImpl>, eCount: { count: number }) { let countN = 0, countE = 0; for (let i = 0, _i = sets.length; i < _i; i++) { if (typeof sets[i] === 'number') countN++; else countE++; } eCount.count = countE; - if (!countN) return MultiSet.Empty; + if (!countN) return AtomSet.Empty; if (countN === sets.length) return ofTuples(sets as ArrayLike<IntTuple>); const packed = new Float64Array(countN); let offset = 0; @@ -504,7 +504,7 @@ function unionN(sets: ArrayLike<MultiSetImpl>, eCount: { count: number }) { return ofTuples(packed as any); } -function unionInto(data: { [key: number]: OrderedSet }, a: MultiSetElements) { +function unionInto(data: { [key: number]: OrderedSet }, a: AtomSetElements) { const keys = a.keys; for (let i = 0, _i = OrderedSet.size(keys); i < _i; i++) { const k = OrderedSet.getAt(keys, i); diff --git a/src/structure/data.ts b/src/mol-data/structure/data.ts similarity index 100% rename from src/structure/data.ts rename to src/mol-data/structure/data.ts diff --git a/src/structure/model.ts b/src/mol-data/structure/model.ts similarity index 98% rename from src/structure/model.ts rename to src/mol-data/structure/model.ts index dd1dbcd1e..167801cc9 100644 --- a/src/structure/model.ts +++ b/src/mol-data/structure/model.ts @@ -6,7 +6,7 @@ import * as Data from './data' import { Selectors } from './selectors' -import { Vec3, Mat4 } from '../utils/linear-algebra' +import { Vec3, Mat4 } from '../../common/math/linear-algebra' let _uid = 0; /** Model-related unique identifiers */ diff --git a/src/structure/selectors.ts b/src/mol-data/structure/selectors.ts similarity index 100% rename from src/structure/selectors.ts rename to src/mol-data/structure/selectors.ts diff --git a/src/structure/selectors/common.ts b/src/mol-data/structure/selectors/common.ts similarity index 100% rename from src/structure/selectors/common.ts rename to src/mol-data/structure/selectors/common.ts diff --git a/src/structure/selectors/mmcif.ts b/src/mol-data/structure/selectors/mmcif.ts similarity index 100% rename from src/structure/selectors/mmcif.ts rename to src/mol-data/structure/selectors/mmcif.ts diff --git a/src/index.ts b/src/mol-data/structure/structure.ts similarity index 59% rename from src/index.ts rename to src/mol-data/structure/structure.ts index e20061a12..d13a9ee15 100644 --- a/src/index.ts +++ b/src/mol-data/structure/structure.ts @@ -1,7 +1,6 @@ /** * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. * - * @author Alexander Rose <alexander.rose@weirdbyte.de> + * @author David Sehnal <david.sehnal@gmail.com> */ -// TODO: fix me diff --git a/src/structure/symmetry.ts b/src/mol-data/structure/symmetry.ts similarity index 100% rename from src/structure/symmetry.ts rename to src/mol-data/structure/symmetry.ts diff --git a/src/structure/topology/connected-components.ts b/src/mol-data/structure/topology/connected-components.ts similarity index 100% rename from src/structure/topology/connected-components.ts rename to src/mol-data/structure/topology/connected-components.ts diff --git a/src/structure/topology/secondary-structure.ts b/src/mol-data/structure/topology/secondary-structure.ts similarity index 100% rename from src/structure/topology/secondary-structure.ts rename to src/mol-data/structure/topology/secondary-structure.ts diff --git a/src/reader/spec/cif.spec.ts b/src/mol-io/reader/_spec/cif.spec.ts similarity index 100% rename from src/reader/spec/cif.spec.ts rename to src/mol-io/reader/_spec/cif.spec.ts diff --git a/src/reader/spec/column.spec.ts b/src/mol-io/reader/_spec/column.spec.ts similarity index 100% rename from src/reader/spec/column.spec.ts rename to src/mol-io/reader/_spec/column.spec.ts diff --git a/src/reader/spec/gro.spec.ts b/src/mol-io/reader/_spec/gro.spec.ts similarity index 100% rename from src/reader/spec/gro.spec.ts rename to src/mol-io/reader/_spec/gro.spec.ts diff --git a/src/reader/cif/binary/decoder.ts b/src/mol-io/reader/cif/binary/decoder.ts similarity index 100% rename from src/reader/cif/binary/decoder.ts rename to src/mol-io/reader/cif/binary/decoder.ts diff --git a/src/reader/cif/binary/encoding.ts b/src/mol-io/reader/cif/binary/encoding.ts similarity index 100% rename from src/reader/cif/binary/encoding.ts rename to src/mol-io/reader/cif/binary/encoding.ts diff --git a/src/reader/cif/binary/field.ts b/src/mol-io/reader/cif/binary/field.ts similarity index 100% rename from src/reader/cif/binary/field.ts rename to src/mol-io/reader/cif/binary/field.ts diff --git a/src/reader/cif/binary/parser.ts b/src/mol-io/reader/cif/binary/parser.ts similarity index 96% rename from src/reader/cif/binary/parser.ts rename to src/mol-io/reader/cif/binary/parser.ts index 958f6bfa2..851e6974a 100644 --- a/src/reader/cif/binary/parser.ts +++ b/src/mol-io/reader/cif/binary/parser.ts @@ -9,7 +9,7 @@ import * as Encoding from './encoding' import Field from './field' import Result from '../../result' import decodeMsgPack from '../../../utils/msgpack/decode' -import Computation from '../../../utils/computation' +import Computation from '../../../../common/computation' function checkVersions(min: number[], current: number[]) { for (let i = 0; i < 2; i++) { diff --git a/src/reader/cif/data-model.ts b/src/mol-io/reader/cif/data-model.ts similarity index 100% rename from src/reader/cif/data-model.ts rename to src/mol-io/reader/cif/data-model.ts diff --git a/src/reader/cif/index.ts b/src/mol-io/reader/cif/index.ts similarity index 100% rename from src/reader/cif/index.ts rename to src/mol-io/reader/cif/index.ts diff --git a/src/reader/cif/schema.ts b/src/mol-io/reader/cif/schema.ts similarity index 100% rename from src/reader/cif/schema.ts rename to src/mol-io/reader/cif/schema.ts diff --git a/src/reader/cif/schema/ccd.ts b/src/mol-io/reader/cif/schema/ccd.ts similarity index 100% rename from src/reader/cif/schema/ccd.ts rename to src/mol-io/reader/cif/schema/ccd.ts diff --git a/src/reader/cif/schema/ddl.ts b/src/mol-io/reader/cif/schema/ddl.ts similarity index 100% rename from src/reader/cif/schema/ddl.ts rename to src/mol-io/reader/cif/schema/ddl.ts diff --git a/src/reader/cif/schema/density.ts b/src/mol-io/reader/cif/schema/density.ts similarity index 100% rename from src/reader/cif/schema/density.ts rename to src/mol-io/reader/cif/schema/density.ts diff --git a/src/reader/cif/schema/dic.ts b/src/mol-io/reader/cif/schema/dic.ts similarity index 100% rename from src/reader/cif/schema/dic.ts rename to src/mol-io/reader/cif/schema/dic.ts diff --git a/src/reader/cif/schema/mmcif.ts b/src/mol-io/reader/cif/schema/mmcif.ts similarity index 100% rename from src/reader/cif/schema/mmcif.ts rename to src/mol-io/reader/cif/schema/mmcif.ts diff --git a/src/reader/cif/schema/utils.ts b/src/mol-io/reader/cif/schema/utils.ts similarity index 100% rename from src/reader/cif/schema/utils.ts rename to src/mol-io/reader/cif/schema/utils.ts diff --git a/src/reader/cif/text/field.ts b/src/mol-io/reader/cif/text/field.ts similarity index 100% rename from src/reader/cif/text/field.ts rename to src/mol-io/reader/cif/text/field.ts diff --git a/src/reader/cif/text/parser.ts b/src/mol-io/reader/cif/text/parser.ts similarity index 99% rename from src/reader/cif/text/parser.ts rename to src/mol-io/reader/cif/text/parser.ts index 4b86e99a1..1607f4622 100644 --- a/src/reader/cif/text/parser.ts +++ b/src/mol-io/reader/cif/text/parser.ts @@ -26,7 +26,7 @@ import * as Data from '../data-model' import Field from './field' import { Tokens, TokenBuilder } from '../../common/text/tokenizer' import Result from '../../result' -import Computation from '../../../utils/computation' +import Computation from '../../../../common/computation' /** * Types of supported mmCIF tokens. diff --git a/src/reader/common/binary/column.ts b/src/mol-io/reader/common/binary/column.ts similarity index 100% rename from src/reader/common/binary/column.ts rename to src/mol-io/reader/common/binary/column.ts diff --git a/src/reader/common/column.ts b/src/mol-io/reader/common/column.ts similarity index 100% rename from src/reader/common/column.ts rename to src/mol-io/reader/common/column.ts diff --git a/src/reader/common/text/column/fixed.ts b/src/mol-io/reader/common/text/column/fixed.ts similarity index 100% rename from src/reader/common/text/column/fixed.ts rename to src/mol-io/reader/common/text/column/fixed.ts diff --git a/src/reader/common/text/column/token.ts b/src/mol-io/reader/common/text/column/token.ts similarity index 100% rename from src/reader/common/text/column/token.ts rename to src/mol-io/reader/common/text/column/token.ts diff --git a/src/reader/common/text/number-parser.ts b/src/mol-io/reader/common/text/number-parser.ts similarity index 100% rename from src/reader/common/text/number-parser.ts rename to src/mol-io/reader/common/text/number-parser.ts diff --git a/src/reader/common/text/tokenizer.ts b/src/mol-io/reader/common/text/tokenizer.ts similarity index 99% rename from src/reader/common/text/tokenizer.ts rename to src/mol-io/reader/common/text/tokenizer.ts index 17991fbdb..85b72166b 100644 --- a/src/reader/common/text/tokenizer.ts +++ b/src/mol-io/reader/common/text/tokenizer.ts @@ -6,7 +6,7 @@ * @author Alexander Rose <alexander.rose@weirdbyte.de> */ -import Computation from '../../../utils/computation' +import Computation from '../../../../common/computation' export interface Tokenizer { data: string, diff --git a/src/reader/gro/parser.ts b/src/mol-io/reader/gro/parser.ts similarity index 99% rename from src/reader/gro/parser.ts rename to src/mol-io/reader/gro/parser.ts index 7ec1c994b..1cc837935 100644 --- a/src/reader/gro/parser.ts +++ b/src/mol-io/reader/gro/parser.ts @@ -10,7 +10,7 @@ import FixedColumn from '../common/text/column/fixed' import { ColumnType, UndefinedColumn } from '../common/column' import * as Schema from './schema' import Result from '../result' -import Computation from '../../utils/computation' +import Computation from '../../../common/computation' interface State { tokenizer: Tokenizer, diff --git a/src/reader/gro/schema.d.ts b/src/mol-io/reader/gro/schema.d.ts similarity index 100% rename from src/reader/gro/schema.d.ts rename to src/mol-io/reader/gro/schema.d.ts diff --git a/src/reader/mol2/schema.d.ts b/src/mol-io/reader/mol2/schema.d.ts similarity index 100% rename from src/reader/mol2/schema.d.ts rename to src/mol-io/reader/mol2/schema.d.ts diff --git a/src/reader/result.ts b/src/mol-io/reader/result.ts similarity index 100% rename from src/reader/result.ts rename to src/mol-io/reader/result.ts diff --git a/src/utils/msgpack/decode.ts b/src/mol-io/utils/msgpack/decode.ts similarity index 100% rename from src/utils/msgpack/decode.ts rename to src/mol-io/utils/msgpack/decode.ts diff --git a/src/utils/msgpack/encode.ts b/src/mol-io/utils/msgpack/encode.ts similarity index 100% rename from src/utils/msgpack/encode.ts rename to src/mol-io/utils/msgpack/encode.ts diff --git a/src/utils/short-string-pool.ts b/src/mol-io/utils/short-string-pool.ts similarity index 100% rename from src/utils/short-string-pool.ts rename to src/mol-io/utils/short-string-pool.ts diff --git a/src/utils/utf8.ts b/src/mol-io/utils/utf8.ts similarity index 100% rename from src/utils/utf8.ts rename to src/mol-io/utils/utf8.ts diff --git a/src/perf-tests/chunked-array-vs-native.ts b/src/perf-tests/chunked-array-vs-native.ts index 3760b7f3a..8281e459c 100644 --- a/src/perf-tests/chunked-array-vs-native.ts +++ b/src/perf-tests/chunked-array-vs-native.ts @@ -1,5 +1,5 @@ import * as B from 'benchmark' -import ChunkedArray from '../utils/chunked-array' +import ChunkedArray from '../common/collections/chunked-array' function testNative(size: number) { const xs = new Array(size); diff --git a/src/perf-tests/sets.ts b/src/perf-tests/sets.ts index f7f35b74c..eabae6dc0 100644 --- a/src/perf-tests/sets.ts +++ b/src/perf-tests/sets.ts @@ -1,7 +1,7 @@ import * as B from 'benchmark' -import IntTuple from '../structure/collections/int-tuple' -import OrdSet from '../structure/collections/ordered-set' -import MSet from '../structure/collections/multi-set' +import IntTuple from '../common/collections/int-tuple' +import OrdSet from '../common/collections/ordered-set' +import AtomSet from '../mol-data/atom-set' namespace Iteration { const U = 1000, V = 2500; @@ -16,7 +16,7 @@ namespace Iteration { } sets[i * i] = OrdSet.ofSortedArray(set); } - const ms = MSet.create(sets); + const ms = AtomSet.create(sets); export function native() { let s = 0; @@ -26,22 +26,22 @@ namespace Iteration { export function iterators() { let s = 0; - const it = MSet.values(ms); + const it = AtomSet.values(ms); for (let v = it.move(); !it.done; v = it.move()) s += v.snd; return s; } export function elementAt() { let s = 0; - for (let i = 0, _i = MSet.size(ms); i < _i; i++) s += IntTuple.snd(MSet.getAt(ms, i)); + for (let i = 0, _i = AtomSet.size(ms); i < _i; i++) s += IntTuple.snd(AtomSet.getAt(ms, i)); return s; } export function manual() { let s = 0; - const keys = MSet.keys(ms); + const keys = AtomSet.keys(ms); for (let i = 0, _i = OrdSet.size(keys); i < _i; i++) { - const set = MSet.getByKey(ms, OrdSet.getAt(keys, i)); + const set = AtomSet.getByKey(ms, OrdSet.getAt(keys, i)); for (let j = 0, _j = OrdSet.size(set); j < _j; j++) { s += OrdSet.getAt(set, j); } @@ -51,8 +51,8 @@ namespace Iteration { export function manual1() { let s = 0; - for (let i = 0, _i = MSet.keyCount(ms); i < _i; i++) { - const set = MSet.getByIndex(ms, i); + for (let i = 0, _i = AtomSet.keyCount(ms); i < _i; i++) { + const set = AtomSet.getByIndex(ms, i); for (let j = 0, _j = OrdSet.size(set); j < _j; j++) { s += OrdSet.getAt(set, j); } diff --git a/src/perf-tests/sort.ts b/src/perf-tests/sort.ts index b5449793e..f5d2a3f68 100644 --- a/src/perf-tests/sort.ts +++ b/src/perf-tests/sort.ts @@ -1,5 +1,5 @@ import * as B from 'benchmark' -import * as Sort from '../structure/collections/sort' +import * as Sort from '../common/collections/sort' function shuffle(a: number[]) { for (let i = a.length - 1; i > 0; i--) { diff --git a/src/script.ts b/src/script.ts index c10a3e1bd..b74654628 100644 --- a/src/script.ts +++ b/src/script.ts @@ -12,11 +12,13 @@ require('util.promisify').shim(); const readFileAsync = util.promisify(fs.readFile); const writeFileAsync = util.promisify(fs.writeFile); -import Gro from './reader/gro/parser' -import CIF from './reader/cif/index' +import Gro from './mol-io/reader/gro/parser' +import CIF from './mol-io/reader/cif/index' + +import Computation from './common/computation' // import { toTypedFrame as applySchema } from './reader/cif/schema' -import { generateSchema } from './reader/cif/schema/utils' +import { generateSchema } from './mol-io/reader/cif/schema/utils' const file = '1crn.gro' // const file = 'water.gro' @@ -173,7 +175,6 @@ export async function _dic() { _dic(); -import Computation from './utils/computation' const comp = Computation.create(async ctx => { for (let i = 0; i < 0; i++) { await new Promise(res => setTimeout(res, 500)); diff --git a/tsconfig.json b/tsconfig.json index be84a2ed2..750314b79 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "strictNullChecks": true, //"downlevelIteration": true, "lib": [ "es6", "dom" ], - "outDir": "build/js/src" + "outDir": "build/js/src", + "baseUrl": "src" }, - "include": [ "src/**/*" ] + "include": [ "**/*" ] } \ No newline at end of file -- GitLab