app.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /**
  2. * Copyright (c) 2018-2022 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. import { ANVILMembraneOrientation } from '../../extensions/anvil/behavior';
  8. import { CellPack } from '../../extensions/cellpack';
  9. import { DnatcoConfalPyramids } from '../../extensions/dnatco';
  10. import { G3DFormat, G3dProvider } from '../../extensions/g3d/format';
  11. import { Volseg } from '../../extensions/volumes-and-segmentations';
  12. import { GeometryExport } from '../../extensions/geo-export';
  13. import { MAQualityAssessment } from '../../extensions/model-archive/quality-assessment/behavior';
  14. import { QualityAssessmentPLDDTPreset, QualityAssessmentQmeanPreset } from '../../extensions/model-archive/quality-assessment/behavior';
  15. import { QualityAssessment } from '../../extensions/model-archive/quality-assessment/prop';
  16. import { ModelExport } from '../../extensions/model-export';
  17. import { Mp4Export } from '../../extensions/mp4-export';
  18. import { PDBeStructureQualityReport } from '../../extensions/pdbe';
  19. import { RCSBAssemblySymmetry, RCSBValidationReport } from '../../extensions/rcsb';
  20. import { ZenodoImport } from '../../extensions/zenodo';
  21. import { Volume } from '../../mol-model/volume';
  22. import { DownloadStructure, PdbDownloadProvider } from '../../mol-plugin-state/actions/structure';
  23. import { DownloadDensity } from '../../mol-plugin-state/actions/volume';
  24. import { PresetTrajectoryHierarchy } from '../../mol-plugin-state/builder/structure/hierarchy-preset';
  25. import { PresetStructureRepresentations, StructureRepresentationPresetProvider } from '../../mol-plugin-state/builder/structure/representation-preset';
  26. import { DataFormatProvider } from '../../mol-plugin-state/formats/provider';
  27. import { BuiltInTopologyFormat } from '../../mol-plugin-state/formats/topology';
  28. import { BuiltInCoordinatesFormat } from '../../mol-plugin-state/formats/coordinates';
  29. import { BuiltInTrajectoryFormat } from '../../mol-plugin-state/formats/trajectory';
  30. import { BuildInVolumeFormat } from '../../mol-plugin-state/formats/volume';
  31. import { createVolumeRepresentationParams } from '../../mol-plugin-state/helpers/volume-representation-params';
  32. import { PluginStateObject } from '../../mol-plugin-state/objects';
  33. import { StateTransforms } from '../../mol-plugin-state/transforms';
  34. import { TrajectoryFromModelAndCoordinates } from '../../mol-plugin-state/transforms/model';
  35. import { createPluginUI } from '../../mol-plugin-ui/react18';
  36. import { PluginUIContext } from '../../mol-plugin-ui/context';
  37. import { DefaultPluginUISpec, PluginUISpec } from '../../mol-plugin-ui/spec';
  38. import { PluginCommands } from '../../mol-plugin/commands';
  39. import { PluginConfig } from '../../mol-plugin/config';
  40. import { PluginLayoutControlsDisplay } from '../../mol-plugin/layout';
  41. import { PluginSpec } from '../../mol-plugin/spec';
  42. import { PluginState } from '../../mol-plugin/state';
  43. import { StateObjectRef, StateObjectSelector } from '../../mol-state';
  44. import { Asset } from '../../mol-util/assets';
  45. import { Color } from '../../mol-util/color';
  46. import '../../mol-util/polyfill';
  47. import { ObjectKeys } from '../../mol-util/type-helpers';
  48. import { SaccharideCompIdMapType } from '../../mol-model/structure/structure/carbohydrates/constants';
  49. import { Backgrounds } from '../../extensions/backgrounds';
  50. export { PLUGIN_VERSION as version } from '../../mol-plugin/version';
  51. export { setDebugMode, setProductionMode, setTimingMode } from '../../mol-util/debug';
  52. const CustomFormats = [
  53. ['g3d', G3dProvider] as const
  54. ];
  55. const Extensions = {
  56. 'volseg': PluginSpec.Behavior(Volseg),
  57. 'backgrounds': PluginSpec.Behavior(Backgrounds),
  58. 'cellpack': PluginSpec.Behavior(CellPack),
  59. 'dnatco-confal-pyramids': PluginSpec.Behavior(DnatcoConfalPyramids),
  60. 'pdbe-structure-quality-report': PluginSpec.Behavior(PDBeStructureQualityReport),
  61. 'rcsb-assembly-symmetry': PluginSpec.Behavior(RCSBAssemblySymmetry),
  62. 'rcsb-validation-report': PluginSpec.Behavior(RCSBValidationReport),
  63. 'anvil-membrane-orientation': PluginSpec.Behavior(ANVILMembraneOrientation),
  64. 'g3d': PluginSpec.Behavior(G3DFormat),
  65. 'model-export': PluginSpec.Behavior(ModelExport),
  66. 'mp4-export': PluginSpec.Behavior(Mp4Export),
  67. 'geo-export': PluginSpec.Behavior(GeometryExport),
  68. 'ma-quality-assessment': PluginSpec.Behavior(MAQualityAssessment),
  69. 'zenodo-import': PluginSpec.Behavior(ZenodoImport),
  70. };
  71. const DefaultViewerOptions = {
  72. customFormats: CustomFormats as [string, DataFormatProvider][],
  73. extensions: ObjectKeys(Extensions),
  74. layoutIsExpanded: true,
  75. layoutShowControls: true,
  76. layoutShowRemoteState: true,
  77. layoutControlsDisplay: 'reactive' as PluginLayoutControlsDisplay,
  78. layoutShowSequence: true,
  79. layoutShowLog: true,
  80. layoutShowLeftPanel: true,
  81. collapseLeftPanel: false,
  82. collapseRightPanel: false,
  83. disableAntialiasing: PluginConfig.General.DisableAntialiasing.defaultValue,
  84. pixelScale: PluginConfig.General.PixelScale.defaultValue,
  85. pickScale: PluginConfig.General.PickScale.defaultValue,
  86. pickPadding: PluginConfig.General.PickPadding.defaultValue,
  87. enableWboit: PluginConfig.General.EnableWboit.defaultValue,
  88. enableDpoit: PluginConfig.General.EnableDpoit.defaultValue,
  89. preferWebgl1: PluginConfig.General.PreferWebGl1.defaultValue,
  90. allowMajorPerformanceCaveat: PluginConfig.General.AllowMajorPerformanceCaveat.defaultValue,
  91. powerPreference: PluginConfig.General.PowerPreference.defaultValue,
  92. viewportShowExpand: PluginConfig.Viewport.ShowExpand.defaultValue,
  93. viewportShowControls: PluginConfig.Viewport.ShowControls.defaultValue,
  94. viewportShowSettings: PluginConfig.Viewport.ShowSettings.defaultValue,
  95. viewportShowSelectionMode: PluginConfig.Viewport.ShowSelectionMode.defaultValue,
  96. viewportShowAnimation: PluginConfig.Viewport.ShowAnimation.defaultValue,
  97. viewportShowTrajectoryControls: PluginConfig.Viewport.ShowTrajectoryControls.defaultValue,
  98. pluginStateServer: PluginConfig.State.DefaultServer.defaultValue,
  99. volumeStreamingServer: PluginConfig.VolumeStreaming.DefaultServer.defaultValue,
  100. volumeStreamingDisabled: !PluginConfig.VolumeStreaming.Enabled.defaultValue,
  101. pdbProvider: PluginConfig.Download.DefaultPdbProvider.defaultValue,
  102. emdbProvider: PluginConfig.Download.DefaultEmdbProvider.defaultValue,
  103. saccharideCompIdMapType: 'default' as SaccharideCompIdMapType,
  104. };
  105. type ViewerOptions = typeof DefaultViewerOptions;
  106. export class Viewer {
  107. constructor(public plugin: PluginUIContext) {
  108. }
  109. static async create(elementOrId: string | HTMLElement, options: Partial<ViewerOptions> = {}) {
  110. const definedOptions = {} as any;
  111. // filter for defined properies only so the default values
  112. // are property applied
  113. for (const p of Object.keys(options) as (keyof ViewerOptions)[]) {
  114. if (options[p] !== void 0) definedOptions[p] = options[p];
  115. }
  116. const o: ViewerOptions = { ...DefaultViewerOptions, ...definedOptions };
  117. const defaultSpec = DefaultPluginUISpec();
  118. const spec: PluginUISpec = {
  119. actions: defaultSpec.actions,
  120. behaviors: [
  121. ...defaultSpec.behaviors,
  122. ...o.extensions.map(e => Extensions[e]),
  123. ],
  124. animations: [...defaultSpec.animations || []],
  125. customParamEditors: defaultSpec.customParamEditors,
  126. customFormats: o?.customFormats,
  127. layout: {
  128. initial: {
  129. isExpanded: o.layoutIsExpanded,
  130. showControls: o.layoutShowControls,
  131. controlsDisplay: o.layoutControlsDisplay,
  132. regionState: {
  133. bottom: 'full',
  134. left: o.collapseLeftPanel ? 'collapsed' : 'full',
  135. right: o.collapseRightPanel ? 'hidden' : 'full',
  136. top: 'full',
  137. }
  138. },
  139. },
  140. components: {
  141. ...defaultSpec.components,
  142. controls: {
  143. ...defaultSpec.components?.controls,
  144. top: o.layoutShowSequence ? undefined : 'none',
  145. bottom: o.layoutShowLog ? undefined : 'none',
  146. left: o.layoutShowLeftPanel ? undefined : 'none',
  147. },
  148. remoteState: o.layoutShowRemoteState ? 'default' : 'none',
  149. },
  150. config: [
  151. [PluginConfig.General.DisableAntialiasing, o.disableAntialiasing],
  152. [PluginConfig.General.PixelScale, o.pixelScale],
  153. [PluginConfig.General.PickScale, o.pickScale],
  154. [PluginConfig.General.PickPadding, o.pickPadding],
  155. [PluginConfig.General.EnableWboit, o.enableWboit],
  156. [PluginConfig.General.EnableDpoit, o.enableDpoit],
  157. [PluginConfig.General.PreferWebGl1, o.preferWebgl1],
  158. [PluginConfig.General.AllowMajorPerformanceCaveat, o.allowMajorPerformanceCaveat],
  159. [PluginConfig.General.PowerPreference, o.powerPreference],
  160. [PluginConfig.Viewport.ShowExpand, o.viewportShowExpand],
  161. [PluginConfig.Viewport.ShowControls, o.viewportShowControls],
  162. [PluginConfig.Viewport.ShowSettings, o.viewportShowSettings],
  163. [PluginConfig.Viewport.ShowSelectionMode, o.viewportShowSelectionMode],
  164. [PluginConfig.Viewport.ShowAnimation, o.viewportShowAnimation],
  165. [PluginConfig.Viewport.ShowTrajectoryControls, o.viewportShowTrajectoryControls],
  166. [PluginConfig.State.DefaultServer, o.pluginStateServer],
  167. [PluginConfig.State.CurrentServer, o.pluginStateServer],
  168. [PluginConfig.VolumeStreaming.DefaultServer, o.volumeStreamingServer],
  169. [PluginConfig.VolumeStreaming.Enabled, !o.volumeStreamingDisabled],
  170. [PluginConfig.Download.DefaultPdbProvider, o.pdbProvider],
  171. [PluginConfig.Download.DefaultEmdbProvider, o.emdbProvider],
  172. [PluginConfig.Structure.DefaultRepresentationPreset, ViewerAutoPreset.id],
  173. [PluginConfig.Structure.SaccharideCompIdMapType, o.saccharideCompIdMapType],
  174. ]
  175. };
  176. const element = typeof elementOrId === 'string'
  177. ? document.getElementById(elementOrId)
  178. : elementOrId;
  179. if (!element) throw new Error(`Could not get element with id '${elementOrId}'`);
  180. const plugin = await createPluginUI(element, spec, {
  181. onBeforeUIRender: plugin => {
  182. // the preset needs to be added before the UI renders otherwise
  183. // "Download Structure" wont be able to pick it up
  184. plugin.builders.structure.representation.registerPreset(ViewerAutoPreset);
  185. }
  186. });
  187. return new Viewer(plugin);
  188. }
  189. setRemoteSnapshot(id: string) {
  190. const url = `${this.plugin.config.get(PluginConfig.State.CurrentServer)}/get/${id}`;
  191. return PluginCommands.State.Snapshots.Fetch(this.plugin, { url });
  192. }
  193. loadSnapshotFromUrl(url: string, type: PluginState.SnapshotType) {
  194. return PluginCommands.State.Snapshots.OpenUrl(this.plugin, { url, type });
  195. }
  196. loadStructureFromUrl(url: string, format: BuiltInTrajectoryFormat = 'mmcif', isBinary = false, options?: LoadStructureOptions & { label?: string }) {
  197. const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
  198. return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
  199. source: {
  200. name: 'url',
  201. params: {
  202. url: Asset.Url(url),
  203. format: format as any,
  204. isBinary,
  205. label: options?.label,
  206. options: { ...params.source.params.options, representationParams: options?.representationParams as any },
  207. }
  208. }
  209. }));
  210. }
  211. async loadAllModelsOrAssemblyFromUrl(url: string, format: BuiltInTrajectoryFormat = 'mmcif', isBinary = false, options?: LoadStructureOptions) {
  212. const plugin = this.plugin;
  213. const data = await plugin.builders.data.download({ url, isBinary }, { state: { isGhost: true } });
  214. const trajectory = await plugin.builders.structure.parseTrajectory(data, format);
  215. await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, 'all-models', { useDefaultIfSingleModel: true, representationPresetParams: options?.representationParams });
  216. }
  217. async loadStructureFromData(data: string | number[], format: BuiltInTrajectoryFormat, options?: { dataLabel?: string }) {
  218. const _data = await this.plugin.builders.data.rawData({ data, label: options?.dataLabel });
  219. const trajectory = await this.plugin.builders.structure.parseTrajectory(_data, format);
  220. await this.plugin.builders.structure.hierarchy.applyPreset(trajectory, 'default');
  221. }
  222. loadPdb(pdb: string, options?: LoadStructureOptions) {
  223. const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
  224. const provider = this.plugin.config.get(PluginConfig.Download.DefaultPdbProvider)!;
  225. return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
  226. source: {
  227. name: 'pdb' as const,
  228. params: {
  229. provider: {
  230. id: pdb,
  231. server: {
  232. name: provider,
  233. params: PdbDownloadProvider[provider].defaultValue as any
  234. }
  235. },
  236. options: { ...params.source.params.options, representationParams: options?.representationParams as any },
  237. }
  238. }
  239. }));
  240. }
  241. loadPdbDev(pdbDev: string) {
  242. const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
  243. return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
  244. source: {
  245. name: 'pdb-dev' as const,
  246. params: {
  247. provider: {
  248. id: pdbDev,
  249. encoding: 'bcif',
  250. },
  251. options: params.source.params.options,
  252. }
  253. }
  254. }));
  255. }
  256. loadEmdb(emdb: string, options?: { detail?: number }) {
  257. const provider = this.plugin.config.get(PluginConfig.Download.DefaultEmdbProvider)!;
  258. return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadDensity, {
  259. source: {
  260. name: 'pdb-emd-ds' as const,
  261. params: {
  262. provider: {
  263. id: emdb,
  264. server: provider,
  265. },
  266. detail: options?.detail ?? 3,
  267. }
  268. }
  269. }));
  270. }
  271. loadAlphaFoldDb(afdb: string) {
  272. const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
  273. return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
  274. source: {
  275. name: 'alphafolddb' as const,
  276. params: {
  277. id: afdb,
  278. options: {
  279. ...params.source.params.options,
  280. representation: 'preset-structure-representation-ma-quality-assessment-plddt'
  281. },
  282. }
  283. }
  284. }));
  285. }
  286. loadModelArchive(id: string) {
  287. const params = DownloadStructure.createDefaultParams(this.plugin.state.data.root.obj!, this.plugin);
  288. return this.plugin.runTask(this.plugin.state.data.applyAction(DownloadStructure, {
  289. source: {
  290. name: 'modelarchive' as const,
  291. params: {
  292. id,
  293. options: params.source.params.options,
  294. }
  295. }
  296. }));
  297. }
  298. /**
  299. * @example Load X-ray density from volume server
  300. viewer.loadVolumeFromUrl({
  301. url: 'https://www.ebi.ac.uk/pdbe/densities/x-ray/1tqn/cell?detail=3',
  302. format: 'dscif',
  303. isBinary: true
  304. }, [{
  305. type: 'relative',
  306. value: 1.5,
  307. color: 0x3362B2
  308. }, {
  309. type: 'relative',
  310. value: 3,
  311. color: 0x33BB33,
  312. volumeIndex: 1
  313. }, {
  314. type: 'relative',
  315. value: -3,
  316. color: 0xBB3333,
  317. volumeIndex: 1
  318. }], {
  319. entryId: ['2FO-FC', 'FO-FC'],
  320. isLazy: true
  321. });
  322. * *********************
  323. * @example Load EM density from volume server
  324. viewer.loadVolumeFromUrl({
  325. url: 'https://maps.rcsb.org/em/emd-30210/cell?detail=6',
  326. format: 'dscif',
  327. isBinary: true
  328. }, [{
  329. type: 'relative',
  330. value: 1,
  331. color: 0x3377aa
  332. }], {
  333. entryId: 'EMD-30210',
  334. isLazy: true
  335. });
  336. */
  337. async loadVolumeFromUrl({ url, format, isBinary }: { url: string, format: BuildInVolumeFormat, isBinary: boolean }, isovalues: VolumeIsovalueInfo[], options?: { entryId?: string | string[], isLazy?: boolean }) {
  338. const plugin = this.plugin;
  339. if (!plugin.dataFormats.get(format)) {
  340. throw new Error(`Unknown density format: ${format}`);
  341. }
  342. if (options?.isLazy) {
  343. const update = this.plugin.build();
  344. update.toRoot().apply(StateTransforms.Data.LazyVolume, {
  345. url,
  346. format,
  347. entryId: options?.entryId,
  348. isBinary,
  349. isovalues: isovalues.map(v => ({ alpha: 1, volumeIndex: 0, ...v }))
  350. });
  351. return update.commit();
  352. }
  353. return plugin.dataTransaction(async () => {
  354. const data = await plugin.builders.data.download({ url, isBinary }, { state: { isGhost: true } });
  355. const parsed = await plugin.dataFormats.get(format)!.parse(plugin, data, { entryId: options?.entryId });
  356. const firstVolume = (parsed.volume || parsed.volumes[0]) as StateObjectSelector<PluginStateObject.Volume.Data>;
  357. if (!firstVolume?.isOk) throw new Error('Failed to parse any volume.');
  358. const repr = plugin.build();
  359. for (const iso of isovalues) {
  360. const volume: StateObjectSelector<PluginStateObject.Volume.Data> = parsed.volumes?.[iso.volumeIndex ?? 0] ?? parsed.volume;
  361. const volumeData = volume.cell!.obj!.data;
  362. repr
  363. .to(volume)
  364. .apply(StateTransforms.Representation.VolumeRepresentation3D, createVolumeRepresentationParams(this.plugin, firstVolume.data!, {
  365. type: 'isosurface',
  366. typeParams: { alpha: iso.alpha ?? 1, isoValue: Volume.adjustedIsoValue(volumeData, iso.value, iso.type) },
  367. color: 'uniform',
  368. colorParams: { value: iso.color }
  369. }));
  370. }
  371. await repr.commit();
  372. });
  373. }
  374. /**
  375. * @example
  376. * viewer.loadTrajectory({
  377. * model: { kind: 'model-url', url: 'villin.gro', format: 'gro' },
  378. * coordinates: { kind: 'coordinates-url', url: 'villin.xtc', format: 'xtc', isBinary: true },
  379. * preset: 'all-models' // or 'default'
  380. * });
  381. */
  382. async loadTrajectory(params: LoadTrajectoryParams) {
  383. const plugin = this.plugin;
  384. let model: StateObjectSelector;
  385. if (params.model.kind === 'model-data' || params.model.kind === 'model-url') {
  386. const data = params.model.kind === 'model-data'
  387. ? await plugin.builders.data.rawData({ data: params.model.data, label: params.modelLabel })
  388. : await plugin.builders.data.download({ url: params.model.url, isBinary: params.model.isBinary, label: params.modelLabel });
  389. const trajectory = await plugin.builders.structure.parseTrajectory(data, params.model.format ?? 'mmcif');
  390. model = await plugin.builders.structure.createModel(trajectory);
  391. } else {
  392. const data = params.model.kind === 'topology-data'
  393. ? await plugin.builders.data.rawData({ data: params.model.data, label: params.modelLabel })
  394. : await plugin.builders.data.download({ url: params.model.url, isBinary: params.model.isBinary, label: params.modelLabel });
  395. const provider = plugin.dataFormats.get(params.model.format);
  396. model = await provider!.parse(plugin, data);
  397. }
  398. const data = params.coordinates.kind === 'coordinates-data'
  399. ? await plugin.builders.data.rawData({ data: params.coordinates.data, label: params.coordinatesLabel })
  400. : await plugin.builders.data.download({ url: params.coordinates.url, isBinary: params.coordinates.isBinary, label: params.coordinatesLabel });
  401. const provider = plugin.dataFormats.get(params.coordinates.format);
  402. const coords = await provider!.parse(plugin, data);
  403. const trajectory = await plugin.build().toRoot()
  404. .apply(TrajectoryFromModelAndCoordinates, {
  405. modelRef: model.ref,
  406. coordinatesRef: coords.ref
  407. }, { dependsOn: [model.ref, coords.ref] })
  408. .commit();
  409. const preset = await plugin.builders.structure.hierarchy.applyPreset(trajectory, params.preset ?? 'default');
  410. return { model, coords, preset };
  411. }
  412. handleResize() {
  413. this.plugin.layout.events.updated.next(void 0);
  414. }
  415. }
  416. export interface LoadStructureOptions {
  417. representationParams?: StructureRepresentationPresetProvider.CommonParams
  418. }
  419. export interface VolumeIsovalueInfo {
  420. type: 'absolute' | 'relative',
  421. value: number,
  422. color: Color,
  423. alpha?: number,
  424. volumeIndex?: number
  425. }
  426. export interface LoadTrajectoryParams {
  427. model: { kind: 'model-url', url: string, format?: BuiltInTrajectoryFormat /* mmcif */, isBinary?: boolean }
  428. | { kind: 'model-data', data: string | number[] | ArrayBuffer | Uint8Array, format?: BuiltInTrajectoryFormat /* mmcif */ }
  429. | { kind: 'topology-url', url: string, format: BuiltInTopologyFormat, isBinary?: boolean }
  430. | { kind: 'topology-data', data: string | number[] | ArrayBuffer | Uint8Array, format: BuiltInTopologyFormat },
  431. modelLabel?: string,
  432. coordinates: { kind: 'coordinates-url', url: string, format: BuiltInCoordinatesFormat, isBinary?: boolean }
  433. | { kind: 'coordinates-data', data: string | number[] | ArrayBuffer | Uint8Array, format: BuiltInCoordinatesFormat },
  434. coordinatesLabel?: string,
  435. preset?: keyof PresetTrajectoryHierarchy
  436. }
  437. export const ViewerAutoPreset = StructureRepresentationPresetProvider({
  438. id: 'preset-structure-representation-viewer-auto',
  439. display: {
  440. name: 'Automatic (w/ Annotation)', group: 'Annotation',
  441. description: 'Show standard automatic representation but colored by quality assessment (if available in the model).'
  442. },
  443. isApplicable(a) {
  444. return (
  445. !!a.data.models.some(m => QualityAssessment.isApplicable(m, 'pLDDT')) ||
  446. !!a.data.models.some(m => QualityAssessment.isApplicable(m, 'qmean'))
  447. );
  448. },
  449. params: () => StructureRepresentationPresetProvider.CommonParams,
  450. async apply(ref, params, plugin) {
  451. const structureCell = StateObjectRef.resolveAndCheck(plugin.state.data, ref);
  452. const structure = structureCell?.obj?.data;
  453. if (!structureCell || !structure) return {};
  454. if (!!structure.models.some(m => QualityAssessment.isApplicable(m, 'pLDDT'))) {
  455. return await QualityAssessmentPLDDTPreset.apply(ref, params, plugin);
  456. } else if (!!structure.models.some(m => QualityAssessment.isApplicable(m, 'qmean'))) {
  457. return await QualityAssessmentQmeanPreset.apply(ref, params, plugin);
  458. } else {
  459. return await PresetStructureRepresentations.auto.apply(ref, params, plugin);
  460. }
  461. }
  462. });