stage.ts 8.6 KB

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