Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions dist/js/basis/basis.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import { BasisSchema, Coordinate3DSchema, Vector3DSchema } from "@mat3ra/esse/dist/js/types";
import { BaseInMemoryEntitySchema, BasisSchema, Coordinate3DSchema, Vector3DSchema } from "@mat3ra/esse/dist/js/types";
import { Cell } from "../cell/cell";
import { AtomicCoordinateValue, Coordinates } from "./coordinates";
import { AtomicElementValue, Elements } from "./elements";
Expand Down Expand Up @@ -30,7 +30,8 @@ export interface ElementsAndCoordinatesConfig {
units?: BasisSchema["units"];
cell?: Cell;
}
export declare class Basis extends InMemoryEntity implements BasisSchema {
type BasisEntitySchema = BasisConfig & BaseInMemoryEntitySchema;
export declare class Basis extends InMemoryEntity<BasisEntitySchema> implements BasisSchema {
static defaultConfig: BasisSchema;
units: BasisSchema["units"];
cell: Cell;
Expand All @@ -46,17 +47,17 @@ export declare class Basis extends InMemoryEntity implements BasisSchema {
set coordinates(coordinates: BasisSchema["coordinates"]);
get labels(): BasisSchema["labels"];
set labels(labels: BasisSchema["labels"]);
toJSON(exclude?: string[]): BasisSchema;
clone(): Basis;
toJSON(exclude?: (keyof BasisConfig)[]): BasisSchema;
clone(): this;
removeAllAtoms(): void;
get cellRounded(): import("@mat3ra/esse/dist/js/types").Matrix3X3Schema;
get elementsArray(): object[];
getElementsAsObject(): BasisSchema["elements"];
get coordinatesAsArray(): Coordinate3DSchema[];
get isInCartesianUnits(): boolean;
get isInCrystalUnits(): boolean;
toCartesian(): void;
toCrystal(): void;
toCartesian(): this;
toCrystal(): this;
getElementByIndex(idx: number): AtomicElementValue;
getElementById(id: number): AtomicElementValue;
getCoordinateValueByIndex(idx: number): AtomicCoordinateValue;
Expand Down
9 changes: 4 additions & 5 deletions dist/js/basis/basis.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ class Basis extends entity_1.InMemoryEntity {
set labels(labels) {
this._labels = labels_1.Labels.fromObjects(labels || []);
}
// TODO: figure out how to override toJSON in the parent class with generic classes
// @ts-ignore
toJSON(exclude = ["cell"]) {
var _a;
return {
Expand All @@ -96,7 +94,6 @@ class Basis extends entity_1.InMemoryEntity {
...(((_a = this.labels) === null || _a === void 0 ? void 0 : _a.length) ? { labels: this.labels } : {}),
};
}
// @ts-ignore
clone() {
const instance = super.clone();
instance.cell = this.cell.clone();
Expand Down Expand Up @@ -127,15 +124,17 @@ class Basis extends entity_1.InMemoryEntity {
}
toCartesian() {
if (this.isInCartesianUnits)
return;
return this;
this._coordinates.mapArrayInPlace((point) => this.cell.convertPointToCartesian(point));
this.units = constants_1.ATOMIC_COORD_UNITS.cartesian;
return this;
}
toCrystal() {
if (this.isInCrystalUnits)
return;
return this;
this._coordinates.mapArrayInPlace((point) => this.cell.convertPointToCrystal(point));
this.units = constants_1.ATOMIC_COORD_UNITS.crystal;
return this;
}
getElementByIndex(idx) {
return this._elements.getElementValueByIndex(idx);
Expand Down
2 changes: 1 addition & 1 deletion dist/js/basis/constrained_basis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface ElementsCoordinatesAndConstraintsConfig extends ElementsAndCoor
* @extends Basis
*/
export declare class ConstrainedBasis extends Basis {
_constraints: AtomicConstraints;
private _constraints;
constructor(config: ConstrainedBasisConfig);
static fromElementsCoordinatesAndConstraints(config: ElementsCoordinatesAndConstraintsConfig): ConstrainedBasis;
get constraints(): AtomicConstraintsSchema;
Expand Down
3 changes: 1 addition & 2 deletions dist/js/basis/constrained_basis.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const helpers_1 = require("./helpers");
class ConstrainedBasis extends basis_1.Basis {
constructor(config) {
super(config);
const { constraints } = config;
this._constraints = constraints_1.AtomicConstraints.fromObjects(constraints || []); // `constraints` is an Array with ids
this._constraints = constraints_1.AtomicConstraints.fromObjects(config.constraints); // `constraints` is an Array with ids
}
static fromElementsCoordinatesAndConstraints(config) {
const basisConfig = this._convertValuesToConfig(config);
Expand Down
5 changes: 5 additions & 0 deletions dist/js/generated/MaterialSchemaMixin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import type { MaterialPropertiesSchema } from "@mat3ra/esse/dist/js/types";
export type MaterialSchemaMixin = MaterialPropertiesSchema;
export type MaterialInMemoryEntity = InMemoryEntity & MaterialSchemaMixin;
export declare function materialSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & MaterialSchemaMixin;
76 changes: 76 additions & 0 deletions dist/js/generated/MaterialSchemaMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.materialSchemaMixin = void 0;
function materialSchemaMixin(item) {
// @ts-expect-error
const properties = {
get formula() {
return this.prop("formula");
},
set formula(value) {
this.setProp("formula", value);
},
get unitCellFormula() {
return this.prop("unitCellFormula");
},
set unitCellFormula(value) {
this.setProp("unitCellFormula", value);
},
get basis() {
return this.requiredProp("basis");
},
set basis(value) {
this.setProp("basis", value);
},
get lattice() {
return this.requiredProp("lattice");
},
set lattice(value) {
this.setProp("lattice", value);
},
get derivedProperties() {
return this.prop("derivedProperties");
},
set derivedProperties(value) {
this.setProp("derivedProperties", value);
},
get external() {
return this.prop("external");
},
set external(value) {
this.setProp("external", value);
},
get src() {
return this.prop("src");
},
set src(value) {
this.setProp("src", value);
},
get scaledHash() {
return this.prop("scaledHash");
},
set scaledHash(value) {
this.setProp("scaledHash", value);
},
get icsdId() {
return this.prop("icsdId");
},
set icsdId(value) {
this.setProp("icsdId", value);
},
get isNonPeriodic() {
return this.prop("isNonPeriodic");
},
set isNonPeriodic(value) {
this.setProp("isNonPeriodic", value);
},
get consistencyChecks() {
return this.prop("consistencyChecks");
},
set consistencyChecks(value) {
this.setProp("consistencyChecks", value);
},
};
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
}
exports.materialSchemaMixin = materialSchemaMixin;
7 changes: 4 additions & 3 deletions dist/js/lattice/lattice.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import { LatticeSchema, LatticeTypeEnum, LatticeTypeExtendedEnum, LatticeVectorsSchema, Matrix3X3Schema } from "@mat3ra/esse/dist/js/types";
import { BaseInMemoryEntitySchema, LatticeSchema, LatticeTypeEnum, LatticeTypeExtendedEnum, LatticeVectorsSchema, Matrix3X3Schema } from "@mat3ra/esse/dist/js/types";
import { Cell } from "../cell/cell";
import { UnitCell } from "./unit_cell";
/**
Expand All @@ -10,7 +10,8 @@ export { defaultNonPeriodicMinimumLatticeSize, diatomicLatticePaddingFactor, mol
export declare class LatticeVectors extends Cell implements LatticeVectorsSchema {
}
export type { LatticeVectorsSchema };
export declare class Lattice extends InMemoryEntity implements LatticeSchema {
type LatticeEntitySchema = LatticeSchema & BaseInMemoryEntitySchema;
export declare class Lattice extends InMemoryEntity<LatticeEntitySchema> implements LatticeSchema {
static defaultConfig: LatticeSchema;
a: LatticeSchema["a"];
b: LatticeSchema["b"];
Expand Down Expand Up @@ -63,5 +64,5 @@ export declare class Lattice extends InMemoryEntity implements LatticeSchema {
* @example {a: true, b: false, c: false, alpha: true, beta: false, gamma: false}
*/
get editables(): {};
toJSON(exclude?: string[]): LatticeSchema;
toJSON(exclude?: (keyof LatticeSchema)[]): LatticeSchema;
}
3 changes: 1 addition & 2 deletions dist/js/lattice/lattice.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ class Lattice extends entity_1.InMemoryEntity {
}
return object;
}
// @ts-ignore
toJSON(exclude) {
toJSON(exclude = []) {
return {
...super.toJSON(exclude),
vectors: this.vectors.toJSON(),
Expand Down
2 changes: 1 addition & 1 deletion dist/js/made.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export declare const Made: {
cartesian: string;
};
Material: typeof Material;
defaultMaterialConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema;
defaultMaterialConfig: import("./material").MaterialConfig;
Lattice: typeof Lattice;
Cell: typeof Cell;
UnitCell: typeof UnitCell;
Expand Down
83 changes: 26 additions & 57 deletions dist/js/material.d.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
import { type DefaultableInMemoryEntity, InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import { type HasConsistencyChecks } from "@mat3ra/code/dist/js/entity/mixins/HasConsistencyChecksMixin";
import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import { type Defaultable } from "@mat3ra/code/dist/js/entity/mixins/DefaultableMixin";
import { type HashedEntity } from "@mat3ra/code/dist/js/entity/mixins/HashedEntityMixin";
import { type HasMetadata } from "@mat3ra/code/dist/js/entity/mixins/HasMetadataMixin";
import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
import type { AtomicConstraintsSchema, ConsistencyCheck, DerivedPropertiesSchema, FileSourceSchema, LatticeSchema, MaterialSchema } from "@mat3ra/esse/dist/js/types";
import { type NamedEntity } from "@mat3ra/code/dist/js/entity/mixins/NamedEntityMixin";
import type { AtomicConstraintsSchema, BasisSchema, ConsistencyCheck, DerivedPropertiesSchema, FileSourceSchema, LatticeSchema, MaterialSchema } from "@mat3ra/esse/dist/js/types";
import type { BasisConfig } from "./basis/basis";
import { type ConstrainedBasisConfig, ConstrainedBasis } from "./basis/constrained_basis";
import { Constraint } from "./constraints/constraints";
import { ConstrainedBasis } from "./basis/constrained_basis";
import { type MaterialSchemaMixin } from "./generated/MaterialSchemaMixin";
import { Lattice } from "./lattice/lattice";
interface Material extends HasConsistencyChecks, DefaultableInMemoryEntity, Required<HasMetadata<MaterialSchema["metadata"]>> {
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export type MaterialConfig = PartialBy<MaterialSchema, "name" | "metadata" | "hash">;
export declare const defaultMaterialConfig: MaterialConfig;
interface BaseMaterial extends MaterialSchemaMixin, NamedEntity, Defaultable, HashedEntity, Required<HasMetadata<MaterialSchema["metadata"]>> {
}
type MaterialSchemaWithConsistencyChecksAsString = Omit<MaterialSchema, "consistencyChecks"> & {
consistencyChecks?: ConsistencyCheck[];
};
type OptionallyConstrainedBasisConfig = BasisConfig & Partial<Pick<ConstrainedBasisConfig, "constraints">>;
type Schema = MaterialSchemaWithConsistencyChecksAsString;
export declare const defaultMaterialConfig: MaterialSchema;
declare class Material extends InMemoryEntity implements Schema {
declare class BaseMaterial extends InMemoryEntity<MaterialSchema> {
}
declare class Material extends BaseMaterial implements MaterialSchema {
static createDefault: () => Material;
static get defaultConfig(): MaterialSchema;
static get defaultConfig(): MaterialConfig;
static constructMaterialFileSource(fileName: string, fileContent: string, fileExtension: string): FileSourceSchema;
get name(): string;
set name(name: string);
get src(): FileSourceSchema | undefined;
set src(src: FileSourceSchema | undefined);
private constraints;
constructor(config: MaterialConfig, constraints?: AtomicConstraintsSchema);
updateFormula(): void;
/**
* Gets Bolean value for whether or not a material is non-periodic vs periodic.
* False = periodic, True = non-periodic
*/
get isNonPeriodic(): boolean;
/**
* @summary Sets the value of isNonPeriodic based on Boolean value passed as an argument.
*/
set isNonPeriodic(bool: boolean);
updateHash(): void;
/**
* @summary Returns the specific derived property (as specified by name) for a material.
*/
Expand Down Expand Up @@ -71,29 +61,16 @@ declare class Material extends InMemoryEntity implements Schema {
* @summary Returns the derived properties array for a material.
*/
getDerivedProperties(): DerivedPropertiesSchema;
/**
* Gets material's formula
*/
get formula(): string;
get unitCellFormula(): string;
unsetFileProps(): void;
/**
* @param textOrObject Basis text or JSON object.
* @param format Format (xyz, etc.)
* @param unitz crystal/cartesian
*/
setBasis(textOrObject: string | BasisConfig, format?: string, unitz?: string): void;
setBasisConstraints(constraints: Constraint[]): void;
setBasisConstraintsFromArrayOfObjects(constraints: AtomicConstraintsSchema): void;
get basis(): OptionallyConstrainedBasisConfig;
get Basis(): ConstrainedBasis;
setBasis(basis: BasisConfig): void;
setBasis(basis: string, format: "xyz", unitz?: BasisSchema["units"]): void;
getBasis(constraints?: AtomicConstraintsSchema): ConstrainedBasis;
setLattice(lattice: LatticeSchema): void;
getLattice(): Lattice;
/**
* High-level access to unique elements from material instead of basis.
*/
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")[];
get lattice(): LatticeSchema;
set lattice(config: LatticeSchema);
get Lattice(): Lattice;
/**
* Returns the inchi string from the derivedProperties for a non-periodic material, or throws an error if the
* inchi cannot be found.
Expand All @@ -111,23 +88,15 @@ declare class Material extends InMemoryEntity implements Schema {
* @param isScaled Whether to scale the lattice parameter 'a' to 1.
*/
calculateHash(salt?: string, isScaled?: boolean, bypassNonPeriodicCheck?: boolean): string;
set hash(hash: string);
get hash(): string;
/**
* Calculates hash from basis and lattice as above + scales lattice properties to make lattice.a = 1
*/
get scaledHash(): string;
get external(): MaterialSchema["external"];
set external(external: MaterialSchema["external"]);
/**
* Converts basis to crystal/fractional coordinates.
*/
toCrystal(): void;
toCrystal(constraints?: AtomicConstraintsSchema): void;
/**
* Converts current material's basis coordinates to cartesian.
* No changes if coordinates already cartesian.
*/
toCartesian(): void;
toCartesian(constraints?: AtomicConstraintsSchema): void;
/**
* Returns material's basis in XYZ format.
*/
Expand Down Expand Up @@ -164,6 +133,6 @@ declare class Material extends InMemoryEntity implements Schema {
* @returns Array of checks results
*/
getBasisConsistencyChecks(): ConsistencyCheck[];
toJSON(): MaterialSchema & AnyObject;
toJSON(): MaterialSchema;
}
export { Material };
Loading
Loading