stage.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /**
  2. * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import Viewer from './viewer'
  7. import { StateContext } from './state/context';
  8. import { Progress } from 'mol-task';
  9. import { MmcifUrlToModel, ModelToStructure, StructureToSpacefill, StructureToBallAndStick, StructureToDistanceRestraint, StructureToCartoon, StructureToBackbone } from './state/transform';
  10. import { UrlEntity } from './state/entity';
  11. import { SpacefillProps } from 'mol-geo/representation/structure/spacefill';
  12. import { Context } from 'mol-app/context/context';
  13. import { BallAndStickProps } from 'mol-geo/representation/structure/ball-and-stick';
  14. import { CartoonProps } from 'mol-geo/representation/structure/cartoon';
  15. import { DistanceRestraintProps } from 'mol-geo/representation/structure/distance-restraint';
  16. import { BackboneProps } from 'mol-geo/representation/structure/backbone';
  17. import { Queries as Q, StructureProperties as SP, Query, Selection } from 'mol-model/structure';
  18. const spacefillProps: SpacefillProps = {
  19. doubleSided: true,
  20. colorTheme: { name: 'chain-id' },
  21. quality: 'auto',
  22. useFog: false
  23. }
  24. const ballAndStickProps: BallAndStickProps = {
  25. doubleSided: true,
  26. colorTheme: { name: 'chain-id' },
  27. sizeTheme: { name: 'uniform', value: 0.05 },
  28. linkRadius: 0.05,
  29. quality: 'auto',
  30. useFog: false
  31. }
  32. const distanceRestraintProps: DistanceRestraintProps = {
  33. doubleSided: true,
  34. colorTheme: { name: 'chain-id' },
  35. linkRadius: 0.5,
  36. quality: 'auto',
  37. useFog: false
  38. }
  39. const backboneProps: BackboneProps = {
  40. doubleSided: true,
  41. colorTheme: { name: 'chain-id' },
  42. quality: 'auto',
  43. useFog: false
  44. }
  45. const cartoonProps: CartoonProps = {
  46. doubleSided: true,
  47. colorTheme: { name: 'chain-id' },
  48. quality: 'auto',
  49. useFog: false
  50. }
  51. export class Stage {
  52. viewer: Viewer
  53. ctx = new StateContext(Progress.format)
  54. constructor(public globalContext: Context) {
  55. }
  56. initRenderer (canvas: HTMLCanvasElement, container: HTMLDivElement) {
  57. this.viewer = Viewer.create(canvas, container)
  58. this.viewer.animate()
  59. this.ctx.viewer = this.viewer
  60. // this.loadPdbid('1jj2')
  61. // this.loadPdbid('4umt') // ligand has bond with order 3
  62. // this.loadPdbid('1crn') // small
  63. this.loadPdbid('1hrv') // viral assembly
  64. // this.loadPdbid('1rb8') // virus TODO funky inter unit bonds rendering
  65. // this.loadPdbid('1blu') // metal coordination
  66. // this.loadPdbid('3pqr') // inter unit bonds
  67. // this.loadPdbid('4v5a') // ribosome
  68. // this.loadPdbid('3j3q') // ...
  69. // this.loadPdbid('3sn6') // discontinuous chains
  70. // this.loadMmcifUrl(`../../examples/1cbs_full.bcif`)
  71. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000001.cif`) // ok
  72. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000002.cif`) // ok
  73. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000003.cif`) // ok
  74. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000004.cif`) // TODO issue with cross-link extraction
  75. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000005.cif`) // TODO only three spacefill atoms rendered
  76. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000006.cif`) // TODO only three spacefill atoms rendered
  77. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000007.cif`) // TODO only three spacefill atoms rendered
  78. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000008.cif`) // ok
  79. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000010.cif`) // ok
  80. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000011.cif`) // ok
  81. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000012.cif`) // ok
  82. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000014.cif`) // ok
  83. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000016.cif`) // TODO only three spacefill atoms rendered
  84. }
  85. async loadMmcifUrl (url: string) {
  86. const urlEntity = UrlEntity.ofUrl(this.ctx, url)
  87. const modelEntity = await MmcifUrlToModel.apply(this.ctx, urlEntity)
  88. const structureEntity = await ModelToStructure.apply(this.ctx, modelEntity)
  89. StructureToBallAndStick.apply(this.ctx, structureEntity, { ...ballAndStickProps, visible: true })
  90. StructureToSpacefill.apply(this.ctx, structureEntity, { ...spacefillProps, visible: false })
  91. StructureToDistanceRestraint.apply(this.ctx, structureEntity, { ...distanceRestraintProps, visible: false })
  92. // StructureToBackbone.apply(this.ctx, structureEntity, { ...backboneProps, visible: true })
  93. StructureToCartoon.apply(this.ctx, structureEntity, { ...cartoonProps, visible: false })
  94. this.globalContext.components.sequenceView.setState({ structure: structureEntity.value });
  95. const structureEntity2 = await ModelToStructure.apply(this.ctx, modelEntity)
  96. const q1 = Q.generators.atoms({
  97. residueTest: l => SP.residue.label_seq_id(l) > 30
  98. });
  99. structureEntity2.value = Selection.unionStructure(await Query(q1)(structureEntity2.value).run());
  100. StructureToBackbone.apply(this.ctx, structureEntity2, { ...backboneProps, visible: true })
  101. StructureToCartoon.apply(this.ctx, structureEntity2, { ...cartoonProps, visible: true })
  102. }
  103. loadPdbid (pdbid: string) {
  104. return this.loadMmcifUrl(`http://www.ebi.ac.uk/pdbe/static/entry/${pdbid}_updated.cif`)
  105. // return this.loadMmcifUrl(`https://files.rcsb.org/download/${pdbid}.cif`)
  106. }
  107. dispose () {
  108. // TODO
  109. }
  110. }