Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
d9dced28
Commit
d9dced28
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
Better typing for Mapped param
parent
b272c3a5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/mol-plugin/state/actions/basic.ts
+39
-55
39 additions, 55 deletions
src/mol-plugin/state/actions/basic.ts
src/mol-util/param-definition.ts
+16
-4
16 additions, 4 deletions
src/mol-util/param-definition.ts
with
55 additions
and
59 deletions
src/mol-plugin/state/actions/basic.ts
+
39
−
55
View file @
d9dced28
...
...
@@ -21,64 +21,48 @@ import { ElementSymbolColorThemeParams } from 'mol-theme/color/element-symbol';
// TODO: "structure parser provider"
export
{
DownloadStructure
}
namespace
DownloadStructure
{
export
type
Source
=
PD
.
NamedParamUnion
<
ObtainStructureHelpers
.
ControlMap
>
export
interface
Params
{
source
:
Source
}
}
namespace
ObtainStructureHelpers
{
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
})
type
DownloadStructure
=
typeof
DownloadStructure
const
DownloadStructure
=
StateAction
.
build
({
from
:
PluginStateObject
.
Root
,
display
:
{
name
:
'
Download Structure
'
,
description
:
'
Load a structure from the provided source and create its default Assembly and visual.
'
},
params
:
{
source
:
PD
.
MappedStatic
(
'
bcif-static
'
,
{
'
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
})
},
{
options
:
[
[
'
pdbe-updated
'
,
'
PDBe Updated
'
],
[
'
rcsb
'
,
'
RCSB
'
],
[
'
bcif-static
'
,
'
BinaryCIF (static PDBe Updated)
'
],
[
'
url
'
,
'
URL
'
]
]
})
}
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
getControls
(
key
:
string
)
{
return
(
ControlMap
as
any
)[
key
];
}
export
function
getUrl
(
src
:
DownloadStructure
.
Source
):
Transformer
.
Params
<
Download
>
{
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
}
`
};
case
'
rcsb
'
:
return
{
url
:
`https://files.rcsb.org/download/
${
src
.
params
.
toUpperCase
()}
.cif`
,
isBinary
:
false
,
label
:
`RCSB:
${
src
.
params
}
`
};
case
'
bcif-static
'
:
return
{
url
:
`https://webchem.ncbr.muni.cz/ModelServer/static/bcif/
${
src
.
params
.
toLowerCase
()}
`
,
isBinary
:
true
,
label
:
`BinaryCIF:
${
src
.
params
}
`
};
default
:
throw
new
Error
(
`
${(
src
as
any
).
name
}
not supported.`
);
}
})(({
params
,
state
})
=>
{
const
b
=
state
.
build
();
const
src
=
params
.
source
;
let
url
:
Transformer
.
Params
<
Download
>
;
switch
(
src
.
name
)
{
case
'
url
'
:
url
=
src
.
params
;
break
;
case
'
pdbe-updated
'
:
url
=
{
url
:
`https://www.ebi.ac.uk/pdbe/static/entry/
${
src
.
params
.
toLowerCase
()}
_updated.cif`
,
isBinary
:
false
,
label
:
`PDBe:
${
src
.
params
}
`
};
break
;
case
'
rcsb
'
:
url
=
{
url
:
`https://files.rcsb.org/download/
${
src
.
params
.
toUpperCase
()}
.cif`
,
isBinary
:
false
,
label
:
`RCSB:
${
src
.
params
}
`
};
break
;
case
'
bcif-static
'
:
url
=
{
url
:
`https://webchem.ncbr.muni.cz/ModelServer/static/bcif/
${
src
.
params
.
toLowerCase
()}
`
,
isBinary
:
true
,
label
:
`BinaryCIF:
${
src
.
params
}
`
};
break
;
default
:
throw
new
Error
(
`
${(
src
as
any
).
name
}
not supported.`
);
}
}
const
DownloadStructure
=
StateAction
.
create
<
PluginStateObject
.
Root
,
void
,
DownloadStructure
.
Params
>
({
from
:
[
PluginStateObject
.
Root
],
display
:
{
name
:
'
Download Structure
'
,
description
:
'
Load a structure from PDBe and create its default Assembly and visual
'
},
params
:
()
=>
({
source
:
PD
.
Mapped
(
'
bcif-static
'
,
ObtainStructureHelpers
.
SourceOptions
,
ObtainStructureHelpers
.
getControls
)
}),
run
({
params
,
state
})
{
const
b
=
state
.
build
();
// const query = MolScriptBuilder.struct.generator.atomGroups({
// // 'atom-test': MolScriptBuilder.core.rel.eq([
// // MolScriptBuilder.struct.atomProperty.macromolecular.label_comp_id(),
// // MolScriptBuilder.es('C')
// // ]),
// 'residue-test': MolScriptBuilder.core.rel.eq([
// MolScriptBuilder.struct.atomProperty.macromolecular.label_comp_id(),
// 'ALA'
// ])
// });
const
url
=
ObtainStructureHelpers
.
getUrl
(
params
.
source
);
const
data
=
b
.
toRoot
().
apply
(
StateTransforms
.
Data
.
Download
,
url
);
return
state
.
update
(
createStructureTree
(
data
));
}
const
data
=
b
.
toRoot
().
apply
(
StateTransforms
.
Data
.
Download
,
url
);
return
state
.
update
(
createStructureTree
(
data
));
});
export
const
OpenStructure
=
StateAction
.
build
({
...
...
This diff is collapsed.
Click to expand it.
src/mol-util/param-definition.ts
+
16
−
4
View file @
d9dced28
...
...
@@ -151,17 +151,29 @@ 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
>
>
{
export
interface
Mapped
<
T
extends
NamedParams
<
any
,
any
>>
extends
Base
<
T
>
{
type
:
'
mapped
'
,
select
:
Select
<
string
>
,
map
(
name
:
string
):
Any
}
export
function
Mapped
<
T
>
(
defaultKey
:
string
,
names
:
[
string
,
string
][],
map
:
Mapped
<
T
>
[
'
map
'
]
,
info
?:
Info
):
Mapped
<
T
>
{
return
setInfo
<
Mapped
<
T
>>
({
export
function
Mapped
<
T
>
(
defaultKey
:
string
,
names
:
[
string
,
string
][],
map
:
(
name
:
string
)
=>
Any
,
info
?:
Info
):
Mapped
<
NamedParams
<
T
>
>
{
return
setInfo
<
Mapped
<
NamedParams
<
T
>
>>
({
type
:
'
mapped
'
,
defaultValue
:
{
name
:
defaultKey
,
params
:
map
(
defaultKey
).
defaultValue
as
any
},
select
:
Select
<
string
>
(
defaultKey
,
names
,
info
),
map
},
info
);
map
},
info
);
}
export
function
MappedStatic
<
C
extends
Params
>
(
defaultKey
:
keyof
C
,
map
:
C
,
info
?:
Info
&
{
options
?:
[
keyof
C
,
string
][]
}):
Mapped
<
NamedParamUnion
<
C
>>
{
const
options
:
[
string
,
string
][]
=
info
&&
info
.
options
?
info
.
options
as
[
string
,
string
][]
:
Object
.
keys
(
map
).
map
(
k
=>
[
k
,
k
])
as
[
string
,
string
][];
return
setInfo
<
Mapped
<
NamedParamUnion
<
C
>>>
({
type
:
'
mapped
'
,
defaultValue
:
{
name
:
defaultKey
,
params
:
map
[
defaultKey
].
defaultValue
}
as
any
,
select
:
Select
<
string
>
(
defaultKey
as
string
,
options
,
info
),
map
:
key
=>
map
[
key
]
},
info
);
}
export
interface
Converted
<
T
,
C
>
extends
Base
<
T
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment