stage.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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, StructureToCarbohydrate } from './state/transform';
  10. import { UrlEntity } from './state/entity';
  11. import { SpacefillProps } from 'mol-geo/representation/structure/representation/spacefill';
  12. import { Context } from 'mol-app/context/context';
  13. import { BallAndStickProps } from 'mol-geo/representation/structure/representation/ball-and-stick';
  14. import { CartoonProps } from 'mol-geo/representation/structure/representation/cartoon';
  15. import { DistanceRestraintProps } from 'mol-geo/representation/structure/representation/distance-restraint';
  16. import { BackboneProps } from 'mol-geo/representation/structure/representation/backbone';
  17. import { CarbohydrateProps } from 'mol-geo/representation/structure/representation/carbohydrate';
  18. // import { Queries as Q, StructureProperties as SP, Query, Selection } from 'mol-model/structure';
  19. const spacefillProps: Partial<SpacefillProps> = {
  20. doubleSided: true,
  21. colorTheme: { name: 'chain-id' },
  22. quality: 'auto',
  23. useFog: false
  24. }
  25. const ballAndStickProps: Partial<BallAndStickProps> = {
  26. doubleSided: true,
  27. colorTheme: { name: 'chain-id' },
  28. sizeTheme: { name: 'uniform', value: 0.15 },
  29. linkRadius: 0.15,
  30. quality: 'auto',
  31. useFog: false
  32. }
  33. const distanceRestraintProps: Partial<DistanceRestraintProps> = {
  34. doubleSided: true,
  35. colorTheme: { name: 'chain-id' },
  36. linkRadius: 0.5,
  37. quality: 'auto',
  38. useFog: false
  39. }
  40. const backboneProps: Partial<BackboneProps> = {
  41. doubleSided: true,
  42. colorTheme: { name: 'chain-id' },
  43. sizeTheme: { name: 'uniform', value: 0.3 },
  44. quality: 'auto',
  45. useFog: false,
  46. alpha: 0.5
  47. }
  48. const cartoonProps: Partial<CartoonProps> = {
  49. doubleSided: true,
  50. colorTheme: { name: 'chain-id' },
  51. sizeTheme: { name: 'uniform', value: 0.13, factor: 1 },
  52. aspectRatio: 8,
  53. quality: 'auto',
  54. useFog: false
  55. }
  56. const carbohydrateProps: Partial<CarbohydrateProps> = {
  57. doubleSided: true,
  58. colorTheme: { name: 'carbohydrate-symbol' },
  59. sizeTheme: { name: 'uniform', value: 1, factor: 1 },
  60. quality: 'highest',
  61. useFog: false
  62. }
  63. export class Stage {
  64. viewer: Viewer
  65. ctx = new StateContext(Progress.format)
  66. constructor(public globalContext: Context) {
  67. }
  68. initRenderer (canvas: HTMLCanvasElement, container: HTMLDivElement) {
  69. this.viewer = Viewer.create(canvas, container)
  70. this.viewer.animate()
  71. this.ctx.viewer = this.viewer
  72. // this.loadPdbid('1jj2')
  73. // this.loadPdbid('1grm') // helix-like sheets
  74. // this.loadPdbid('4umt') // ligand has bond with order 3
  75. // this.loadPdbid('1crn') // small
  76. // this.loadPdbid('1hrv') // viral assembly
  77. // this.loadPdbid('1rb8') // virus
  78. // this.loadPdbid('1blu') // metal coordination
  79. this.loadPdbid('3pqr') // inter unit bonds, two polymer chains, ligands, water, carbohydrates linked to protein
  80. // this.loadPdbid('4v5a') // ribosome
  81. // this.loadPdbid('3j3q') // ...
  82. // this.loadPdbid('2np2') // dna
  83. // this.loadPdbid('1d66') // dna
  84. // this.loadPdbid('9dna') // A form dna
  85. // this.loadPdbid('1bna') // B form dna
  86. // this.loadPdbid('199d') // C form dna
  87. // this.loadPdbid('4lb6') // Z form dna
  88. // this.loadPdbid('1egk') // 4-way dna-rna junction
  89. // this.loadPdbid('1y26') // rna
  90. // this.loadPdbid('1xv6') // rna, modified nucleotides
  91. // this.loadPdbid('3bbm') // rna with linker
  92. // this.loadPdbid('1euq') // t-rna
  93. // this.loadPdbid('2e2i') // rna, dna, protein
  94. // this.loadPdbid('1gfl') // GFP, flourophore has carbonyl oxygen removed
  95. // this.loadPdbid('1sfi') // contains cyclic peptid
  96. // this.loadPdbid('3sn6') // discontinuous chains
  97. // this.loadPdbid('2zex') // contains carbohydrate polymer
  98. // this.loadPdbid('3sgj') // contains carbohydrate polymer
  99. // this.loadPdbid('3ina') // contains GlcN and IdoA
  100. // this.loadPdbid('1umz') // contains Xyl (Xyloglucan)
  101. // this.loadPdbid('1mfb') // contains Abe
  102. // this.loadPdbid('2gdu') // contains sucrose
  103. // this.loadPdbid('2fnc') // contains maltotriose
  104. // this.loadPdbid('4zs9') // contains raffinose
  105. // this.loadPdbid('2yft') // contains kestose
  106. // this.loadPdbid('2b5t') // contains large carbohydrate polymer
  107. // this.loadPdbid('1b5f') // contains carbohydrate with alternate locations
  108. // this.loadMmcifUrl(`../../examples/1cbs_full.bcif`)
  109. // this.loadMmcifUrl(`../../examples/1cbs_updated.cif`)
  110. // this.loadMmcifUrl(`../../examples/1crn.cif`)
  111. // this.loadPdbid('5u0q') // mixed dna/rna in same polymer
  112. // this.loadPdbid('5u0q') // temp
  113. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000001.cif`) // ok
  114. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000002.cif`) // ok
  115. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000003.cif`) // ok
  116. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000004.cif`) // TODO issue with cross-link extraction
  117. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000005.cif`) // ok
  118. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000006.cif`) // TODO only three spacefill atoms rendered
  119. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000007.cif`) // TODO only three spacefill atoms rendered
  120. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000008.cif`) // ok
  121. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000010.cif`) // ok
  122. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000011.cif`) // ok
  123. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000012.cif`) // ok
  124. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000014.cif`) // ok
  125. // this.loadMmcifUrl(`../../../test/pdb-dev/PDBDEV_00000016.cif`) // TODO only three spacefill atoms rendered
  126. }
  127. async loadMmcifUrl (url: string) {
  128. const urlEntity = UrlEntity.ofUrl(this.ctx, url)
  129. const modelEntity = await MmcifUrlToModel.apply(this.ctx, urlEntity)
  130. console.log(modelEntity.value)
  131. const structureEntity = await ModelToStructure.apply(this.ctx, modelEntity)
  132. StructureToBallAndStick.apply(this.ctx, structureEntity, { ...ballAndStickProps, visible: true })
  133. StructureToSpacefill.apply(this.ctx, structureEntity, { ...spacefillProps, visible: false })
  134. StructureToDistanceRestraint.apply(this.ctx, structureEntity, { ...distanceRestraintProps, visible: false })
  135. StructureToBackbone.apply(this.ctx, structureEntity, { ...backboneProps, visible: false })
  136. StructureToCartoon.apply(this.ctx, structureEntity, { ...cartoonProps, visible: true })
  137. StructureToCarbohydrate.apply(this.ctx, structureEntity, { ...carbohydrateProps, visible: true })
  138. StructureCenter.apply(this.ctx, structureEntity)
  139. this.globalContext.components.sequenceView.setState({ structure: structureEntity.value });
  140. // const structureEntity2 = await ModelToStructure.apply(this.ctx, modelEntity)
  141. // const q1 = Q.generators.atoms({
  142. // residueTest: l => SP.residue.label_seq_id(l) < 7
  143. // });
  144. // structureEntity2.value = Selection.unionStructure(await Query(q1)(structureEntity2.value).run());
  145. // await StructureToBackbone.apply(this.ctx, structureEntity2, { ...backboneProps, visible: true })
  146. // await StructureToCartoon.apply(this.ctx, structureEntity2, { ...cartoonProps, visible: true })
  147. // await StructureToBallAndStick.apply(this.ctx, structureEntity2, { ...ballAndStickProps, visible: false })
  148. // StructureCenter.apply(this.ctx, structureEntity2)
  149. }
  150. loadPdbid (pdbid: string) {
  151. // return this.loadMmcifUrl(`http://www.ebi.ac.uk/pdbe/static/entry/${pdbid}_updated.cif`)
  152. return this.loadMmcifUrl(`https://files.rcsb.org/download/${pdbid}.cif`)
  153. }
  154. dispose () {
  155. // TODO
  156. }
  157. }