@ccp-nc/crystvis-js 0.4.13

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 (100) hide show
  1. package/.eslintrc.json +16 -0
  2. package/.github/workflows/test-mocha.yml +30 -0
  3. package/.vscode/settings.json +4 -0
  4. package/LICENSE +21 -0
  5. package/README.html +1127 -0
  6. package/README.md +76 -0
  7. package/demo/demo.css +30 -0
  8. package/demo/index.html +76 -0
  9. package/demo/main.js +143 -0
  10. package/docs/.nojekyll +0 -0
  11. package/docs-tutorials/Events.md +57 -0
  12. package/docs-tutorials/Queries.md +50 -0
  13. package/fonts/Rubik/OFL.txt +93 -0
  14. package/fonts/Rubik/README.txt +77 -0
  15. package/fonts/Rubik/Rubik-Italic-VariableFont_wght.ttf +0 -0
  16. package/fonts/Rubik/Rubik-VariableFont_wght.ttf +0 -0
  17. package/fonts/Rubik/static/Rubik-Black.ttf +0 -0
  18. package/fonts/Rubik/static/Rubik-BlackItalic.ttf +0 -0
  19. package/fonts/Rubik/static/Rubik-Bold.ttf +0 -0
  20. package/fonts/Rubik/static/Rubik-BoldItalic.ttf +0 -0
  21. package/fonts/Rubik/static/Rubik-ExtraBold.ttf +0 -0
  22. package/fonts/Rubik/static/Rubik-ExtraBoldItalic.ttf +0 -0
  23. package/fonts/Rubik/static/Rubik-Italic.ttf +0 -0
  24. package/fonts/Rubik/static/Rubik-Light.ttf +0 -0
  25. package/fonts/Rubik/static/Rubik-LightItalic.ttf +0 -0
  26. package/fonts/Rubik/static/Rubik-Medium.ttf +0 -0
  27. package/fonts/Rubik/static/Rubik-MediumItalic.ttf +0 -0
  28. package/fonts/Rubik/static/Rubik-Regular.ttf +0 -0
  29. package/fonts/Rubik/static/Rubik-SemiBold.ttf +0 -0
  30. package/fonts/Rubik/static/Rubik-SemiBoldItalic.ttf +0 -0
  31. package/index.html +25 -0
  32. package/index.js +11 -0
  33. package/jsconf.json +14 -0
  34. package/lib/assets/fonts/Rubik-Medium.fnt +297 -0
  35. package/lib/assets/fonts/Rubik-Medium.png +0 -0
  36. package/lib/assets/fonts/bmpfonts.in.js +16 -0
  37. package/lib/assets/fonts/bmpfonts.js +9 -0
  38. package/lib/assets/fonts/font.js +82 -0
  39. package/lib/assets/fonts/index.js +14 -0
  40. package/lib/assets/fonts/threebmfont.js +28 -0
  41. package/lib/data.js +125 -0
  42. package/lib/formats/cell.js +114 -0
  43. package/lib/formats/cif.js +22 -0
  44. package/lib/formats/magres.js +337 -0
  45. package/lib/formats/xyz.js +124 -0
  46. package/lib/loader.js +87 -0
  47. package/lib/model.js +2076 -0
  48. package/lib/modelview.js +382 -0
  49. package/lib/nmrdata.js +2898 -0
  50. package/lib/orbit.js +1233 -0
  51. package/lib/primitives/atoms.js +261 -0
  52. package/lib/primitives/cell.js +160 -0
  53. package/lib/primitives/dither.js +156 -0
  54. package/lib/primitives/ellipsoid.js +183 -0
  55. package/lib/primitives/geometries.js +20 -0
  56. package/lib/primitives/index.js +48 -0
  57. package/lib/primitives/isosurface.js +171 -0
  58. package/lib/primitives/shapes.js +100 -0
  59. package/lib/primitives/sprites.js +172 -0
  60. package/lib/query.js +158 -0
  61. package/lib/render.js +440 -0
  62. package/lib/selbox.js +361 -0
  63. package/lib/shaders/aura.frag +26 -0
  64. package/lib/shaders/aura.vert +37 -0
  65. package/lib/shaders/dither.frag +42 -0
  66. package/lib/shaders/dither.vert +8 -0
  67. package/lib/shaders/index.in.js +17 -0
  68. package/lib/shaders/index.js +25 -0
  69. package/lib/shaders/msdf300.frag +25 -0
  70. package/lib/shaders/msdf300.vert +45 -0
  71. package/lib/tensor.js +227 -0
  72. package/lib/utils.js +168 -0
  73. package/lib/visualizer.js +480 -0
  74. package/package.json +106 -0
  75. package/scripts/build-bundle.js +17 -0
  76. package/scripts/build-fonts.js +43 -0
  77. package/scripts/build-resources.js +46 -0
  78. package/scripts/plugins-shim.js +10 -0
  79. package/test/chemdata.js +69 -0
  80. package/test/data/CHA.cif +74 -0
  81. package/test/data/H2O.xyz +8 -0
  82. package/test/data/H2_bound.xyz +4 -0
  83. package/test/data/ethanol.cell +25 -0
  84. package/test/data/ethanol.magres +238 -0
  85. package/test/data/example_single.cif +789 -0
  86. package/test/data/frac.cell +8 -0
  87. package/test/data/org.cif +427 -0
  88. package/test/data/pyridine.xyz +13 -0
  89. package/test/data/si8.xyz +10 -0
  90. package/test/loader.js +107 -0
  91. package/test/model.js +368 -0
  92. package/test/query.js +135 -0
  93. package/test/tensor.js +133 -0
  94. package/test/test-html/examples.js +1485 -0
  95. package/test/test-html/index.html +33 -0
  96. package/test/test-html/index.js +279 -0
  97. package/tools/compile_colors.py +120 -0
  98. package/tools/compile_periodic.py +96 -0
  99. package/tools/ptable.json +497 -0
  100. package/tools/test +5844 -0
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @fileoverview Function for loading XYZ files
5
+ * @module
6
+ */
7
+
8
+ import _ from 'lodash';
9
+ import { Atoms } from 'crystcif-parse';
10
+
11
+ function load(contents, filename='xyz') {
12
+
13
+ // Split the file into lines
14
+ let lines = _.split(contents, '\n');
15
+
16
+ // Parse the first line: number of atoms
17
+ let N = parseInt(_.trim(lines[0]));
18
+ if (isNaN(N) || lines.length < N + 2) {
19
+ throw Error('Invalid XYZ file');
20
+ }
21
+
22
+ // Parse the second line: comments
23
+ let info = lines[1];
24
+ // Check if it's extended format
25
+ let ext = false;
26
+ let rext = /([A-Za-z]+)=(([A-Za-z0-9.:]+)|"([\s0-9.]+)")/g;
27
+ let m = rext.exec(info);
28
+ let matches = [];
29
+ let cell = null;
30
+ let arrays = [];
31
+ while (m != null) {
32
+ matches.push(m);
33
+ m = rext.exec(info);
34
+ }
35
+ if (matches.length > 0) {
36
+ // It's extended! But does it have the right keywords?
37
+ let props = {};
38
+ for (let i = 0; i < matches.length; ++i) {
39
+ m = matches[i];
40
+ props[m[1]] = m[3] || m[4];
41
+ }
42
+ if ((_.has(props, 'Lattice') && _.has(props, 'Properties'))) {
43
+ // It's valid!
44
+ ext = true;
45
+ // Parse the lattice
46
+ let latt = _.split(props['Lattice'], /\s+/);
47
+ cell = [];
48
+ for (let i = 0; i < 3; ++i) {
49
+ cell.push(_.map(latt.slice(3 * i, 3 * i + 3), parseFloat));
50
+ if (cell[i].indexOf(NaN) > -1) {
51
+ throw Error('Invalid Extended XYZ file');
52
+ }
53
+ }
54
+ if (props['Properties'].slice(0, 19) != 'species:S:1:pos:R:3') {
55
+ throw Error('Invalid Extended XYZ file');
56
+ }
57
+ // Parse the properties
58
+ let propre = /([A-Za-z]+):(S|R|I):([0-9]+)/g;
59
+ let columns = [];
60
+ m = propre.exec(props['Properties'])
61
+ while (m != null) {
62
+ columns.push({
63
+ 'name': m[1],
64
+ 'type': m[2],
65
+ 'n': parseInt(m[3]),
66
+ 'val': [],
67
+ });
68
+ m = propre.exec(props['Properties']);
69
+ }
70
+ // We know the first two are just species and pos
71
+ arrays = columns.slice(2);
72
+ }
73
+
74
+ info = _.omit(props, ['Lattice', 'Properties']);
75
+ } else {
76
+ info = {
77
+ 'comment': info
78
+ };
79
+ }
80
+
81
+ // Parse the following lines: atoms
82
+ let elems = [];
83
+ let pos = [];
84
+ for (let i = 0; i < N; ++i) {
85
+ let lspl = _.split(lines[i + 2], /\s+/);
86
+ elems.push(lspl[0]);
87
+ pos.push(_.map(lspl.slice(1, 4), parseFloat));
88
+ if (pos.indexOf(NaN) > -1) {
89
+ throw Error('Invalid XYZ file');
90
+ }
91
+
92
+ // Any additional parsing required?
93
+ if (ext) {
94
+ lspl.splice(0, 4);
95
+ for (let j = 0; j < arrays.length; ++j) {
96
+ let v = [];
97
+ let parser = {
98
+ 'S': String,
99
+ 'R': parseFloat,
100
+ 'I': parseInt,
101
+ }[arrays[j].type];
102
+ for (let k = 0; k < arrays[j].n; ++k) {
103
+ v.push(parser(lspl.splice(0)));
104
+ }
105
+ v = v.length > 1 ? v : v[0];
106
+ arrays[j].val.push(v);
107
+ }
108
+ }
109
+ }
110
+
111
+ let a = new Atoms(elems, pos, cell, info);
112
+ if (ext) {
113
+ for (let i = 0; i < arrays.length; ++i) {
114
+ a.set_array(arrays[i].name, arrays[i].val);
115
+ }
116
+ }
117
+
118
+ let structs = {};
119
+ structs[filename] = a;
120
+
121
+ return structs;
122
+ }
123
+
124
+ export { load };
package/lib/loader.js ADDED
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @fileoverview Class for loading different types of input files
5
+ * @module
6
+ */
7
+
8
+ import * as CIF from './formats/cif.js';
9
+ import * as XYZ from './formats/xyz.js';
10
+ import * as Magres from './formats/magres.js';
11
+ import * as CELL from './formats/cell.js';
12
+
13
+ import { addStaticVar } from './utils.js';
14
+
15
+ /**
16
+ * Loader - Object used to load various file types into Atoms objects and
17
+ * store any status and error messages resulting from failure.
18
+ */
19
+ class Loader {
20
+
21
+ constructor() {
22
+ this._status = Loader.STATUS_UNUSED;
23
+ this._error = '';
24
+ }
25
+
26
+ get status() {
27
+ return this._status;
28
+ }
29
+
30
+ get error_message() {
31
+ return this._error;
32
+ }
33
+
34
+ /** Load file from its contents and format
35
+ *
36
+ * @param {String} contents File contents
37
+ * @param {String} format File extension
38
+ * @param {String} filename Name of the file. If provided, this will be
39
+ * added as a prefix to all the names in the dictionary
40
+ *
41
+ * @return {Object} Dictionary of parsed structure(s)
42
+ */
43
+ load(contents, format='cif', filename=null) {
44
+
45
+ const parsers = {
46
+ cif: CIF,
47
+ xyz: XYZ,
48
+ magres: Magres,
49
+ cell: CELL
50
+ };
51
+
52
+ format = format.toLowerCase();
53
+
54
+ if (!(format in parsers)) {
55
+ throw Error('Invalid file format');
56
+ }
57
+
58
+ this._error = '';
59
+
60
+ let structs;
61
+
62
+ try {
63
+ if (filename)
64
+ structs = parsers[format].load(contents, filename);
65
+ else
66
+ structs = parsers[format].load(contents);
67
+ } catch (err) {
68
+ this._status = Loader.STATUS_ERROR;
69
+ this._error = err.message || err;
70
+ return;
71
+ }
72
+
73
+ this._status = Loader.STATUS_SUCCESS;
74
+
75
+ return structs;
76
+ }
77
+ }
78
+
79
+ // Define static properties old style, for better compatibility
80
+ addStaticVar(Loader, 'STATUS_UNUSED', -1);
81
+ addStaticVar(Loader, 'STATUS_SUCCESS', 0);
82
+ addStaticVar(Loader, 'STATUS_ERROR', 1);
83
+
84
+
85
+ export {
86
+ Loader
87
+ }