|
@@ -5,102 +5,14 @@
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
* @author Alexander Rose <alexander.rose@weirdbyte.de>
|
|
*/
|
|
*/
|
|
|
|
|
|
-import { VolumeIsoValue } from '../../mol-model/volume';
|
|
|
|
import { PluginContext } from '../../mol-plugin/context';
|
|
import { PluginContext } from '../../mol-plugin/context';
|
|
-import { State, StateAction, StateBuilder, StateTransformer } from '../../mol-state';
|
|
|
|
|
|
+import { StateAction, StateTransformer } from '../../mol-state';
|
|
import { Task } from '../../mol-task';
|
|
import { Task } from '../../mol-task';
|
|
-import { ColorNames } from '../../mol-util/color/names';
|
|
|
|
-import { FileInfo, getFileInfo } from '../../mol-util/file-info';
|
|
|
|
|
|
+import { getFileInfo } from '../../mol-util/file-info';
|
|
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
|
import { ParamDefinition as PD } from '../../mol-util/param-definition';
|
|
import { PluginStateObject } from '../objects';
|
|
import { PluginStateObject } from '../objects';
|
|
-import { StateTransforms } from '../transforms';
|
|
|
|
import { Download } from '../transforms/data';
|
|
import { Download } from '../transforms/data';
|
|
-import { VolumeRepresentation3DHelpers } from '../transforms/representation';
|
|
|
|
-import { DataFormatProvider, guessCifVariant, DataFormatBuilderOptions } from './data-format';
|
|
|
|
-
|
|
|
|
-export const Ccp4Provider: DataFormatProvider<any> = {
|
|
|
|
- label: 'CCP4/MRC/BRIX',
|
|
|
|
- description: 'CCP4/MRC/BRIX',
|
|
|
|
- stringExtensions: [],
|
|
|
|
- binaryExtensions: ['ccp4', 'mrc', 'map'],
|
|
|
|
- isApplicable: (info: FileInfo, data: Uint8Array) => {
|
|
|
|
- return info.ext === 'ccp4' || info.ext === 'mrc' || info.ext === 'map'
|
|
|
|
- },
|
|
|
|
- getDefaultBuilder: (ctx: PluginContext, data, options: DataFormatBuilderOptions, state: State) => {
|
|
|
|
- return Task.create('CCP4/MRC/BRIX default builder', async taskCtx => {
|
|
|
|
- let tree: StateBuilder.To<any> = state.build().to(data)
|
|
|
|
- .apply(StateTransforms.Data.ParseCcp4, {}, { state: { isGhost: true } })
|
|
|
|
- .apply(StateTransforms.Volume.VolumeFromCcp4)
|
|
|
|
- if (options.visuals) {
|
|
|
|
- tree = tree.apply(StateTransforms.Representation.VolumeRepresentation3D)
|
|
|
|
- }
|
|
|
|
- await state.updateTree(tree).runInContext(taskCtx)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const Dsn6Provider: DataFormatProvider<any> = {
|
|
|
|
- label: 'DSN6/BRIX',
|
|
|
|
- description: 'DSN6/BRIX',
|
|
|
|
- stringExtensions: [],
|
|
|
|
- binaryExtensions: ['dsn6', 'brix'],
|
|
|
|
- isApplicable: (info: FileInfo, data: Uint8Array) => {
|
|
|
|
- return info.ext === 'dsn6' || info.ext === 'brix'
|
|
|
|
- },
|
|
|
|
- getDefaultBuilder: (ctx: PluginContext, data, options: DataFormatBuilderOptions, state: State) => {
|
|
|
|
- return Task.create('DSN6/BRIX default builder', async taskCtx => {
|
|
|
|
- let tree: StateBuilder.To<any> = state.build().to(data)
|
|
|
|
- .apply(StateTransforms.Data.ParseDsn6, {}, { state: { isGhost: true } })
|
|
|
|
- .apply(StateTransforms.Volume.VolumeFromDsn6)
|
|
|
|
- if (options.visuals) {
|
|
|
|
- tree = tree.apply(StateTransforms.Representation.VolumeRepresentation3D)
|
|
|
|
- }
|
|
|
|
- await state.updateTree(tree).runInContext(taskCtx)
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const DscifProvider: DataFormatProvider<any> = {
|
|
|
|
- label: 'DensityServer CIF',
|
|
|
|
- description: 'DensityServer CIF',
|
|
|
|
- stringExtensions: ['cif'],
|
|
|
|
- binaryExtensions: ['bcif'],
|
|
|
|
- isApplicable: (info: FileInfo, data: Uint8Array | string) => {
|
|
|
|
- return guessCifVariant(info, data) === 'dscif' ? true : false
|
|
|
|
- },
|
|
|
|
- getDefaultBuilder: (ctx: PluginContext, data, options: DataFormatBuilderOptions, state: State) => {
|
|
|
|
- return Task.create('DensityServer CIF default builder', async taskCtx => {
|
|
|
|
- const cifBuilder = state.build().to(data).apply(StateTransforms.Data.ParseCif)
|
|
|
|
- const cifStateObject = await state.updateTree(cifBuilder).runInContext(taskCtx)
|
|
|
|
- const b = state.build().to(cifBuilder.ref);
|
|
|
|
- const blocks = cifStateObject.data.blocks.slice(1); // zero block contains query meta-data
|
|
|
|
- let tree: StateBuilder.To<any, any>
|
|
|
|
- if (blocks.length === 1) {
|
|
|
|
- tree = b
|
|
|
|
- .apply(StateTransforms.Volume.VolumeFromDensityServerCif, { blockHeader: blocks[0].header })
|
|
|
|
- if (options.visuals) {
|
|
|
|
- tree = tree.apply(StateTransforms.Representation.VolumeRepresentation3D, VolumeRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'isosurface', { isoValue: VolumeIsoValue.relative(1.5), alpha: 0.3 }, 'uniform', { value: ColorNames.teal }))
|
|
|
|
- }
|
|
|
|
- } else if (blocks.length === 2) {
|
|
|
|
- tree = b
|
|
|
|
- .apply(StateTransforms.Volume.VolumeFromDensityServerCif, { blockHeader: blocks[0].header })
|
|
|
|
- if (options.visuals) {
|
|
|
|
- tree = tree.apply(StateTransforms.Representation.VolumeRepresentation3D, VolumeRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'isosurface', { isoValue: VolumeIsoValue.relative(1.5), alpha: 0.3 }, 'uniform', { value: ColorNames.blue }))
|
|
|
|
- }
|
|
|
|
- const vol = tree.to(cifBuilder.ref)
|
|
|
|
- .apply(StateTransforms.Volume.VolumeFromDensityServerCif, { blockHeader: blocks[1].header })
|
|
|
|
- const posParams = VolumeRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'isosurface', { isoValue: VolumeIsoValue.relative(3), alpha: 0.3 }, 'uniform', { value: ColorNames.green })
|
|
|
|
- tree = vol.apply(StateTransforms.Representation.VolumeRepresentation3D, posParams)
|
|
|
|
- const negParams = VolumeRepresentation3DHelpers.getDefaultParamsStatic(ctx, 'isosurface', { isoValue: VolumeIsoValue.relative(-3), alpha: 0.3 }, 'uniform', { value: ColorNames.red })
|
|
|
|
- tree = tree.to(vol.ref).apply(StateTransforms.Representation.VolumeRepresentation3D, negParams)
|
|
|
|
- } else {
|
|
|
|
- throw new Error('unknown number of blocks')
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- await state.updateTree(tree).runInContext(taskCtx);
|
|
|
|
- })
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+import { DataFormatProvider } from '../formats/provider';
|
|
|
|
|
|
export { DownloadDensity };
|
|
export { DownloadDensity };
|
|
type DownloadDensity = typeof DownloadDensity
|
|
type DownloadDensity = typeof DownloadDensity
|
|
@@ -108,7 +20,7 @@ const DownloadDensity = StateAction.build({
|
|
from: PluginStateObject.Root,
|
|
from: PluginStateObject.Root,
|
|
display: { name: 'Download Density', description: 'Load a density from the provided source and create its default visual.' },
|
|
display: { name: 'Download Density', description: 'Load a density from the provided source and create its default visual.' },
|
|
params: (a, ctx: PluginContext) => {
|
|
params: (a, ctx: PluginContext) => {
|
|
- const { options } = ctx.dataFormat.registry
|
|
|
|
|
|
+ const { options } = ctx.dataFormats
|
|
return {
|
|
return {
|
|
source: PD.MappedStatic('pdb-xray', {
|
|
source: PD.MappedStatic('pdb-xray', {
|
|
'pdb-xray': PD.Group({
|
|
'pdb-xray': PD.Group({
|
|
@@ -147,10 +59,10 @@ const DownloadDensity = StateAction.build({
|
|
})
|
|
})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-})(({ params, state }, ctx: PluginContext) => Task.create('Download Density', async taskCtx => {
|
|
|
|
|
|
+})(({ params }, plugin: PluginContext) => Task.create('Download Density', async taskCtx => {
|
|
const src = params.source;
|
|
const src = params.source;
|
|
let downloadParams: StateTransformer.Params<Download>;
|
|
let downloadParams: StateTransformer.Params<Download>;
|
|
- let provider: DataFormatProvider<any>
|
|
|
|
|
|
+ let provider: DataFormatProvider | undefined;
|
|
|
|
|
|
switch (src.name) {
|
|
switch (src.name) {
|
|
case 'url':
|
|
case 'url':
|
|
@@ -196,24 +108,30 @@ const DownloadDensity = StateAction.build({
|
|
default: throw new Error(`${(src as any).name} not supported.`);
|
|
default: throw new Error(`${(src as any).name} not supported.`);
|
|
}
|
|
}
|
|
|
|
|
|
- const data = await ctx.builders.data.download(downloadParams);
|
|
|
|
|
|
+ const data = await plugin.builders.data.download(downloadParams);
|
|
|
|
|
|
switch (src.name) {
|
|
switch (src.name) {
|
|
case 'url':
|
|
case 'url':
|
|
downloadParams = src.params;
|
|
downloadParams = src.params;
|
|
- provider = src.params.format === 'auto' ? ctx.dataFormat.registry.auto(getFileInfo(downloadParams.url), data.cell?.obj!) : ctx.dataFormat.registry.get(src.params.format)
|
|
|
|
|
|
+ provider = src.params.format === 'auto' ? plugin.dataFormats.auto(getFileInfo(downloadParams.url), data.cell?.obj!) : plugin.dataFormats.get(src.params.format)
|
|
break;
|
|
break;
|
|
case 'pdb-xray':
|
|
case 'pdb-xray':
|
|
provider = src.params.provider.server === 'pdbe'
|
|
provider = src.params.provider.server === 'pdbe'
|
|
- ? ctx.dataFormat.registry.get('ccp4')
|
|
|
|
- : ctx.dataFormat.registry.get('dsn6')
|
|
|
|
|
|
+ ? plugin.dataFormats.get('ccp4')
|
|
|
|
+ : plugin.dataFormats.get('dsn6')
|
|
break;
|
|
break;
|
|
case 'pdb-emd-ds':
|
|
case 'pdb-emd-ds':
|
|
case 'pdb-xray-ds':
|
|
case 'pdb-xray-ds':
|
|
- provider = ctx.dataFormat.registry.get('dscif')
|
|
|
|
|
|
+ provider = plugin.dataFormats.get('dscif')
|
|
break;
|
|
break;
|
|
default: throw new Error(`${(src as any).name} not supported.`);
|
|
default: throw new Error(`${(src as any).name} not supported.`);
|
|
}
|
|
}
|
|
|
|
|
|
- await provider.getDefaultBuilder(ctx, data, { visuals: true }, state).runInContext(taskCtx)
|
|
|
|
|
|
+ if (!provider) {
|
|
|
|
+ plugin.log.warn('DownloadDensity: Format provider not found.');
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const volumes = await provider.parse(plugin, data);
|
|
|
|
+ await provider.visuals?.(plugin, volumes);
|
|
}));
|
|
}));
|