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

guess cif variants (to seperate mmcif and dscif)

parent c8821fb1
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition'; ...@@ -13,6 +13,7 @@ import { ParamDefinition as PD } from 'mol-util/param-definition';
import { Ccp4Provider, Dsn6Provider, DscifProvider } from './volume'; import { Ccp4Provider, Dsn6Provider, DscifProvider } from './volume';
import { StateTransforms } from '../transforms'; import { StateTransforms } from '../transforms';
import { MmcifProvider, PdbProvider, GroProvider } from './structure'; import { MmcifProvider, PdbProvider, GroProvider } from './structure';
import msgpackDecode from 'mol-io/common/msgpack/decode'
export class DataFormatRegistry<D extends PluginStateObject.Data.Binary | PluginStateObject.Data.String> { export class DataFormatRegistry<D extends PluginStateObject.Data.Binary | PluginStateObject.Data.String> {
private _list: { name: string, provider: DataFormatProvider<D> }[] = [] private _list: { name: string, provider: DataFormatProvider<D> }[] = []
...@@ -140,3 +141,17 @@ export const OpenFile = StateAction.build({ ...@@ -140,3 +141,17 @@ export const OpenFile = StateAction.build({
// need to await the 2nd update the so that the enclosing Task finishes after the update is done. // need to await the 2nd update the so that the enclosing Task finishes after the update is done.
await provider.getDefaultBuilder(ctx, b, state).runInContext(taskCtx) await provider.getDefaultBuilder(ctx, b, state).runInContext(taskCtx)
})); }));
//
type cifVariants = 'dscif' | -1
export function guessCifVariant(info: FileInfo, data: Uint8Array | string): cifVariants {
if (info.ext === 'bcif') {
try {
if (msgpackDecode(data as Uint8Array).encoder.startsWith('VolumeServer')) return 'dscif'
} catch { }
} else if (info.ext === 'cif') {
if ((data as string).startsWith('data_SERVER\n#\n_density_server_result')) return 'dscif'
}
return -1
}
\ No newline at end of file
...@@ -13,7 +13,7 @@ import { StateTransforms } from '../transforms'; ...@@ -13,7 +13,7 @@ import { StateTransforms } from '../transforms';
import { Download } from '../transforms/data'; import { Download } from '../transforms/data';
import { StructureRepresentation3DHelpers } from '../transforms/representation'; import { StructureRepresentation3DHelpers } from '../transforms/representation';
import { CustomModelProperties, StructureSelection } from '../transforms/model'; import { CustomModelProperties, StructureSelection } from '../transforms/model';
import { DataFormatProvider } from './data-format'; import { DataFormatProvider, guessCifVariant } from './data-format';
import { FileInfo } from 'mol-util/file-info'; import { FileInfo } from 'mol-util/file-info';
import { Task } from 'mol-task'; import { Task } from 'mol-task';
import { StructureElement } from 'mol-model/structure'; import { StructureElement } from 'mol-model/structure';
...@@ -24,7 +24,10 @@ export const MmcifProvider: DataFormatProvider<any> = { ...@@ -24,7 +24,10 @@ export const MmcifProvider: DataFormatProvider<any> = {
stringExtensions: ['cif', 'mmcif', 'mcif'], stringExtensions: ['cif', 'mmcif', 'mcif'],
binaryExtensions: ['bcif'], binaryExtensions: ['bcif'],
isApplicable: (info: FileInfo, data: Uint8Array | string) => { isApplicable: (info: FileInfo, data: Uint8Array | string) => {
return info.ext === 'cif' || info.ext === 'mmcif' || info.ext === 'mcif' || info.ext === 'bcif' if (info.ext === 'mmcif' || info.ext === 'mcif') return true
// assume cif/bcif files that are not DensityServer CIF are mmCIF
if (info.ext === 'cif' || info.ext === 'bcif') return guessCifVariant(info, data) !== 'dscif'
return false
}, },
getDefaultBuilder: (ctx: PluginContext, data: StateBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, state: State) => { getDefaultBuilder: (ctx: PluginContext, data: StateBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, state: State) => {
return Task.create('mmCIF default builder', async taskCtx => { return Task.create('mmCIF default builder', async taskCtx => {
......
...@@ -16,7 +16,7 @@ import { PluginStateObject } from '../objects'; ...@@ -16,7 +16,7 @@ import { PluginStateObject } from '../objects';
import { StateTransforms } from '../transforms'; import { StateTransforms } from '../transforms';
import { Download } from '../transforms/data'; import { Download } from '../transforms/data';
import { VolumeRepresentation3DHelpers } from '../transforms/representation'; import { VolumeRepresentation3DHelpers } from '../transforms/representation';
import { DataFormatProvider } from './data-format'; import { DataFormatProvider, guessCifVariant } from './data-format';
export const Ccp4Provider: DataFormatProvider<any> = { export const Ccp4Provider: DataFormatProvider<any> = {
label: 'CCP4/MRC/BRIX', label: 'CCP4/MRC/BRIX',
...@@ -59,10 +59,10 @@ export const DscifProvider: DataFormatProvider<any> = { ...@@ -59,10 +59,10 @@ export const DscifProvider: DataFormatProvider<any> = {
description: 'DensityServer CIF', description: 'DensityServer CIF',
stringExtensions: ['cif'], stringExtensions: ['cif'],
binaryExtensions: ['bcif'], binaryExtensions: ['bcif'],
isApplicable: (info: FileInfo, data: Uint8Array) => { isApplicable: (info: FileInfo, data: Uint8Array | string) => {
return info.ext === 'cif' || info.ext === 'bcif' return guessCifVariant(info, data) === 'dscif' ? true : false
}, },
getDefaultBuilder: (ctx: PluginContext, data: StateBuilder.To<PluginStateObject.Data.Binary>, state: State) => { getDefaultBuilder: (ctx: PluginContext, data: StateBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, state: State) => {
return Task.create('DensityServer CIF default builder', async taskCtx => { return Task.create('DensityServer CIF default builder', async taskCtx => {
const cifBuilder = data.apply(StateTransforms.Data.ParseCif) const cifBuilder = data.apply(StateTransforms.Data.ParseCif)
const cifStateObject = await state.updateTree(cifBuilder).runInContext(taskCtx) const cifStateObject = await state.updateTree(cifBuilder).runInContext(taskCtx)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment