matsci-parse 0.3.0 → 0.3.1
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.
- package/dist/main.js +359 -338
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class S {
|
|
2
2
|
constructor(s, e, t = {}) {
|
|
3
3
|
this.speciesIndex = s, this.cart = e, this.props = t;
|
|
4
4
|
}
|
|
@@ -9,34 +9,53 @@ class v {
|
|
|
9
9
|
this.props[s] = e;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
-
function B(
|
|
13
|
-
return
|
|
12
|
+
function B(i) {
|
|
13
|
+
return i.sites.some((s) => Array.isArray(s.props.selectiveDynamics));
|
|
14
14
|
}
|
|
15
|
-
function M(
|
|
16
|
-
return
|
|
15
|
+
function M(i) {
|
|
16
|
+
return i * Math.PI / 180;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
18
|
+
function O(i, s) {
|
|
19
|
+
return i.map(
|
|
20
20
|
(e) => e[0] * s[0] + e[1] * s[1] + e[2] * s[2]
|
|
21
21
|
);
|
|
22
22
|
}
|
|
23
|
-
function k(
|
|
24
|
-
const
|
|
25
|
-
s * Math.cos(
|
|
26
|
-
s * Math.sin(
|
|
23
|
+
function k(i, s, e, t, m, o) {
|
|
24
|
+
const n = M(t), u = M(m), a = M(o), b = [i, 0, 0], h = [
|
|
25
|
+
s * Math.cos(a),
|
|
26
|
+
s * Math.sin(a),
|
|
27
27
|
0
|
|
28
|
-
],
|
|
29
|
-
return [
|
|
28
|
+
], r = e * Math.cos(u), l = e * (Math.cos(n) - Math.cos(u) * Math.cos(a)) / Math.sin(a), y = Math.sqrt(e * e - r * r - l * l);
|
|
29
|
+
return [b, h, [r, l, y]];
|
|
30
30
|
}
|
|
31
|
-
function U(
|
|
32
|
-
const [e, t,
|
|
31
|
+
function U(i, s) {
|
|
32
|
+
const [e, t, m] = s;
|
|
33
33
|
return [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
i[0] * e[0] + i[1] * t[0] + i[2] * m[0],
|
|
35
|
+
i[0] * e[1] + i[1] * t[1] + i[2] * m[1],
|
|
36
|
+
i[0] * e[2] + i[1] * t[2] + i[2] * m[2]
|
|
37
37
|
];
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
function X(i) {
|
|
40
|
+
const [[s, e, t], [m, o, n], [u, a, b]] = i, h = o * b - n * a, r = -(m * b - n * u), l = m * a - o * u, y = -(e * b - t * a), c = s * b - t * u, p = -(s * a - e * u), N = e * n - t * o, g = -(s * n - t * m), _ = s * o - e * m, v = s * h + e * r + t * l;
|
|
41
|
+
if (Math.abs(v) < 1e-12)
|
|
42
|
+
throw new Error("Matrix is singular and cannot be inverted");
|
|
43
|
+
const f = 1 / v;
|
|
44
|
+
return [
|
|
45
|
+
[h * f, y * f, N * f],
|
|
46
|
+
[r * f, c * f, g * f],
|
|
47
|
+
[l * f, p * f, _ * f]
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
function J(i, s) {
|
|
51
|
+
const [e, t, m] = s, o = [
|
|
52
|
+
[e[0], t[0], m[0]],
|
|
53
|
+
[e[1], t[1], m[1]],
|
|
54
|
+
[e[2], t[2], m[2]]
|
|
55
|
+
], n = X(o);
|
|
56
|
+
return O(n, i);
|
|
57
|
+
}
|
|
58
|
+
class F {
|
|
40
59
|
/**
|
|
41
60
|
* Creates a new CrystalStructure.
|
|
42
61
|
*
|
|
@@ -93,9 +112,9 @@ class I {
|
|
|
93
112
|
* @param position - Optional index at which to insert the site. Defaults to appending at the end.
|
|
94
113
|
*/
|
|
95
114
|
addSite(s, e, t) {
|
|
96
|
-
let
|
|
97
|
-
|
|
98
|
-
const o = new
|
|
115
|
+
let m = this.species.indexOf(s);
|
|
116
|
+
m === -1 && (this.species.push(s), m = this.species.length - 1);
|
|
117
|
+
const o = new S(m, e);
|
|
99
118
|
t === void 0 || t >= this.sites.length ? this.sites.push(o) : t < 0 ? this.sites.unshift(o) : this.sites.splice(t, 0, o);
|
|
100
119
|
}
|
|
101
120
|
/**
|
|
@@ -167,18 +186,18 @@ class I {
|
|
|
167
186
|
"Scale must be a number, a 3-element array, or a 3x3 matrix"
|
|
168
187
|
);
|
|
169
188
|
const t = this.lattice.map(
|
|
170
|
-
(o) =>
|
|
171
|
-
),
|
|
172
|
-
const
|
|
189
|
+
(o) => O(e, o)
|
|
190
|
+
), m = this.sites.map((o) => {
|
|
191
|
+
const n = O(
|
|
173
192
|
e,
|
|
174
193
|
o.cart
|
|
175
194
|
);
|
|
176
|
-
return new
|
|
195
|
+
return new S(o.speciesIndex, n, o.props);
|
|
177
196
|
});
|
|
178
|
-
return new
|
|
197
|
+
return new F({
|
|
179
198
|
lattice: t,
|
|
180
199
|
species: [...this.species],
|
|
181
|
-
sites:
|
|
200
|
+
sites: m
|
|
182
201
|
});
|
|
183
202
|
}
|
|
184
203
|
// ---------- Internal validation ----------
|
|
@@ -212,9 +231,9 @@ class I {
|
|
|
212
231
|
_validateSites(s) {
|
|
213
232
|
if (!Array.isArray(s)) throw new Error("Sites must be an array");
|
|
214
233
|
return s.map((e) => {
|
|
215
|
-
if (e instanceof
|
|
234
|
+
if (e instanceof S) return e;
|
|
216
235
|
if (typeof e == "object" && typeof e.speciesIndex == "number" && Array.isArray(e.cart) && e.cart.length === 3)
|
|
217
|
-
return this._validateSpeciesIndex(e.speciesIndex), new
|
|
236
|
+
return this._validateSpeciesIndex(e.speciesIndex), new S(
|
|
218
237
|
e.speciesIndex,
|
|
219
238
|
e.cart,
|
|
220
239
|
e.props ?? {}
|
|
@@ -233,27 +252,27 @@ class I {
|
|
|
233
252
|
throw new Error("speciesIndex out of bounds");
|
|
234
253
|
}
|
|
235
254
|
}
|
|
236
|
-
class
|
|
255
|
+
class Z {
|
|
237
256
|
constructor(s) {
|
|
238
257
|
this.spatialUnits = "angstrom", this._invalid = !0;
|
|
239
|
-
const { origin: e, basis: t, shape:
|
|
240
|
-
if (o.length !==
|
|
258
|
+
const { origin: e, basis: t, shape: m, values: o, components: n = 1, units: u } = s, [a, b, h] = m;
|
|
259
|
+
if (o.length !== a * b * h * n)
|
|
241
260
|
throw new Error(
|
|
242
|
-
`Invalid values length: expected ${
|
|
261
|
+
`Invalid values length: expected ${a * b * h * n}, got ${o.length}`
|
|
243
262
|
);
|
|
244
|
-
this.origin = e, this.basis = t, this.shape =
|
|
263
|
+
this.origin = e, this.basis = t, this.shape = m, this.values = o, this.components = n, this.units = u;
|
|
245
264
|
}
|
|
246
265
|
invalidate() {
|
|
247
266
|
this._invalid = !0;
|
|
248
267
|
}
|
|
249
268
|
map(s) {
|
|
250
|
-
const [e, t,
|
|
251
|
-
for (let o = 0; o <
|
|
252
|
-
for (let
|
|
253
|
-
for (let
|
|
254
|
-
for (let
|
|
255
|
-
const
|
|
256
|
-
this.values[
|
|
269
|
+
const [e, t, m] = this.shape;
|
|
270
|
+
for (let o = 0; o < m; o++)
|
|
271
|
+
for (let n = 0; n < t; n++)
|
|
272
|
+
for (let u = 0; u < e; u++)
|
|
273
|
+
for (let a = 0; a < this.components; a++) {
|
|
274
|
+
const b = this.index(u, n, o, a);
|
|
275
|
+
this.values[b] = s(this.values[b], u, n, o, a);
|
|
257
276
|
}
|
|
258
277
|
this.invalidate();
|
|
259
278
|
}
|
|
@@ -266,15 +285,15 @@ class X {
|
|
|
266
285
|
mean() {
|
|
267
286
|
return (this._invalid || this._mean === void 0) && this.computeStats(), this._mean;
|
|
268
287
|
}
|
|
269
|
-
index(s, e, t,
|
|
270
|
-
const [o,
|
|
271
|
-
return (s + o * (e +
|
|
288
|
+
index(s, e, t, m = 0) {
|
|
289
|
+
const [o, n] = this.shape;
|
|
290
|
+
return (s + o * (e + n * t)) * this.components + m;
|
|
272
291
|
}
|
|
273
|
-
get(s, e, t,
|
|
274
|
-
return this.values[this.index(s, e, t,
|
|
292
|
+
get(s, e, t, m = 0) {
|
|
293
|
+
return this.values[this.index(s, e, t, m)];
|
|
275
294
|
}
|
|
276
|
-
set(s, e, t,
|
|
277
|
-
this.values[this.index(s, e, t,
|
|
295
|
+
set(s, e, t, m, o = 0) {
|
|
296
|
+
this.values[this.index(s, e, t, o)] = m, this.invalidate();
|
|
278
297
|
}
|
|
279
298
|
normalize() {
|
|
280
299
|
const s = this.min(), e = this.max();
|
|
@@ -282,11 +301,11 @@ class X {
|
|
|
282
301
|
}
|
|
283
302
|
/** Convert grid index → Cartesian position */
|
|
284
303
|
position(s, e, t) {
|
|
285
|
-
const [
|
|
304
|
+
const [m, o, n] = this.basis;
|
|
286
305
|
return [
|
|
287
|
-
this.origin[0] + s *
|
|
288
|
-
this.origin[1] + s *
|
|
289
|
-
this.origin[2] + s *
|
|
306
|
+
this.origin[0] + s * m[0] + e * o[0] + t * n[0],
|
|
307
|
+
this.origin[1] + s * m[1] + e * o[1] + t * n[1],
|
|
308
|
+
this.origin[2] + s * m[2] + e * o[2] + t * n[2]
|
|
290
309
|
];
|
|
291
310
|
}
|
|
292
311
|
voxelVolume() {
|
|
@@ -300,114 +319,114 @@ class X {
|
|
|
300
319
|
}
|
|
301
320
|
computeStats() {
|
|
302
321
|
const s = this.values.length;
|
|
303
|
-
let e = 1 / 0, t = -1 / 0,
|
|
322
|
+
let e = 1 / 0, t = -1 / 0, m = 0;
|
|
304
323
|
for (let o = 0; o < s; o++) {
|
|
305
|
-
const
|
|
306
|
-
|
|
324
|
+
const n = this.values[o];
|
|
325
|
+
n < e && (e = n), n > t && (t = n), m += n;
|
|
307
326
|
}
|
|
308
|
-
this._min = e, this._max = t, this._mean =
|
|
327
|
+
this._min = e, this._max = t, this._mean = m / s, this._invalid = !1;
|
|
309
328
|
}
|
|
310
329
|
}
|
|
311
|
-
function
|
|
312
|
-
return
|
|
330
|
+
function I(i) {
|
|
331
|
+
return i.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
313
332
|
}
|
|
314
|
-
function
|
|
315
|
-
const e = [], t = B(
|
|
316
|
-
e.push("Generated by matsci-parse"), e.push("1.0"),
|
|
317
|
-
e.push(
|
|
333
|
+
function Q(i, s = 6) {
|
|
334
|
+
const e = [], t = B(i);
|
|
335
|
+
e.push("Generated by matsci-parse"), e.push("1.0"), i.lattice.forEach((n) => {
|
|
336
|
+
e.push(n.map((u) => u.toFixed(s)).join(" "));
|
|
318
337
|
});
|
|
319
|
-
const
|
|
320
|
-
new Set(
|
|
321
|
-
), o =
|
|
322
|
-
(
|
|
338
|
+
const m = Array.from(
|
|
339
|
+
new Set(i.sites.map((n) => i.species[n.speciesIndex]))
|
|
340
|
+
), o = m.map(
|
|
341
|
+
(n) => i.sites.filter((u) => i.species[u.speciesIndex] === n).length
|
|
323
342
|
);
|
|
324
|
-
return e.push(
|
|
325
|
-
|
|
326
|
-
const
|
|
343
|
+
return e.push(m.join(" ")), e.push(o.join(" ")), t && e.push("Selective dynamics"), e.push("Cartesian"), m.forEach((n) => {
|
|
344
|
+
i.sites.filter((u) => i.species[u.speciesIndex] === n).forEach((u) => {
|
|
345
|
+
const a = u.cart.map((b) => b.toFixed(s)).join(" ");
|
|
327
346
|
if (t) {
|
|
328
|
-
const h = (Array.isArray(
|
|
329
|
-
e.push(`${
|
|
347
|
+
const h = (Array.isArray(u.props?.selectiveDynamics) ? u.props.selectiveDynamics : [!0, !0, !0]).map((r) => r ? "T" : "F").join(" ");
|
|
348
|
+
e.push(`${a} ${h}`);
|
|
330
349
|
} else
|
|
331
|
-
e.push(
|
|
350
|
+
e.push(a);
|
|
332
351
|
});
|
|
333
352
|
}), e.join(`
|
|
334
353
|
`);
|
|
335
354
|
}
|
|
336
|
-
function
|
|
355
|
+
function z(i) {
|
|
337
356
|
let s = 0;
|
|
338
357
|
s++;
|
|
339
|
-
const e = parseFloat(
|
|
340
|
-
for (let
|
|
358
|
+
const e = parseFloat(i[s++]), t = [];
|
|
359
|
+
for (let r = 0; r < 3; r++)
|
|
341
360
|
t.push(
|
|
342
|
-
|
|
361
|
+
i[s++].split(/\s+/).map((l) => parseFloat(l) * e)
|
|
343
362
|
);
|
|
344
|
-
let
|
|
345
|
-
/^[A-Za-z]/.test(
|
|
346
|
-
const
|
|
347
|
-
o || (o =
|
|
348
|
-
let
|
|
349
|
-
|
|
350
|
-
const
|
|
351
|
-
return o.forEach((
|
|
352
|
-
for (let
|
|
353
|
-
const
|
|
363
|
+
let m = i[s].trim(), o;
|
|
364
|
+
/^[A-Za-z]/.test(m) && (o = m.split(/\s+/), s++);
|
|
365
|
+
const n = i[s++].split(/\s+/).map(Number);
|
|
366
|
+
o || (o = n.map((r, l) => `X${l + 1}`));
|
|
367
|
+
let u = !1;
|
|
368
|
+
i[s]?.toLowerCase().startsWith("s") && (u = !0, s++);
|
|
369
|
+
const b = i[s++].toLowerCase().startsWith("d"), h = [];
|
|
370
|
+
return o.forEach((r, l) => {
|
|
371
|
+
for (let y = 0; y < n[l]; y++) {
|
|
372
|
+
const c = i[s++].split(/\s+/).map(Number);
|
|
354
373
|
let p;
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
] : p =
|
|
374
|
+
b ? p = [
|
|
375
|
+
c[0] * t[0][0] + c[1] * t[1][0] + c[2] * t[2][0],
|
|
376
|
+
c[0] * t[0][1] + c[1] * t[1][1] + c[2] * t[2][1],
|
|
377
|
+
c[0] * t[0][2] + c[1] * t[1][2] + c[2] * t[2][2]
|
|
378
|
+
] : p = c.slice(0, 3);
|
|
360
379
|
const N = {};
|
|
361
|
-
if (
|
|
362
|
-
const g =
|
|
380
|
+
if (u) {
|
|
381
|
+
const g = c.slice(3, 6).map((_) => _ === 1);
|
|
363
382
|
g.length === 3 && (N.selectiveDynamics = g);
|
|
364
383
|
}
|
|
365
|
-
h.push(new
|
|
384
|
+
h.push(new S(l, p, N));
|
|
366
385
|
}
|
|
367
386
|
}), {
|
|
368
|
-
structure: new
|
|
387
|
+
structure: new F({ lattice: t, species: o, sites: h }),
|
|
369
388
|
linesConsumed: s
|
|
370
389
|
};
|
|
371
390
|
}
|
|
372
|
-
function
|
|
373
|
-
const s =
|
|
374
|
-
return
|
|
391
|
+
function ss(i) {
|
|
392
|
+
const s = I(i);
|
|
393
|
+
return z(s).structure;
|
|
375
394
|
}
|
|
376
|
-
function
|
|
395
|
+
function es(i, s = 6) {
|
|
377
396
|
const e = [];
|
|
378
|
-
return e.push("CRYSTAL"), e.push("PRIMVEC"),
|
|
379
|
-
e.push(t.map((
|
|
380
|
-
}), e.push("PRIMCOORD"), e.push(`${
|
|
381
|
-
const
|
|
397
|
+
return e.push("CRYSTAL"), e.push("PRIMVEC"), i.lattice.forEach((t) => {
|
|
398
|
+
e.push(t.map((m) => m.toFixed(s)).join(" "));
|
|
399
|
+
}), e.push("PRIMCOORD"), e.push(`${i.numSites} 1`), i.sites.forEach((t) => {
|
|
400
|
+
const m = i.species[t.speciesIndex];
|
|
382
401
|
e.push(
|
|
383
|
-
`${
|
|
402
|
+
`${m} ${t.cart.map((o) => o.toFixed(s)).join(" ")}`
|
|
384
403
|
);
|
|
385
404
|
}), e.join(`
|
|
386
405
|
`);
|
|
387
406
|
}
|
|
388
|
-
function
|
|
389
|
-
const s =
|
|
407
|
+
function ts(i) {
|
|
408
|
+
const s = I(i), e = [], t = [], m = [];
|
|
390
409
|
let o = 0;
|
|
391
410
|
for (; o < s.length && s[o].toUpperCase() !== "PRIMVEC"; ) o++;
|
|
392
411
|
if (o === s.length) throw new Error("PRIMVEC block not found in XSF");
|
|
393
412
|
o++;
|
|
394
|
-
for (let
|
|
413
|
+
for (let u = 0; u < 3; u++)
|
|
395
414
|
e.push(s[o++].split(/\s+/).map(Number));
|
|
396
415
|
for (; o < s.length && s[o].toUpperCase() !== "PRIMCOORD"; ) o++;
|
|
397
416
|
if (o === s.length) throw new Error("PRIMCOORD block not found in XSF");
|
|
398
417
|
o++;
|
|
399
|
-
const [
|
|
400
|
-
for (let
|
|
401
|
-
const
|
|
402
|
-
let
|
|
403
|
-
|
|
418
|
+
const [n] = s[o++].split(/\s+/).map(Number);
|
|
419
|
+
for (let u = 0; u < n; u++) {
|
|
420
|
+
const a = s[o++].split(/\s+/), b = a[0], h = a.slice(1, 4).map(Number);
|
|
421
|
+
let r = t.indexOf(b);
|
|
422
|
+
r === -1 && (t.push(b), r = t.length - 1), m.push(new S(r, h));
|
|
404
423
|
}
|
|
405
|
-
return new
|
|
424
|
+
return new F({ lattice: e, species: t, sites: m });
|
|
406
425
|
}
|
|
407
|
-
function
|
|
408
|
-
const e = [], t =
|
|
426
|
+
function os(i, s = 6) {
|
|
427
|
+
const e = [], t = i.sites.length;
|
|
409
428
|
e.push(String(t));
|
|
410
|
-
const
|
|
429
|
+
const m = B(i), o = i.lattice, n = [
|
|
411
430
|
o[0][0],
|
|
412
431
|
o[1][0],
|
|
413
432
|
o[2][0],
|
|
@@ -417,115 +436,115 @@ function es(m, s = 6) {
|
|
|
417
436
|
o[0][2],
|
|
418
437
|
o[1][2],
|
|
419
438
|
o[2][2]
|
|
420
|
-
].join(" "),
|
|
439
|
+
].join(" "), u = [
|
|
421
440
|
"species:S:1",
|
|
422
441
|
"pos:R:3",
|
|
423
|
-
|
|
442
|
+
m ? "selectiveDynamics:L:3" : null
|
|
424
443
|
].filter(Boolean).join(":");
|
|
425
|
-
e.push(`Lattice="${
|
|
426
|
-
for (const
|
|
427
|
-
const
|
|
428
|
-
let
|
|
429
|
-
if (
|
|
430
|
-
const
|
|
431
|
-
|
|
444
|
+
e.push(`Lattice="${n}" Properties=${u}`);
|
|
445
|
+
for (const a of i.sites) {
|
|
446
|
+
const b = i.species[a.speciesIndex], [h, r, l] = a.cart;
|
|
447
|
+
let y = `${b} ${h.toFixed(s)} ${r.toFixed(s)} ${l.toFixed(s)}`;
|
|
448
|
+
if (m) {
|
|
449
|
+
const c = Array.isArray(a.props?.selectiveDynamics) ? a.props.selectiveDynamics : [!0, !0, !0];
|
|
450
|
+
y += " " + c.map((p) => p ? "T" : "F").join(" ");
|
|
432
451
|
}
|
|
433
|
-
e.push(
|
|
452
|
+
e.push(y);
|
|
434
453
|
}
|
|
435
454
|
return e.join(`
|
|
436
455
|
`);
|
|
437
456
|
}
|
|
438
|
-
function
|
|
439
|
-
const s =
|
|
457
|
+
function is(i) {
|
|
458
|
+
const s = I(i);
|
|
440
459
|
let e = 0;
|
|
441
460
|
const t = parseInt(s[e++], 10);
|
|
442
461
|
if (!Number.isFinite(t))
|
|
443
462
|
throw new Error("Invalid XYZ: first line must be atom count");
|
|
444
|
-
const
|
|
445
|
-
for (const
|
|
446
|
-
let p =
|
|
447
|
-
p.startsWith('"') && (p = p.slice(1, -1)), o[
|
|
463
|
+
const m = s[e++], o = {}, n = /(\w+)=(".*?"|\S+)/g;
|
|
464
|
+
for (const c of m.matchAll(n)) {
|
|
465
|
+
let p = c[2];
|
|
466
|
+
p.startsWith('"') && (p = p.slice(1, -1)), o[c[1]] = p;
|
|
448
467
|
}
|
|
449
|
-
let
|
|
468
|
+
let u;
|
|
450
469
|
if (o.Lattice) {
|
|
451
|
-
const
|
|
452
|
-
if (
|
|
453
|
-
|
|
454
|
-
[
|
|
455
|
-
[
|
|
456
|
-
[
|
|
470
|
+
const c = o.Lattice.split(/\s+/).map(Number);
|
|
471
|
+
if (c.length !== 9) throw new Error("Invalid Lattice in extended XYZ");
|
|
472
|
+
u = [
|
|
473
|
+
[c[0], c[3], c[6]],
|
|
474
|
+
[c[1], c[4], c[7]],
|
|
475
|
+
[c[2], c[5], c[8]]
|
|
457
476
|
];
|
|
458
477
|
} else
|
|
459
478
|
throw new Error("Lattice must be present in extended XYZ format");
|
|
460
|
-
let
|
|
479
|
+
let a = 0, b = 1, h = null;
|
|
461
480
|
if (o.Properties) {
|
|
462
|
-
const
|
|
481
|
+
const c = o.Properties.split(":");
|
|
463
482
|
let p = 0;
|
|
464
|
-
for (let N = 0; N <
|
|
465
|
-
const g =
|
|
466
|
-
g === "species" && (
|
|
483
|
+
for (let N = 0; N < c.length; N += 3) {
|
|
484
|
+
const g = c[N], _ = parseInt(c[N + 2], 10);
|
|
485
|
+
g === "species" && (a = p), g === "pos" && (b = p), g === "selectiveDynamics" && (h = p), p += _;
|
|
467
486
|
}
|
|
468
487
|
}
|
|
469
|
-
const
|
|
470
|
-
for (let
|
|
471
|
-
const p = s[e++].split(/\s+/), N = p[
|
|
472
|
-
l.has(N) || (l.set(N,
|
|
473
|
-
const g = l.get(N), _ = p.slice(
|
|
488
|
+
const r = [], l = /* @__PURE__ */ new Map(), y = [];
|
|
489
|
+
for (let c = 0; c < t; c++) {
|
|
490
|
+
const p = s[e++].split(/\s+/), N = p[a];
|
|
491
|
+
l.has(N) || (l.set(N, r.length), r.push(N));
|
|
492
|
+
const g = l.get(N), _ = p.slice(b, b + 3).map(Number), v = {};
|
|
474
493
|
if (h !== null) {
|
|
475
|
-
const
|
|
476
|
-
|
|
494
|
+
const f = p.slice(h, h + 3).map((d) => d.toUpperCase() === "T");
|
|
495
|
+
f.length === 3 && (v.selectiveDynamics = f);
|
|
477
496
|
}
|
|
478
|
-
|
|
497
|
+
y.push(new S(g, _, v));
|
|
479
498
|
}
|
|
480
|
-
return new
|
|
499
|
+
return new F({ lattice: u, species: r, sites: y });
|
|
481
500
|
}
|
|
482
|
-
function C(
|
|
483
|
-
return
|
|
501
|
+
function C(i, s) {
|
|
502
|
+
return i[0] * s[0] + i[1] * s[1] + i[2] * s[2];
|
|
484
503
|
}
|
|
485
|
-
function L(
|
|
486
|
-
return Math.sqrt(C(
|
|
504
|
+
function L(i) {
|
|
505
|
+
return Math.sqrt(C(i, i));
|
|
487
506
|
}
|
|
488
|
-
function P(
|
|
489
|
-
return
|
|
507
|
+
function P(i) {
|
|
508
|
+
return i * 180 / Math.PI;
|
|
490
509
|
}
|
|
491
|
-
function
|
|
492
|
-
const [e, t,
|
|
510
|
+
function G(i, s) {
|
|
511
|
+
const [e, t, m] = s, o = e[0] * (t[1] * m[2] - t[2] * m[1]) - e[1] * (t[0] * m[2] - t[2] * m[0]) + e[2] * (t[0] * m[1] - t[1] * m[0]);
|
|
493
512
|
if (Math.abs(o) < 1e-12)
|
|
494
513
|
throw new Error("Singular lattice matrix");
|
|
495
|
-
const
|
|
514
|
+
const n = [
|
|
496
515
|
[
|
|
497
|
-
(t[1] *
|
|
498
|
-
(e[2] *
|
|
516
|
+
(t[1] * m[2] - t[2] * m[1]) / o,
|
|
517
|
+
(e[2] * m[1] - e[1] * m[2]) / o,
|
|
499
518
|
(e[1] * t[2] - e[2] * t[1]) / o
|
|
500
519
|
],
|
|
501
520
|
[
|
|
502
|
-
(t[2] *
|
|
503
|
-
(e[0] *
|
|
521
|
+
(t[2] * m[0] - t[0] * m[2]) / o,
|
|
522
|
+
(e[0] * m[2] - e[2] * m[0]) / o,
|
|
504
523
|
(e[2] * t[0] - e[0] * t[2]) / o
|
|
505
524
|
],
|
|
506
525
|
[
|
|
507
|
-
(t[0] *
|
|
508
|
-
(e[1] *
|
|
526
|
+
(t[0] * m[1] - t[1] * m[0]) / o,
|
|
527
|
+
(e[1] * m[0] - e[0] * m[1]) / o,
|
|
509
528
|
(e[0] * t[1] - e[1] * t[0]) / o
|
|
510
529
|
]
|
|
511
530
|
];
|
|
512
531
|
return [
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
532
|
+
i[0] * n[0][0] + i[1] * n[1][0] + i[2] * n[2][0],
|
|
533
|
+
i[0] * n[0][1] + i[1] * n[1][1] + i[2] * n[2][1],
|
|
534
|
+
i[0] * n[0][2] + i[1] * n[1][2] + i[2] * n[2][2]
|
|
516
535
|
];
|
|
517
536
|
}
|
|
518
|
-
function ms(
|
|
519
|
-
const [e, t,
|
|
520
|
-
let
|
|
537
|
+
function ms(i, s = 6) {
|
|
538
|
+
const [e, t, m] = i.lattice, o = L(e), n = L(t), u = L(m), a = P(Math.acos(C(t, m) / (n * u))), b = P(Math.acos(C(e, m) / (o * u))), h = P(Math.acos(C(e, t) / (o * n)));
|
|
539
|
+
let r = `data_made_with_matsci-parse
|
|
521
540
|
_symmetry_space_group_name_H-M 'P 1'
|
|
522
541
|
_symmetry_Int_Tables_number 1
|
|
523
542
|
|
|
524
543
|
_cell_length_a ${o.toFixed(s)}
|
|
525
|
-
_cell_length_b ${
|
|
526
|
-
_cell_length_c ${
|
|
527
|
-
_cell_angle_alpha ${
|
|
528
|
-
_cell_angle_beta ${
|
|
544
|
+
_cell_length_b ${n.toFixed(s)}
|
|
545
|
+
_cell_length_c ${u.toFixed(s)}
|
|
546
|
+
_cell_angle_alpha ${a.toFixed(s)}
|
|
547
|
+
_cell_angle_beta ${b.toFixed(s)}
|
|
529
548
|
_cell_angle_gamma ${h.toFixed(s)}
|
|
530
549
|
|
|
531
550
|
loop_
|
|
@@ -535,73 +554,73 @@ function ms(m, s = 6) {
|
|
|
535
554
|
_atom_site_fract_y
|
|
536
555
|
_atom_site_fract_z
|
|
537
556
|
`;
|
|
538
|
-
return
|
|
539
|
-
const
|
|
540
|
-
|
|
557
|
+
return i.sites.forEach((l, y) => {
|
|
558
|
+
const c = i.species[l.speciesIndex], p = G(l.cart, i.lattice);
|
|
559
|
+
r += `${c}${y + 1} ${c} ${p[0].toFixed(s)} ${p[1].toFixed(
|
|
541
560
|
6
|
|
542
561
|
)} ${p[2].toFixed(s)}
|
|
543
562
|
`;
|
|
544
|
-
}),
|
|
563
|
+
}), r;
|
|
545
564
|
}
|
|
546
|
-
function
|
|
547
|
-
const s =
|
|
548
|
-
let e = 0, t = 0,
|
|
549
|
-
const
|
|
550
|
-
let h = !1,
|
|
551
|
-
for (const
|
|
552
|
-
const d =
|
|
565
|
+
function ns(i) {
|
|
566
|
+
const s = I(i);
|
|
567
|
+
let e = 0, t = 0, m = 0, o = 0, n = 0, u = 0, a = [];
|
|
568
|
+
const b = [];
|
|
569
|
+
let h = !1, r = [], l = !1;
|
|
570
|
+
for (const f of s) {
|
|
571
|
+
const d = f.trim();
|
|
553
572
|
if (d) {
|
|
554
573
|
if (d.startsWith("_cell_length_a")) e = parseFloat(d.split(/\s+/)[1]);
|
|
555
574
|
else if (d.startsWith("_cell_length_b"))
|
|
556
575
|
t = parseFloat(d.split(/\s+/)[1]);
|
|
557
576
|
else if (d.startsWith("_cell_length_c"))
|
|
558
|
-
|
|
577
|
+
m = parseFloat(d.split(/\s+/)[1]);
|
|
559
578
|
else if (d.startsWith("_cell_angle_alpha"))
|
|
560
579
|
o = parseFloat(d.split(/\s+/)[1]);
|
|
561
580
|
else if (d.startsWith("_cell_angle_beta"))
|
|
562
|
-
|
|
581
|
+
n = parseFloat(d.split(/\s+/)[1]);
|
|
563
582
|
else if (d.startsWith("_cell_angle_gamma"))
|
|
564
|
-
|
|
583
|
+
u = parseFloat(d.split(/\s+/)[1]);
|
|
565
584
|
else if (d.startsWith("loop_")) {
|
|
566
|
-
h = !0,
|
|
585
|
+
h = !0, r = [], l = !1;
|
|
567
586
|
continue;
|
|
568
587
|
}
|
|
569
588
|
if (h && d.startsWith("_")) {
|
|
570
|
-
|
|
589
|
+
r.push(d), d.includes("_atom_site_") && (l = !0);
|
|
571
590
|
continue;
|
|
572
591
|
}
|
|
573
592
|
if (h && !d.startsWith("_")) {
|
|
574
|
-
l && (
|
|
593
|
+
l && (a.length === 0 && (a = [...r]), b.push(d.split(/\s+/)));
|
|
575
594
|
continue;
|
|
576
595
|
}
|
|
577
596
|
}
|
|
578
597
|
}
|
|
579
|
-
if (
|
|
598
|
+
if (a.length === 0)
|
|
580
599
|
throw new Error("No _atom_site loop found in CIF");
|
|
581
|
-
const
|
|
582
|
-
if (N < 0 || g < 0 || _ < 0 ||
|
|
600
|
+
const y = k(e, t, m, o, n, u), c = [], p = [], N = a.findIndex((f) => f.includes("fract_x")), g = a.findIndex((f) => f.includes("fract_y")), _ = a.findIndex((f) => f.includes("fract_z")), v = a.findIndex((f) => f.includes("type_symbol"));
|
|
601
|
+
if (N < 0 || g < 0 || _ < 0 || v < 0)
|
|
583
602
|
throw new Error("CIF missing required _atom_site columns");
|
|
584
|
-
for (const
|
|
603
|
+
for (const f of b) {
|
|
585
604
|
const d = [
|
|
586
|
-
parseFloat(
|
|
587
|
-
parseFloat(
|
|
588
|
-
parseFloat(
|
|
589
|
-
], w = U(d,
|
|
590
|
-
let x =
|
|
591
|
-
x === -1 && (x =
|
|
592
|
-
}
|
|
593
|
-
return new
|
|
605
|
+
parseFloat(f[N]),
|
|
606
|
+
parseFloat(f[g]),
|
|
607
|
+
parseFloat(f[_])
|
|
608
|
+
], w = U(d, y);
|
|
609
|
+
let x = c.indexOf(f[v]);
|
|
610
|
+
x === -1 && (x = c.length, c.push(f[v])), p.push(new S(x, w));
|
|
611
|
+
}
|
|
612
|
+
return new F({ lattice: y, species: c, sites: p });
|
|
594
613
|
}
|
|
595
|
-
function
|
|
614
|
+
function Y(i) {
|
|
596
615
|
let s = [];
|
|
597
616
|
const e = [];
|
|
598
|
-
for (let
|
|
599
|
-
const
|
|
600
|
-
if (!(!
|
|
601
|
-
let h = 0,
|
|
602
|
-
for (; h < 3 &&
|
|
603
|
-
const l =
|
|
604
|
-
l !== "" && (s.push(l.split(/\s+/).map(Number)), h++),
|
|
617
|
+
for (let a = 0; a < i.length; a++) {
|
|
618
|
+
const b = i[a].trim();
|
|
619
|
+
if (!(!b || b.startsWith("&")) && /^CELL_PARAMETERS/i.test(b)) {
|
|
620
|
+
let h = 0, r = a + 1;
|
|
621
|
+
for (; h < 3 && r < i.length; ) {
|
|
622
|
+
const l = i[r].trim();
|
|
623
|
+
l !== "" && (s.push(l.split(/\s+/).map(Number)), h++), r++;
|
|
605
624
|
}
|
|
606
625
|
if (h < 3) throw new Error("Incomplete CELL_PARAMETERS block");
|
|
607
626
|
break;
|
|
@@ -609,49 +628,49 @@ function G(m) {
|
|
|
609
628
|
}
|
|
610
629
|
if (s.length !== 3)
|
|
611
630
|
throw new Error("CELL_PARAMETERS block not found or incomplete");
|
|
612
|
-
let t = !1,
|
|
613
|
-
for (let
|
|
614
|
-
const
|
|
615
|
-
if (!(!
|
|
616
|
-
if (/^ATOMIC_POSITIONS/i.test(
|
|
631
|
+
let t = !1, m = "angstrom";
|
|
632
|
+
for (let a = 0; a < i.length; a++) {
|
|
633
|
+
const b = i[a].trim();
|
|
634
|
+
if (!(!b || b.startsWith("&"))) {
|
|
635
|
+
if (/^ATOMIC_POSITIONS/i.test(b)) {
|
|
617
636
|
t = !0;
|
|
618
|
-
const h =
|
|
619
|
-
|
|
637
|
+
const h = b.match(/^ATOMIC_POSITIONS\s+(\w+)/i);
|
|
638
|
+
m = h ? h[1].toLowerCase() : "angstrom";
|
|
620
639
|
continue;
|
|
621
640
|
}
|
|
622
641
|
if (t) {
|
|
623
|
-
const h =
|
|
624
|
-
if (h.length < 4 || !/^[A-Za-z]/.test(h[0]) || h.slice(1, 4).some((
|
|
642
|
+
const h = b.split(/\s+/);
|
|
643
|
+
if (h.length < 4 || !/^[A-Za-z]/.test(h[0]) || h.slice(1, 4).some((r) => Number.isNaN(Number(r))))
|
|
625
644
|
break;
|
|
626
|
-
e.push(
|
|
645
|
+
e.push(b);
|
|
627
646
|
}
|
|
628
647
|
}
|
|
629
648
|
}
|
|
630
649
|
if (e.length === 0)
|
|
631
650
|
throw new Error("ATOMIC_POSITIONS block not found");
|
|
632
|
-
const o =
|
|
633
|
-
for (const
|
|
634
|
-
const
|
|
635
|
-
|
|
651
|
+
const o = m === "crystal", n = [];
|
|
652
|
+
for (const a of e) {
|
|
653
|
+
const b = a.split(/\s+/)[0];
|
|
654
|
+
n.includes(b) || n.push(b);
|
|
636
655
|
}
|
|
637
|
-
const
|
|
638
|
-
for (const
|
|
639
|
-
const
|
|
656
|
+
const u = [];
|
|
657
|
+
for (const a of e) {
|
|
658
|
+
const b = a.split(/\s+/), h = b[0], r = b.slice(1, 4).map(Number);
|
|
640
659
|
let l;
|
|
641
660
|
o ? l = [
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
] : l =
|
|
661
|
+
r[0] * s[0][0] + r[1] * s[1][0] + r[2] * s[2][0],
|
|
662
|
+
r[0] * s[0][1] + r[1] * s[1][1] + r[2] * s[2][1],
|
|
663
|
+
r[0] * s[0][2] + r[1] * s[1][2] + r[2] * s[2][2]
|
|
664
|
+
] : l = r, u.push(new S(n.indexOf(h), l));
|
|
646
665
|
}
|
|
647
666
|
return {
|
|
648
|
-
structure: new
|
|
649
|
-
linesConsumed:
|
|
667
|
+
structure: new F({ lattice: s, species: n, sites: u }),
|
|
668
|
+
linesConsumed: i.length
|
|
650
669
|
};
|
|
651
670
|
}
|
|
652
|
-
function
|
|
653
|
-
const s =
|
|
654
|
-
return
|
|
671
|
+
function as(i) {
|
|
672
|
+
const s = I(i);
|
|
673
|
+
return Y(s).structure;
|
|
655
674
|
}
|
|
656
675
|
const D = {
|
|
657
676
|
1: { atomicNumber: 1, symbol: "H", name: "Hydrogen", mass: 1.008 },
|
|
@@ -772,7 +791,7 @@ const D = {
|
|
|
772
791
|
116: { atomicNumber: 116, symbol: "Lv", name: "Livermorium", mass: 293 },
|
|
773
792
|
117: { atomicNumber: 117, symbol: "Ts", name: "Tennessine", mass: 294 },
|
|
774
793
|
118: { atomicNumber: 118, symbol: "Og", name: "Oganesson", mass: 294 }
|
|
775
|
-
},
|
|
794
|
+
}, q = {
|
|
776
795
|
angstrom: 1,
|
|
777
796
|
// canonical
|
|
778
797
|
bohr: 0.529177,
|
|
@@ -782,70 +801,70 @@ const D = {
|
|
|
782
801
|
cm: 1e8,
|
|
783
802
|
m: 1e10,
|
|
784
803
|
fm: 1e-5
|
|
785
|
-
},
|
|
804
|
+
}, K = {
|
|
786
805
|
Å: "angstrom",
|
|
787
806
|
μm: "um"
|
|
788
|
-
},
|
|
789
|
-
conversions:
|
|
790
|
-
aliases:
|
|
791
|
-
convert(
|
|
792
|
-
const t = (
|
|
793
|
-
return
|
|
807
|
+
}, $ = {
|
|
808
|
+
conversions: q,
|
|
809
|
+
aliases: K,
|
|
810
|
+
convert(i, s, e) {
|
|
811
|
+
const t = (n) => this.aliases[n] ?? n, m = t(s), o = t(e);
|
|
812
|
+
return m === o ? i : i * this.conversions[m] / this.conversions[o];
|
|
794
813
|
},
|
|
795
|
-
convertArray(
|
|
796
|
-
return
|
|
814
|
+
convertArray(i, s, e) {
|
|
815
|
+
return i.map((t) => this.convert(t, s, e));
|
|
797
816
|
}
|
|
798
|
-
},
|
|
799
|
-
function
|
|
817
|
+
}, R = 1.8897268;
|
|
818
|
+
function rs(i, s) {
|
|
800
819
|
const e = [];
|
|
801
820
|
e.push("Generated by matsci-parse"), e.push("Volumetric data export");
|
|
802
|
-
const
|
|
821
|
+
const m = [...s.origin].map((l) => l * R);
|
|
803
822
|
e.push(
|
|
804
|
-
`${
|
|
823
|
+
`${i.numSites} ${m.map((l) => l.toFixed(6)).join(" ")}`
|
|
805
824
|
);
|
|
806
|
-
const o = s.shape,
|
|
825
|
+
const o = s.shape, n = s.basis;
|
|
807
826
|
for (let l = 0; l < 3; l++) {
|
|
808
|
-
|
|
809
|
-
const
|
|
810
|
-
e.push(`${o[l]} ${
|
|
827
|
+
n[l];
|
|
828
|
+
const y = n[l].map((c) => c * R);
|
|
829
|
+
e.push(`${o[l]} ${y.map((c) => c.toFixed(6)).join(" ")}`);
|
|
811
830
|
}
|
|
812
|
-
for (const l of
|
|
813
|
-
const
|
|
814
|
-
(g) => g.symbol ===
|
|
831
|
+
for (const l of i.sites) {
|
|
832
|
+
const y = i.species[l.speciesIndex], c = Object.values(D).find(
|
|
833
|
+
(g) => g.symbol === y
|
|
815
834
|
)?.atomicNumber;
|
|
816
|
-
if (!
|
|
817
|
-
throw new Error(`Unknown element symbol: ${
|
|
835
|
+
if (!c)
|
|
836
|
+
throw new Error(`Unknown element symbol: ${y}`);
|
|
818
837
|
[...l.cart];
|
|
819
|
-
const p = l.cart.map((g) => g *
|
|
838
|
+
const p = l.cart.map((g) => g * R), N = (l.getProp("charge") ?? 0).toFixed(6);
|
|
820
839
|
e.push(
|
|
821
|
-
`${
|
|
840
|
+
`${c} ${N} ${p.map((g) => g.toFixed(6)).join(" ")}`
|
|
822
841
|
);
|
|
823
842
|
}
|
|
824
|
-
const
|
|
825
|
-
let
|
|
843
|
+
const u = s.values, [a, b, h] = o;
|
|
844
|
+
let r = [];
|
|
826
845
|
for (let l = 0; l < h; l++)
|
|
827
|
-
for (let
|
|
828
|
-
for (let
|
|
829
|
-
const p = s.index(
|
|
830
|
-
|
|
846
|
+
for (let y = 0; y < b; y++)
|
|
847
|
+
for (let c = 0; c < a; c++) {
|
|
848
|
+
const p = s.index(c, y, l);
|
|
849
|
+
r.push(u[p].toExponential(8)), r.length === 6 && (e.push(r.join(" ")), r = []);
|
|
831
850
|
}
|
|
832
|
-
return
|
|
851
|
+
return r.length > 0 && e.push(r.join(" ")), e.join(`
|
|
833
852
|
`);
|
|
834
853
|
}
|
|
835
|
-
function
|
|
836
|
-
let
|
|
837
|
-
|
|
838
|
-
const o = m
|
|
839
|
-
let
|
|
854
|
+
function H(i, s = "bohr", e = "bohr", t = "bohr") {
|
|
855
|
+
let m = 0;
|
|
856
|
+
m += 2;
|
|
857
|
+
const o = i[m].split(/\s+/), n = parseInt(o[0]);
|
|
858
|
+
let u = [
|
|
840
859
|
parseFloat(o[1]),
|
|
841
860
|
parseFloat(o[2]),
|
|
842
861
|
parseFloat(o[3])
|
|
843
862
|
];
|
|
844
|
-
|
|
845
|
-
const
|
|
846
|
-
let
|
|
847
|
-
[parseFloat(
|
|
848
|
-
[parseFloat(
|
|
863
|
+
m++;
|
|
864
|
+
const a = i[m++].split(/\s+/), b = i[m++].split(/\s+/), h = i[m++].split(/\s+/);
|
|
865
|
+
let r = [
|
|
866
|
+
[parseFloat(a[1]), parseFloat(a[2]), parseFloat(a[3])],
|
|
867
|
+
[parseFloat(b[1]), parseFloat(b[2]), parseFloat(b[3])],
|
|
849
868
|
[
|
|
850
869
|
parseFloat(h[1]),
|
|
851
870
|
parseFloat(h[2]),
|
|
@@ -853,87 +872,89 @@ function V(m, s = "bohr", e = "bohr", t = "bohr") {
|
|
|
853
872
|
]
|
|
854
873
|
];
|
|
855
874
|
const l = [
|
|
856
|
-
parseInt(
|
|
857
|
-
parseInt(
|
|
875
|
+
parseInt(a[0], 10),
|
|
876
|
+
parseInt(b[0], 10),
|
|
858
877
|
parseInt(h[0], 10)
|
|
859
|
-
],
|
|
860
|
-
for (let w = 0; w <
|
|
861
|
-
const x = m
|
|
862
|
-
if (x.length < 5) throw new Error(`Malformed atom line: "${m
|
|
863
|
-
const A = parseInt(x[0], 10),
|
|
878
|
+
], y = [], c = /* @__PURE__ */ new Map(), p = [];
|
|
879
|
+
for (let w = 0; w < n; w++, m++) {
|
|
880
|
+
const x = i[m].trim().split(/\s+/);
|
|
881
|
+
if (x.length < 5) throw new Error(`Malformed atom line: "${i[m]}"`);
|
|
882
|
+
const A = parseInt(x[0], 10), V = parseFloat(x[1]), W = [
|
|
864
883
|
parseFloat(x[2]),
|
|
865
884
|
parseFloat(x[3]),
|
|
866
885
|
parseFloat(x[4])
|
|
867
|
-
],
|
|
868
|
-
if (!
|
|
869
|
-
const E =
|
|
870
|
-
let T =
|
|
871
|
-
T === void 0 && (T =
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
|
|
886
|
+
], j = D[A];
|
|
887
|
+
if (!j) throw new Error(`Unknown atomic number: ${A}`);
|
|
888
|
+
const E = j.symbol;
|
|
889
|
+
let T = c.get(E);
|
|
890
|
+
T === void 0 && (T = y.length, y.push(E), c.set(E, T)), p.push(new S(T, W, { charge: V }));
|
|
891
|
+
}
|
|
892
|
+
u = $.convertArray(
|
|
893
|
+
u,
|
|
875
894
|
s,
|
|
876
895
|
"angstrom"
|
|
877
|
-
),
|
|
878
|
-
(w) =>
|
|
896
|
+
), r = r.map(
|
|
897
|
+
(w) => $.convertArray(
|
|
879
898
|
w,
|
|
880
899
|
t,
|
|
881
900
|
"angstrom"
|
|
882
901
|
)
|
|
883
902
|
), p.forEach((w) => {
|
|
884
|
-
w.cart =
|
|
903
|
+
w.cart = $.convertArray(
|
|
885
904
|
w.cart,
|
|
886
905
|
e,
|
|
887
906
|
"angstrom"
|
|
888
907
|
);
|
|
889
908
|
});
|
|
890
|
-
const N =
|
|
909
|
+
const N = r.map(
|
|
891
910
|
(w, x) => w.map((A) => A * l[x])
|
|
892
|
-
), g = new
|
|
911
|
+
), g = new F({
|
|
893
912
|
lattice: N,
|
|
894
|
-
species:
|
|
913
|
+
species: y,
|
|
895
914
|
sites: p
|
|
896
|
-
}), _ = l[0] * l[1] * l[2],
|
|
897
|
-
let
|
|
898
|
-
for (;
|
|
899
|
-
const w = m
|
|
915
|
+
}), _ = l[0] * l[1] * l[2], v = new Float32Array(_);
|
|
916
|
+
let f = 0;
|
|
917
|
+
for (; m < i.length && f < _; ) {
|
|
918
|
+
const w = i[m++].trim().split(/\s+/);
|
|
900
919
|
for (const x of w)
|
|
901
|
-
x &&
|
|
920
|
+
x && f < _ && (v[f] = parseFloat(x), f++);
|
|
902
921
|
}
|
|
903
|
-
if (
|
|
904
|
-
throw new Error(`Cube file truncated: expected ${_}, got ${
|
|
905
|
-
const d = new
|
|
906
|
-
origin:
|
|
907
|
-
basis:
|
|
922
|
+
if (f !== _)
|
|
923
|
+
throw new Error(`Cube file truncated: expected ${_}, got ${f}`);
|
|
924
|
+
const d = new Z({
|
|
925
|
+
origin: u,
|
|
926
|
+
basis: r,
|
|
908
927
|
shape: l,
|
|
909
|
-
values:
|
|
928
|
+
values: v,
|
|
910
929
|
units: "e/ų"
|
|
911
930
|
});
|
|
912
|
-
return { structure: g, volumetricData: d, linesConsumed:
|
|
931
|
+
return { structure: g, volumetricData: d, linesConsumed: m };
|
|
913
932
|
}
|
|
914
|
-
function
|
|
915
|
-
const s =
|
|
916
|
-
return
|
|
933
|
+
function cs(i) {
|
|
934
|
+
const s = I(i);
|
|
935
|
+
return H(s).volumetricData;
|
|
917
936
|
}
|
|
918
|
-
function
|
|
919
|
-
const s =
|
|
920
|
-
return
|
|
937
|
+
function ls(i) {
|
|
938
|
+
const s = I(i);
|
|
939
|
+
return H(s).structure;
|
|
921
940
|
}
|
|
922
941
|
export {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
942
|
+
F as CrystalStructure,
|
|
943
|
+
S as Site,
|
|
944
|
+
Z as VolumetricData,
|
|
945
|
+
J as cartesianToFractional,
|
|
946
|
+
ns as cifToStructure,
|
|
947
|
+
ls as cubeToStructure,
|
|
948
|
+
cs as cubeToVolumetric,
|
|
949
|
+
U as fractionalToCartesian,
|
|
950
|
+
H as parseCube,
|
|
951
|
+
ss as poscarToStructure,
|
|
952
|
+
as as pwToStructure,
|
|
932
953
|
ms as structureToCif,
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
954
|
+
Q as structureToPoscar,
|
|
955
|
+
es as structureToXsf,
|
|
956
|
+
os as structureToXyz,
|
|
957
|
+
rs as volumetricToCube,
|
|
958
|
+
ts as xsfToStructure,
|
|
959
|
+
is as xyzToStructure
|
|
939
960
|
};
|