58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
window.Af3MolstarViewer = {
|
|
async create(elementId) {
|
|
if (!window.molstar) {
|
|
throw new Error('Mol* 静态资源未加载');
|
|
}
|
|
const viewer = await molstar.Viewer.create(elementId, {
|
|
layoutIsExpanded: false,
|
|
layoutShowControls: false,
|
|
viewportShowExpand: true,
|
|
viewportShowControls: true,
|
|
viewportShowSettings: true,
|
|
});
|
|
|
|
return {
|
|
async load(url, representation = 'cartoon') {
|
|
const MVSData = molstar.PluginExtensions.mvs.MVSData;
|
|
const builder = MVSData.createBuilder();
|
|
const structure = builder
|
|
.download({ url })
|
|
.parse({ format: 'mmcif' })
|
|
.modelStructure();
|
|
|
|
structure
|
|
.component({ selector: { label_asym_id: 'A' } })
|
|
.representation({ type: representation })
|
|
.color({ color: '#0066cc' });
|
|
structure
|
|
.component({ selector: { label_asym_id: 'B' } })
|
|
.representation({ type: representation })
|
|
.color({ color: '#f28e00' });
|
|
builder.canvas({ background_color: '#ffffff' });
|
|
|
|
await molstar.PluginExtensions.mvs.loadMVS(
|
|
viewer.plugin,
|
|
builder.getState(),
|
|
{
|
|
sourceUrl: undefined,
|
|
sanityChecks: true,
|
|
replaceExisting: true,
|
|
},
|
|
);
|
|
},
|
|
|
|
resetCamera() {
|
|
viewer.plugin.canvas3d?.requestCameraReset();
|
|
},
|
|
|
|
dispose() {
|
|
viewer.plugin.dispose();
|
|
},
|
|
};
|
|
},
|
|
};
|
|
})();
|