Skip to content
Snippets Groups Projects
Commit 4f70aa55 authored by David Sehnal's avatar David Sehnal
Browse files

nicer CIF encoder API

parent 397961af
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,7 @@
import Iterator from 'mol-base/collections/iterator'
import CIF, { Category } from 'mol-io/reader/cif'
import TextCIFEncoder from 'mol-io/writer/cif/encoder/text'
import BinaryCIFEncoder from 'mol-io/writer/cif/encoder/binary'
import * as Encoder from 'mol-io/writer/cif/encoder'
import * as Encoder from 'mol-io/writer/cif'
import * as fs from 'fs'
import classify from './field-classifier'
......@@ -42,7 +40,7 @@ function getCategoryInstanceProvider(cat: Category): Encoder.CategoryProvider {
export default async function convert(path: string, asText = false) {
const cif = await getCIF(path);
const encoder = asText ? new TextCIFEncoder() : new BinaryCIFEncoder('mol* cif2bcif');
const encoder = Encoder.create({ binary: !asText, encoderName: 'mol* cif2bcif' });
for (const b of cif.blocks) {
encoder.startDataBlock(b.header);
for (const c of b.categoryNames) {
......
......@@ -6,10 +6,8 @@
import { Column, Table } from 'mol-base/collections/database'
import Iterator from 'mol-base/collections/iterator'
import * as Encoder from 'mol-io/writer/cif/encoder'
import * as Encoder from 'mol-io/writer/cif'
//import { mmCIF_Schema } from 'mol-io/reader/cif/schema/mmcif'
import TextCIFEncoder from 'mol-io/writer/cif/encoder/text'
import BinaryCIFEncoder from 'mol-io/writer/cif/encoder/binary'
import { Structure, Atom, AtomSet } from '../structure'
import { Model } from '../model'
import P from '../query/properties'
......@@ -149,7 +147,7 @@ function to_mmCIF(name: string, structure: Structure, asBinary = false) {
const model = models[0];
const ctx: Context = { structure, model };
const w = asBinary ? new BinaryCIFEncoder('mol*') : new TextCIFEncoder();
const w = Encoder.create({ binary: asBinary });
w.startDataBlock(name);
w.writeCategory(entityProvider, [ctx]);
......
/**
* Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import TextCIFEncoder from './cif/encoder/text'
import BinaryCIFEncoder from './cif/encoder/binary'
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();
}
\ No newline at end of file
......@@ -5,8 +5,7 @@
*/
import Iterator from 'mol-base/collections/iterator'
import * as Enc from 'mol-io/writer/cif/encoder'
import CW from 'mol-io/writer/cif/encoder/text'
import * as Enc from 'mol-io/writer/cif'
const category1: Enc.CategoryDefinition<number> = {
name: 'test',
......@@ -51,7 +50,7 @@ function getInstance(ctx: { cat: Enc.CategoryDefinition<number>, rowCount: numbe
}
}
const w = new CW();
const w = Enc.create();
w.startDataBlock('test');
w.writeCategory(getInstance, [{ rowCount: 5, cat: category1 }]);
......
......@@ -237,6 +237,10 @@ export namespace PropertyAccess {
// return s;
// }
export function write(s: Structure) {
console.log(to_mmCIF('test', s));
}
export async function run() {
//const { structures, models } = await readCIF('./examples/1cbs_full.bcif');
const { structures, models } = await readCIF('e:/test/quick/3j3q_full.bcif');
......@@ -286,7 +290,7 @@ export namespace PropertyAccess {
chainTest: Q.pred.inSet(P.chain.auth_asym_id, ['A', 'B', 'C', 'D']),
residueTest: Q.pred.eq(P.residue.auth_comp_id, 'ALA')
});
const q0r = q(structures[0]);
q(structures[0]);
//console.log(to_mmCIF('test', Selection.union(q0r)));
console.time('q1')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment