@mat3ra/made 2026.8.7-0 → 2026.8.13-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.
- package/.mocharc.json +2 -2
- package/dist/js/Material.d.ts +219 -0
- package/dist/js/Material.js +457 -0
- package/dist/js/basis/basis.d.ts +14 -9
- package/dist/js/basis/basis.js +15 -13
- package/dist/js/basis/constrained_basis.d.ts +9 -7
- package/dist/js/basis/constrained_basis.js +4 -4
- package/dist/js/generated/MaterialSchemaMixin.d.ts +5 -0
- package/dist/js/generated/MaterialSchemaMixin.js +69 -0
- package/dist/js/lattice/lattice.d.ts +4 -3
- package/dist/js/lattice/lattice.js +1 -2
- package/dist/js/made.d.ts +12 -12
- package/dist/js/made.js +38 -5
- package/dist/js/parsers/espresso.d.ts +2 -3
- package/dist/js/parsers/espresso.js +0 -1
- package/dist/js/parsers/native_format_parsers.d.ts +9 -8
- package/dist/js/parsers/native_format_parsers.js +6 -6
- package/dist/js/parsers/parsers.d.ts +6 -6
- package/dist/js/parsers/poscar.d.ts +5 -4
- package/dist/js/parsers/poscar.js +3 -2
- package/dist/js/parsers/xyz.d.ts +3 -5
- package/dist/js/parsers/xyz.js +3 -4
- package/dist/js/parsers/xyz_combinatorial_basis.js +3 -1
- package/dist/js/tools/basis.d.ts +1 -1
- package/dist/js/tools/index.d.ts +7 -7
- package/dist/js/tools/material.d.ts +1 -1
- package/dist/js/tools/material.js +8 -7
- package/dist/js/tools/supercell.d.ts +4 -5
- package/dist/js/tools/supercell.js +2 -4
- package/dist/js/tools/surface.d.ts +4 -4
- package/dist/js/tools/surface.js +2 -7
- package/package.json +6 -6
- package/scripts/generate-mixins.ts +28 -0
- package/src/js/Material.ts +618 -0
- package/src/js/basis/basis.ts +38 -25
- package/src/js/basis/constrained_basis.ts +12 -11
- package/src/js/basis/coordinates.ts +0 -1
- package/src/js/cell/cell.ts +0 -1
- package/src/js/generated/MaterialSchemaMixin.ts +79 -0
- package/src/js/lattice/lattice.ts +6 -4
- package/src/js/lattice/reciprocal/lattice_reciprocal.ts +19 -6
- package/src/js/made.ts +1 -1
- package/src/js/parsers/espresso.ts +2 -3
- package/src/js/parsers/native_format_parsers.ts +9 -8
- package/src/js/parsers/poscar.ts +12 -6
- package/src/js/parsers/xyz.ts +9 -6
- package/src/js/parsers/xyz_combinatorial_basis.ts +5 -2
- package/src/js/tools/basis.ts +0 -1
- package/src/js/tools/cell.ts +0 -1
- package/src/js/tools/material.ts +13 -11
- package/src/js/tools/supercell.ts +8 -7
- package/src/js/tools/surface.ts +7 -17
- package/src/py/mat3ra/made/material.py +6 -5
- package/tests/fixtures/si-standata.json +2 -2
- package/tests/js/basis/basis.ts +8 -8
- package/tests/js/fixtures.ts +12 -9
- package/tests/js/material/material.ts +161 -0
- package/tests/js/parsers/espresso.ts +2 -5
- package/tests/js/parsers/poscar.ts +2 -2
- package/tests/js/register-esse-schemas.cjs +10 -0
- package/tests/js/tools/supercell.ts +2 -2
- package/tests/js/tools/surface.ts +6 -10
- package/dist/js/material.d.ts +0 -169
- package/dist/js/material.js +0 -362
- package/src/js/material.ts +0 -458
- package/tests/js/material.test.ts +0 -42
package/.mocharc.json
CHANGED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
2
|
+
import { type Defaultable } from "@mat3ra/code/dist/js/entity/mixins/DefaultableMixin";
|
|
3
|
+
import { type HasMetadata } from "@mat3ra/code/dist/js/entity/mixins/HasMetadataMixin";
|
|
4
|
+
import { type NamedEntity } from "@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin";
|
|
5
|
+
import type { JSONSchema } from "@mat3ra/esse/dist/js/esse/utils";
|
|
6
|
+
import type { AtomicConstraintsSchema, BasisSchema, ConsistencyCheck, DerivedPropertiesSchema, FileSourceSchema, LatticeSchema, MaterialEnhancedHashedSchema, MaterialEnhancedSchema, MaterialHashedSchema, MaterialSchema } from "@mat3ra/esse/dist/js/types";
|
|
7
|
+
import { type BasisConfig } from "./basis/basis";
|
|
8
|
+
import { type ConstrainedBasisConfig, ConstrainedBasis } from "./basis/constrained_basis";
|
|
9
|
+
import { type MaterialSchemaMixin } from "./generated/MaterialSchemaMixin";
|
|
10
|
+
import { Lattice } from "./lattice/lattice";
|
|
11
|
+
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
12
|
+
/**
|
|
13
|
+
* Bundle of material JSON-schema variants used by {@link Material} projections.
|
|
14
|
+
* Web-app passes extended schemas here so `toJSON*` return types stay precise.
|
|
15
|
+
*/
|
|
16
|
+
export type MaterialSchemaMap = {
|
|
17
|
+
pure: MaterialSchema;
|
|
18
|
+
enhanced: MaterialEnhancedSchema;
|
|
19
|
+
hashed: MaterialHashedSchema;
|
|
20
|
+
enhancedHashed: MaterialEnhancedHashedSchema;
|
|
21
|
+
};
|
|
22
|
+
/** Default ESSE schema map (no web-app extensions). */
|
|
23
|
+
export type DefaultMaterialSchemas = MaterialSchemaMap;
|
|
24
|
+
/**
|
|
25
|
+
* Constructor config: constraints/hash/metadata optional — normalized in the constructor
|
|
26
|
+
* (`parseConstrainedBasis` + {@link Material.updateHash}; `metadata` defaults to `{}`).
|
|
27
|
+
*/
|
|
28
|
+
export type MaterialConfig<S extends MaterialEnhancedHashedSchema = MaterialEnhancedHashedSchema> = Omit<PartialBy<S, "name" | "metadata" | "hash" | "scaledHash">, "basis"> & {
|
|
29
|
+
basis: MaterialSchema["basis"] | MaterialEnhancedSchema["basis"];
|
|
30
|
+
};
|
|
31
|
+
export declare const defaultMaterialConfig: MaterialEnhancedSchema;
|
|
32
|
+
interface BaseMaterial<S extends MaterialEnhancedHashedSchema = MaterialEnhancedHashedSchema> extends MaterialSchemaMixin, NamedEntity, Defaultable, Required<HasMetadata<S["metadata"]>> {
|
|
33
|
+
}
|
|
34
|
+
declare class BaseMaterial<S extends MaterialEnhancedHashedSchema = MaterialEnhancedHashedSchema> extends InMemoryEntity<S> {
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Unified material. Pass extended schemas via {@link MaterialSchemaMap} so each
|
|
38
|
+
* `toJSON*` returns the web-app (or other host) schema type.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* type WebappSchemas = {
|
|
43
|
+
* pure: MaterialSchema;
|
|
44
|
+
* enhanced: WebappMaterialEnhancedSchema;
|
|
45
|
+
* hashed: WebappMaterialHashedSchema;
|
|
46
|
+
* enhancedHashed: WebappMaterialEnhancedSchema;
|
|
47
|
+
* };
|
|
48
|
+
* class CoreMaterial extends Material<WebappSchemas> {}
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare class Material<Schemas extends MaterialSchemaMap = DefaultMaterialSchemas> extends BaseMaterial<Schemas["enhancedHashed"]> {
|
|
52
|
+
static createDefault: () => Material<MaterialSchemaMap>;
|
|
53
|
+
/**
|
|
54
|
+
* Schema used by {@link InMemoryEntity.clean} / {@link toJSON}.
|
|
55
|
+
* Defaults to enhanced+hashed; subclasses / web-app Core* may override.
|
|
56
|
+
*/
|
|
57
|
+
static get jsonSchema(): JSONSchema;
|
|
58
|
+
/** Schema for {@link toJSONPure} — override in web-app if the base material schema is extended. */
|
|
59
|
+
static get jsonSchemaPure(): JSONSchema;
|
|
60
|
+
/** Schema for {@link toJSONEnhanced}. */
|
|
61
|
+
static get jsonSchemaEnhanced(): JSONSchema;
|
|
62
|
+
/** Schema for {@link toJSONHashed}. */
|
|
63
|
+
static get jsonSchemaHashed(): JSONSchema;
|
|
64
|
+
/** Schema for {@link toJSONEnhancedHashed}. */
|
|
65
|
+
static get jsonSchemaEnhancedHashed(): JSONSchema;
|
|
66
|
+
static get defaultConfig(): MaterialEnhancedSchema;
|
|
67
|
+
static constructMaterialFileSource(fileName: string, fileContent: string, fileExtension: string): FileSourceSchema;
|
|
68
|
+
/**
|
|
69
|
+
* @param config - Partial entity input. `basis.constraints` / `hash` / `metadata` may be omitted;
|
|
70
|
+
* constraints and hash are filled here; missing `metadata` becomes `{}`.
|
|
71
|
+
* `NoInfer` keeps `Schemas` from being inferred from the config object literal.
|
|
72
|
+
*/
|
|
73
|
+
constructor(config: NoInfer<MaterialConfig>);
|
|
74
|
+
get hash(): Schemas["enhancedHashed"]["hash"];
|
|
75
|
+
set hash(value: Schemas["enhancedHashed"]["hash"]);
|
|
76
|
+
get scaledHash(): Schemas["enhancedHashed"]["scaledHash"];
|
|
77
|
+
set scaledHash(value: Schemas["enhancedHashed"]["scaledHash"]);
|
|
78
|
+
/**
|
|
79
|
+
* Recompute and store {@link hash} from the current basis/lattice (or InChI if non-periodic).
|
|
80
|
+
* When non-periodic but InChI is not derived yet (e.g. designer toggle before butler), use
|
|
81
|
+
* geometric hash so setters do not throw — same practical UX as main before auto-updateHash.
|
|
82
|
+
*/
|
|
83
|
+
updateHash(): void;
|
|
84
|
+
get basis(): Schemas["enhancedHashed"]["basis"];
|
|
85
|
+
set basis(value: Schemas["enhancedHashed"]["basis"]);
|
|
86
|
+
get lattice(): Schemas["enhancedHashed"]["lattice"];
|
|
87
|
+
set lattice(value: Schemas["enhancedHashed"]["lattice"]);
|
|
88
|
+
updateFormula(): void;
|
|
89
|
+
/**
|
|
90
|
+
* @summary Returns the specific derived property (as specified by name) for a material.
|
|
91
|
+
*/
|
|
92
|
+
getDerivedPropertyByName(name: string): {
|
|
93
|
+
name?: "volume";
|
|
94
|
+
units?: "angstrom^3";
|
|
95
|
+
value: number;
|
|
96
|
+
} | {
|
|
97
|
+
name?: "density";
|
|
98
|
+
units?: "g/cm^3";
|
|
99
|
+
value: number;
|
|
100
|
+
} | {
|
|
101
|
+
pointGroupSymbol?: string;
|
|
102
|
+
spaceGroupSymbol?: string;
|
|
103
|
+
tolerance?: {
|
|
104
|
+
units?: "angstrom";
|
|
105
|
+
value: number;
|
|
106
|
+
};
|
|
107
|
+
name?: "symmetry";
|
|
108
|
+
} | {
|
|
109
|
+
name?: "elemental_ratio";
|
|
110
|
+
value: number;
|
|
111
|
+
element?: string;
|
|
112
|
+
} | {
|
|
113
|
+
name?: "p-norm";
|
|
114
|
+
degree?: number;
|
|
115
|
+
value: number;
|
|
116
|
+
} | {
|
|
117
|
+
name?: "inchi";
|
|
118
|
+
value: string;
|
|
119
|
+
} | {
|
|
120
|
+
name?: "inchi_key";
|
|
121
|
+
value: string;
|
|
122
|
+
} | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* @summary Returns the derived properties array for a material.
|
|
125
|
+
*/
|
|
126
|
+
getDerivedProperties(): DerivedPropertiesSchema;
|
|
127
|
+
unsetFileProps(): void;
|
|
128
|
+
setBasis(basis: BasisConfig | ConstrainedBasisConfig): void;
|
|
129
|
+
setBasis(basis: string, format: "xyz", units?: BasisSchema["units"]): void;
|
|
130
|
+
private setBasisConstraints;
|
|
131
|
+
setBasisConstraintsFromArrayOfObjects(constraints: AtomicConstraintsSchema): void;
|
|
132
|
+
getBasis(): ConstrainedBasis;
|
|
133
|
+
setLattice(lattice: LatticeSchema): void;
|
|
134
|
+
getLattice(): Lattice;
|
|
135
|
+
/**
|
|
136
|
+
* High-level access to unique elements from material instead of basis.
|
|
137
|
+
*/
|
|
138
|
+
get uniqueElements(): ("H" | "He" | "Li" | "Be" | "B" | "C" | "N" | "O" | "F" | "Ne" | "Na" | "Mg" | "Al" | "Si" | "P" | "S" | "Cl" | "Ar" | "K" | "Ca" | "Sc" | "Ti" | "V" | "Cr" | "Mn" | "Fe" | "Co" | "Ni" | "Cu" | "Zn" | "Ga" | "Ge" | "As" | "Se" | "Br" | "Kr" | "Rb" | "Sr" | "Y" | "Zr" | "Nb" | "Mo" | "Tc" | "Ru" | "Rh" | "Pd" | "Ag" | "Cd" | "In" | "Sn" | "Sb" | "Te" | "I" | "Xe" | "Cs" | "Ba" | "La" | "Ce" | "Pr" | "Nd" | "Pm" | "Sm" | "Eu" | "Gd" | "Tb" | "Dy" | "Ho" | "Er" | "Tm" | "Yb" | "Lu" | "Hf" | "Ta" | "W" | "Re" | "Os" | "Ir" | "Pt" | "Au" | "Hg" | "Tl" | "Pb" | "Bi" | "Po" | "At" | "Rn" | "Fr" | "Ra" | "Ac" | "Th" | "Pa" | "U" | "Np" | "Pu" | "Am" | "Cm" | "Bk" | "Cf" | "Es" | "Fm" | "Md" | "No" | "Lr" | "Rf" | "Db" | "Sg" | "Bh" | "Hs" | "Mt" | "Ds" | "Rg" | "Cn" | "Nh" | "Fl" | "Mc" | "Lv" | "Ts" | "Og" | "X" | "Vac")[];
|
|
139
|
+
/**
|
|
140
|
+
* Returns the inchi string from the derivedProperties for a non-periodic material, or throws an error if the
|
|
141
|
+
* inchi cannot be found.
|
|
142
|
+
* @returns {String}
|
|
143
|
+
*/
|
|
144
|
+
getInchiStringForHash(): string;
|
|
145
|
+
/**
|
|
146
|
+
* Calculates hash from basis and lattice. Algorithm expects the following:
|
|
147
|
+
* - asserts lattice units to be angstrom
|
|
148
|
+
* - asserts basis units to be crystal
|
|
149
|
+
* - asserts basis coordinates and lattice measurements are rounded to hash precision
|
|
150
|
+
* - forms strings for lattice and basis
|
|
151
|
+
* - creates MD5 hash from basisStr + latticeStr + salt
|
|
152
|
+
* @param salt Salt for hashing, empty string by default.
|
|
153
|
+
* @param isScaled Whether to scale the lattice parameter 'a' to 1.
|
|
154
|
+
*/
|
|
155
|
+
calculateHash(salt?: string, isScaled?: boolean, bypassNonPeriodicCheck?: boolean): string;
|
|
156
|
+
/**
|
|
157
|
+
* Converts basis to crystal/fractional coordinates.
|
|
158
|
+
*/
|
|
159
|
+
toCrystal(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Converts current material's basis coordinates to cartesian.
|
|
162
|
+
* No changes if coordinates already cartesian.
|
|
163
|
+
*/
|
|
164
|
+
toCartesian(): void;
|
|
165
|
+
/**
|
|
166
|
+
* Returns material's basis in XYZ format (includes atomic constraints when present).
|
|
167
|
+
*/
|
|
168
|
+
getBasisAsXyz(fractional?: boolean): string;
|
|
169
|
+
/**
|
|
170
|
+
* Returns material in Quantum Espresso output format:
|
|
171
|
+
* ```
|
|
172
|
+
* CELL_PARAMETERS (angstroms)
|
|
173
|
+
* -0.543131284 -0.000000000 0.543131284
|
|
174
|
+
* -0.000000000 0.543131284 0.543131284
|
|
175
|
+
* -0.543131284 0.543131284 0.000000000
|
|
176
|
+
*
|
|
177
|
+
* ATOMIC_POSITIONS (crystal)
|
|
178
|
+
* Si 0.000000000 0.000000000 -0.000000000
|
|
179
|
+
* Si 0.250000000 0.250000000 0.250000000
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
getAsQEFormat(): string;
|
|
183
|
+
/**
|
|
184
|
+
* Returns material in POSCAR format. Pass `true` to ignore original poscar source and re-serialize.
|
|
185
|
+
*/
|
|
186
|
+
getAsPOSCAR(ignoreOriginal?: boolean, omitConstraints?: boolean): string;
|
|
187
|
+
/**
|
|
188
|
+
* Returns a copy of the material with conventional cell constructed instead of primitive.
|
|
189
|
+
*/
|
|
190
|
+
getACopyWithConventionalCell(): this;
|
|
191
|
+
/**
|
|
192
|
+
* @summary a series of checks for the material and returns an array of results in ConsistencyChecks format.
|
|
193
|
+
* @returns Array of checks results
|
|
194
|
+
*/
|
|
195
|
+
getConsistencyChecks(): ConsistencyCheck[];
|
|
196
|
+
/**
|
|
197
|
+
* @summary a series of checks for the material's basis and returns an array of results in ConsistencyChecks format.
|
|
198
|
+
* @returns Array of checks results
|
|
199
|
+
*/
|
|
200
|
+
getBasisConsistencyChecks(): ConsistencyCheck[];
|
|
201
|
+
/**
|
|
202
|
+
* Full material JSON: constrained basis + hash fields from live getters.
|
|
203
|
+
* Variants below AJV-clean this payload against the matching ESSE schema.
|
|
204
|
+
* Builds from `_json` (not `super.toJSON`) so we do not pre-clean against
|
|
205
|
+
* {@link Material.jsonSchema} before projecting to a narrower schema.
|
|
206
|
+
*/
|
|
207
|
+
private getFullJSON;
|
|
208
|
+
/**
|
|
209
|
+
* Clone {@link getFullJSON} and validate/clean against `jsonSchema` via AJV
|
|
210
|
+
* (same path as {@link InMemoryEntity.validateData} / {@link InMemoryEntity.clean}).
|
|
211
|
+
*/
|
|
212
|
+
private cleanFullJSONAgainstSchema;
|
|
213
|
+
toJSONPure(): Schemas["pure"];
|
|
214
|
+
toJSONEnhanced(): Schemas["enhanced"];
|
|
215
|
+
toJSONHashed(): Schemas["hashed"];
|
|
216
|
+
toJSONEnhancedHashed(): Schemas["enhancedHashed"];
|
|
217
|
+
toJSON(): Schemas["enhancedHashed"];
|
|
218
|
+
}
|
|
219
|
+
export default Material;
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.defaultMaterialConfig = void 0;
|
|
7
|
+
const entity_1 = require("@mat3ra/code/dist/js/entity");
|
|
8
|
+
const in_memory_1 = require("@mat3ra/code/dist/js/entity/in_memory");
|
|
9
|
+
const DefaultableMixin_1 = require("@mat3ra/code/dist/js/entity/mixins/DefaultableMixin");
|
|
10
|
+
const HasMetadataMixin_1 = require("@mat3ra/code/dist/js/entity/mixins/HasMetadataMixin");
|
|
11
|
+
const NamedEntityMixin_1 = require("@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin");
|
|
12
|
+
const clone_1 = require("@mat3ra/code/dist/js/utils/clone");
|
|
13
|
+
const JSONSchemasInterface_1 = __importDefault(require("@mat3ra/esse/dist/js/esse/JSONSchemasInterface"));
|
|
14
|
+
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
15
|
+
const constrained_basis_1 = require("./basis/constrained_basis");
|
|
16
|
+
const conventional_cell_1 = require("./cell/conventional_cell");
|
|
17
|
+
const constraints_1 = require("./constraints/constraints");
|
|
18
|
+
const MaterialSchemaMixin_1 = require("./generated/MaterialSchemaMixin");
|
|
19
|
+
const lattice_1 = require("./lattice/lattice");
|
|
20
|
+
const parsers_1 = __importDefault(require("./parsers/parsers"));
|
|
21
|
+
const supercell_1 = __importDefault(require("./tools/supercell"));
|
|
22
|
+
/** ESSE `$id` values for material schema variants. */
|
|
23
|
+
const MATERIAL_SCHEMA_IDS = {
|
|
24
|
+
pure: "material",
|
|
25
|
+
enhanced: "material-enhanced",
|
|
26
|
+
hashed: "material-hashed",
|
|
27
|
+
enhancedHashed: "material-enhanced-hashed",
|
|
28
|
+
};
|
|
29
|
+
function parseConstrainedBasis(textOrObject, format, units) {
|
|
30
|
+
if (typeof textOrObject === "string") {
|
|
31
|
+
if (format !== "xyz") {
|
|
32
|
+
throw new Error("Invalid format");
|
|
33
|
+
}
|
|
34
|
+
return parsers_1.default.xyz.toBasisConfig(textOrObject, units);
|
|
35
|
+
}
|
|
36
|
+
if ("constraints" in textOrObject) {
|
|
37
|
+
return textOrObject;
|
|
38
|
+
}
|
|
39
|
+
return { ...textOrObject, constraints: [] };
|
|
40
|
+
}
|
|
41
|
+
exports.defaultMaterialConfig = {
|
|
42
|
+
name: "Silicon FCC",
|
|
43
|
+
basis: {
|
|
44
|
+
elements: [
|
|
45
|
+
{
|
|
46
|
+
id: 0,
|
|
47
|
+
value: "Si",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
id: 1,
|
|
51
|
+
value: "Si",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
coordinates: [
|
|
55
|
+
{
|
|
56
|
+
id: 0,
|
|
57
|
+
value: [0.0, 0.0, 0.0],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
id: 1,
|
|
61
|
+
value: [0.25, 0.25, 0.25],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
units: "crystal",
|
|
65
|
+
constraints: [],
|
|
66
|
+
},
|
|
67
|
+
lattice: {
|
|
68
|
+
// Primitive cell for Diamond FCC Silicon at ambient conditions
|
|
69
|
+
type: "FCC",
|
|
70
|
+
a: 3.867,
|
|
71
|
+
b: 3.867,
|
|
72
|
+
c: 3.867,
|
|
73
|
+
alpha: 60,
|
|
74
|
+
beta: 60,
|
|
75
|
+
gamma: 60,
|
|
76
|
+
units: {
|
|
77
|
+
length: "angstrom",
|
|
78
|
+
angle: "degree",
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
metadata: {},
|
|
82
|
+
};
|
|
83
|
+
class BaseMaterial extends entity_1.InMemoryEntity {
|
|
84
|
+
}
|
|
85
|
+
(0, MaterialSchemaMixin_1.materialSchemaMixin)(BaseMaterial.prototype);
|
|
86
|
+
(0, NamedEntityMixin_1.namedEntityMixin)(BaseMaterial.prototype);
|
|
87
|
+
(0, DefaultableMixin_1.defaultableEntityMixin)(BaseMaterial);
|
|
88
|
+
(0, HasMetadataMixin_1.hasMetadataMixin)(BaseMaterial.prototype);
|
|
89
|
+
/**
|
|
90
|
+
* Unified material. Pass extended schemas via {@link MaterialSchemaMap} so each
|
|
91
|
+
* `toJSON*` returns the web-app (or other host) schema type.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* type WebappSchemas = {
|
|
96
|
+
* pure: MaterialSchema;
|
|
97
|
+
* enhanced: WebappMaterialEnhancedSchema;
|
|
98
|
+
* hashed: WebappMaterialHashedSchema;
|
|
99
|
+
* enhancedHashed: WebappMaterialEnhancedSchema;
|
|
100
|
+
* };
|
|
101
|
+
* class CoreMaterial extends Material<WebappSchemas> {}
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
class Material extends BaseMaterial {
|
|
105
|
+
/**
|
|
106
|
+
* Schema used by {@link InMemoryEntity.clean} / {@link toJSON}.
|
|
107
|
+
* Defaults to enhanced+hashed; subclasses / web-app Core* may override.
|
|
108
|
+
*/
|
|
109
|
+
static get jsonSchema() {
|
|
110
|
+
return this.jsonSchemaEnhancedHashed;
|
|
111
|
+
}
|
|
112
|
+
/** Schema for {@link toJSONPure} — override in web-app if the base material schema is extended. */
|
|
113
|
+
static get jsonSchemaPure() {
|
|
114
|
+
return JSONSchemasInterface_1.default.getRequiredSchemaById(MATERIAL_SCHEMA_IDS.pure);
|
|
115
|
+
}
|
|
116
|
+
/** Schema for {@link toJSONEnhanced}. */
|
|
117
|
+
static get jsonSchemaEnhanced() {
|
|
118
|
+
return JSONSchemasInterface_1.default.getRequiredSchemaById(MATERIAL_SCHEMA_IDS.enhanced);
|
|
119
|
+
}
|
|
120
|
+
/** Schema for {@link toJSONHashed}. */
|
|
121
|
+
static get jsonSchemaHashed() {
|
|
122
|
+
return JSONSchemasInterface_1.default.getRequiredSchemaById(MATERIAL_SCHEMA_IDS.hashed);
|
|
123
|
+
}
|
|
124
|
+
/** Schema for {@link toJSONEnhancedHashed}. */
|
|
125
|
+
static get jsonSchemaEnhancedHashed() {
|
|
126
|
+
return JSONSchemasInterface_1.default.getRequiredSchemaById(MATERIAL_SCHEMA_IDS.enhancedHashed);
|
|
127
|
+
}
|
|
128
|
+
static get defaultConfig() {
|
|
129
|
+
return exports.defaultMaterialConfig;
|
|
130
|
+
}
|
|
131
|
+
static constructMaterialFileSource(fileName, fileContent, fileExtension) {
|
|
132
|
+
return {
|
|
133
|
+
extension: fileExtension,
|
|
134
|
+
filename: fileName,
|
|
135
|
+
text: fileContent,
|
|
136
|
+
hash: crypto_js_1.default.MD5(fileContent).toString(),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @param config - Partial entity input. `basis.constraints` / `hash` / `metadata` may be omitted;
|
|
141
|
+
* constraints and hash are filled here; missing `metadata` becomes `{}`.
|
|
142
|
+
* `NoInfer` keeps `Schemas` from being inferred from the config object literal.
|
|
143
|
+
*/
|
|
144
|
+
constructor(config) {
|
|
145
|
+
var _a, _b, _c, _d;
|
|
146
|
+
const basis = parseConstrainedBasis(config.basis);
|
|
147
|
+
super({
|
|
148
|
+
...config,
|
|
149
|
+
basis,
|
|
150
|
+
name: (_b = (_a = config.name) !== null && _a !== void 0 ? _a : config.formula) !== null && _b !== void 0 ? _b : "",
|
|
151
|
+
metadata: (_c = config.metadata) !== null && _c !== void 0 ? _c : {},
|
|
152
|
+
hash: (_d = config.hash) !== null && _d !== void 0 ? _d : "",
|
|
153
|
+
});
|
|
154
|
+
this.formula = config.formula || this.getBasis().formula;
|
|
155
|
+
this.name = this.name || this.formula;
|
|
156
|
+
this.updateHash();
|
|
157
|
+
}
|
|
158
|
+
get hash() {
|
|
159
|
+
return this.requiredProp("hash");
|
|
160
|
+
}
|
|
161
|
+
set hash(value) {
|
|
162
|
+
this.setProp("hash", value);
|
|
163
|
+
}
|
|
164
|
+
get scaledHash() {
|
|
165
|
+
return this.prop("scaledHash");
|
|
166
|
+
}
|
|
167
|
+
set scaledHash(value) {
|
|
168
|
+
this.setProp("scaledHash", value);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Recompute and store {@link hash} from the current basis/lattice (or InChI if non-periodic).
|
|
172
|
+
* When non-periodic but InChI is not derived yet (e.g. designer toggle before butler), use
|
|
173
|
+
* geometric hash so setters do not throw — same practical UX as main before auto-updateHash.
|
|
174
|
+
*/
|
|
175
|
+
updateHash() {
|
|
176
|
+
const hasInchi = Boolean(this.getDerivedPropertyByName("inchi"));
|
|
177
|
+
this.hash =
|
|
178
|
+
this.isNonPeriodic && !hasInchi
|
|
179
|
+
? this.calculateHash("", false, true)
|
|
180
|
+
: this.calculateHash();
|
|
181
|
+
}
|
|
182
|
+
// Override schema-mixin accessors so basis/lattice changes keep hash in sync.
|
|
183
|
+
get basis() {
|
|
184
|
+
return this.requiredProp("basis");
|
|
185
|
+
}
|
|
186
|
+
set basis(value) {
|
|
187
|
+
this.setProp("basis", value);
|
|
188
|
+
this.updateHash();
|
|
189
|
+
}
|
|
190
|
+
get lattice() {
|
|
191
|
+
return this.requiredProp("lattice");
|
|
192
|
+
}
|
|
193
|
+
set lattice(value) {
|
|
194
|
+
this.setProp("lattice", value);
|
|
195
|
+
this.updateHash();
|
|
196
|
+
}
|
|
197
|
+
updateFormula() {
|
|
198
|
+
const basis = this.getBasis();
|
|
199
|
+
this.formula = basis.formula;
|
|
200
|
+
this.unitCellFormula = basis.unitCellFormula;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* @summary Returns the specific derived property (as specified by name) for a material.
|
|
204
|
+
*/
|
|
205
|
+
getDerivedPropertyByName(name) {
|
|
206
|
+
return this.getDerivedProperties().find((x) => x.name === name);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* @summary Returns the derived properties array for a material.
|
|
210
|
+
*/
|
|
211
|
+
getDerivedProperties() {
|
|
212
|
+
var _a;
|
|
213
|
+
return (_a = this.derivedProperties) !== null && _a !== void 0 ? _a : [];
|
|
214
|
+
}
|
|
215
|
+
unsetFileProps() {
|
|
216
|
+
this.unsetProp("src");
|
|
217
|
+
this.unsetProp("icsdId");
|
|
218
|
+
this.unsetProp("external");
|
|
219
|
+
}
|
|
220
|
+
setBasis(textOrObject, format, units) {
|
|
221
|
+
this.basis = parseConstrainedBasis(textOrObject, format, units);
|
|
222
|
+
this.unsetFileProps();
|
|
223
|
+
this.updateFormula();
|
|
224
|
+
}
|
|
225
|
+
setBasisConstraints(constraints) {
|
|
226
|
+
this.setBasis({
|
|
227
|
+
...this.basis,
|
|
228
|
+
constraints: constraints.map((constraint) => ({
|
|
229
|
+
id: constraint.id,
|
|
230
|
+
value: constraint.value,
|
|
231
|
+
})),
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
setBasisConstraintsFromArrayOfObjects(constraints) {
|
|
235
|
+
this.setBasisConstraints(constraints.map((constraint) => constraints_1.Constraint.fromValueAndId(constraint.value, constraint.id)));
|
|
236
|
+
}
|
|
237
|
+
getBasis() {
|
|
238
|
+
return new constrained_basis_1.ConstrainedBasis({
|
|
239
|
+
...parseConstrainedBasis(this.basis),
|
|
240
|
+
cell: this.getLattice().vectors,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
setLattice(lattice) {
|
|
244
|
+
const basis = this.getBasis();
|
|
245
|
+
const originalIsInCrystalUnits = basis.isInCrystalUnits;
|
|
246
|
+
basis.toCartesian();
|
|
247
|
+
basis.cell = new lattice_1.Lattice(lattice).vectors;
|
|
248
|
+
if (originalIsInCrystalUnits) {
|
|
249
|
+
basis.toCrystal();
|
|
250
|
+
}
|
|
251
|
+
this.basis = basis.toJSON();
|
|
252
|
+
this.lattice = lattice;
|
|
253
|
+
this.unsetFileProps();
|
|
254
|
+
}
|
|
255
|
+
getLattice() {
|
|
256
|
+
return new lattice_1.Lattice(this.lattice);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* High-level access to unique elements from material instead of basis.
|
|
260
|
+
*/
|
|
261
|
+
get uniqueElements() {
|
|
262
|
+
return this.getBasis().uniqueElements;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns the inchi string from the derivedProperties for a non-periodic material, or throws an error if the
|
|
266
|
+
* inchi cannot be found.
|
|
267
|
+
* @returns {String}
|
|
268
|
+
*/
|
|
269
|
+
getInchiStringForHash() {
|
|
270
|
+
const inchi = this.getDerivedPropertyByName("inchi");
|
|
271
|
+
if (inchi) {
|
|
272
|
+
return inchi.value;
|
|
273
|
+
}
|
|
274
|
+
throw new Error("Hash cannot be created. Missing InChI string in derivedProperties");
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Calculates hash from basis and lattice. Algorithm expects the following:
|
|
278
|
+
* - asserts lattice units to be angstrom
|
|
279
|
+
* - asserts basis units to be crystal
|
|
280
|
+
* - asserts basis coordinates and lattice measurements are rounded to hash precision
|
|
281
|
+
* - forms strings for lattice and basis
|
|
282
|
+
* - creates MD5 hash from basisStr + latticeStr + salt
|
|
283
|
+
* @param salt Salt for hashing, empty string by default.
|
|
284
|
+
* @param isScaled Whether to scale the lattice parameter 'a' to 1.
|
|
285
|
+
*/
|
|
286
|
+
calculateHash(salt = "", isScaled = false, bypassNonPeriodicCheck = false) {
|
|
287
|
+
let message;
|
|
288
|
+
if (!this.isNonPeriodic || bypassNonPeriodicCheck) {
|
|
289
|
+
message =
|
|
290
|
+
this.getBasis().hashString +
|
|
291
|
+
"#" +
|
|
292
|
+
this.getLattice().getHashString(isScaled) +
|
|
293
|
+
"#" +
|
|
294
|
+
salt;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
message = this.getInchiStringForHash();
|
|
298
|
+
}
|
|
299
|
+
return crypto_js_1.default.MD5(message).toString();
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Converts basis to crystal/fractional coordinates.
|
|
303
|
+
*/
|
|
304
|
+
toCrystal() {
|
|
305
|
+
this.setBasis(this.getBasis().toCrystal().toJSON());
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Converts current material's basis coordinates to cartesian.
|
|
309
|
+
* No changes if coordinates already cartesian.
|
|
310
|
+
*/
|
|
311
|
+
toCartesian() {
|
|
312
|
+
this.setBasis(this.getBasis().toCartesian().toJSON());
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Returns material's basis in XYZ format (includes atomic constraints when present).
|
|
316
|
+
*/
|
|
317
|
+
getBasisAsXyz(fractional = false) {
|
|
318
|
+
return parsers_1.default.xyz.fromMaterial(this.toJSONEnhanced(), fractional);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Returns material in Quantum Espresso output format:
|
|
322
|
+
* ```
|
|
323
|
+
* CELL_PARAMETERS (angstroms)
|
|
324
|
+
* -0.543131284 -0.000000000 0.543131284
|
|
325
|
+
* -0.000000000 0.543131284 0.543131284
|
|
326
|
+
* -0.543131284 0.543131284 0.000000000
|
|
327
|
+
*
|
|
328
|
+
* ATOMIC_POSITIONS (crystal)
|
|
329
|
+
* Si 0.000000000 0.000000000 -0.000000000
|
|
330
|
+
* Si 0.250000000 0.250000000 0.250000000
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
getAsQEFormat() {
|
|
334
|
+
return parsers_1.default.espresso.toEspressoFormat(this.toJSONPure());
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Returns material in POSCAR format. Pass `true` to ignore original poscar source and re-serialize.
|
|
338
|
+
*/
|
|
339
|
+
getAsPOSCAR(ignoreOriginal = false, omitConstraints = false) {
|
|
340
|
+
var _a;
|
|
341
|
+
// By default return original source if exists
|
|
342
|
+
if (((_a = this.src) === null || _a === void 0 ? void 0 : _a.extension) === "poscar" && !ignoreOriginal) {
|
|
343
|
+
return this.src.text;
|
|
344
|
+
}
|
|
345
|
+
return parsers_1.default.poscar.toPoscar(this.toJSONEnhanced(), omitConstraints);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Returns a copy of the material with conventional cell constructed instead of primitive.
|
|
349
|
+
*/
|
|
350
|
+
getACopyWithConventionalCell() {
|
|
351
|
+
const material = this.clone();
|
|
352
|
+
const lattice = this.getLattice();
|
|
353
|
+
// if conventional and primitive cells are the same => return a copy.
|
|
354
|
+
if ((0, conventional_cell_1.isConventionalCellSameAsPrimitiveForLatticeType)(lattice.type)) {
|
|
355
|
+
return material;
|
|
356
|
+
}
|
|
357
|
+
const conventionalSupercellMatrix = conventional_cell_1.PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS[lattice.type];
|
|
358
|
+
const conventionalLatticeType = conventional_cell_1.PRIMITIVE_TO_CONVENTIONAL_CELL_LATTICE_TYPES[lattice.type];
|
|
359
|
+
const config = supercell_1.default.generateConfig(this, conventionalSupercellMatrix);
|
|
360
|
+
config.lattice.type = conventionalLatticeType;
|
|
361
|
+
config.name = `${this.name} - conventional cell`;
|
|
362
|
+
return this.clone(config);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* @summary a series of checks for the material and returns an array of results in ConsistencyChecks format.
|
|
366
|
+
* @returns Array of checks results
|
|
367
|
+
*/
|
|
368
|
+
getConsistencyChecks() {
|
|
369
|
+
const basisChecks = this.getBasisConsistencyChecks();
|
|
370
|
+
// any other Material checks can be added here
|
|
371
|
+
return basisChecks;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* @summary a series of checks for the material's basis and returns an array of results in ConsistencyChecks format.
|
|
375
|
+
* @returns Array of checks results
|
|
376
|
+
*/
|
|
377
|
+
getBasisConsistencyChecks() {
|
|
378
|
+
const checks = [];
|
|
379
|
+
const limit = 1000;
|
|
380
|
+
const basis = this.getBasis();
|
|
381
|
+
if (basis.elements.length < limit) {
|
|
382
|
+
const overlappingAtomsGroups = basis.getOverlappingAtoms();
|
|
383
|
+
overlappingAtomsGroups.forEach(({ id1, id2, element1, element2 }) => {
|
|
384
|
+
checks.push({
|
|
385
|
+
key: `basis.coordinates.${id1}`,
|
|
386
|
+
name: "atomsOverlap",
|
|
387
|
+
severity: "warning",
|
|
388
|
+
message: `Atom ${element1} is too close to ${element2} at position ${id2 + 1}`,
|
|
389
|
+
}, {
|
|
390
|
+
key: `basis.coordinates.${id2}`,
|
|
391
|
+
name: "atomsOverlap",
|
|
392
|
+
severity: "warning",
|
|
393
|
+
message: `Atom ${element2} is too close to ${element1} at position ${id1 + 1}`,
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
return checks;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Full material JSON: constrained basis + hash fields from live getters.
|
|
401
|
+
* Variants below AJV-clean this payload against the matching ESSE schema.
|
|
402
|
+
* Builds from `_json` (not `super.toJSON`) so we do not pre-clean against
|
|
403
|
+
* {@link Material.jsonSchema} before projecting to a narrower schema.
|
|
404
|
+
*/
|
|
405
|
+
getFullJSON() {
|
|
406
|
+
const fullJSON = {
|
|
407
|
+
...(0, clone_1.clone)(this._json),
|
|
408
|
+
lattice: this.getLattice().toJSON(),
|
|
409
|
+
basis: this.getBasis().toJSON(),
|
|
410
|
+
isNonPeriodic: this.isNonPeriodic,
|
|
411
|
+
hash: this.hash,
|
|
412
|
+
};
|
|
413
|
+
if (this.scaledHash !== undefined) {
|
|
414
|
+
fullJSON.scaledHash = this.scaledHash;
|
|
415
|
+
}
|
|
416
|
+
return fullJSON;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Clone {@link getFullJSON} and validate/clean against `jsonSchema` via AJV
|
|
420
|
+
* (same path as {@link InMemoryEntity.validateData} / {@link InMemoryEntity.clean}).
|
|
421
|
+
*/
|
|
422
|
+
cleanFullJSONAgainstSchema(jsonSchema) {
|
|
423
|
+
var _a, _b, _c;
|
|
424
|
+
try {
|
|
425
|
+
return this.constructor.validateData((0, clone_1.deepClone)(this.getFullJSON()), true, jsonSchema);
|
|
426
|
+
}
|
|
427
|
+
catch (err) {
|
|
428
|
+
// validateData throws EntityError with only the code as message — log details for DevTools.
|
|
429
|
+
if (err instanceof in_memory_1.EntityError) {
|
|
430
|
+
console.error("Material.toJSON validation failed", {
|
|
431
|
+
code: err.code,
|
|
432
|
+
error: (_a = err.details) === null || _a === void 0 ? void 0 : _a.error,
|
|
433
|
+
json: (_b = err.details) === null || _b === void 0 ? void 0 : _b.json,
|
|
434
|
+
schema: (_c = err.details) === null || _c === void 0 ? void 0 : _c.schema,
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
throw err;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
toJSONPure() {
|
|
441
|
+
return this.cleanFullJSONAgainstSchema(this.constructor.jsonSchemaPure);
|
|
442
|
+
}
|
|
443
|
+
toJSONEnhanced() {
|
|
444
|
+
return this.cleanFullJSONAgainstSchema(this.constructor.jsonSchemaEnhanced);
|
|
445
|
+
}
|
|
446
|
+
toJSONHashed() {
|
|
447
|
+
return this.cleanFullJSONAgainstSchema(this.constructor.jsonSchemaHashed);
|
|
448
|
+
}
|
|
449
|
+
toJSONEnhancedHashed() {
|
|
450
|
+
return this.cleanFullJSONAgainstSchema(this.constructor.jsonSchemaEnhancedHashed);
|
|
451
|
+
}
|
|
452
|
+
toJSON() {
|
|
453
|
+
// Same payload as toJSONEnhancedHashed when jsonSchema is the enhanced-hashed default.
|
|
454
|
+
return this.cleanFullJSONAgainstSchema(this.constructor.jsonSchema);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
exports.default = Material;
|