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

mol-plugin: tweaks

parent 9c27896a
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { PluginCommands } from './command';
import { PluginSpec } from './spec';
import { DownloadAtomicStructure, CreateComplexRepresentation, OpenAtomicStructure } from './state/actions/basic';
import { DownloadStructure, CreateComplexRepresentation, OpenStructure } from './state/actions/basic';
import { StateTransforms } from './state/transforms';
import { PluginBehaviors } from './behavior';
......@@ -21,8 +21,8 @@ function getParam(name: string, regex: string): string {
const DefaultSpec: PluginSpec = {
actions: [
PluginSpec.Action(DownloadAtomicStructure),
PluginSpec.Action(OpenAtomicStructure),
PluginSpec.Action(DownloadStructure),
PluginSpec.Action(OpenStructure),
PluginSpec.Action(CreateComplexRepresentation),
PluginSpec.Action(StateTransforms.Data.Download),
PluginSpec.Action(StateTransforms.Data.ParseCif),
......
......@@ -17,32 +17,30 @@ import { StateTreeBuilder } from 'mol-state/tree/builder';
// TODO: "structure parser provider"
export { DownloadAtomicStructure }
namespace DownloadAtomicStructure {
export type Sources = 'pdbe-updated' | 'rcsb' | 'bcif-static' | 'url'
export type Source = ObtainStructureHelpers.MapParams<Sources, typeof ObtainStructureHelpers.ControlMap>
export { DownloadStructure }
namespace DownloadStructure {
export type Source = PD.NamedParamUnion<ObtainStructureHelpers.ControlMap>
export interface Params {
source: Source
}
}
namespace ObtainStructureHelpers {
export const SourceOptions: [DownloadAtomicStructure.Sources, string][] = [
['pdbe-updated', 'PDBe Updated'],
['rcsb', 'RCSB'],
['bcif-static', 'BinaryCIF (static PDBe Updated)'],
['url', 'URL']
];
export const ControlMap = {
'pdbe-updated': PD.Text('1cbs', { label: 'Id' }),
'rcsb': PD.Text('1tqn', { label: 'Id' }),
'bcif-static': PD.Text('1tqn', { label: 'Id' }),
'url': PD.Group({ url: PD.Text(''), isBinary: PD.Boolean(false) }, { isExpanded: true })
}
export function getControls(key: string) { return (ControlMap as any)[key]; }
export type MapParams<P extends DownloadAtomicStructure.Sources, Map extends { [K in P]: PD.Any }> = P extends DownloadAtomicStructure.Sources ? PD.NamedParams<Map[P]['defaultValue'], P> : never
export type ControlMap = typeof ControlMap
export const SourceOptions: [keyof ControlMap, string][] = [
['pdbe-updated', 'PDBe Updated'],
['rcsb', 'RCSB'],
['bcif-static', 'BinaryCIF (static PDBe Updated)'],
['url', 'URL']
];
export function getUrl(src: DownloadAtomicStructure.Source): Download.Params {
export function getControls(key: string) { return (ControlMap as any)[key]; }
export function getUrl(src: DownloadStructure.Source): Download.Params {
switch (src.name) {
case 'url': return src.params;
case 'pdbe-updated': return { url: `https://www.ebi.ac.uk/pdbe/static/entry/${src.params.toLowerCase()}_updated.cif`, isBinary: false, label: `PDBe: ${src.params}` };
......@@ -52,7 +50,7 @@ namespace ObtainStructureHelpers {
}
}
}
const DownloadAtomicStructure = StateAction.create<PluginStateObject.Root, void, DownloadAtomicStructure.Params>({
const DownloadStructure = StateAction.create<PluginStateObject.Root, void, DownloadStructure.Params>({
from: [PluginStateObject.Root],
display: {
name: 'Download Structure',
......@@ -76,11 +74,11 @@ const DownloadAtomicStructure = StateAction.create<PluginStateObject.Root, void,
const url = ObtainStructureHelpers.getUrl(params.source);
const data = b.toRoot().apply(StateTransforms.Data.Download, url);
return state.update(atomicStructureTree(data));
return state.update(createStructureTree(data));
}
});
export const OpenAtomicStructure = StateAction.create<PluginStateObject.Root, void, { file: File }>({
export const OpenStructure = StateAction.create<PluginStateObject.Root, void, { file: File }>({
from: [PluginStateObject.Root],
display: {
name: 'Open Structure',
......@@ -90,11 +88,11 @@ export const OpenAtomicStructure = StateAction.create<PluginStateObject.Root, vo
apply({ params, state }) {
const b = state.build();
const data = b.toRoot().apply(StateTransforms.Data.ReadFile, { file: params.file, isBinary: /\.bcif$/i.test(params.file.name) });
return state.update(atomicStructureTree(data));
return state.update(createStructureTree(data));
}
});
function atomicStructureTree(b: StateTreeBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>): StateTree {
function createStructureTree(b: StateTreeBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>): StateTree {
const root = b
.apply(StateTransforms.Data.ParseCif)
.apply(StateTransforms.Model.TrajectoryFromMmCif, {})
......
......@@ -146,6 +146,7 @@ export namespace ParamDefinition {
}
export interface NamedParams<T = any, K = string> { name: K, params: T }
export type NamedParamUnion<P extends Params, K = keyof P> = K extends any ? NamedParams<P[K]['defaultValue'], K> : never
export interface Mapped<T> extends Base<NamedParams<T>> {
type: 'mapped',
select: Select<string>,
......
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