stage.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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, StructureCenter } 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. // colorTheme: { name: 'uniform', value: 0xFF0000 },
  43. quality: 'auto',
  44. useFog: false,
  45. alpha: 0.5
  46. }
  47. const cartoonProps: CartoonProps = {
  48. doubleSided: true,
  49. colorTheme: { name: 'chain-id' },
  50. // colorTheme: { name: 'uniform', value: 0x2200CC },
  51. quality: 'auto',
  52. useFog: false
  53. }
  54. export class Stage {
  55. viewer: Viewer
  56. ctx = new StateContext(Progress.format)
  57. constructor(public globalContext: Context) {
  58. }
  59. initRenderer (canvas: HTMLCanvasElement, container: HTMLDivElement) {
  60. this.viewer = Viewer.create(canvas, container)
  61. this.viewer.animate()
  62. this.ctx.viewer = this.viewer
  63. // this.loadPdbid('1jj2')
  64. // this.loadPdbid('4umt') // ligand has bond with order 3
  65. // this.loadPdbid('1crn') // small
  66. // this.loadPdbid('1hrv') // viral assembly
  67. // this.loadPdbid('1rb8') // virus
  68. // this.loadPdbid('1blu') // metal coordination
  69. // this.loadPdbid('3pqr') // inter unit bonds, two polymer chains, ligands, water
  70. // this.loadPdbid('4v5a') // ribosome
  71. // this.loadPdbid('3j3q') // ...
  72. this.loadPdbid('3sn6') // discontinuous chains
  73. // this.loadMmcifUrl(`../../examples/1cbs_full.bcif`)
  74. // this.loadMmcifUrl(`../../examples/1cbs_updated.cif`)
  75. // this.loadMmcifUrl(`../../examples/1crn.cif`)
  76. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000001.cif`) // ok
  77. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000002.cif`) // ok
  78. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000003.cif`) // ok
  79. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000004.cif`) // TODO issue with cross-link extraction
  80. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000005.cif`) // ok
  81. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000006.cif`) // TODO only three spacefill atoms rendered
  82. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000007.cif`) // TODO only three spacefill atoms rendered
  83. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000008.cif`) // ok
  84. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000010.cif`) // ok
  85. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000011.cif`) // ok
  86. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000012.cif`) // ok
  87. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000014.cif`) // ok
  88. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000016.cif`) // TODO only three spacefill atoms rendered
  89. }
  90. async loadMmcifUrl (url: string) {
  91. const urlEntity = UrlEntity.ofUrl(this.ctx, url)
  92. const modelEntity = await MmcifUrlToModel.apply(this.ctx, urlEntity)
  93. console.log(modelEntity.value)
  94. const structureEntity = await ModelToStructure.apply(this.ctx, modelEntity)
  95. StructureToBallAndStick.apply(this.ctx, structureEntity, { ...ballAndStickProps, visible: false })
  96. StructureToSpacefill.apply(this.ctx, structureEntity, { ...spacefillProps, visible: false })
  97. StructureToDistanceRestraint.apply(this.ctx, structureEntity, { ...distanceRestraintProps, visible: false })
  98. StructureToBackbone.apply(this.ctx, structureEntity, { ...backboneProps, visible: true })
  99. StructureToCartoon.apply(this.ctx, structureEntity, { ...cartoonProps, visible: true })
  100. StructureCenter.apply(this.ctx, structureEntity)
  101. this.globalContext.components.sequenceView.setState({ structure: structureEntity.value });
  102. // const structureEntity2 = await ModelToStructure.apply(this.ctx, modelEntity)
  103. // const q1 = Q.generators.atoms({
  104. // residueTest: l => SP.residue.label_seq_id(l) < 7
  105. // });
  106. // structureEntity2.value = Selection.unionStructure(await Query(q1)(structureEntity2.value).run());
  107. // await StructureToBackbone.apply(this.ctx, structureEntity2, { ...backboneProps, visible: true })
  108. // await StructureToCartoon.apply(this.ctx, structureEntity2, { ...cartoonProps, visible: true })
  109. // await StructureToBallAndStick.apply(this.ctx, structureEntity2, { ...ballAndStickProps, visible: false })
  110. // StructureCenter.apply(this.ctx, structureEntity2)
  111. }
  112. loadPdbid (pdbid: string) {
  113. return this.loadMmcifUrl(`http://www.ebi.ac.uk/pdbe/static/entry/${pdbid}_updated.cif`)
  114. // return this.loadMmcifUrl(`https://files.rcsb.org/download/${pdbid}.cif`)
  115. }
  116. dispose () {
  117. // TODO
  118. }
  119. }