mirror of
https://github.com/molstar/molstar.git
synced 2026-06-04 13:30:24 +08:00
MVSX (#1041)
* MVSX format provider * MVS: Integration examples * MVS: drag-and-drop support for MVSX * MVS: support for URL param mvs-format=mvsx * MVS: docs for MVSX * MVS: mvs-render supports MVSX * Update README
This commit is contained in:
@@ -44,6 +44,8 @@ A complete list of supported node types and their parameters is described by the
|
||||
|
||||
### Encoding
|
||||
|
||||
#### MVSJ
|
||||
|
||||
A MolViewSpec tree can be encoded and stored in `.mvsj` format, which is basically a JSON representation of the tree with additional metadata:
|
||||
|
||||
```json
|
||||
@@ -68,6 +70,24 @@ A MolViewSpec tree can be encoded and stored in `.mvsj` format, which is basical
|
||||
```
|
||||
Complete file: [1cbs.mvsj](../../../examples/mvs/1cbs.mvsj)
|
||||
|
||||
#### MVSX
|
||||
|
||||
The MolViewSpec tree can also be stored in a `.mvsx` format. This is simply a ZIP archive containing:
|
||||
- main file `index.mvsj` (contains the MolViewSpec tree encoded as MVSJ),
|
||||
- any number of other files, such as MVS annotations or structure files.
|
||||
|
||||
The advantage of this format is that the main file can reference other files in the archive using relative URIs. Thus the view description along with all necessary data can be stored as a single MVSX file.
|
||||
|
||||
It is important that the `index.mvsj` be at the top level of the archive, not in a subdirectory (
|
||||
```
|
||||
$ ls example/
|
||||
annotations-1h9t.cif index.mvsj
|
||||
$ zip -r example.mvsx example/ # Wrong, won't create a valid MVSX file
|
||||
$ cd example/; zip -r ../example.mvsx * # Correct
|
||||
```
|
||||
|
||||
Example: [1ht9.mvsx](../../../examples/mvs/1h9t.mvsx)
|
||||
|
||||
|
||||
## MolViewSpec extension functionality
|
||||
|
||||
@@ -75,20 +95,24 @@ Mol* MolViewSpec extension provides functionality for building, validating, and
|
||||
|
||||
### Graphical user interface
|
||||
|
||||
- **Drag&drop support:** The easiest way to load a MVS view into Mol* Viewer is to drag a `.mvsj` file and drop it in a browser window with Mol* Viewer.
|
||||
- **Drag&drop support:** The easiest way to load a MVS view into Mol* Viewer is to drag a `.mvsj` or `.mvsx` file and drop it in a browser window with Mol* Viewer.
|
||||
|
||||
- **Load via menu:** Another way to load a MVS view is to use "Download File" or "Open Files" action, available in the "Home" tab in the left panel. For these actions, the "Format" parameter must be set to "MVSJ" (in the "Miscellaneous" category) or "Auto".
|
||||
- **Load via menu:** Another way to load a MVS view is to use "Download File" or "Open Files" action, available in the "Home" tab in the left panel. For these actions, the "Format" parameter must be set to "MVSJ" or "MVSX" (in the "Miscellaneous" category) or "Auto".
|
||||
|
||||
- **URL parameters:** Mol* Viewer supports `mvs-url`, `mvs-data`, and `mvs-format` URL parameters to specify a MVS view to be loaded when the viewer is initialized.
|
||||
- `mvs-url` specifies the address from which the MVS view should be retrieved.
|
||||
- `mvs-data` specifies the MVS view data directly. Keep in mind that some characters must be escaped to be used in the URL. Also beware that URLs longer than 2000 character may not work in all browsers.
|
||||
- `mvs-format` specifies the format of the MVS view data (from `mvs-url` or `mvs-data`). The only allowed (and default) value is `mvsj`, as this is currently the only supported format.
|
||||
- `mvs-data` specifies the MVS view data directly. Keep in mind that some characters must be escaped to be used in the URL. Also beware that URLs longer than 2000 character may not work in all browsers. Because of these limitations, the preferred method it to host the data somewhere and use `mvs-url` instead.
|
||||
- `mvs-format` specifies the format of the MVS view data from `mvs-url` or `mvs-data`. Allowed values are `mvsj` and `mvsx` (default is `mvsj`).
|
||||
|
||||
Examples of URL parameter usage:
|
||||
|
||||
- https://molstar.org/viewer?mvs-format=mvsj&mvs-url=https://raw.githubusercontent.com/molstar/molstar/master/examples/mvs/1cbs.mvsj
|
||||
- https://molstar.org/viewer/?mvs-format=mvsj&mvs-url=https://raw.githubusercontent.com/molstar/molstar/master/examples/mvs/1cbs.mvsj
|
||||
|
||||
- https://molstar.org/viewer?mvs-format=mvsj&mvs-data=%7B%22metadata%22%3A%7B%22title%22%3A%22Example%20MolViewSpec%20-%201cbs%20with%20labelled%20protein%20and%20ligand%22%2C%22version%22%3A%221%22%2C%22timestamp%22%3A%222023-11-24T10%3A38%3A17.483%22%7D%2C%22root%22%3A%7B%22kind%22%3A%22root%22%2C%22children%22%3A%5B%7B%22kind%22%3A%22download%22%2C%22params%22%3A%7B%22url%22%3A%22https%3A//www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22parse%22%2C%22params%22%3A%7B%22format%22%3A%22bcif%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22structure%22%2C%22params%22%3A%7B%22type%22%3A%22model%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22component%22%2C%22params%22%3A%7B%22selector%22%3A%22polymer%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22representation%22%2C%22params%22%3A%7B%22type%22%3A%22cartoon%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22color%22%2C%22params%22%3A%7B%22color%22%3A%22green%22%7D%7D%2C%7B%22kind%22%3A%22color%22%2C%22params%22%3A%7B%22selector%22%3A%7B%22label_asym_id%22%3A%22A%22%2C%22beg_label_seq_id%22%3A1%2C%22end_label_seq_id%22%3A50%7D%2C%22color%22%3A%22%236688ff%22%7D%7D%5D%7D%2C%7B%22kind%22%3A%22label%22%2C%22params%22%3A%7B%22text%22%3A%22Protein%22%7D%7D%5D%7D%2C%7B%22kind%22%3A%22component%22%2C%22params%22%3A%7B%22selector%22%3A%22ligand%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22representation%22%2C%22params%22%3A%7B%22type%22%3A%22ball_and_stick%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22color%22%2C%22params%22%3A%7B%22color%22%3A%22%23cc3399%22%7D%7D%5D%7D%2C%7B%22kind%22%3A%22label%22%2C%22params%22%3A%7B%22text%22%3A%22Retinoic%20Acid%22%7D%7D%5D%7D%5D%7D%5D%7D%5D%7D%2C%7B%22kind%22%3A%22canvas%22%2C%22params%22%3A%7B%22background_color%22%3A%22%23ffffee%22%7D%7D%2C%7B%22kind%22%3A%22camera%22%2C%22params%22%3A%7B%22target%22%3A%5B17%2C21%2C27%5D%2C%22position%22%3A%5B41%2C34%2C69%5D%2C%22up%22%3A%5B-0.129%2C0.966%2C-0.224%5D%7D%7D%5D%7D%7D
|
||||
- https://molstar.org/viewer/?mvs-format=mvsx&mvs-url=https://raw.githubusercontent.com/molstar/molstar/master/examples/mvs/1h9t.mvsx
|
||||
|
||||
- https://molstar.org/viewer/?mvs-format=mvsj&mvs-data=%7B%22metadata%22%3A%7B%22title%22%3A%22Example%20MolViewSpec%20-%201cbs%20with%20labelled%20protein%20and%20ligand%22%2C%22version%22%3A%221%22%2C%22timestamp%22%3A%222023-11-24T10%3A38%3A17.483%22%7D%2C%22root%22%3A%7B%22kind%22%3A%22root%22%2C%22children%22%3A%5B%7B%22kind%22%3A%22download%22%2C%22params%22%3A%7B%22url%22%3A%22https%3A//www.ebi.ac.uk/pdbe/entry-files/1cbs.bcif%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22parse%22%2C%22params%22%3A%7B%22format%22%3A%22bcif%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22structure%22%2C%22params%22%3A%7B%22type%22%3A%22model%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22component%22%2C%22params%22%3A%7B%22selector%22%3A%22polymer%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22representation%22%2C%22params%22%3A%7B%22type%22%3A%22cartoon%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22color%22%2C%22params%22%3A%7B%22color%22%3A%22green%22%7D%7D%2C%7B%22kind%22%3A%22color%22%2C%22params%22%3A%7B%22selector%22%3A%7B%22label_asym_id%22%3A%22A%22%2C%22beg_label_seq_id%22%3A1%2C%22end_label_seq_id%22%3A50%7D%2C%22color%22%3A%22%236688ff%22%7D%7D%5D%7D%2C%7B%22kind%22%3A%22label%22%2C%22params%22%3A%7B%22text%22%3A%22Protein%22%7D%7D%5D%7D%2C%7B%22kind%22%3A%22component%22%2C%22params%22%3A%7B%22selector%22%3A%22ligand%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22representation%22%2C%22params%22%3A%7B%22type%22%3A%22ball_and_stick%22%7D%2C%22children%22%3A%5B%7B%22kind%22%3A%22color%22%2C%22params%22%3A%7B%22color%22%3A%22%23cc3399%22%7D%7D%5D%7D%2C%7B%22kind%22%3A%22label%22%2C%22params%22%3A%7B%22text%22%3A%22Retinoic%20Acid%22%7D%7D%5D%7D%5D%7D%5D%7D%5D%7D%2C%7B%22kind%22%3A%22canvas%22%2C%22params%22%3A%7B%22background_color%22%3A%22%23ffffee%22%7D%7D%2C%7B%22kind%22%3A%22camera%22%2C%22params%22%3A%7B%22target%22%3A%5B17%2C21%2C27%5D%2C%22position%22%3A%5B41%2C34%2C69%5D%2C%22up%22%3A%5B-0.129%2C0.966%2C-0.224%5D%7D%7D%5D%7D%7D
|
||||
|
||||
- https://molstar.org/viewer/?mvs-format=mvsx&mvs-data=base64,UEsDBBQAAAAIADSFPlhDx8RXYwEAAGwFAAAUABwAYW5ub3RhdGlvbnMtMWg5dC5jaWZVVAkAA8MmuWVuvbtldXgLAAEE9gEAAAQUAAAAlZJNj4IwEIbv/RVNPPSkacGPckT8TDabPe6emkq72ARbF9iD/34LFBV1FSbh7YTh4Z1hELzgjOyDgnGtTcELZXQOQGrMkQEWm8PRaKmLfJTynUwZz08HpkSrck5BCD8yU0ilwfycRXDxHoJFpUu4NqkAm/pYwWifmkwJCdaXdHtJmy6uOrtt47q0kwmry7n8uatKLZ5UY2M9Hzi1byWZ+T2WbAhtBPaiPoRoIMR0ijGyqZ1yuFNaKJ0geI5RBdAxhJ5PSgBjSmsgjE/pMDIhbFEj+wFbDnHcAP85zO8dKH3mEFWHEzQgBGPOnQP8vHp347BoA6KKBvh6ACzbwLeNeoZy/XfPW2DTF1i1AYyFqIHmH0I3wLovsO0LlJuezJygTDZ9ozeVcC2aLcBcFSVLKmA6c9IRIB5x8hrwamDipDMQOOkKzKiT14BfAh72S+nY0rzf0OMa6D60A7oPXQF9Zh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E9gEAAAQUAAAAUEsBAh4DFAAAAAgAmoBBWIYJ/AiRAgAAGxUAAAoAGAAAAAAAAQAAAKSBsQEAAGluZGV4Lm12c2pVVAUAAyTBu2V1eAsAAQT2AQAABBQAAABQSwUGAAAAAAIAAgCqAAAAhgQAAAAA
|
||||
|
||||
|
||||
### Programming interface
|
||||
@@ -126,7 +150,7 @@ const mvsData2: MVSData = builder.getState();
|
||||
await loadMVS(this.plugin, mvsData2, { replaceExisting: false });
|
||||
```
|
||||
|
||||
When using the pre-built Mol* plugin bundle, `MVSData` and `loadMVS` are exposed as `molstar.PluginExtensions.mvs.MVSData` and `molstar.PluginExtensions.mvs.loadMVS`. Furthermore, the `molstar.Viewer` class has `loadMvsFromUrl` and `loadMvsData` methods, providing the same functionality as `mvs-url` and `mvs-data` URL parameters.
|
||||
When using the pre-built Mol* plugin bundle, `MVSData` and `loadMVS` are exposed as `molstar.PluginExtensions.mvs.MVSData` and `molstar.PluginExtensions.mvs.loadMVS`. Furthermore, the `molstar.Viewer` class has `loadMvsFromUrl` and `loadMvsData` methods, providing the same functionality as `mvs-url` and `mvs-data` URL parameters. See the [integration examples](./integration-examples.html) page for a demonstration.
|
||||
|
||||
|
||||
### Command-line utilities
|
||||
|
||||
@@ -101,6 +101,8 @@ assuming that the JSON annotation file shown in the previous section is availabl
|
||||
|
||||
The `uri` parameter can also hold a URI reference (relative URI). In such cases, this URI reference is relative to the URI of the MVS file itself (e.g. if the MVS file is available from `https://example.org/spanish/inquisition/expectations.mvsj`, then the relative URI `./annotations.json` is equivalent to `https://example.org/spanish/inquisition/annotations.json`). This is however not applicable in all cases (e.g. the MVS tree can be constructed ad-hoc within a web application, therefore it has no URI; or the MVS file is loaded from a local disk using drag&drop, therefore the relative location is not accessible by the browser).
|
||||
|
||||
A special case is when the MVS tree is saved in MVSX format. An MVSX file is a ZIP archive containing the MVS tree in `index.mvsj` and possibly other files. In this case, the relative URIs will resolve to the files within the archive (e.g. `./annotations.json` points to the file `annotations.json` stored in the MSVX archive).
|
||||
|
||||
### From source
|
||||
|
||||
The MVS annotations can in fact be stored within the same mmCIF file from which the structure coordinates are loaded. To reference these annotations, we can use `color_from_source`, `label_from_source`, `tooltip_from_source`, and `component_from_source` nodes. Example:
|
||||
|
||||
112
docs/extensions/mvs/integration-examples.html
Normal file
112
docs/extensions/mvs/integration-examples.html
Normal file
@@ -0,0 +1,112 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<!-- Replace "latest" by the specific version you want to use, e.g. "4.0.0" -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/molstar@latest/build/viewer/molstar.js"></script>
|
||||
<!-- Replace "latest" by the specific version you want to use, e.g. "4.0.0" -->
|
||||
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/molstar@latest/build/viewer/molstar.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Integration of Mol* with MolViewSpec Extension</h1>
|
||||
<p>
|
||||
This page demonstrates several methods to integrate Mol* Viewer in a web page and use MolViewSpec functionality.
|
||||
See the source HTML to see the actual code.
|
||||
</p>
|
||||
|
||||
|
||||
<h2>Method 1: Get MVS view from a server and pass to the viewer</h2>
|
||||
<p>
|
||||
The recommended method is to serve the MVS view files by your server (either as static files or generated by the
|
||||
server on-demand) and call the <code>loadMvsFromUrl</code> method to retrieve and load them.
|
||||
This example uses a MVS view file from the address specified in the <code>sourceUrl</code> variable.
|
||||
If the MVS view file contains relative references, they will be resolved as relative to <code>sourceUrl</code>.
|
||||
</p>
|
||||
|
||||
<div id="viewer1" style="position: relative; width: 500px; height: 500px;"></div>
|
||||
<script>
|
||||
const sourceUrl = 'https://raw.githubusercontent.com/molstar/molstar/master/examples/mvs/1h9t_domain_labels.mvsj';
|
||||
molstar.Viewer.create('viewer1', { layoutIsExpanded: false, layoutShowControls: false })
|
||||
.then(viewer => viewer.loadMvsFromUrl(sourceUrl, 'mvsj'));
|
||||
</script>
|
||||
|
||||
|
||||
<p>
|
||||
A variation of this method uses <code>molstar.PluginExtensions.mvs.loadMVS</code> instead of
|
||||
<code>loadMvsFromUrl</code> and allows replacing the MVS view after it has been loaded.
|
||||
</p>
|
||||
|
||||
<div id="viewer1b" style="position: relative; width: 500px; height: 500px;"></div>
|
||||
<button onclick="loadView1();">View 1</button>
|
||||
<button onclick="loadView2();">View 2</button>
|
||||
<script>
|
||||
let theViewer;
|
||||
function load(viewer, url, replace) {
|
||||
fetch(url)
|
||||
.then(response => response.text())
|
||||
.then(text => molstar.PluginExtensions.mvs.MVSData.fromMVSJ(text))
|
||||
.then(mvsData => molstar.PluginExtensions.mvs.loadMVS(viewer.plugin, mvsData, { sourceUrl: url, sanityChecks: true, replaceExisting: replace }));
|
||||
}
|
||||
function loadView1() {
|
||||
load(theViewer, 'https://raw.githubusercontent.com/molstar/molstar/master/examples/mvs/1cbs.mvsj', true);
|
||||
}
|
||||
function loadView2() {
|
||||
load(theViewer, 'https://raw.githubusercontent.com/molstar/molstar/master/examples/mvs/1cbs-focus.mvsj', true);
|
||||
}
|
||||
molstar.Viewer.create('viewer1b', { layoutIsExpanded: false, layoutShowControls: false })
|
||||
.then(viewer => {
|
||||
theViewer = viewer;
|
||||
loadView1();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<h2>Method 2: Construct MVS view on frontend and pass to the viewer</h2>
|
||||
<p>
|
||||
Another option is to utilize the MVS builder provided by the extension to build the view on frontend and then
|
||||
pass it to the viewer. This example builds the view in plain JavaScript, directly in a <script> tag in
|
||||
HTML. However, for a better developer experience consider writing the code in TypeScript.
|
||||
If the built MVS view contains relative references, they will be resolved as relative to the URL of this HTML
|
||||
page.
|
||||
</p>
|
||||
|
||||
<div id="viewer2" style="position: relative; width: 500px; height: 500px;"></div>
|
||||
<script>
|
||||
// Build an ad-hoc MVS view
|
||||
const builder = molstar.PluginExtensions.mvs.MVSData.createBuilder();
|
||||
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: 'ligand' })
|
||||
.label({ text: 'Retinoic acid' })
|
||||
.focus({})
|
||||
.representation({ type: 'ball_and_stick' })
|
||||
.color({ color: '#cc3399' });
|
||||
const mvsData = builder.getState();
|
||||
|
||||
// Initialize viewer and load MVSJ
|
||||
const mvsj = molstar.PluginExtensions.mvs.MVSData.toMVSJ(mvsData);
|
||||
molstar.Viewer.create('viewer2', { layoutIsExpanded: false, layoutShowControls: false })
|
||||
.then(viewer => viewer.loadMvsData(mvsj, 'mvsj'));
|
||||
|
||||
// // Alternative initialization and loading (avoids encoding and again decoding the data, allows changing the view by using `replaceExisting: true`):
|
||||
// molstar.Viewer.create('viewer2', { layoutIsExpanded: false, layoutShowControls: false })
|
||||
// .then(viewer => molstar.PluginExtensions.mvs.loadMVS(viewer.plugin, mvsData, { sourceUrl: undefined, sanityChecks: true, replaceExisting: false }));
|
||||
</script>
|
||||
|
||||
|
||||
<p>
|
||||
Again, there is variation with using <code>molstar.PluginExtensions.mvs.loadMVS</code> instead of
|
||||
<code>loadMvsData</code>.
|
||||
</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user