-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.qmd
More file actions
205 lines (150 loc) · 6.23 KB
/
example.qmd
File metadata and controls
205 lines (150 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
title: "MolViewSpec Quarto Extension Example"
format:
html:
toc: true
toc-depth: 2
filters:
- molviewspec-quarto
---
## Installation
To use this extension in your Quarto project, run the following command in your terminal:
```bash
quarto add molstar/molviewspec-quarto
```
Then add the filter to your document's YAML front matter and can use `.molviewspec` within a codeblock header.
```yaml
---
title: "My Document"
format: html
filters:
- molviewspec-quarto
---
```
````markdown
```{.molviewspec}
// this is how you can add molviewspec block in your markdown
// JS code here
```
````
## Examples
### Basic Example
Here's a simple example that loads and displays a protein structure. We are using the [molstar](https://molstar.org) and [mol-view-stories](http://molstar.org/mol-view-stories) Javascript libraries
dynamically build up [mol-view-spec](https://molstar.org/mol-view-spec/) state tree which is rendered on a molstar canvas. Try it out!
```{.molviewspec title="Basic Protein Structure (1CBS)"}
const structure = builder
.download({ url: 'https://www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif' })
.parse({ format: 'bcif' })
.modelStructure();
structure
.component({ selector: 'polymer' })
.representation({ type: 'cartoon' })
.color({ color: 'blue' });
// try color: '#ccffaa'
```
### Selections and Multiple Components
This example adds a few additional features. We use the `builder` to make muleiple different represetnations and selections. One for the `polymer`, one for the `water`, and one for the `ligand`.
We also use `focus` to center the canvas on the ligand. Because we are building a state tree, anytime we with to branch we
need to explicitly branch in our code - e.g. on ligand we use both `focus` and `representation`.
```{.molviewspec title="Protein with Ligand"}
const structure = builder
.download({ url: 'https://www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif' })
.parse({ format: 'bcif' })
.modelStructure();
structure
.component({ selector: 'polymer' })
.representation({ type: 'cartoon' })
.color({ color: 'green' });
structure
.component({ selector: 'water' })
.representation({ type: 'ball_and_stick' })
.color({ color: 'lightblue' });
const ligand = structure
.component({ selector: 'ligand' });
ligand.focus()
ligand
.representation({ type: 'ball_and_stick' })
.color({ color: '#cc3399' });
```
### Adding Controls
When `controls="true"` is set, you can:
- Toggle auto-update on/off to control when the viewer re-renders
- Click "Show execution log" to see execution details and any errors
- Edit the code and see changes in real-time (when auto-update is on)
````markdown
```{.molviewspec controls="true"}
// this block will be rendered with controls
```
````
```{.molviewspec controls="true" title="Interactive Controls Demo"}
const structure = builder
.download({ url: 'https://www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif' })
.parse({ format: 'bcif' })
.modelStructure();
structure
.component({ selector: 'polymer' })
.representation({ type: 'cartoon' })
.color({ color: 'purple' });
```
### Hiding Code
You can split your code into two parts using `---` as a separator:
- **Hidden code** (above `---`): Runs but doesn't appear in the editor - useful for setup, imports, or shared variables
- **Scene code** (below `---`): Appears in the editor and is editable
```{.molviewspec title="Using Story and Scene Code"}
// This is hidden code - it runs but won't show in the editor
const structure = builder
.download({ url: 'https://www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif' })
.parse({ format: 'bcif' })
.modelStructure();
---
// This is scene code - it appears in the editor and is editable
structure
.component({ selector: 'polymer' })
.representation({ type: 'cartoon' })
.color({ color: 'purple' });
```
### Writing Functions
You can write functions to save space and improve reusabilty.
```{.molviewspec}
// we are declaring a function
function molecule(){
return builder
.download({ url: 'https://www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif' })
.parse({ format: 'bcif' })
.modelStructure();
}
// and now we are using it
const structure = molecule();
structure
.component({ selector: 'polymer' })
.representation({ type: 'cartoon' })
.color({ color: 'orange' });
```
## Supported Attributes
You can customize molviewspec code blocks using the following attributes:
### Container Attributes
- **title**: Optional title displayed in the header. If empty, no header is shown.
- **controls**: Enable interactive controls - "true" or "false" (default: "false"). When enabled, shows a bottom control panel with auto-update toggle and execution log toggle. This automatically enables `showBottomControlPanel="true"`, `showAutoUpdateToggle="true"`, and `showLog="true"`.
## MolViewSpec Builder API
The builder API provides a fluent interface for creating molecular visualizations. Key methods include:
- `download()`: Download a structure from a URL
- `parse()`: Parse the downloaded file (formats: bcif, cif, pdb, etc.)
- `modelStructure()`: Create a model structure node
- `component()`: Select parts of the structure (polymer, ligand, water, etc.)
- `representation()`: Add a visual representation (cartoon, ball_and_stick, surface, spacefill, etc.)
- `color()`: Apply colors (named colors like 'red', 'blue', or hex codes like '#cc3399')
- `label()`: Add text labels
- `focus()`: Focus the camera on a component
For more information about MolViewSpec:
- [MolViewSpec Documentation](https://molstar.org/mol-view-spec-docs/)
- [Integration Examples](https://molstar.org/mol-view-spec-docs/mvs-molstar-extension/integration/)
- [MolStar Website](https://molstar.org/)
## Technical Notes
This quarto extension wraps [MolStar-Components](https://zachcp.github.io/molstar-components/) which
in turn uses the code from the [Mol-View-Stories](https://molstar.org/mol-view-stories/) project.
- Each block creates an independent interactive viewer
- The extension automatically manages all JavaScript and CSS dependencies
- The viewer is fully interactive and allows rotation, zooming, and selection
- Use `{.molviewspec}` with a dot prefix for the code block class
- The MolStar library is bundled with the extension for offline use
- Write JavaScript code using the `builder` variable to construct your view