/** * Copyright (c) 2019-2022 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author Alexander Rose * @author David Sehnal */ import { decodeMsgPack } from '../../mol-io/common/msgpack/decode'; import { PluginContext } from '../../mol-plugin/context'; import { StateObjectRef } from '../../mol-state'; import { FileNameInfo } from '../../mol-util/file-info'; import { PluginStateObject } from '../objects'; export interface DataFormatProvider

{ label: string, description: string, category?: string, stringExtensions?: string[], binaryExtensions?: string[], isApplicable?(info: FileNameInfo, data: string | Uint8Array): boolean, parse(plugin: PluginContext, data: StateObjectRef, params?: P): Promise, visuals?(plugin: PluginContext, data: R): Promise | undefined } export function DataFormatProvider

(provider: P): P { return provider; } type cifVariants = 'dscif' | 'segcif' | 'coreCif' | -1 export function guessCifVariant(info: FileNameInfo, data: Uint8Array | string): cifVariants { if (info.ext === 'bcif') { try { // TODO: find a way to run msgpackDecode only once // now it is run twice, here and during file parsing const { encoder } = decodeMsgPack(data as Uint8Array); if (encoder.startsWith('VolumeServer')) return 'dscif'; // TODO: assumes volseg-volume-server only serves segments if (encoder.startsWith('volseg-volume-server')) return 'segcif'; } catch (e) { console.error(e); } } else if (info.ext === 'cif') { const str = data as string; if (str.startsWith('data_SERVER\n#\n_density_server_result')) return 'dscif'; if (str.startsWith('data_SERVER\n#\ndata_SEGMENTATION_DATA')) return 'segcif'; if (str.includes('atom_site_fract_x') || str.includes('atom_site.fract_x')) return 'coreCif'; } return -1; }