Using Mol* In Codepen
frederickparsons-tandemai opened this issue · comments
Hi Mol* team!
We've been thinking about contributing to the Mol* documentation with a set of examples similar to NGL's gallery. I've been trying to setup codepen to work with Mol* and I almost have things working but I've reached a blocker.
![image](https://private-user-images.githubusercontent.com/110400964/331750843-ab91df89-bc8a-4ed6-8443-46d8ad218711.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjA1NDM1ODIsIm5iZiI6MTcyMDU0MzI4MiwicGF0aCI6Ii8xMTA0MDA5NjQvMzMxNzUwODQzLWFiOTFkZjg5LWJjOGEtNGVkNi04NDQzLTQ2ZDhhZDIxODcxMS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcwOVQxNjQxMjJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT05ODIyZmFkMGUzMzIxNjhhNGYzMjZlMzRhN2MzYzcxMGIwZGEzNDFiMTk1YzY1ZmZiNjdjMDRjMDlkNzA2MzMzJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.Afym7WG0SFh2AwUIH6_M5UiakvuuzuXeDbV0Y0TEdqA)
https://codepen.io/frederickparsons92/pen/NWVxGyW
This is the code I've been trying to use. Basically it's failing in the call to plugin.initViewer(canvas, parent)
.
<div id='molstar-parent' style='position: absolute; top: 0; left: 0; right: 0; bottom: 0'>
<canvas id='molstar-canvas' style='position: absolute; top: 0; left: 0; right: 0; bottom: 0'></canvas>
</div>
import {
DefaultPluginSpec,
PluginSpec,
} from "https://esm.sh/molstar/lib/mol-plugin/spec";
import { PluginContext } from "https://esm.sh/molstar/lib/mol-plugin/context";
import { PluginConfig } from "https://esm.sh/molstar/lib/mol-plugin/config";
const MySpec: PluginSpec = {
...DefaultPluginSpec(),
config: [[PluginConfig.VolumeStreaming.Enabled, false]],
};
async function init() {
const plugin = new PluginContext(MySpec);
await plugin.init();
const canvas = document.getElementById("molstar-canvas");
const parent = document.getElementById("molstar-parent");
try {
plugin.initViewer(canvas, parent);
} catch (e) {
console.error("Failed to init Mol*");
}
const data = await plugin.builders.data.download(
{ url: "https://models.rcsb.org/4hhb.bcif", isBinary: true },
{ state: { isGhost: true } }
);
const trajectory = await plugin.builders.structure.parseTrajectory(
data,
"mmcif"
); //format is 'mmcif' or 'pdb' etc.
await plugin.builders.structure.hierarchy.applyPreset(trajectory, "default");
}
document.addEventListener("DOMContentLoaded", () => {
init();
});
Have you managed to get Mol* working in Codepen before? Any help here is appreciated. Hoping we can get to learn Mol* through this gallery collaboration :)
found a way: https://codepen.io/frederickparsons92/pen/bGyEpvj