@mat3ra/made 2024.3.26-0 → 2024.3.27-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/js/basis/basis.d.ts +12 -4
- package/dist/js/basis/basis.js +24 -12
- package/package.json +1 -1
- package/src/js/basis/basis.ts +27 -12
package/dist/js/basis/basis.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export declare class Basis {
|
|
|
60
60
|
static get defaultCell(): [import("@mat3ra/esse/dist/js/types").ArrayOf3NumberElementsSchema, import("@mat3ra/esse/dist/js/types").ArrayOf3NumberElementsSchema, import("@mat3ra/esse/dist/js/types").ArrayOf3NumberElementsSchema];
|
|
61
61
|
/**
|
|
62
62
|
* Serialize class instance to JSON.
|
|
63
|
+
* @param skipRounding - Whether to skip rounding the resulting lattice values, defaults to `false`.
|
|
63
64
|
* @example As below:
|
|
64
65
|
{
|
|
65
66
|
"elements" : [
|
|
@@ -95,12 +96,12 @@ export declare class Basis {
|
|
|
95
96
|
[
|
|
96
97
|
1,
|
|
97
98
|
0,
|
|
98
|
-
|
|
99
|
+
0
|
|
99
100
|
],
|
|
100
101
|
[
|
|
101
|
-
|
|
102
|
+
0,
|
|
102
103
|
1,
|
|
103
|
-
|
|
104
|
+
0
|
|
104
105
|
],
|
|
105
106
|
[
|
|
106
107
|
0,
|
|
@@ -110,7 +111,14 @@ export declare class Basis {
|
|
|
110
111
|
]
|
|
111
112
|
}
|
|
112
113
|
*/
|
|
113
|
-
toJSON(): BasisSchema;
|
|
114
|
+
toJSON(skipRounding?: boolean): BasisSchema;
|
|
115
|
+
/** Return coordinates rounded to default precision */
|
|
116
|
+
get coordinatesRounded(): {
|
|
117
|
+
id: number;
|
|
118
|
+
value: number[];
|
|
119
|
+
}[];
|
|
120
|
+
/** Return cell with vectors values rounded to default precision */
|
|
121
|
+
get cellRounded(): number[][];
|
|
114
122
|
/**
|
|
115
123
|
* Create an identical copy of the class instance.
|
|
116
124
|
* @param extraContext - Extra context to be passed to the new class instance on creation.
|
package/dist/js/basis/basis.js
CHANGED
|
@@ -45,6 +45,7 @@ class Basis {
|
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
47
|
* Serialize class instance to JSON.
|
|
48
|
+
* @param skipRounding - Whether to skip rounding the resulting lattice values, defaults to `false`.
|
|
48
49
|
* @example As below:
|
|
49
50
|
{
|
|
50
51
|
"elements" : [
|
|
@@ -80,12 +81,12 @@ class Basis {
|
|
|
80
81
|
[
|
|
81
82
|
1,
|
|
82
83
|
0,
|
|
83
|
-
|
|
84
|
+
0
|
|
84
85
|
],
|
|
85
86
|
[
|
|
86
|
-
|
|
87
|
+
0,
|
|
87
88
|
1,
|
|
88
|
-
|
|
89
|
+
0
|
|
89
90
|
],
|
|
90
91
|
[
|
|
91
92
|
0,
|
|
@@ -95,12 +96,12 @@ class Basis {
|
|
|
95
96
|
]
|
|
96
97
|
}
|
|
97
98
|
*/
|
|
98
|
-
toJSON() {
|
|
99
|
+
toJSON(skipRounding = false) {
|
|
99
100
|
const json = {
|
|
100
101
|
elements: this.elements,
|
|
101
|
-
coordinates: this.coordinates,
|
|
102
|
+
coordinates: skipRounding ? this.coordinates : this.coordinatesRounded,
|
|
102
103
|
units: this.units,
|
|
103
|
-
cell: this.cell,
|
|
104
|
+
cell: skipRounding ? this.cell : this.cellRounded,
|
|
104
105
|
};
|
|
105
106
|
if (!underscore_1.default.isEmpty(this.labels)) {
|
|
106
107
|
return JSON.parse(JSON.stringify({
|
|
@@ -110,6 +111,19 @@ class Basis {
|
|
|
110
111
|
}
|
|
111
112
|
return JSON.parse(JSON.stringify(json));
|
|
112
113
|
}
|
|
114
|
+
/** Return coordinates rounded to default precision */
|
|
115
|
+
get coordinatesRounded() {
|
|
116
|
+
return this.coordinates.map((coordinate) => {
|
|
117
|
+
return {
|
|
118
|
+
id: coordinate.id,
|
|
119
|
+
value: coordinate.value.map((x) => math_1.default.precise(math_1.default.roundToZero(x))),
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/** Return cell with vectors values rounded to default precision */
|
|
124
|
+
get cellRounded() {
|
|
125
|
+
return this.cell.map((vector) => vector.map((x) => math_1.default.precise(math_1.default.roundToZero(x))));
|
|
126
|
+
}
|
|
113
127
|
/**
|
|
114
128
|
* Create an identical copy of the class instance.
|
|
115
129
|
* @param extraContext - Extra context to be passed to the new class instance on creation.
|
|
@@ -331,12 +345,10 @@ class Basis {
|
|
|
331
345
|
/* Returns array of atomic labels E.g., ["1", "2", "", ""] */
|
|
332
346
|
get atomicLabelsArray() {
|
|
333
347
|
var _a;
|
|
334
|
-
const labelsArray =
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
labelsArray.push(atomicLabel);
|
|
339
|
-
}
|
|
348
|
+
const labelsArray = Array.from({ length: this.elements.length }, (_) => "");
|
|
349
|
+
(_a = this.labels) === null || _a === void 0 ? void 0 : _a.map((item) => {
|
|
350
|
+
labelsArray[item.id] = item.value.toString();
|
|
351
|
+
});
|
|
340
352
|
return labelsArray;
|
|
341
353
|
}
|
|
342
354
|
/* Returns array of elements with labels E.g., ["Fe1", "Fe2", "O", "O"] */
|
package/package.json
CHANGED
package/src/js/basis/basis.ts
CHANGED
|
@@ -101,6 +101,7 @@ export class Basis {
|
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* Serialize class instance to JSON.
|
|
104
|
+
* @param skipRounding - Whether to skip rounding the resulting lattice values, defaults to `false`.
|
|
104
105
|
* @example As below:
|
|
105
106
|
{
|
|
106
107
|
"elements" : [
|
|
@@ -136,12 +137,12 @@ export class Basis {
|
|
|
136
137
|
[
|
|
137
138
|
1,
|
|
138
139
|
0,
|
|
139
|
-
|
|
140
|
+
0
|
|
140
141
|
],
|
|
141
142
|
[
|
|
142
|
-
|
|
143
|
+
0,
|
|
143
144
|
1,
|
|
144
|
-
|
|
145
|
+
0
|
|
145
146
|
],
|
|
146
147
|
[
|
|
147
148
|
0,
|
|
@@ -151,12 +152,12 @@ export class Basis {
|
|
|
151
152
|
]
|
|
152
153
|
}
|
|
153
154
|
*/
|
|
154
|
-
toJSON(): BasisSchema {
|
|
155
|
+
toJSON(skipRounding = false): BasisSchema {
|
|
155
156
|
const json = {
|
|
156
157
|
elements: this.elements,
|
|
157
|
-
coordinates: this.coordinates,
|
|
158
|
+
coordinates: skipRounding ? this.coordinates : this.coordinatesRounded,
|
|
158
159
|
units: this.units,
|
|
159
|
-
cell: this.cell,
|
|
160
|
+
cell: skipRounding ? this.cell : this.cellRounded,
|
|
160
161
|
};
|
|
161
162
|
|
|
162
163
|
if (!_.isEmpty(this.labels)) {
|
|
@@ -171,6 +172,21 @@ export class Basis {
|
|
|
171
172
|
return JSON.parse(JSON.stringify(json));
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
/** Return coordinates rounded to default precision */
|
|
176
|
+
get coordinatesRounded() {
|
|
177
|
+
return this.coordinates.map((coordinate) => {
|
|
178
|
+
return {
|
|
179
|
+
id: coordinate.id,
|
|
180
|
+
value: coordinate.value.map((x) => math.precise(math.roundToZero(x))),
|
|
181
|
+
};
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Return cell with vectors values rounded to default precision */
|
|
186
|
+
get cellRounded() {
|
|
187
|
+
return this.cell.map((vector) => vector.map((x) => math.precise(math.roundToZero(x))));
|
|
188
|
+
}
|
|
189
|
+
|
|
174
190
|
/**
|
|
175
191
|
* Create an identical copy of the class instance.
|
|
176
192
|
* @param extraContext - Extra context to be passed to the new class instance on creation.
|
|
@@ -423,12 +439,11 @@ export class Basis {
|
|
|
423
439
|
|
|
424
440
|
/* Returns array of atomic labels E.g., ["1", "2", "", ""] */
|
|
425
441
|
get atomicLabelsArray(): string[] {
|
|
426
|
-
const labelsArray =
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
442
|
+
const labelsArray = Array.from({ length: this.elements.length }, (_) => "");
|
|
443
|
+
this.labels?.map((item: { id: number; value: number }) => {
|
|
444
|
+
labelsArray[item.id] = item.value.toString();
|
|
445
|
+
});
|
|
446
|
+
|
|
432
447
|
return labelsArray;
|
|
433
448
|
}
|
|
434
449
|
|