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

added some mol-io helper methods

parent 2446334b
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
* Copyright (c) 2017 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 Database from './db/database'
......@@ -9,4 +10,6 @@ import Table from './db/table'
import Column from './db/column'
import * as ColumnHelpers from './db/column-helpers'
export { Database, Table, Column, ColumnHelpers }
\ No newline at end of file
type DatabaseCollection = { [name: string]: Database<Database.Schema> }
export { DatabaseCollection, Database, Table, Column, ColumnHelpers }
\ No newline at end of file
......@@ -13,6 +13,7 @@ import { mmCIF_Schema, mmCIF_Database } from './cif/schema/mmcif'
import { CCD_Schema, CCD_Database } from './cif/schema/ccd'
export default {
parse: (data: string|Uint8Array) => typeof data === 'string' ? parseText(data) : parseBinary(data),
parseText,
parseBinary,
toDatabase,
......
......@@ -2,14 +2,35 @@
* Copyright (c) 2017 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 { Database, DatabaseCollection } from 'mol-data/db'
import TextCIFEncoder from './cif/encoder/text'
import BinaryCIFEncoder from './cif/encoder/binary'
import { CategoryDefinition } from './cif/encoder'
export * from './cif/encoder'
export function create(params?: { binary?: boolean, encoderName?: string }) {
const { binary = false, encoderName = 'mol*' } = params || {};
return binary ? new BinaryCIFEncoder(encoderName) : new TextCIFEncoder();
}
type CIFEncoder = BinaryCIFEncoder<{}> | TextCIFEncoder<{}>
export function writeDatabase(encoder: CIFEncoder, name: string, database: Database<Database.Schema>) {
encoder.startDataBlock(name);
for (const table of database._tableNames) {
encoder.writeCategory(
CategoryDefinition.instanceProviderOfTable(table, database[table])
);
}
}
export function writeDatabaseCollection(encoder: CIFEncoder, collection: DatabaseCollection) {
for (const name of Object.keys(collection)) {
writeDatabase(encoder, name, collection[name])
}
}
\ No newline at end of file
......@@ -153,4 +153,15 @@ export namespace CategoryDefinition {
export function ofTable<S extends Table.Schema>(name: string, table: Table<S>): CategoryDefinition<number> {
return { name, fields: FieldDefinitions.ofSchema(table._schema) }
}
export function instanceProviderOfTable(name: string, table: Table<Table.Schema>): CategoryProvider {
return function (ctx: any) {
return {
data: table,
definition: ofTable(name, table),
keys: () => Iterator.Range(0, table._rowCount - 1),
rowCount: table._rowCount
};
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment