url-loader.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 * as React from 'react'
  7. import { View } from '../view';
  8. import { TransformListController } from '../../controller/transform/list';
  9. import { UrlEntity } from 'mol-view/state/entity';
  10. import { ModelToStructure, StructureToBallAndStick, StructureToSpacefill, StructureToDistanceRestraint, StructureToBackbone, MmcifUrlToModel, StructureToCartoon } from 'mol-view/state/transform';
  11. import { StateContext } from 'mol-view/state/context';
  12. import { SpacefillProps } from 'mol-geo/representation/structure/representation/spacefill';
  13. import { BallAndStickProps } from 'mol-geo/representation/structure/representation/ball-and-stick';
  14. import { DistanceRestraintProps } from 'mol-geo/representation/structure/representation/distance-restraint';
  15. import { BackboneProps } from 'mol-geo/representation/structure/representation/backbone';
  16. import { CartoonProps } from 'mol-geo/representation/structure/representation/cartoon';
  17. const spacefillProps: Partial<SpacefillProps> = {
  18. doubleSided: true,
  19. colorTheme: { name: 'chain-id' },
  20. quality: 'auto',
  21. useFog: false
  22. }
  23. const ballAndStickProps: Partial<BallAndStickProps> = {
  24. doubleSided: true,
  25. colorTheme: { name: 'chain-id' },
  26. sizeTheme: { name: 'uniform', value: 0.05 },
  27. linkRadius: 0.05,
  28. quality: 'auto',
  29. useFog: false
  30. }
  31. const distanceRestraintProps: Partial<DistanceRestraintProps> = {
  32. doubleSided: true,
  33. colorTheme: { name: 'chain-id' },
  34. linkRadius: 0.5,
  35. quality: 'auto',
  36. useFog: false
  37. }
  38. const backboneProps: Partial<BackboneProps> = {
  39. doubleSided: true,
  40. colorTheme: { name: 'chain-id' },
  41. quality: 'auto',
  42. useFog: false
  43. }
  44. const cartoonProps: Partial<CartoonProps> = {
  45. doubleSided: true,
  46. colorTheme: { name: 'chain-id' },
  47. quality: 'auto',
  48. useFog: false
  49. }
  50. function getPdbdevUrl(pdbdevId: string) {
  51. return `https://pdb-dev.wwpdb.org/static/cif/${pdbdevId}.cif`
  52. }
  53. const exampleUrls = {
  54. PDBDEV_00000001: getPdbdevUrl('PDBDEV_00000001'), // ok
  55. PDBDEV_00000002: getPdbdevUrl('PDBDEV_00000002'), // ok
  56. PDBDEV_00000003: getPdbdevUrl('PDBDEV_00000003'), // ok
  57. PDBDEV_00000004: getPdbdevUrl('PDBDEV_00000004'), // TODO issue with cross-link extraction
  58. PDBDEV_00000005: getPdbdevUrl('PDBDEV_00000005'), // ok
  59. PDBDEV_00000006: getPdbdevUrl('PDBDEV_00000006'), // TODO only three spacefill atoms rendered
  60. PDBDEV_00000007: getPdbdevUrl('PDBDEV_00000007'), // TODO only three spacefill atoms rendered
  61. PDBDEV_00000008: getPdbdevUrl('PDBDEV_00000008'), // ok
  62. PDBDEV_00000010: getPdbdevUrl('PDBDEV_00000010'), // ok
  63. PDBDEV_00000011: getPdbdevUrl('PDBDEV_00000011'), // ok
  64. PDBDEV_00000012: getPdbdevUrl('PDBDEV_00000012'), // ok
  65. PDBDEV_00000014: getPdbdevUrl('PDBDEV_00000014'), // ok
  66. PDBDEV_00000016: getPdbdevUrl('PDBDEV_00000016'),
  67. }
  68. export class UrlLoader extends View<TransformListController, { }, { ctx: StateContext }> {
  69. async load(name: keyof typeof exampleUrls) {
  70. console.log(exampleUrls[name])
  71. const ctx = this.props.ctx
  72. const urlEntity = UrlEntity.ofUrl(ctx, exampleUrls[name])
  73. console.log(await urlEntity.value.getData())
  74. const modelEntity = await MmcifUrlToModel.apply(ctx, urlEntity)
  75. const structureEntity = await ModelToStructure.apply(ctx, modelEntity)
  76. StructureToBallAndStick.apply(ctx, structureEntity, { ...ballAndStickProps, visible: true })
  77. StructureToSpacefill.apply(ctx, structureEntity, { ...spacefillProps, visible: false })
  78. StructureToDistanceRestraint.apply(ctx, structureEntity, { ...distanceRestraintProps, visible: false })
  79. StructureToBackbone.apply(ctx, structureEntity, { ...backboneProps, visible: true })
  80. StructureToCartoon.apply(ctx, structureEntity, { ...cartoonProps, visible: false })
  81. }
  82. render() {
  83. const exampleOptions = Object.keys(exampleUrls).map(name => {
  84. return <option key={name} value={name}>{name}</option>
  85. })
  86. return <div className='molstar-transformer-wrapper'>
  87. <div className='molstar-panel molstar-control molstar-transformer molstar-panel-expanded'>
  88. <div className='molstar-panel-body'>
  89. <div>
  90. <div className='molstar-control-row molstar-options-group'>
  91. <span>Examples</span>
  92. <div>
  93. <select
  94. className='molstar-form-control'
  95. value=''
  96. onChange={(e) => {
  97. if (e.target.value) {
  98. this.load(e.target.value as keyof typeof exampleUrls)}
  99. }
  100. }
  101. >
  102. <option key='' value=''></option>
  103. {exampleOptions}
  104. </select>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </div>;
  111. }
  112. }