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

ability to load more PDB ids at once (as separate structures), various tweaks

parent d1b8b6da
No related branches found
No related tags found
No related merge requests found
...@@ -28,10 +28,11 @@ export const InitVolumeStreaming = StateAction.build({ ...@@ -28,10 +28,11 @@ export const InitVolumeStreaming = StateAction.build({
params(a) { params(a) {
return { return {
method: PD.Select<VolumeServerInfo.Kind>(getStreamingMethod(a && a.data), [['em', 'EM'], ['x-ray', 'X-Ray']]), method: PD.Select<VolumeServerInfo.Kind>(getStreamingMethod(a && a.data), [['em', 'EM'], ['x-ray', 'X-Ray']]),
id: PD.Text((a && a.data.models[0].label) || ''), id: PD.Text((a && a.data.models.length > 0 && a.data.models[0].label) || ''),
serverUrl: PD.Text('https://webchem.ncbr.muni.cz/DensityServer') serverUrl: PD.Text('https://webchem.ncbr.muni.cz/DensityServer')
}; };
} },
isApplicable: (a) => a.data.models.length === 1
})(({ ref, state, params }, plugin: PluginContext) => Task.create('Volume Streaming', async taskCtx => { })(({ ref, state, params }, plugin: PluginContext) => Task.create('Volume Streaming', async taskCtx => {
// TODO: custom react view for this and the VolumeStreamingBehavior transformer // TODO: custom react view for this and the VolumeStreamingBehavior transformer
......
...@@ -105,29 +105,41 @@ const DownloadStructure = StateAction.build({ ...@@ -105,29 +105,41 @@ const DownloadStructure = StateAction.build({
})(({ params, state }, ctx: PluginContext) => { })(({ params, state }, ctx: PluginContext) => {
const b = state.build(); const b = state.build();
const src = params.source; const src = params.source;
let downloadParams: StateTransformer.Params<Download>; let downloadParams: StateTransformer.Params<Download>[];
switch (src.name) { switch (src.name) {
case 'url': case 'url':
downloadParams = { url: src.params.url, isBinary: src.params.isBinary }; downloadParams = [{ url: src.params.url, isBinary: src.params.isBinary }];
break; break;
case 'pdbe-updated': case 'pdbe-updated':
downloadParams = { url: `https://www.ebi.ac.uk/pdbe/static/entry/${src.params.id.toLowerCase()}_updated.cif`, isBinary: false, label: `PDBe: ${src.params.id}` }; downloadParams = getDownloadParams(src.params.id, id => `https://www.ebi.ac.uk/pdbe/static/entry/${id.toLowerCase()}_updated.cif`, id => `PDBe: ${id}`, false);
break; break;
case 'rcsb': case 'rcsb':
downloadParams = { url: `https://files.rcsb.org/download/${src.params.id.toUpperCase()}.cif`, isBinary: false, label: `RCSB: ${src.params.id}` }; downloadParams = getDownloadParams(src.params.id, id => `https://files.rcsb.org/download/${id.toUpperCase()}.cif`, id => `RCSB: ${id}`, false);
break; break;
case 'bcif-static': case 'bcif-static':
downloadParams = { url: `https://webchem.ncbr.muni.cz/ModelServer/static/bcif/${src.params.id.toLowerCase()}`, isBinary: true, label: `BinaryCIF: ${src.params.id}` }; downloadParams = getDownloadParams(src.params.id, id => `https://webchem.ncbr.muni.cz/ModelServer/static/bcif/${id.toLowerCase()}`, id => `BinaryCIF: ${id}`, true);
break; break;
default: throw new Error(`${(src as any).name} not supported.`); default: throw new Error(`${(src as any).name} not supported.`);
} }
const data = b.toRoot().apply(StateTransforms.Data.Download, downloadParams, { props: { isGhost: true }}); for (const download of downloadParams) {
const traj = createModelTree(data, src.name === 'url' ? src.params.format : 'cif'); const data = b.toRoot().apply(StateTransforms.Data.Download, download, { props: { isGhost: true }});
return state.updateTree(createStructureTree(ctx, traj, params.source.params.supportProps)); const traj = createModelTree(data, src.name === 'url' ? src.params.format : 'cif');
createStructureTree(ctx, traj, params.source.params.supportProps)
}
return state.updateTree(b);
}); });
function getDownloadParams(src: string, url: (id: string) => string, label: (id: string) => string, isBinary: boolean): StateTransformer.Params<Download>[] {
const ids = src.split(',').map(id => id.trim()).filter(id => !!id && id.length >= 4);
const ret: StateTransformer.Params<Download>[] = [];
for (const id of ids) {
ret.push({ url: url(id), isBinary, label: label(id) })
}
return ret;
}
function createModelTree(b: StateBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, format: 'pdb' | 'cif' | 'gro' = 'cif') { function createModelTree(b: StateBuilder.To<PluginStateObject.Data.Binary | PluginStateObject.Data.String>, format: 'pdb' | 'cif' | 'gro' = 'cif') {
let parsed: StateBuilder.To<PluginStateObject.Molecule.Trajectory> let parsed: StateBuilder.To<PluginStateObject.Molecule.Trajectory>
switch (format) { switch (format) {
......
...@@ -178,7 +178,7 @@ class PluginStateSnapshotManager extends PluginComponent<{ ...@@ -178,7 +178,7 @@ class PluginStateSnapshotManager extends PluginComponent<{
const snapshot = this.setCurrent(next)!; const snapshot = this.setCurrent(next)!;
await this.plugin.state.setSnapshot(snapshot); await this.plugin.state.setSnapshot(snapshot);
const delay = typeof snapshot.durationInMs !== 'undefined' ? snapshot.durationInMs : this.state.nextSnapshotDelayInMs; const delay = typeof snapshot.durationInMs !== 'undefined' ? snapshot.durationInMs : this.state.nextSnapshotDelayInMs;
this.timeoutHandle = setTimeout(this.next, delay); if (this.state.isPlaying) this.timeoutHandle = setTimeout(this.next, delay);
}; };
play() { play() {
......
...@@ -266,7 +266,6 @@ const UserStructureSelection = PluginStateTransform.BuiltIn({ ...@@ -266,7 +266,6 @@ const UserStructureSelection = PluginStateTransform.BuiltIn({
const compiled = compile<Sel>(query); const compiled = compile<Sel>(query);
const result = compiled(new QueryContext(a.data)); const result = compiled(new QueryContext(a.data));
const s = Sel.unionStructure(result); const s = Sel.unionStructure(result);
if (s.elementCount === 0) return StateObject.Null;
const props = { label: `${params.label || 'Selection'}`, description: structureDesc(s) }; const props = { label: `${params.label || 'Selection'}`, description: structureDesc(s) };
return new SO.Molecule.Structure(s, props); return new SO.Molecule.Structure(s, props);
} }
......
...@@ -163,7 +163,7 @@ namespace Language { ...@@ -163,7 +163,7 @@ namespace Language {
} }
function isNumber(value: string) { function isNumber(value: string) {
return /-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?/.test(value); return /-?(0|[1-9][0-9]*)([.][0-9]+)?([eE][+-]?[0-9]+)?/.test(value) && !isNaN(+value);
} }
export function parse(input: string): Expression[] { export function parse(input: string): Expression[] {
......
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