diff --git a/src/mol-base/collections/integer/_spec/interval.spec.ts b/src/mol-base/collections/integer/_spec/interval.spec.ts index cda22df8eaf9cde2c640ca6e2216b02dc1772dac..9aa97bdbd534c1a6c44111b39f2c7b3875be1a88 100644 --- a/src/mol-base/collections/integer/_spec/interval.spec.ts +++ b/src/mol-base/collections/integer/_spec/interval.spec.ts @@ -69,5 +69,8 @@ describe('interval', () => { test('predIndexInt', Interval.findPredecessorIndexInInterval(r05, 0, Interval.ofRange(2, 3)), 2); test('predIndexInt1', Interval.findPredecessorIndexInInterval(r05, 4, Interval.ofRange(2, 3)), 4); + test('predIndexInt2', Interval.findPredecessorIndex(Interval.ofRange(3, 10), 5), 2); + test('predIndexInt3', Interval.findPredecessorIndexInInterval(Interval.ofRange(3, 10), 5, Interval.ofRange(2, 6)), 2); + testI('findRange', Interval.findRange(r05, 2, 3), Interval.ofRange(2, 3)); }); \ No newline at end of file diff --git a/src/mol-base/collections/integer/_spec/segmentation.spec.ts b/src/mol-base/collections/integer/_spec/segmentation.spec.ts index 8732383fa97d9b242cac13dd23de64f6c365c3b9..6047b09c120c39712dbfa12e717b35795e6f4a41 100644 --- a/src/mol-base/collections/integer/_spec/segmentation.spec.ts +++ b/src/mol-base/collections/integer/_spec/segmentation.spec.ts @@ -11,7 +11,7 @@ import Segmentation from '../segmentation' describe('segments', () => { const data = OrderedSet.ofSortedArray([4, 9, 10, 11, 14, 15, 16]); const segs = Segmentation.create([0, 4, 10, 12, 13, 15, 25]); - + it('size', () => expect(Segmentation.count(segs)).toBe(6)); it('project', () => { @@ -50,47 +50,68 @@ describe('segments', () => { expect(count).toBe(4); }); - // it('iteration range', () => { - // const segs = Segmentation.create([0, 2, 4]); - // const dataRange = OrderedSet.ofBounds(0, 4); - - // const it = Segmentation.transientSegments(segs, dataRange); - - // const t = Object.create(null); - // let count = 0; - // while (it.hasNext) { - // count++; - // const s = it.move(); - // for (let j = s.start; j < s.end; j++) { - // const x = t[s.index]; - // const v = OrderedSet.getAt(dataRange, j); - // if (!x) t[s.index] = [v]; - // else x[x.length] = v; - // } - // } - // expect(count).toBe(2); - // expect(t).toEqual({ 0: [0, 1], 1: [2, 3] }); - // }); - - // it('iteration range 1', () => { - // const segs = Segmentation.create([0, 2, 4]); - // const dataRange = OrderedSet.ofBounds(0, 4); - - // const it = Segmentation.transientSegments(segs, dataRange, { index: 0, start: 2, end: 4 }); - - // const t = Object.create(null); - // let count = 0; - // while (it.hasNext) { - // count++; - // const s = it.move(); - // for (let j = s.start; j < s.end; j++) { - // const x = t[s.index]; - // const v = OrderedSet.getAt(dataRange, j); - // if (!x) t[s.index] = [v]; - // else x[x.length] = v; - // } - // } - // expect(count).toBe(1); - // expect(t).toEqual({ 1: [2, 3] }); - // }); + it('units', () => { + const data = OrderedSet.ofBounds(0, 4); + const segs = Segmentation.create([0, 1, 2, 3, 4]); + const it = Segmentation.transientSegments(segs, data, { index: 0, start: 2, end: 4 }); + + const t = Object.create(null); + let count = 0; + while (it.hasNext) { + count++; + const s = it.move(); + for (let j = s.start; j < s.end; j++) { + const x = t[s.index]; + const v = OrderedSet.getAt(data, j); + if (!x) t[s.index] = [v]; + else x[x.length] = v; + } + } + expect(t).toEqual({ 2: [2], 3: [3] }); + expect(count).toBe(2); + }); + + it('iteration range', () => { + const segs = Segmentation.create([0, 2, 4]); + const dataRange = OrderedSet.ofBounds(0, 4); + + const it = Segmentation.transientSegments(segs, dataRange); + + const t = Object.create(null); + let count = 0; + while (it.hasNext) { + count++; + const s = it.move(); + for (let j = s.start; j < s.end; j++) { + const x = t[s.index]; + const v = OrderedSet.getAt(dataRange, j); + if (!x) t[s.index] = [v]; + else x[x.length] = v; + } + } + expect(count).toBe(2); + expect(t).toEqual({ 0: [0, 1], 1: [2, 3] }); + }); + + it('iteration range 1', () => { + const segs = Segmentation.create([0, 2, 4]); + const dataRange = OrderedSet.ofBounds(0, 4); + + const it = Segmentation.transientSegments(segs, dataRange, { index: 0, start: 2, end: 4 }); + + const t = Object.create(null); + let count = 0; + while (it.hasNext) { + count++; + const s = it.move(); + for (let j = s.start; j < s.end; j++) { + const x = t[s.index]; + const v = OrderedSet.getAt(dataRange, j); + if (!x) t[s.index] = [v]; + else x[x.length] = v; + } + } + expect(count).toBe(1); + expect(t).toEqual({ 1: [2, 3] }); + }); }); diff --git a/src/mol-base/collections/integer/impl/interval.ts b/src/mol-base/collections/integer/impl/interval.ts index 00354c32edac05cfc6d65a8e4d971775059de110..3a265b8b266bdf81bd1cf841377c4140039770fb 100644 --- a/src/mol-base/collections/integer/impl/interval.ts +++ b/src/mol-base/collections/integer/impl/interval.ts @@ -43,11 +43,12 @@ export function findPredecessorIndex(int: Tuple, v: number) { } export function findPredecessorIndexInInterval(int: Tuple, v: number, bounds: Tuple) { - const bS = start(bounds) - if (v <= bS) return bS; + const bS = start(bounds); + const s = start(int); + if (v <= bS + s) return bS; const bE = end(bounds); - if (v >= bE) return bE; - return v - start(int); + if (v >= bE + s) return bE; + return v - s; } export function findRange(int: Tuple, min: number, max: number) { diff --git a/src/mol-base/collections/integer/impl/segmentation.ts b/src/mol-base/collections/integer/impl/segmentation.ts index 1da81db5d999b298122e8488d6e0f4425e80b425..f9b7d6f4230aca4c34c4f8f638620677d648a8ef 100644 --- a/src/mol-base/collections/integer/impl/segmentation.ts +++ b/src/mol-base/collections/integer/impl/segmentation.ts @@ -91,6 +91,7 @@ export class SegmentIterator implements Iterator<Segs.Segment> { const max = OrderedSet.getAt(this.set, sMax); this.segmentMin = this.getSegmentIndex(min); this.segmentMax = this.getSegmentIndex(max); + this.hasNext = this.segmentMax >= this.segmentMin && Interval.size(this.setRange) > 0; } diff --git a/src/mol-data/structure.ts b/src/mol-data/structure.ts new file mode 100644 index 0000000000000000000000000000000000000000..5542ea39939397d841b9449c0c4ce19352b722d9 --- /dev/null +++ b/src/mol-data/structure.ts @@ -0,0 +1,9 @@ +/** + * Copyright (c) 2017 molio contributors, licensed under MIT, See LICENSE file for more info. + * + * @author David Sehnal <david.sehnal@gmail.com> + */ + +export * from './structure/model' +export * from './structure/structure' +export * from './structure/query' \ No newline at end of file diff --git a/src/mol-data/structure/model.ts b/src/mol-data/structure/model.ts index 70d5c31f2380055c388c5a0c07b08d417d8a4f05..1fd76534768b57ae6fa2386a6befaa78d1ea32e2 100644 --- a/src/mol-data/structure/model.ts +++ b/src/mol-data/structure/model.ts @@ -5,7 +5,7 @@ */ import Model from './model/model' -import ModelDataFormat from './model/data-format' -import * as ModelConstants from './model/constants' +import * as Constants from './model/constants' +import Format from './model/format' -export { Model, ModelConstants, ModelDataFormat } \ No newline at end of file +export { Model, Constants, Format } \ No newline at end of file diff --git a/src/mol-data/structure/model/data-format.ts b/src/mol-data/structure/model/format.ts similarity index 53% rename from src/mol-data/structure/model/data-format.ts rename to src/mol-data/structure/model/format.ts index a12b0a5d08d4f16361cf325a14ffdb9f041e1d01..e1878bbdb8ded54aff9da4db4882fa1cebc02363 100644 --- a/src/mol-data/structure/model/data-format.ts +++ b/src/mol-data/structure/model/format.ts @@ -4,11 +4,13 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Database as mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif' - -export interface mmCIF { kind: 'mmCIF', data: mmCIF_Database } +import { mmCIF_Database } from 'mol-io/reader/cif/schema/mmcif' type Format = - | mmCIF + | Format.mmCIF + +namespace Format { + export interface mmCIF { kind: 'mmCIF', data: mmCIF_Database } +} export default Format \ No newline at end of file diff --git a/src/mol-data/structure/model/builders/mmcif.ts b/src/mol-data/structure/model/formats/mmcif.ts similarity index 89% rename from src/mol-data/structure/model/builders/mmcif.ts rename to src/mol-data/structure/model/formats/mmcif.ts index 6e38b03a3f821d026d7acd48ca2ff6d868121f16..5f6cf3c9c6ebace88b2b45f2600cfa38889a6963 100644 --- a/src/mol-data/structure/model/builders/mmcif.ts +++ b/src/mol-data/structure/model/formats/mmcif.ts @@ -4,16 +4,18 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { mmCIF } from '../data-format' +import Format from '../format' import Model from '../model' +import * as Hierarchy from '../properties/hierarchy' +import Conformation from '../properties/conformation' import { Column, Table } from 'mol-base/collections/database' import { Interval, Segmentation } from 'mol-base/collections/integer' import { newUUID } from 'mol-base/utils/uuid' -import * as Hierarchy from '../properties/hierarchy' -import Conformation from '../properties/conformation' import findHierarchyKeys from '../utils/hierarchy-keys' -function findModelBounds({ data }: mmCIF, startIndex: number) { +import mmCIF_Format = Format.mmCIF + +function findModelBounds({ data }: mmCIF_Format, startIndex: number) { const num = data.atom_site.pdbx_PDB_model_num; const atomCount = num.rowCount; if (!num.isDefined) return Interval.ofBounds(startIndex, atomCount); @@ -22,7 +24,7 @@ function findModelBounds({ data }: mmCIF, startIndex: number) { return Interval.ofBounds(startIndex, endIndex); } -function findHierarchyOffsets({ data }: mmCIF, bounds: Interval) { +function findHierarchyOffsets({ data }: mmCIF_Format, bounds: Interval) { const start = Interval.start(bounds), end = Interval.end(bounds); const residues = [start], chains = [start]; @@ -37,12 +39,11 @@ function findHierarchyOffsets({ data }: mmCIF, bounds: Interval) { if (newResidue) residues[residues.length] = i; if (newChain) chains[chains.length] = i; - } - + } return { residues, chains }; } -function createHierarchyData({ data }: mmCIF, bounds: Interval, offsets: { residues: ArrayLike<number>, chains: ArrayLike<number> }): Hierarchy.Data { +function createHierarchyData({ data }: mmCIF_Format, bounds: Interval, offsets: { residues: ArrayLike<number>, chains: ArrayLike<number> }): Hierarchy.Data { const { atom_site } = data; const start = Interval.start(bounds), end = Interval.end(bounds); const atoms = Table.ofColumns(Hierarchy.AtomsSchema, { @@ -60,7 +61,7 @@ function createHierarchyData({ data }: mmCIF, bounds: Interval, offsets: { resid return { atoms, residues, chains, entities: data.entity }; } -function getConformation({ data }: mmCIF, bounds: Interval): Conformation { +function getConformation({ data }: mmCIF_Format, bounds: Interval): Conformation { const start = Interval.start(bounds), end = Interval.end(bounds); const { atom_site } = data; return { @@ -81,7 +82,7 @@ function isHierarchyDataEqual(a: Hierarchy.Hierarchy, b: Hierarchy.Data) { && Table.areEqual(a.atoms as Table<Hierarchy.AtomsSchema>, b.atoms as Table<Hierarchy.AtomsSchema>) } -function createModel(format: mmCIF, bounds: Interval, previous?: Model): Model { +function createModel(format: mmCIF_Format, bounds: Interval, previous?: Model): Model { const hierarchyOffsets = findHierarchyOffsets(format, bounds); const hierarchyData = createHierarchyData(format, bounds, hierarchyOffsets); @@ -97,7 +98,6 @@ function createModel(format: mmCIF, bounds: Interval, previous?: Model): Model { chainSegments: Segmentation.ofOffsets(hierarchyOffsets.chains, bounds), } const hierarchyKeys = findHierarchyKeys(hierarchyData, hierarchySegments); - return { id: newUUID(), sourceData: format, @@ -108,7 +108,7 @@ function createModel(format: mmCIF, bounds: Interval, previous?: Model): Model { }; } -function buildModels(format: mmCIF): ReadonlyArray<Model> { +function buildModels(format: mmCIF_Format): ReadonlyArray<Model> { const models: Model[] = []; const atomCount = format.data.atom_site._rowCount; diff --git a/src/mol-data/structure/model/model.ts b/src/mol-data/structure/model/model.ts index 4eef29c376e5abbae13be178c3a3d0760219906f..9cdfd3787284c68adbc86da838b55debbbec2bfd 100644 --- a/src/mol-data/structure/model/model.ts +++ b/src/mol-data/structure/model/model.ts @@ -4,12 +4,12 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import DataFormat from './data-format' +import UUID from 'mol-base/utils/uuid' +import Format from './format' import HierarchyProperties from './properties/hierarchy' import ConformationProperties from './properties/conformation' -import UUID from 'mol-base/utils/uuid' +import from_mmCIF from './formats/mmcif' -import buildMmCIF from './builders/mmcif' /** * Interface to the "source data" of the molecule. @@ -21,7 +21,7 @@ interface Model extends Readonly<{ modelNum: number, - sourceData: DataFormat, + sourceData: Format, hierarchy: HierarchyProperties, conformation: ConformationProperties, @@ -30,9 +30,9 @@ interface Model extends Readonly<{ }> { } namespace Model { - export function create(format: DataFormat) { + export function create(format: Format) { switch (format.kind) { - case 'mmCIF': return buildMmCIF(format); + case 'mmCIF': return from_mmCIF(format); } } } diff --git a/src/mol-data/structure/model/properties/hierarchy.ts b/src/mol-data/structure/model/properties/hierarchy.ts index 9f6c0d81e3b7a065bdcf4ff49112a9a4149bb3a3..365c3943a09743ee4ecb4c4f2a27bb4a0391290b 100644 --- a/src/mol-data/structure/model/properties/hierarchy.ts +++ b/src/mol-data/structure/model/properties/hierarchy.ts @@ -6,7 +6,7 @@ import { Column, Table } from 'mol-base/collections/database' import { Segmentation } from 'mol-base/collections/integer' -import { Schema as mmCIF } from 'mol-io/reader/cif/schema/mmcif' +import { mmCIF_Schema as mmCIF } from 'mol-io/reader/cif/schema/mmcif' const _esCache = Object.create(null); export interface ElementSymbol extends String { '@type': 'element-symbol' } diff --git a/src/mol-data/structure/query.ts b/src/mol-data/structure/query.ts index a228f7bb6f3a032c1a57f53e29a61307d9120ee5..4a8bf6150e5b28990211f94ea72ea9a5e1cb7559 100644 --- a/src/mol-data/structure/query.ts +++ b/src/mol-data/structure/query.ts @@ -9,4 +9,9 @@ import Query from './query/query' import * as generators from './query/generators' import * as props from './query/properties' -export { Selection, Query, generators, props } \ No newline at end of file +export const Queries = { + generators, + props +} + +export { Selection, Query } \ No newline at end of file diff --git a/src/mol-data/structure/query/generators.ts b/src/mol-data/structure/query/generators.ts index 0ea357af41ea38d9829b2f02f4d6a8a4be77a7f9..eb6cb540346d750af3826f70c31d76fe3d32078b 100644 --- a/src/mol-data/structure/query/generators.ts +++ b/src/mol-data/structure/query/generators.ts @@ -5,10 +5,9 @@ */ import Query from './query' -//import Selection from './selection' import * as P from './properties' import { AtomSet, Atom } from '../structure' -import { OrderedSet } from 'mol-base/collections/integer' +import { OrderedSet, Segmentation } from 'mol-base/collections/integer' export interface AtomGroupsSpec { entityTest: Atom.Predicate, @@ -62,16 +61,49 @@ function atomGroupsLinear(atomTest: Atom.Predicate): Query { function atomGroupsSegmented({ entityTest, chainTest, residueTest, atomTest }: AtomGroupsSpec): Query { return structure => { + const { atoms, units } = structure; + const unitIds = AtomSet.unitIds(atoms); + const l = Atom.Location(); + const builder = AtomSet.Builder(atoms); + for (let i = 0, _i = unitIds.length; i < _i; i++) { + const unitId = unitIds[i]; + const unit = units[unitId]; + l.unit = unit; + const set = AtomSet.unitGetByIndex(atoms, i); - throw 'nyi' + builder.beginUnit(); + const chainsIt = Segmentation.transientSegments(unit.hierarchy.chainSegments, set); + const residues = unit.hierarchy.residueSegments; + while (chainsIt.hasNext) { + const chainSegment = chainsIt.move(); + l.atom = OrderedSet.getAt(set, chainSegment.start); + // test entity and chain + if (!entityTest(l) || !chainTest(l)) continue; + + const residuesIt = Segmentation.transientSegments(residues, set, chainSegment); + while (residuesIt.hasNext) { + const residueSegment = residuesIt.move(); + l.atom = OrderedSet.getAt(set, residueSegment.start); + + // test residue + if (!residueTest(l)) continue; + + for (let j = residueSegment.start, _j = residueSegment.end; j < _j; j++) { + l.atom = OrderedSet.getAt(set, j); + if (atomTest(l)) builder.addToUnit(l.atom); + } + } + } + builder.commitUnit(unitId); + } + + return { units, atoms: builder.getSet() }; }; } function atomGroupsGrouped({ entityTest, chainTest, residueTest, atomTest, groupBy }: AtomGroupsSpec): Query { return structure => { - - throw 'nyi' }; } diff --git a/src/mol-data/structure/query/properties.ts b/src/mol-data/structure/query/properties.ts index 808cb4dbfdfc00b53c9d622bd06e6d698c87b522..18bf1d5cb4451ad4313b88da93e192da254d1951 100644 --- a/src/mol-data/structure/query/properties.ts +++ b/src/mol-data/structure/query/properties.ts @@ -17,7 +17,8 @@ export const atom = { } export const residue = { - auth_seq_id: Atom.property(l => l.unit.hierarchy.residues.auth_seq_id.value(l.unit.residueIndex[l.atom])) + auth_seq_id: Atom.property(l => l.unit.hierarchy.residues.auth_seq_id.value(l.unit.residueIndex[l.atom])), + auth_comp_id: Atom.property(l => l.unit.hierarchy.residues.auth_comp_id.value(l.unit.residueIndex[l.atom])) } export const chain = { diff --git a/src/mol-data/structure/structure/structure.ts b/src/mol-data/structure/structure/structure.ts index 4b2cf5daa305ede7c0e0abd76efd440ce76e713c..14c10d4c7d893893aa38998caf92f5a2426d7c58 100644 --- a/src/mol-data/structure/structure/structure.ts +++ b/src/mol-data/structure/structure/structure.ts @@ -4,7 +4,7 @@ * @author David Sehnal <david.sehnal@gmail.com> */ -import { Model } from '../model' +import { Model, Format } from '../model' import Unit from './unit' import Operator from './operator' import AtomSet from './atom/set' @@ -18,6 +18,11 @@ interface Structure extends Readonly<{ namespace Structure { export const Empty = { units: {}, atoms: AtomSet.Empty }; + export function ofData(format: Format) { + const models = Model.create(format); + return models.map(ofModel); + } + export function ofModel(model: Model): Structure { const chains = model.hierarchy.chainSegments; const builder = Builder(); diff --git a/src/mol-io/reader/cif.ts b/src/mol-io/reader/cif.ts index 8b22eec8c103d76da655d3605b3372f111ff70d5..1a57f99fe09e4860b1cbf8d75f64f7ddab5c4014 100644 --- a/src/mol-io/reader/cif.ts +++ b/src/mol-io/reader/cif.ts @@ -8,7 +8,7 @@ import parseText from './cif/text/parser' import parseBinary from './cif/binary/parser' import { Frame } from './cif/data-model' import { toDatabase } from './cif/schema' -import { Schema as mmCIF_Schema, Database as mmCIF_Database } from './cif/schema/mmcif' +import { mmCIF_Schema, mmCIF_Database } from './cif/schema/mmcif' export default { parseText, diff --git a/src/mol-io/reader/cif/schema/dic.ts b/src/mol-io/reader/cif/schema/dic.ts index fc6c0dd02a90772141bba8ef5a844c266f417a61..712a667f4e12b7c0b09860dbdd557ab6bf726444 100644 --- a/src/mol-io/reader/cif/schema/dic.ts +++ b/src/mol-io/reader/cif/schema/dic.ts @@ -60,7 +60,7 @@ const item_units_conversion = { // TODO save frame dic schema -export const Schema = { +export const CIFDictionary_Schema = { datablock, dictionary, dictionary_history, @@ -71,5 +71,5 @@ export const Schema = { item_units_conversion } -export type Schema = typeof Schema; -export interface Database extends Database.Tables<typeof Schema> { } \ No newline at end of file +export type CIFDictionary_Schema = typeof CIFDictionary_Schema; +export interface CIFDictionary_Database extends Database.Tables<CIFDictionary_Schema> { } \ No newline at end of file diff --git a/src/mol-io/reader/cif/schema/mmcif.ts b/src/mol-io/reader/cif/schema/mmcif.ts index 9682fef280ee359fa0ef22f0122ec81912ec8795..9f478aa5c0aa07b1c5548b34f1523ed0d807a040 100644 --- a/src/mol-io/reader/cif/schema/mmcif.ts +++ b/src/mol-io/reader/cif/schema/mmcif.ts @@ -228,7 +228,7 @@ const atom_site = { pdbx_PDB_model_num: int } -export const Schema = { +export const mmCIF_Schema = { entry, entity, exptl, @@ -246,5 +246,5 @@ export const Schema = { atom_site }; -export type Schema = typeof Schema; -export interface Database extends Database<typeof Schema> { } \ No newline at end of file +export type mmCIF_Schema = typeof mmCIF_Schema; +export interface mmCIF_Database extends Database<mmCIF_Schema> { } \ No newline at end of file diff --git a/src/perf-tests/structure.ts b/src/perf-tests/structure.ts index 23bd4e97a79049230c7c0e17d3d9da30127a3a79..34d5126ac3b557a8b408f68a60910c33bc92e657 100644 --- a/src/perf-tests/structure.ts +++ b/src/perf-tests/structure.ts @@ -10,9 +10,7 @@ import * as util from 'util' import * as fs from 'fs' import CIF from 'mol-io/reader/cif' -import { Model } from 'mol-data/structure/model' -import { Structure, Atom, AtomSet } from 'mol-data/structure/structure' -import * as Q from 'mol-data/structure/query' +import { Structure, Model, Queries as Q, Atom, AtomSet } from 'mol-data/structure' import { OrderedSet as OrdSet, Segmentation } from 'mol-base/collections/integer' require('util.promisify').shim(); @@ -92,6 +90,7 @@ export namespace PropertyAccess { let s = 0; + let vA = 0, cC = 0, rC = 0; for (let i = 0, _i = unitIds.length; i < _i; i++) { const unit = units[unitIds[i]]; l.unit = unit; @@ -100,18 +99,26 @@ export namespace PropertyAccess { const chainsIt = Segmentation.transientSegments(unit.hierarchy.chainSegments, set); const residues = unit.hierarchy.residueSegments; while (chainsIt.hasNext) { + cC++; + const chainSegment = chainsIt.move(); const residuesIt = Segmentation.transientSegments(residues, set, chainSegment); while (residuesIt.hasNext) { + rC++; const residueSegment = residuesIt.move(); + // l.atom = OrdSet.getAt(set, residueSegment.start); + // console.log(unit.hierarchy.residues.auth_comp_id.value(unit.residueIndex[l.atom]), l.atom, OrdSet.getAt(set, residueSegment.end)) for (let j = residueSegment.start, _j = residueSegment.end; j < _j; j++) { l.atom = OrdSet.getAt(set, j); + vA++; s += p(l); } } } } + console.log('seg atom count', vA, cC, rC); + return s; } @@ -228,8 +235,8 @@ export namespace PropertyAccess { // } export async function run() { - const { structures, models } = await readCIF('./examples/1cbs_full.bcif'); - //const { structures, models } = await readCIF('e:/test/quick/1jj2_full.bcif'); + //const { structures, models } = await readCIF('./examples/1cbs_full.bcif'); + const { structures, models } = await readCIF('e:/test/quick/1jj2_full.bcif'); //const { structures, models } = await readCIF('e:/test/quick/3j3q_updated.cif'); console.log('parsed'); @@ -237,6 +244,7 @@ export namespace PropertyAccess { console.log(baseline(models[0])); console.log(sumProperty(structures[0], l => l.unit.model.conformation.atomId.value(l.atom))); console.log(sumPropertySegmented(structures[0], l => l.unit.model.conformation.atomId.value(l.atom))); + //console.log(sumPropertySegmentedMutable(structures[0], l => l.unit.model.conformation.atomId.value(l.atom))); console.log(sumPropertyAtomSetIt(structures[0], l => l.unit.model.conformation.atomId.value(l.atom))); //console.log(sumProperty(structures[0], Property.cachedAtomColumn(m => m.conformation.atomId))); @@ -245,25 +253,33 @@ export namespace PropertyAccess { //const authSeqId = Atom.property(l => l.unit.hierarchy.residues.auth_seq_id.value(l.unit.residueIndex[l.atom])); - const auth_seq_id = Q.props.residue.auth_seq_id; - const q = Q.generators.atomGroups({ atomTest: l => auth_seq_id(l) < 3 }); - const qr = q(structures[0]); - console.log(qr); + //const auth_seq_id = Q.props.residue.auth_seq_id; + const auth_comp_id = Q.props.residue.auth_comp_id; + //const auth_asym_id = Q.props.chain.auth_asym_id; + //const set = new Set(['A', 'B', 'C', 'D']); + //const q = Q.generators.atomGroups({ atomTest: l => auth_seq_id(l) < 3 }); + const q = Q.generators.atomGroups({ atomTest: l => auth_comp_id(l) === 'ALA' }); + const q1 = Q.generators.atomGroups({ residueTest: l => auth_comp_id(l) === 'ALA' }); + //const q2 = Q.generators.atomGroups({ chainTest: l => set.has(auth_asym_id(l)), residueTest: l => auth_comp_id(l) === 'ALA' }); + q(structures[0]); + q1(structures[0]); + //console.log(q1(structures[0])); //const col = models[0].conformation.atomId.value; const suite = new B.Suite(); suite + .add('test q', () => q1(structures[0])) //.add('test int', () => sumProperty(structures[0], l => col(l.atom))) - .add('sum residue', () => sumPropertyResidue(structures[0], l => l.unit.hierarchy.residues.auth_seq_id.value(l.unit.residueIndex[l.atom]))) + // .add('sum residue', () => sumPropertyResidue(structures[0], l => l.unit.hierarchy.residues.auth_seq_id.value(l.unit.residueIndex[l.atom]))) - .add('baseline', () => baseline(models[0])) - .add('direct', () => sumDirect(structures[0])) + // .add('baseline', () => baseline(models[0])) + // .add('direct', () => sumDirect(structures[0])) //.add('normal int', () => sumProperty(structures[0], l => l.unit.model.conformation.atomId.value(l.atom))) //.add('atom set it int', () => sumPropertyAtomSetIt(structures[0], l => l.unit.conformation.atomId.value(l.atom))) // .add('segmented faster int', () => sumPropertySegmented(structures[0], l => l.unit.conformation.atomId.value(l.atom))) // .add('faster int', () => sumProperty(structures[0], l => l.unit.conformation.atomId.value(l.atom))) - .add('segmented faster _x', () => sumPropertySegmented(structures[0], l => l.unit.conformation.__x[l.atom])) - .add('faster _x', () => sumProperty(structures[0], l => l.unit.conformation.__x[l.atom] + l.unit.conformation.__y[l.atom] + l.unit.conformation.__z[l.atom])) + //.add('segmented faster _x', () => sumPropertySegmented(structures[0], l => l.unit.conformation.__x[l.atom])) + //.add('faster _x', () => sumProperty(structures[0], l => l.unit.conformation.__x[l.atom] + l.unit.conformation.__y[l.atom] + l.unit.conformation.__z[l.atom])) //.add('segmented mut faster int', () => sumPropertySegmentedMutable(structures[0], l => l.unit.conformation.atomId.value(l.atom))) //.add('normal shortcut int', () => sumProperty(structures[0], l => l.conformation.atomId.value(l.atom))) //.add('cached int', () => sumProperty(structures[0], Property.cachedAtomColumn(m => m.conformation.atomId))) diff --git a/src/script.ts b/src/script.ts index 55a43f4b352d9bf37ddd6b140518443eca89c051..8207880be1ce4cd3bcea5794b6aca404a0c59a03 100644 --- a/src/script.ts +++ b/src/script.ts @@ -17,7 +17,7 @@ import CIF from 'mol-io/reader/cif' import Computation from 'mol-base/computation' -import buildModels from 'mol-data/structure/model/builders/mmcif' +import { Model } from 'mol-data/structure/model' // import { toTypedFrame as applySchema } from './reader/cif/schema' import { generateSchema } from 'mol-io/reader/cif/schema/utils' @@ -115,11 +115,11 @@ async function runCIF(input: string | Uint8Array) { console.log(mmcif.pdbx_struct_oper_list.matrix.value(0)); console.time('createModels'); - const models = buildModels({ kind: 'mmCIF', data: mmcif }); + const models = Model.create({ kind: 'mmCIF', data: mmcif }); console.timeEnd('createModels'); for (let i = 0; i < models.length; i++) { - console.log(models[i].id); + console.log(models[i].id, models[i].conformation.id); } // console.log(models[0].hierarchy.isMonotonous);