Browse Source

CIF writer tweaks

David Sehnal 7 years ago
parent
commit
09fe6032da

+ 1 - 2
src/apps/domain-annotation-server/utils.ts

@@ -20,8 +20,7 @@ function ofSchema(schema: Table.Schema) {
     const fields: Encoder.FieldDefinition[] = [];
     for (const k of Object.keys(schema)) {
         const t = schema[k];
-        // TODO: matrix/vector/support
-        const type = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
+        const type: any = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
         fields.push({ name: k, type, value: columnValue(k), valueKind: columnValueKind(k) })
     }
     return fields;

+ 1 - 1
src/mol-data/structure/export/mmcif.ts

@@ -49,7 +49,7 @@ function ofSchema(schema: Table.Schema) {
     for (const k of Object.keys(schema)) {
         const t = schema[k];
         // TODO: matrix/vector/support
-        const type = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
+        const type: any = t.kind === 'str' ? Encoder.FieldType.Str : t.kind === 'int' ? Encoder.FieldType.Int : Encoder.FieldType.Float;
         fields.push({ name: k, type, value: columnValue(k), valueKind: columnValueKind(k) })
     }
     return fields;

+ 7 - 6
src/mol-io/writer/cif/encoder.ts

@@ -13,17 +13,18 @@ export const enum FieldType {
     Str, Int, Float
 }
 
-export interface FieldDefinition<Key = any, Data = any> {
+export interface FieldDefinitionBase<Key, Data> {
     name: string,
-    type: FieldType,
-    value(key: Key, data: Data): string | number,
-    valueKind?: (key: Key, data: Data) => Column.ValueKind
-
-    /** determine whether to include this field base on the context */
+    valueKind?: (key: Key, data: Data) => Column.ValueKind,
     // TODO:
     // shouldInclude?: (data: Data) => boolean
 }
 
+export type FieldDefinition<Key = any, Data = any> =
+    | FieldDefinitionBase<Key, Data> & { type: FieldType.Str, value(key: Key, data: Data): string }
+    | FieldDefinitionBase<Key, Data> & { type: FieldType.Int, value(key: Key, data: Data): number }
+    | FieldDefinitionBase<Key, Data> & { type: FieldType.Float, value(key: Key, data: Data): number }
+
 export interface FieldFormat {
     // TODO
     // textDecimalPlaces: number,

+ 1 - 1
src/mol-io/writer/cif/encoder/text.ts

@@ -79,7 +79,7 @@ function writeValue(builder: StringBuilder, data: any, key: any, f: Enc.FieldDef
         } else if (t === Enc.FieldType.Int) {
             writeInteger(builder, val as number);
         } else {
-            writeFloat(builder, val as number, 1000);
+            writeFloat(builder, val as number, 1000000);
         }
     }
     return false;