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
b272c3a5
You need to sign in or sign up before continuing.
Commit
b272c3a5
authored
6 years ago
by
David Sehnal
Browse files
Options
Downloads
Patches
Plain Diff
mol-state: coarser StateAction syntax
parent
ec1dc600
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-plugin/state/actions/basic.ts
+34
-40
34 additions, 40 deletions
src/mol-plugin/state/actions/basic.ts
src/mol-state/action.ts
+6
-4
6 additions, 4 deletions
src/mol-state/action.ts
src/mol-state/state.ts
+1
-1
1 addition, 1 deletion
src/mol-state/state.ts
with
41 additions
and
45 deletions
src/mol-plugin/state/actions/basic.ts
+
34
−
40
View file @
b272c3a5
...
...
@@ -60,7 +60,7 @@ const DownloadStructure = StateAction.create<PluginStateObject.Root, void, Downl
description
:
'
Load a structure from PDBe and create its default Assembly and visual
'
},
params
:
()
=>
({
source
:
PD
.
Mapped
(
'
bcif-static
'
,
ObtainStructureHelpers
.
SourceOptions
,
ObtainStructureHelpers
.
getControls
)
}),
apply
({
params
,
state
})
{
run
({
params
,
state
})
{
const
b
=
state
.
build
();
// const query = MolScriptBuilder.struct.generator.atomGroups({
...
...
@@ -85,12 +85,10 @@ export const OpenStructure = StateAction.build({
display
:
{
name
:
'
Open Structure
'
,
description
:
'
Load a structure from file and create its default Assembly and visual
'
},
from
:
PluginStateObject
.
Root
,
params
:
{
file
:
PD
.
File
({
accept
:
'
.cif,.bcif
'
})
}
})({
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
(
createStructureTree
(
data
));
}
})(({
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
(
createStructureTree
(
data
));
});
function
createStructureTree
(
b
:
StateTreeBuilder
.
To
<
PluginStateObject
.
Data
.
Binary
|
PluginStateObject
.
Data
.
String
>
):
StateTree
{
...
...
@@ -125,18 +123,16 @@ function complexRepresentation(root: StateTreeBuilder.To<PluginStateObject.Molec
sizeTheme
:
{
name
:
'
uniform
'
,
params
:
PD
.
getDefaultValues
(
UniformSizeThemeParams
)
},
})
root
.
apply
(
StateTransforms
.
Model
.
StructureComplexElement
,
{
type
:
'
spheres
'
});
// TODO: create spheres visual
// TODO: create spheres visual
}
export
const
CreateComplexRepresentation
=
StateAction
.
build
({
display
:
{
name
:
'
Create Complex
'
,
description
:
'
Split the structure into Sequence/Water/Ligands/...
'
},
from
:
PluginStateObject
.
Molecule
.
Structure
})({
apply
({
ref
,
state
})
{
const
root
=
state
.
build
().
to
(
ref
);
complexRepresentation
(
root
);
return
state
.
update
(
root
.
getTree
());
}
})(({
ref
,
state
})
=>
{
const
root
=
state
.
build
().
to
(
ref
);
complexRepresentation
(
root
);
return
state
.
update
(
root
.
getTree
());
});
export
const
UpdateTrajectory
=
StateAction
.
build
({
...
...
@@ -145,32 +141,30 @@ export const UpdateTrajectory = StateAction.build({
action
:
PD
.
Select
<
'
advance
'
|
'
reset
'
>
(
'
advance
'
,
[[
'
advance
'
,
'
Advance
'
],
[
'
reset
'
,
'
Reset
'
]]),
by
:
PD
.
makeOptional
(
PD
.
Numeric
(
1
,
{
min
:
-
1
,
max
:
1
,
step
:
1
}))
}
})({
apply
({
params
,
state
})
{
const
models
=
state
.
select
(
q
=>
q
.
rootsOfType
(
PluginStateObject
.
Molecule
.
Model
)
.
filter
(
c
=>
c
.
transform
.
transformer
===
StateTransforms
.
Model
.
ModelFromTrajectory
));
const
update
=
state
.
build
();
if
(
params
.
action
===
'
reset
'
)
{
for
(
const
m
of
models
)
{
update
.
to
(
m
.
transform
.
ref
).
update
(
StateTransforms
.
Model
.
ModelFromTrajectory
,
()
=>
({
modelIndex
:
0
}));
}
}
else
{
for
(
const
m
of
models
)
{
const
parent
=
StateSelection
.
findAncestorOfType
(
state
.
tree
,
state
.
cells
,
m
.
transform
.
ref
,
[
PluginStateObject
.
Molecule
.
Trajectory
]);
if
(
!
parent
||
!
parent
.
obj
)
continue
;
const
traj
=
parent
.
obj
as
PluginStateObject
.
Molecule
.
Trajectory
;
update
.
to
(
m
.
transform
.
ref
).
update
(
StateTransforms
.
Model
.
ModelFromTrajectory
,
old
=>
{
let
modelIndex
=
(
old
.
modelIndex
+
params
.
by
!
)
%
traj
.
data
.
length
;
if
(
modelIndex
<
0
)
modelIndex
+=
traj
.
data
.
length
;
return
{
modelIndex
};
});
}
}
})(({
params
,
state
})
=>
{
const
models
=
state
.
select
(
q
=>
q
.
rootsOfType
(
PluginStateObject
.
Molecule
.
Model
)
.
filter
(
c
=>
c
.
transform
.
transformer
===
StateTransforms
.
Model
.
ModelFromTrajectory
));
const
update
=
state
.
build
();
return
state
.
update
(
update
);
if
(
params
.
action
===
'
reset
'
)
{
for
(
const
m
of
models
)
{
update
.
to
(
m
.
transform
.
ref
).
update
(
StateTransforms
.
Model
.
ModelFromTrajectory
,
()
=>
({
modelIndex
:
0
}));
}
}
else
{
for
(
const
m
of
models
)
{
const
parent
=
StateSelection
.
findAncestorOfType
(
state
.
tree
,
state
.
cells
,
m
.
transform
.
ref
,
[
PluginStateObject
.
Molecule
.
Trajectory
]);
if
(
!
parent
||
!
parent
.
obj
)
continue
;
const
traj
=
parent
.
obj
as
PluginStateObject
.
Molecule
.
Trajectory
;
update
.
to
(
m
.
transform
.
ref
).
update
(
StateTransforms
.
Model
.
ModelFromTrajectory
,
old
=>
{
let
modelIndex
=
(
old
.
modelIndex
+
params
.
by
!
)
%
traj
.
data
.
length
;
if
(
modelIndex
<
0
)
modelIndex
+=
traj
.
data
.
length
;
return
{
modelIndex
};
});
}
}
return
state
.
update
(
update
);
});
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/mol-state/action.ts
+
6
−
4
View file @
b272c3a5
...
...
@@ -42,7 +42,7 @@ namespace StateAction {
/**
* Apply an action that modifies the State specified in Params.
*/
apply
(
params
:
ApplyParams
<
A
,
P
>
,
globalCtx
:
unknown
):
T
|
Task
<
T
>
,
run
(
params
:
ApplyParams
<
A
,
P
>
,
globalCtx
:
unknown
):
T
|
Task
<
T
>
,
/** Test if the transform can be applied to a given node */
isApplicable
?(
a
:
A
,
globalCtx
:
unknown
):
boolean
...
...
@@ -69,7 +69,7 @@ namespace StateAction {
from
:
def
.
from
,
display
:
def
.
display
,
params
:
def
.
params
as
Transformer
.
Definition
<
Transformer
.
From
<
T
>
,
any
,
Transformer
.
Params
<
T
>>
[
'
params
'
],
apply
({
cell
,
state
,
params
})
{
run
({
cell
,
state
,
params
})
{
const
tree
=
state
.
build
().
to
(
cell
.
transform
.
ref
).
apply
(
transformer
,
params
);
return
state
.
update
(
tree
);
}
...
...
@@ -88,7 +88,7 @@ namespace StateAction {
}
export
interface
Define
<
A
extends
StateObject
,
P
>
{
<
T
>
(
def
:
DefinitionBase
<
A
,
T
,
P
>
):
StateAction
<
A
,
T
,
P
>
,
<
T
>
(
def
:
DefinitionBase
<
A
,
T
,
P
>
|
DefinitionBase
<
A
,
T
,
P
>
[
'
run
'
]
):
StateAction
<
A
,
T
,
P
>
,
}
function
root
(
info
:
Type
<
any
,
any
>
):
Define
<
any
,
any
>
{
...
...
@@ -106,7 +106,9 @@ namespace StateAction {
:
!!
info
.
params
?
info
.
params
as
any
:
void
0
,
...
def
...(
typeof
def
===
'
function
'
?
{
run
:
def
}
:
def
)
});
}
...
...
This diff is collapsed.
Click to expand it.
src/mol-state/state.ts
+
1
−
1
View file @
b272c3a5
...
...
@@ -104,7 +104,7 @@ class State {
if
(
!
cell
)
throw
new
Error
(
`'
${
ref
}
' does not exist.`
);
if
(
cell
.
status
!==
'
ok
'
)
throw
new
Error
(
`Action cannot be applied to a cell with status '
${
cell
.
status
}
'`
);
return
runTask
(
action
.
definition
.
apply
({
ref
,
cell
,
a
:
cell
.
obj
!
,
params
,
state
:
this
},
this
.
globalContext
),
ctx
);
return
runTask
(
action
.
definition
.
run
({
ref
,
cell
,
a
:
cell
.
obj
!
,
params
,
state
:
this
},
this
.
globalContext
),
ctx
);
});
}
...
...
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