@ccp-nc/crystvis-js 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/.eslintrc.json +0 -0
  2. package/.github/workflows/test-mocha.yml +3 -3
  3. package/CHANGELOG.md +27 -0
  4. package/LICENSE +0 -0
  5. package/README.html +0 -0
  6. package/README.md +5 -1
  7. package/docs/.nojekyll +0 -0
  8. package/docs/data/search.json +1 -0
  9. package/docs/fonts/Inconsolata-Regular.ttf +0 -0
  10. package/docs/fonts/OpenSans-Regular.ttf +0 -0
  11. package/docs/fonts/WorkSans-Bold.ttf +0 -0
  12. package/docs/index.html +10 -0
  13. package/docs/lib_model.module_js-AtomImage.html +3 -0
  14. package/docs/lib_model.module_js-BondImage.html +3 -0
  15. package/docs/lib_model.module_js-Model.html +3 -0
  16. package/docs/lib_model.module_js.html +3 -0
  17. package/docs/lib_modelview.module_js-ModelView.html +12 -0
  18. package/docs/lib_modelview.module_js.html +3 -0
  19. package/docs/lib_visualizer.module_js-CrystVis.html +3 -0
  20. package/docs/lib_visualizer.module_js.html +3 -0
  21. package/docs/model.js.html +2163 -0
  22. package/docs/modelview.js.html +449 -0
  23. package/docs/scripts/core.js +726 -0
  24. package/docs/scripts/core.min.js +23 -0
  25. package/docs/scripts/resize.js +90 -0
  26. package/docs/scripts/search.js +265 -0
  27. package/docs/scripts/search.min.js +6 -0
  28. package/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  29. package/docs/scripts/third-party/fuse.js +9 -0
  30. package/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  31. package/docs/scripts/third-party/hljs-line-num.js +1 -0
  32. package/docs/scripts/third-party/hljs-original.js +5171 -0
  33. package/docs/scripts/third-party/hljs.js +1 -0
  34. package/docs/scripts/third-party/popper.js +5 -0
  35. package/docs/scripts/third-party/tippy.js +1 -0
  36. package/docs/scripts/third-party/tocbot.js +672 -0
  37. package/docs/scripts/third-party/tocbot.min.js +1 -0
  38. package/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  39. package/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  40. package/docs/styles/clean-jsdoc-theme-light.css +482 -0
  41. package/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  42. package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  43. package/docs/styles/clean-jsdoc-theme.min.css +1 -0
  44. package/docs/tutorial-Events.html +13 -0
  45. package/docs/tutorial-Queries.html +16 -0
  46. package/docs/tutorial-ThreejsMigration.html +25 -0
  47. package/docs/visualizer.js.html +574 -0
  48. package/docs-tutorials/Events.md +0 -0
  49. package/docs-tutorials/Queries.md +0 -0
  50. package/docs-tutorials/ThreejsMigration.md +96 -0
  51. package/fonts/OpenSans/OFL.txt +0 -0
  52. package/fonts/OpenSans/OpenSans-Italic-VariableFont_wdth,wght.ttf +0 -0
  53. package/fonts/OpenSans/OpenSans-VariableFont_wdth,wght.ttf +0 -0
  54. package/fonts/OpenSans/README.txt +0 -0
  55. package/fonts/OpenSans/static/OpenSans/OpenSans-Bold.ttf +0 -0
  56. package/fonts/OpenSans/static/OpenSans/OpenSans-BoldItalic.ttf +0 -0
  57. package/fonts/OpenSans/static/OpenSans/OpenSans-ExtraBold.ttf +0 -0
  58. package/fonts/OpenSans/static/OpenSans/OpenSans-ExtraBoldItalic.ttf +0 -0
  59. package/fonts/OpenSans/static/OpenSans/OpenSans-Italic.ttf +0 -0
  60. package/fonts/OpenSans/static/OpenSans/OpenSans-Light.ttf +0 -0
  61. package/fonts/OpenSans/static/OpenSans/OpenSans-LightItalic.ttf +0 -0
  62. package/fonts/OpenSans/static/OpenSans/OpenSans-Medium.ttf +0 -0
  63. package/fonts/OpenSans/static/OpenSans/OpenSans-MediumItalic.ttf +0 -0
  64. package/fonts/OpenSans/static/OpenSans/OpenSans-Regular.ttf +0 -0
  65. package/fonts/OpenSans/static/OpenSans/OpenSans-SemiBold.ttf +0 -0
  66. package/fonts/OpenSans/static/OpenSans/OpenSans-SemiBoldItalic.ttf +0 -0
  67. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-Bold.ttf +0 -0
  68. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-BoldItalic.ttf +0 -0
  69. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-ExtraBold.ttf +0 -0
  70. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-ExtraBoldItalic.ttf +0 -0
  71. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-Italic.ttf +0 -0
  72. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-Light.ttf +0 -0
  73. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-LightItalic.ttf +0 -0
  74. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-Medium.ttf +0 -0
  75. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-MediumItalic.ttf +0 -0
  76. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-Regular.ttf +0 -0
  77. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-SemiBold.ttf +0 -0
  78. package/fonts/OpenSans/static/OpenSans_Condensed/OpenSans_Condensed-SemiBoldItalic.ttf +0 -0
  79. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Bold.ttf +0 -0
  80. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-BoldItalic.ttf +0 -0
  81. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-ExtraBold.ttf +0 -0
  82. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-ExtraBoldItalic.ttf +0 -0
  83. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Italic.ttf +0 -0
  84. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Light.ttf +0 -0
  85. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-LightItalic.ttf +0 -0
  86. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Medium.ttf +0 -0
  87. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-MediumItalic.ttf +0 -0
  88. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Regular.ttf +0 -0
  89. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-SemiBold.ttf +0 -0
  90. package/fonts/OpenSans/static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-SemiBoldItalic.ttf +0 -0
  91. package/fonts/Rubik/OFL.txt +0 -0
  92. package/fonts/Rubik/README.txt +0 -0
  93. package/fonts/Rubik/Rubik-Italic-VariableFont_wght.ttf +0 -0
  94. package/fonts/Rubik/Rubik-VariableFont_wght.ttf +0 -0
  95. package/fonts/Rubik/static/Rubik-Black.ttf +0 -0
  96. package/fonts/Rubik/static/Rubik-BlackItalic.ttf +0 -0
  97. package/fonts/Rubik/static/Rubik-Bold.ttf +0 -0
  98. package/fonts/Rubik/static/Rubik-BoldItalic.ttf +0 -0
  99. package/fonts/Rubik/static/Rubik-ExtraBold.ttf +0 -0
  100. package/fonts/Rubik/static/Rubik-ExtraBoldItalic.ttf +0 -0
  101. package/fonts/Rubik/static/Rubik-Italic.ttf +0 -0
  102. package/fonts/Rubik/static/Rubik-Light.ttf +0 -0
  103. package/fonts/Rubik/static/Rubik-LightItalic.ttf +0 -0
  104. package/fonts/Rubik/static/Rubik-Medium.ttf +0 -0
  105. package/fonts/Rubik/static/Rubik-MediumItalic.ttf +0 -0
  106. package/fonts/Rubik/static/Rubik-Regular.ttf +0 -0
  107. package/fonts/Rubik/static/Rubik-SemiBold.ttf +0 -0
  108. package/fonts/Rubik/static/Rubik-SemiBoldItalic.ttf +0 -0
  109. package/index.html +0 -0
  110. package/index.js +0 -0
  111. package/jsconf.json +0 -0
  112. package/lib/assets/fonts/bmpfonts.in.js +0 -0
  113. package/lib/assets/fonts/bmpfonts.js +0 -0
  114. package/lib/assets/fonts/font.js +33 -3
  115. package/lib/assets/fonts/index.js +0 -0
  116. package/lib/assets/fonts/threebmfont.js +2 -11
  117. package/lib/data.js +0 -0
  118. package/lib/formats/cell.js +0 -0
  119. package/lib/formats/cif.js +0 -0
  120. package/lib/formats/magres.js +0 -0
  121. package/lib/formats/xyz.js +0 -0
  122. package/lib/loader.js +0 -0
  123. package/lib/model.js +10 -0
  124. package/lib/modelview.js +30 -0
  125. package/lib/nmrdata.js +0 -0
  126. package/lib/orbit.js +77 -1
  127. package/lib/primitives/atoms.js +12 -7
  128. package/lib/primitives/cell.js +1 -1
  129. package/lib/primitives/dither.js +1 -1
  130. package/lib/primitives/ellipsoid.js +23 -5
  131. package/lib/primitives/geometries.js +3 -3
  132. package/lib/primitives/isosurface.js +1 -2
  133. package/lib/primitives/shapes.js +1 -1
  134. package/lib/primitives/sprites.js +9 -2
  135. package/lib/query.js +0 -0
  136. package/lib/render.js +40 -9
  137. package/lib/selbox.js +0 -0
  138. package/lib/shaders/aura.frag +0 -1
  139. package/lib/shaders/aura.vert +0 -1
  140. package/lib/shaders/dither.frag +0 -0
  141. package/lib/shaders/dither.vert +0 -0
  142. package/lib/shaders/index.in.js +0 -0
  143. package/lib/shaders/index.js +4 -4
  144. package/lib/shaders/msdf300.frag +0 -2
  145. package/lib/shaders/msdf300.vert +0 -2
  146. package/lib/visualizer.js +5 -4
  147. package/package.json +20 -20
  148. package/scripts/build-bundle.js +6 -2
  149. package/scripts/build-resources.js +0 -0
  150. package/scripts/plugins-shim.js +0 -0
  151. package/test/data/CHA.cif +0 -0
  152. package/test/data/H2O.xyz +0 -0
  153. package/test/data/H2_bound.xyz +0 -0
  154. package/test/data/bohr.cell +0 -0
  155. package/test/data/ethanol.cell +0 -0
  156. package/test/data/example_single.cif +0 -0
  157. package/test/data/frac.cell +0 -0
  158. package/test/data/org.cif +0 -0
  159. package/test/data/pyridine.xyz +0 -0
  160. package/test/data/si8.xyz +0 -0
  161. package/test/test-html/examples.js +0 -0
  162. package/test/test-html/index.html +0 -0
  163. package/tools/compile_colors.py +0 -0
  164. package/tools/compile_periodic.py +0 -0
  165. package/tools/ptable.json +0 -0
  166. package/tools/test +0 -0
