diff --git a/src/reader/cif/schema/utils.ts b/src/reader/cif/schema/utils.ts index cf52129c0dde8f9369f7281b546edfefa8a27c29..94d68bb2c7b464432cca2c374f2655f2e8fe2df7 100644 --- a/src/reader/cif/schema/utils.ts +++ b/src/reader/cif/schema/utils.ts @@ -1,6 +1,6 @@ // import dic from './dic' -import { Field/*, Category*/ } from '../schema' +import { Field, Block, Category } from '../schema' import * as Data from '../data-model' const pooledStr = Field.pooledStr() @@ -87,28 +87,28 @@ function getField ( category: string, field: string, d: Data.SafeFrame, ctx: Saf } } -function getEnums (d: Data.SafeFrame, ctx: SafeFrameData): string[]|undefined { - const value = getField('_item_enumeration', 'value', d, ctx) - if (value) { - const enums: string[] = [] - for (let i = 0; i < value.rowCount; ++i) { - enums.push(value.str(i)) - // console.log(value.str(i)) - } - return enums - } else { - // console.log(`item_enumeration.value not found for '${d.header}'`) - } -} +// function getEnums (d: Data.SafeFrame, ctx: SafeFrameData): string[]|undefined { +// const value = getField('_item_enumeration', 'value', d, ctx) +// if (value) { +// const enums: string[] = [] +// for (let i = 0; i < value.rowCount; ++i) { +// enums.push(value.str(i)) +// // console.log(value.str(i)) +// } +// return enums +// } else { +// // console.log(`item_enumeration.value not found for '${d.header}'`) +// } +// } function getCode (d: Data.SafeFrame, ctx: SafeFrameData): string|undefined { const code = getField('_item_type', 'code', d, ctx) if (code) { let c = code.str(0) - if (c === 'ucode') { - const enums = getEnums(d, ctx) - if (enums) c += `: ${enums.join('|')}` - } + // if (c === 'ucode') { + // const enums = getEnums(d, ctx) + // if (enums) c += `: ${enums.join('|')}` + // } return c } else { console.log(`item_type.code not found for '${d.header}'`) @@ -116,8 +116,7 @@ function getCode (d: Data.SafeFrame, ctx: SafeFrameData): string|undefined { } export function getSchema (dic: Data.Block) { // todo Block needs to be specialized with safe frames as well - // const schema: { [category: string]: Category.Schema } = {} - const schema: { [category: string]: { [k: string]: string } } = {} + const schema: Block.Schema = {} // { [category: string]: Category.Schema } = {} const categories: SafeFrameCategories = {} const links: SafeFrameLinks = {} @@ -143,7 +142,7 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special Object.keys(categories).forEach(fullName => { const d = categories[fullName] - const categoryName = d.header.substring(0, d.header.indexOf('.')) + const categoryName = d.header.substring(1, d.header.indexOf('.')) const itemName = d.header.substring(d.header.indexOf('.') + 1) let fields if (categoryName in schema) { @@ -155,11 +154,11 @@ export function getSchema (dic: Data.Block) { // todo Block needs to be special const code = getCode(d, { categories, links }) if (code) { - fields[itemName] = code // getFieldType(code) + fields[itemName] = getFieldType(code) } else { console.log(`could not determine code for '${d.header}'`) } }) - return schema + return schema as Block.Instance<any> } diff --git a/src/script.ts b/src/script.ts index 07040421f2f4556d4e65b6d1bbb732743dc1af60..4f5615a1225f9a77ac08b37cb9e05e8c35f85840 100644 --- a/src/script.ts +++ b/src/script.ts @@ -14,6 +14,7 @@ const readFileAsync = util.promisify(fs.readFile); import Gro from './reader/gro/parser' import CIF from './reader/cif/index' +import { apply as applySchema } from './reader/cif/schema' import { getSchema } from './reader/cif/schema/utils' const file = '1crn.gro' @@ -107,11 +108,22 @@ async function runCIF(input: string | Uint8Array) { console.log(mmcif.atom_site.Cartn_x.value(0)); console.log(mmcif.entity.type.toArray()); console.log(mmcif.pdbx_struct_oper_list.matrix.value(0)); + + const schema = await _dic() + if (schema) { + const mmcif2 = applySchema(schema, data) + // console.log(util.inspect(mmcif2.atom_site, {showHidden: false, depth: 3})) + console.log(mmcif2.atom_site.Cartn_x.value(0)); + console.log(mmcif2.entity.type.toArray()); + // console.log(mmcif2.pdbx_struct_oper_list.matrix.value(0)); // TODO + } else { + console.log('error getting mmcif schema from dic') + } } export async function _cif() { let path = `./examples/1cbs_updated.cif`; - path = '../test/3j3q.cif' // lets have a relative path for big test files + // path = '../test/3j3q.cif' // lets have a relative path for big test files const input = await readFileAsync(path, 'utf8') console.log('------------------'); console.log('Text CIF:'); @@ -127,7 +139,7 @@ export async function _cif() { runCIF(input2); } -// _cif(); +_cif(); async function runDic(input: string | Uint8Array) { console.time('parseDic'); @@ -144,6 +156,8 @@ async function runDic(input: string | Uint8Array) { const schema = getSchema(parsed.result.blocks[0]) console.log(util.inspect(schema, {showHidden: false, depth: 3})) // console.log(util.inspect(Object.keys(schema).length, {showHidden: false, depth: 1})) + + return schema } export async function _dic() { @@ -151,10 +165,10 @@ export async function _dic() { const input = await readFileAsync(path, 'utf8') console.log('------------------'); console.log('Text DIC:'); - runDic(input); + return runDic(input); } -_dic(); +// _dic(); import Computation from './utils/computation' const comp = Computation.create(async ctx => {