@@ -0,0 +1,574 @@
1
+ <!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: visualizer.js</title><!--[if lt IE 9]>
2
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3
+ <![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="lib_model.module_js.html">lib/model.js</a></div><div class="sidebar-section-children"><a href="lib_modelview.module_js.html">lib/modelview.js</a></div><div class="sidebar-section-children"><a href="lib_visualizer.module_js.html">lib/visualizer.js</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="lib_model.module_js-AtomImage.html">AtomImage</a></div><div class="sidebar-section-children"><a href="lib_model.module_js-BondImage.html">BondImage</a></div><div class="sidebar-section-children"><a href="lib_model.module_js-Model.html">Model</a></div><div class="sidebar-section-children"><a href="lib_modelview.module_js-ModelView.html">ModelView</a></div><div class="sidebar-section-children"><a href="lib_visualizer.module_js-CrystVis.html">CrystVis</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-tutorials"><div>Tutorials</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="tutorial-Events.html">Events</a></div><div class="sidebar-section-children"><a href="tutorial-Queries.html">Queries</a></div><div class="sidebar-section-children"><a href="tutorial-ThreejsMigration.html">ThreejsMigration</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">visualizer.js</h1></header><article><pre class="prettyprint source lang-js"><code>'use strict';
4
+
5
+ /**
6
+ * @fileoverview Class constituting the main object that plots crystals in the webpage
7
+ * @module
8
+ */
9
+
10
+ import * as _ from 'lodash';
11
+
12
+ import {
13
+ Renderer as Renderer
14
+ } from './render.js';
15
+ // themes
16
+ import {themes} from './render.js';
17
+ import {
18
+ Loader as Loader
19
+ } from './loader.js';
20
+ import {
21
+ Model as Model
22
+ } from './model.js';
23
+ import {
24
+ ModelView as ModelView
25
+ } from './modelview.js';
26
+ import {
27
+ AtomMesh
28
+ } from './primitives/index.js';
29
+ import {
30
+ addStaticVar
31
+ } from './utils.js';
32
+
33
+
34
+ const model_parameter_defaults = {
35
+ supercell: [1, 1, 1],
36
+ molecularCrystal: false
37
+ };
38
+
39
+ /** An object providing a full interface to a renderer for crystallographic models */
40
+ class CrystVis {
41
+
42
+ /**
43
+ * An object providing a full interface to a renderer for crystallographic
44
+ * models
45
+ * @class
46
+ * @param {string} element CSS-style identifier for the HTML element to
47
+ * put the renderer in
48
+ * @param {int} width Window width
49
+ * @param {int} height Window height. If both this and width are
50
+ * set to 0, the window fits its context and
51
+ * automatically resizes with it
52
+ * @param {Object} rendererOptions Options for the renderer
53
+ */
54
+ constructor(element, width = 0, height = 0, rendererOptions = {}) {
55
+
56
+ // Create a renderer
57
+ this._renderer = new Renderer(element, width, height, rendererOptions);
58
+ this._loader = new Loader();
59
+
60
+ this._models = {};
61
+
62
+ this._current_model = null;
63
+ this._current_mname = null;
64
+ this._displayed = null;
65
+ this._selected = null;
66
+ this._notifications = [];
67
+
68
+ // Handling events
69
+ this._atom_click_events = {};
70
+ this._atom_click_events[CrystVis.LEFT_CLICK] = this._defaultAtomLeftClick.bind(this);
71
+ this._atom_click_events[CrystVis.LEFT_CLICK + CrystVis.SHIFT_BUTTON] = this._defaultAtomShiftLeftClick.bind(this);
72
+ this._atom_click_events[CrystVis.LEFT_CLICK + CrystVis.CTRL_BUTTON] = this._defaultAtomCtrlLeftClick.bind(this);
73
+
74
+ this._atom_click_defaults = _.cloneDeep(this._atom_click_events);
75
+
76
+ this._atom_box_event = this._defaultAtomBox.bind(this);
77
+
78
+ this._renderer.addClickListener(this._handleAtomClick.bind(this),
79
+ this._renderer._groups.model, AtomMesh);
80
+ this._renderer.addSelBoxListener(this._handleAtomBox.bind(this),
81
+ this._renderer._groups.model, AtomMesh);
82
+
83
+ // Additional options
84
+ // Hidden (need dedicated setters)
85
+ this._hsel = false; // If true, highlight the selected atoms
86
+
87
+ // Vanilla (no get/set needed)
88
+ this.cifsymtol = 1e-2; // Parameter controlling the tolerance to symmetry when loading CIF files
89
+
90
+ }
91
+
92
+ /**
93
+ * List of loaded models
94
+ * @readonly
95
+ * @type {Array}
96
+ */
97
+ get modelList() {
98
+ return Object.keys(this._models);
99
+ }
100
+
101
+ /**
102
+ * Currently loaded model
103
+ * @readonly
104
+ * @type {Model}
105
+ */
106
+ get model() {
107
+ return this._current_model;
108
+ }
109
+
110
+ /**
111
+ * Name of the currently loaded model
112
+ * @readonly
113
+ * @type {String}
114
+ */
115
+ get modelName() {
116
+ return this._current_mname;
117
+ }
118
+
119
+ /**
120
+ * Displayed atoms
121
+ * @type {ModelView}
122
+ */
123
+ get displayed() {
124
+ return this._displayed;
125
+ }
126
+
127
+ set displayed(d) {
128
+ if (!(d instanceof ModelView)) {
129
+ throw new Error('.displayed must be set with a ModelView');
130
+ }
131
+ this._displayed.hide();
132
+ this._displayed = d;
133
+ this._displayed.show();
134
+ }
135
+
136
+ /**
137
+ * Selected atoms
138
+ * @type {ModelView}
139
+ */
140
+ get selected() {
141
+ return this._selected;
142
+ }
143
+
144
+ set selected(s) {
145
+ if (!(s instanceof ModelView)) {
146
+ throw new Error('.selected must be set with a ModelView');
147
+ }
148
+ this._selected.setProperty('highlighted', false);
149
+ this._selected = s;
150
+ this._selected.setProperty('highlighted', this._hsel);
151
+ }
152
+
153
+ /** Whether the selected atoms should be highlighted with auras
154
+ * @type {bool}
155
+ */
156
+ get highlightSelected() {
157
+ return this._hsel;
158
+ }
159
+
160
+ set highlightSelected(hs) {
161
+ this._hsel = hs;
162
+ if (this._selected) {
163
+ this._selected.setProperty('highlighted', this._hsel);
164
+ }
165
+ }
166
+
167
+ get notifications() {
168
+ return this._notifications;
169
+ }
170
+
171
+ set notifications(n) {
172
+ this._notifications = n;
173
+ }
174
+
175
+
176
+ /** Theme
177
+ * @type {object}
178
+ */
179
+ get theme() {
180
+ return this._renderer.theme;
181
+ }
182
+
183
+ set theme(t) {
184
+ // if t is a string, try to find the corresponding theme
185
+ // from the list of themes
186
+ if (typeof t === 'string') {
187
+ if (themes[t]) {
188
+ t = themes[t];
189
+ } else {
190
+ throw new Error('Theme ' + t + ' not found');
191
+ }
192
+ }
193
+ this._renderer.theme = t;
194
+ }
195
+
196
+
197
+ /**
198
+ * Set a callback function for an event where a user clicks on an atom. The
199
+ * function should take as arguments the atom image for the clicked atom and
200
+ * the event object:
201
+ *
202
+ * function callback(atom, event) {
203
+ * ...
204
+ * }
205
+ *
206
+ * @param {Function} callback Callback function for the event. Passing "null" restores default behaviour
207
+ * @param {int} modifiers Click event. Use the following flags to define it:
208
+ *
209
+ * * CrystVis.LEFT_CLICK
210
+ * * CrystVis.RIGHT_CLICK
211
+ * * CrystVis.MIDDLE_CLICK
212
+ * * CrystVis.CTRL_BUTTON
213
+ * * CrystVis.ALT_BUTTON
214
+ * * CrystVis.SHIFT_BUTTON
215
+ * * CrystVis.CMD_BUTTON
216
+ *
217
+ * For example, CrystVis.LEFT_CLICK + CrystVis.SHIFT_BUTTON
218
+ * defines the event for a click while the Shift key is pressed.
219
+ *
220
+ */
221
+ onAtomClick(callback = null, modifiers = CrystVis.LEFT_CLICK) {
222
+
223
+ // Check that event makes sense
224
+ var lc = modifiers &amp; CrystVis.LEFT_CLICK;
225
+ var mc = modifiers &amp; CrystVis.MIDDLE_CLICK;
226
+ var rc = modifiers &amp; CrystVis.RIGHT_CLICK;
227
+
228
+ if (lc + mc + rc == 0) {
229
+ throw 'Can not set event without any click type';
230
+ }
231
+ if ((lc &amp;&amp; mc) || (lc &amp;&amp; rc) || (mc &amp;&amp; rc)) {
232
+ throw 'Can not set event with two or more click types';
233
+ }
234
+
235
+ if (callback)
236
+ this._atom_click_events[modifiers] = callback.bind(this);
237
+ else
238
+ this._atom_click_events[modifiers] = this._atom_click_defaults[modifiers];
239
+ }
240
+
241
+ /**
242
+ * Set a callback function for an event where a user drags a box around multiple atoms.
243
+ * The function should take as arguments a ModelView including the atoms in the box:
244
+ *
245
+ * function callback(view) {
246
+ * ...
247
+ * }
248
+ *
249
+ * @param {Function} callback Callback function for the event. Passing "null" restores default behaviour
250
+ */
251
+ onAtomBox(callback = null) {
252
+ if (callback)
253
+ this._atom_box_event = callback;
254
+ else
255
+ this._atom_box_event = this._defaultAtomBox.bind(this);
256
+ }
257
+
258
+ _defaultAtomLeftClick(atom, event) {
259
+ var i = atom.imgIndex;
260
+ this.selected = new ModelView(this._current_model, [i]);
261
+ }
262
+ _defaultAtomShiftLeftClick(atom, event) {
263
+ var i = atom.imgIndex;
264
+ this.selected = this.selected.or(new ModelView(this._current_model, [i]));
265
+ }
266
+ _defaultAtomCtrlLeftClick(atom, event) {
267
+ var i = atom.imgIndex;
268
+ this.selected = this.selected.xor(new ModelView(this._current_model, [i]));
269
+ }
270
+
271
+ _defaultAtomBox(view) {
272
+ this.selected = this.selected.xor(view);
273
+ console.log(view);
274
+ }
275
+
276
+ // Callback for when atoms are clicked
277
+ _handleAtomClick(alist, event) {
278
+
279
+ if (alist.length == 0) {
280
+ return;
281
+ }
282
+
283
+ let clicked = alist[0].image;
284
+
285
+ let modifiers = [CrystVis.LEFT_CLICK, CrystVis.MIDDLE_CLICK, CrystVis.RIGHT_CLICK][event.button];
286
+
287
+ modifiers += event.shiftKey * CrystVis.SHIFT_BUTTON;
288
+ modifiers += (event.ctrlKey || event.metaKey) * CrystVis.CTRL_BUTTON;
289
+ modifiers += event.altKey * CrystVis.ALT_BUTTON;
290
+
291
+ var callback = this._atom_click_events[modifiers];
292
+
293
+ if (callback)
294
+ callback(clicked, event);
295
+
296
+ }
297
+
298
+ // Callback for a whole box dragged over atoms
299
+ _handleAtomBox(alist) {
300
+
301
+ var indices = alist.map(function(a) {
302
+ return a.image.imgIndex;
303
+ });
304
+
305
+ var callback = this._atom_box_event;
306
+
307
+ if (callback)
308
+ callback(new ModelView(this._current_model, indices));
309
+ }
310
+
311
+ /**
312
+ * Center the camera on a given point
313
+ *
314
+ * @param {float[]} center Point in model space that the orbiting camera
315
+ * should be centred on and look at
316
+ * @param {float[]} shift Shift (in units of width/height of the canvas) with
317
+ * which the center of the camera should be rendered with
318
+ * respect to the center of the canvas
319
+ */
320
+ centerCamera(center = [0, 0, 0], shift = [0, 0]) {
321
+ const renderer = this._renderer;
322
+
323
+ renderer.resetOrbitCenter(center[0], center[1], center[2]);
324
+ renderer.resetCameraCenter(shift[0], shift[1]);
325
+ }
326
+
327
+ /**
328
+ * Load one or more atomic models from a file's contents
329
+ *
330
+ * @param {String} contents The contents of the structure file
331
+ * @param {String} format The file's format (cif, xyz, etc.). Default is cif.
332
+ * @param {String} prefix Prefix to use when naming the models. Default is empty.
333
+ * @param {Object} parameters Loading parameters:
334
+ *
335
+ * - `supercell`: supercell size (only used if the structure is periodic)
336
+ * - `molecularCrystal`: if true, try to make the model load completing molecules across periodic boundaries
337
+ * - `useNMRActiveIsotopes`: if true, all isotopes are set by default to the most common one with non-zero spin
338
+ * - `vdwScaling`: scale van der Waals radii by a constant factor
339
+ * - `vdwElementScaling`: table of per-element factors to scale VdW radii by
340
+ *
341
+ * @return {Object} Names of the models we tried to load, and values of true/false for successful loading or not
342
+ */
343
+ loadModels(contents, format = 'cif', prefix = null, parameters = {}) {
344
+ // clear existing notifications
345
+ this.clearNotifications();
346
+
347
+ parameters = _.merge(model_parameter_defaults, parameters);
348
+
349
+ // By default, it's cif
350
+ format = format.toLowerCase();
351
+
352
+ // By default, same as the format
353
+ prefix = prefix || format;
354
+
355
+ var structs = this._loader.load(contents, format, prefix);
356
+
357
+ var status = {};
358
+
359
+ if (this._loader.status == Loader.STATUS_ERROR) {
360
+ status[prefix] = this._loader.error_message;
361
+ // display error notification to user
362
+ this.addNotification('Error loading model: '+ prefix);
363
+ this.addNotification(this._loader.error_message);
364
+ return status;
365
+ }
366
+
367
+ // Now make unique names
368
+ for (var n in structs) {
369
+ var iter = 0;
370
+ var coll = true;
371
+ var nn = n;
372
+ while (coll) {
373
+ nn = n + (iter > 0 ? '_' + iter : '');
374
+ coll = nn in this._models;
375
+ iter++;
376
+ }
377
+ var s = structs[n];
378
+ if (!s) {
379
+ status[nn] = 'Model could not load properly';
380
+ this.addNotification('Model '+ nn + ' could not load properly');
381
+ continue;
382
+ }
383
+ this._models[nn] = new Model(s, parameters);
384
+ status[nn] = 0; // Success
385
+ }
386
+
387
+ return status;
388
+ }
389
+
390
+ /**
391
+ * Reload a model, possibly with new parameters
392
+ *
393
+ * @param {String} name Name of the model to reload.
394
+ * @param {Object} parameters Loading parameters as in .loadModels()
395
+ */
396
+ reloadModel(name, parameters = {}) {
397
+ // clear existing notifications from scene
398
+ this.clearNotifications();
399
+
400
+ if (!(name in this._models)) {
401
+ throw 'The requested model does not exist';
402
+ }
403
+
404
+ var current = (this._current_mname == name);
405
+ if (current) {
406
+ // Hide the model to reload it later
407
+ this.displayModel();
408
+ }
409
+
410
+ var s = this._models[name]._atoms_base;
411
+ parameters = _.merge(model_parameter_defaults, parameters);
412
+
413
+ this._models[name] = new Model(s, parameters);
414
+
415
+ if (current) {
416
+ this.displayModel(name);
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Render a model
422
+ *
423
+ * @param {String} name Name of the model to display. If empty, just
424
+ * clear the renderer window.
425
+ */
426
+ displayModel(name = null) {
427
+
428
+ if (this._current_model) {
429
+ // clear notifications from previous model
430
+ this.clearNotifications();
431
+ this.selected = this._current_model.view([]);
432
+ this._current_model.renderer = null;
433
+ this._current_model = null;
434
+ this._current_mname = null;
435
+ }
436
+ this._renderer.clear();
437
+
438
+ if (!name) {
439
+ // If called with nothing, just quit here
440
+ return;
441
+ }
442
+
443
+ // if the model isn't in this._models
444
+ if (!(name in this._models) &amp;&amp; Object.keys(this._models).length > 0) {
445
+ // in case the model does not exist, reset the orbit
446
+ this._renderer.resetOrbitCenter(5,5,5);
447
+ this.addNotification('The requested model does not exist.')
448
+ throw 'The requested model does not exist.';
449
+ }
450
+
451
+ var m = this._models[name];
452
+ m.renderer = this._renderer;
453
+
454
+ this._current_model = m;
455
+ this._current_mname = name;
456
+
457
+ this._displayed = m.find({
458
+ 'cell': [
459
+ [0, 0, 0]
460
+ ]
461
+ });
462
+ this._selected = new ModelView(m, []); // Empty
463
+
464
+ // Set the camera in a way that will center the model
465
+ var c = m.fracToAbs([0.5, 0.5, 0.5]);
466
+ this._renderer.resetOrbitCenter(c[0], c[1], c[2]);
467
+
468
+ this._displayed.show();
469
+ }
470
+
471
+ /**
472
+ * Erase a model from the recorded ones
473
+ *
474
+ * @param {String} name Name of the model to delete
475
+ */
476
+ deleteModel(name) {
477
+
478
+ if (!(name in this._models)) {
479
+ throw 'The requested model does not exist!';
480
+ }
481
+
482
+ if (this._current_mname == name) {
483
+ this.displayModel();
484
+ }
485
+
486
+ delete this._models[name];
487
+ }
488
+
489
+ /**
490
+ * Add a primitive shape to the drawing
491
+ *
492
+ * @param {THREE.Object3D} p Primitive to add
493
+ */
494
+ addPrimitive(p) {
495
+ this._renderer.add(p);
496
+ }
497
+
498
+ /**
499
+ * Remove a primitive shape from the drawing
500
+ *
501
+ * @param {THREE.Object3D} p Primitive to remove
502
+ */
503
+ removePrimitive(p) {
504
+ this._renderer.remove(p);
505
+ }
506
+
507
+ /**
508
+ * Add a notification to the list of notifications to be displayed
509
+ */
510
+ addNotification(n) {
511
+ this._notifications.push(n);
512
+ this.addNotifications();
513
+ }
514
+
515
+ /**
516
+ * Adds all notifications to the drawing
517
+ *
518
+ */
519
+ addNotifications() {
520
+ // remove displayed notifications
521
+ // (doesn't remove them from this._notifications)
522
+ this._renderer.clearNotifications();
523
+ // add full list of notifications
524
+ this._renderer.addNotifications(this._notifications);
525
+ }
526
+
527
+ /**
528
+ * Removes notifications from the drawing
529
+ */
530
+ clearNotifications() {
531
+ this._notifications = [];
532
+ this._renderer.clearNotifications();
533
+ }
534
+
535
+ /**
536
+ * Recover a data URL of a PNG screenshot of the current scene
537
+ *
538
+ * @return {String} A data URL of the PNG screenshot
539
+ */
540
+ getScreenshotData(transparent = true, scale_pixels = 3) {
541
+
542
+ var renderer = this._renderer;
543
+ // save current alpha and antialias settings
544
+ var old_alpha = renderer._r.getClearAlpha();
545
+ var old_PixelRatio = renderer._r.getPixelRatio();
546
+
547
+ // set new alpha and antialias settings
548
+ renderer._r.setClearAlpha(transparent ? 0 : 1);
549
+ renderer._r.setPixelRatio(scale_pixels);
550
+
551
+ // Force a render
552
+ this._renderer._render();
553
+ // Grab the data from the canvas
554
+ var data = renderer._r.domElement.toDataURL();
555
+
556
+ // restore old alpha and antialias settings
557
+ renderer._r.setClearAlpha(old_alpha);
558
+ renderer._r.setPixelRatio(old_PixelRatio);
559
+
560
+ return data;
561
+ }
562
+ }
563
+
564
+ addStaticVar(CrystVis, 'LEFT_CLICK', 1);
565
+ addStaticVar(CrystVis, 'MIDDLE_CLICK', 2);
566
+ addStaticVar(CrystVis, 'RIGHT_CLICK', 4);
567
+ addStaticVar(CrystVis, 'ALT_BUTTON', 8);
568
+ addStaticVar(CrystVis, 'CTRL_BUTTON', 16);
569
+ addStaticVar(CrystVis, 'CMD_BUTTON', 16); // Alias for Mac users
570
+ addStaticVar(CrystVis, 'SHIFT_BUTTON', 32);
571
+
572
+ export {
573
+ CrystVis
574
+ }</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><div class="mobile-nav-links"></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-modules"><div>Modules</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="lib_model.module_js.html">lib/model.js</a></div><div class="sidebar-section-children"><a href="lib_modelview.module_js.html">lib/modelview.js</a></div><div class="sidebar-section-children"><a href="lib_visualizer.module_js.html">lib/visualizer.js</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="lib_model.module_js-AtomImage.html">AtomImage</a></div><div class="sidebar-section-children"><a href="lib_model.module_js-BondImage.html">BondImage</a></div><div class="sidebar-section-children"><a href="lib_model.module_js-Model.html">Model</a></div><div class="sidebar-section-children"><a href="lib_modelview.module_js-ModelView.html">ModelView</a></div><div class="sidebar-section-children"><a href="lib_visualizer.module_js-CrystVis.html">CrystVis</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-tutorials"><div>Tutorials</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="tutorial-Events.html">Events</a></div><div class="sidebar-section-children"><a href="tutorial-Queries.html">Queries</a></div><div class="sidebar-section-children"><a href="tutorial-ThreejsMigration.html">ThreejsMigration</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>
File without changes
File without changes