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
23 changes: 14 additions & 9 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<S extends BasisConfig = BasisConfig> = S & BaseInMemoryEntitySchema;
export declare class Basis<S extends BasisConfig = BasisConfig> extends InMemoryEntity<BasisEntitySchema<S>> implements BasisSchema {
static defaultConfig: BasisSchema;
units: BasisSchema["units"];
cell: Cell;
Expand All @@ -39,24 +40,24 @@ export declare class Basis extends InMemoryEntity implements BasisSchema {
_labels: Labels;
static _convertValuesToConfig({ elements, coordinates, units, cell, labels, }: ElementsAndCoordinatesConfig): BasisConfig;
static fromElementsAndCoordinates({ elements, coordinates, units, cell, labels, }: ElementsAndCoordinatesConfig): Basis;
constructor(config?: BasisConfig);
constructor(config?: NoInfer<S>);
get elements(): BasisSchema["elements"];
set elements(elements: BasisSchema["elements"]);
get coordinates(): BasisSchema["coordinates"];
set coordinates(coordinates: BasisSchema["coordinates"]);
get labels(): BasisSchema["labels"];
set labels(labels: BasisSchema["labels"]);
toJSON(exclude?: string[]): BasisSchema;
clone(): Basis;
toJSON(exclude?: (keyof BasisEntitySchema<S>)[]): BasisEntitySchema<S>;
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 Expand Up @@ -140,12 +141,16 @@ export declare class Basis extends InMemoryEntity implements BasisSchema {
* @summary Returns true if bases are equal, otherwise - false.
* @param anotherBasisClsInstance {Basis} Another Basis.
*/
isEqualTo(anotherBasisClsInstance: Basis): boolean;
isEqualTo(anotherBasisClsInstance: {
hashString: string;
}): boolean;
/**
* @summary Returns true if basis cells are equal, otherwise - false.
* @param anotherBasisClsInstance {Basis} Another Basis.
*/
hasEquivalentCellTo(anotherBasisClsInstance: Basis): boolean;
hasEquivalentCellTo(anotherBasisClsInstance: {
cell: Cell;
}): boolean;
/**
* @summary Returns the minimum cubic lattice size for a non-periodic structure.
* Single-atom structures use the element atomic radius floored at defaultMinimumLatticeSize.
Expand Down
28 changes: 15 additions & 13 deletions dist/js/basis/basis.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const DEFAULT_BASIS_CONFIG = {
],
units: "crystal",
};
// Keep `{` on same line as `implements` to satisfy brace-style (conflicts with Prettier multi-line heritage).
// prettier-ignore
class Basis extends entity_1.InMemoryEntity {
static _convertValuesToConfig({ elements = [], coordinates = [], units = constants_1.ATOMIC_COORD_UNITS.crystal, cell = new cell_1.Cell(), labels = [], }) {
const elementsArrayWithIdsJSON = elements_1.Elements.fromValues(elements).toJSON();
Expand All @@ -57,6 +59,7 @@ class Basis extends entity_1.InMemoryEntity {
labels,
}));
}
// NoInfer: keep default S (or an explicit type arg) instead of inferring S from the config literal.
constructor(config = Basis.defaultConfig) {
super(config);
const { elements, coordinates, units, labels } = config;
Expand Down Expand Up @@ -84,8 +87,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 +97,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 +127,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 Expand Up @@ -310,7 +312,7 @@ class Basis extends entity_1.InMemoryEntity {
/* Returns array of atomic labels E.g., ["1", "2", "", ""] */
get atomicLabelsArray() {
var _a;
const labelsArray = Array.from({ length: this.elements.length }, (_) => "");
const labelsArray = Array.from({ length: this.elements.length }, () => "");
// https://dev.to/maafaishal/benchmarking-for-while-forof-and-arrayforeach-using-performancenow-1jjg
if ((_a = this.labels) === null || _a === void 0 ? void 0 : _a.length) {
for (let i = 0; i < this.labels.length; i++) {
Expand Down Expand Up @@ -447,13 +449,13 @@ class Basis extends entity_1.InMemoryEntity {
for (let i = 0; i < this._elements.values.length; i++) {
for (let j = i + 1; j < this._elements.values.length; j++) {
const distance = utils_1.Utils.math.vDist(this._coordinates.getElementValueByIndex(i), this._coordinates.getElementValueByIndex(j));
if (!distance)
continue;
if (extremum === "max" && distance > resultDistance) {
resultDistance = distance;
}
if (extremum === "min" && distance < resultDistance) {
resultDistance = distance;
if (distance) {
if (extremum === "max" && distance > resultDistance) {
resultDistance = distance;
}
if (extremum === "min" && distance < resultDistance) {
resultDistance = distance;
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions dist/js/basis/constrained_basis.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AtomicCoordinateValue } from "./coordinates";
import { AtomicElementValue } from "./elements";
import { AtomicLabelValue } from "./labels";
export interface ConstrainedBasisConfig extends BasisConfig {
constraints: AtomicConstraintsSchema;
constraints?: AtomicConstraintsSchema;
}
export interface ElementsCoordinatesAndConstraintsConfig extends ElementsAndCoordinatesConfig {
constraints: AtomicConstraintValue[];
Expand All @@ -14,14 +14,14 @@ export interface ElementsCoordinatesAndConstraintsConfig extends ElementsAndCoor
* @summary Extension of the Basis class able to deal with atomic constraints.
* @extends Basis
*/
export declare class ConstrainedBasis extends Basis {
_constraints: AtomicConstraints;
export declare class ConstrainedBasis extends Basis<ConstrainedBasisConfig> {
private _constraints;
constructor(config: ConstrainedBasisConfig);
static fromElementsCoordinatesAndConstraints(config: ElementsCoordinatesAndConstraintsConfig): ConstrainedBasis;
get constraints(): AtomicConstraintsSchema;
set constraints(constraints: AtomicConstraintsSchema);
get AtomicConstraints(): AtomicConstraints;
toJSON(): ConstrainedBasisConfig;
toJSON(exclude?: (keyof ConstrainedBasisConfig)[]): ConstrainedBasisConfig;
getConstraintByIndex(idx: number): AtomicConstraintValue;
getConstraintById(id: number): AtomicConstraintValue;
/**
Expand Down
8 changes: 4 additions & 4 deletions dist/js/basis/constrained_basis.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ const helpers_1 = require("./helpers");
*/
class ConstrainedBasis extends basis_1.Basis {
constructor(config) {
var _a;
super(config);
const { constraints } = config;
this._constraints = constraints_1.AtomicConstraints.fromObjects(constraints || []); // `constraints` is an Array with ids
this._constraints = constraints_1.AtomicConstraints.fromObjects((_a = config.constraints) !== null && _a !== void 0 ? _a : []); // `constraints` is an Array with ids
}
static fromElementsCoordinatesAndConstraints(config) {
const basisConfig = this._convertValuesToConfig(config);
Expand All @@ -32,9 +32,9 @@ class ConstrainedBasis extends basis_1.Basis {
get AtomicConstraints() {
return constraints_1.AtomicConstraints.fromObjects(this.constraints);
}
toJSON() {
toJSON(exclude = ["cell"]) {
return {
...super.toJSON(),
...super.toJSON(exclude),
constraints: this.constraints,
};
}
Expand Down
4 changes: 4 additions & 0 deletions dist/js/generated/MaterialSchemaMixin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
import type { MaterialPropertiesSchema } from "@mat3ra/esse/dist/js/types";
export type MaterialSchemaMixin = MaterialPropertiesSchema;
export declare function materialSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & MaterialSchemaMixin;
75 changes: 75 additions & 0 deletions dist/js/generated/MaterialSchemaMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.materialSchemaMixin = materialSchemaMixin;
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));
}
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 @@ -258,8 +258,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
24 changes: 13 additions & 11 deletions dist/js/made.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DEFAULT_LATTICE_UNITS, LATTICE_TYPE_CONFIGS } from "./lattice/lattice_t
import { ReciprocalLattice } from "./lattice/reciprocal/lattice_reciprocal";
import { UnitCell } from "./lattice/unit_cell";
import { defaultMaterialConfig, Material } from "./material";
import { MaterialHashed } from "./material_hashed";
import parsers from "./parsers/parsers";
import tools from "./tools/index";
export declare const Made: {
Expand All @@ -33,6 +34,7 @@ export declare const Made: {
cartesian: string;
};
Material: typeof Material;
MaterialHashed: typeof MaterialHashed;
defaultMaterialConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema;
Lattice: typeof Lattice;
Cell: typeof Cell;
Expand All @@ -46,37 +48,37 @@ export declare const Made: {
parsers: {
xyz: {
validate: typeof import("./parsers/xyz").validate;
fromMaterial: (materialOrConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema, fractional?: boolean) => string;
fromMaterial: (materialOrConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema, fractional?: boolean, constraints?: import("@mat3ra/esse/dist/js/types").AtomicConstraintsSchema) => string;
toBasisConfig: (txt: string, units?: string, cell?: Cell) => import("./basis/constrained_basis").ConstrainedBasisConfig;
fromBasis: (basisClsInstance: import("./basis/constrained_basis").ConstrainedBasis, coordinatePrintFormat: string) => string;
CombinatorialBasis: typeof import("./parsers/xyz_combinatorial_basis").CombinatorialBasis;
};
poscar: {
isPoscar: (text: string) => boolean;
toPoscar: (materialOrConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema, omitConstraints?: boolean) => string;
fromPoscar: (fileContent: string) => object;
toPoscar: (materialOrConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema, constraints?: import("@mat3ra/esse/dist/js/types").AtomicConstraintsSchema, omitConstraints?: boolean) => string;
fromPoscar: (fileContent: string) => import("./parsers/poscar").MaterialSchemaWithConstraints;
atomicConstraintsCharFromBool: (bool: boolean) => string;
atomsCount: typeof import("./parsers/poscar").atomsCount;
};
cif: {
parseMeta: (txt: string) => import("./parsers/cif").Meta;
};
espresso: {
toEspressoFormat: (materialOrConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema) => string;
toEspressoFormat: (materialOrConfig: import("@mat3ra/esse/dist/js/types").MaterialSchema, constraints?: import("@mat3ra/esse/dist/js/types").AtomicConstraintsSchema) => string;
};
nativeFormatParsers: {
detectFormat: (text: string) => string;
convertFromNativeFormat: (text: string) => any;
detectFormat: (text: string) => "json" | "poscar" | "unknown";
convertFromNativeFormat: (text: string) => import("./parsers/poscar").MaterialSchemaWithConstraints;
};
};
tools: {
surface: {
generateConfig: (material: Material, millerIndices: import("@mat3ra/esse/dist/js/types").Coordinate3DSchema, numberOfLayers?: number, vx?: number, vy?: number) => import("./tools/surface").SlabConfigSchema;
generateConfig: <S extends import("@mat3ra/esse/dist/js/types").MaterialSchema = import("@mat3ra/esse/dist/js/types").MaterialSchema>(material: Material<S>, millerIndices: import("@mat3ra/esse/dist/js/types").Coordinate3DSchema, numberOfLayers?: number, vx?: number, vy?: number) => import("./tools/surface").SlabConfigSchema;
};
supercell: {
generateConfig: (material: Material, supercellMatrix: import("@mat3ra/esse/dist/js/types").Matrix3X3Schema) => {
generateConfig: <S extends import("@mat3ra/esse/dist/js/types").MaterialSchema = import("@mat3ra/esse/dist/js/types").MaterialSchema>(material: Material<S>, supercellMatrix: import("@mat3ra/esse/dist/js/types").Matrix3X3Schema) => {
name: string;
basis: import("@mat3ra/esse/dist/js/types").BasisSchema;
basis: import("./basis/basis").BasisConfig & import("@mat3ra/esse/dist/js/types").BaseInMemoryEntitySchema;
lattice: import("@mat3ra/esse/dist/js/types").LatticeSchema;
};
generateNewBasisWithinSupercell: (basis: Basis | import("./basis/constrained_basis").ConstrainedBasis, cell: Cell, supercell: Cell, supercellMatrix: import("@mat3ra/esse/dist/js/types").Matrix3X3Schema) => Basis;
Expand All @@ -88,7 +90,7 @@ export declare const Made: {
};
basis: {
repeat: (basis: Basis, repetitions: number[]) => Basis;
interpolate: (initialBasis: Basis, finalBasis: Basis, numberOfSteps?: number) => Basis[];
interpolate: (initialBasis: Basis, finalBasis: Basis, numberOfSteps?: number) => Basis<import("./basis/basis").BasisConfig>[];
};
};
LATTICE_TYPE_CONFIGS: import("./lattice/lattice_types").LatticeTypeConfig[];
Expand All @@ -101,4 +103,4 @@ export declare const Made: {
};
};
};
export { coefficients, tolerance, units, ATOMIC_COORD_UNITS, Material, defaultMaterialConfig, Lattice, Cell, UnitCell, defaultNonPeriodicMinimumLatticeSize, diatomicLatticePaddingFactor, molecularLatticePaddingFactor, ReciprocalLattice, Basis, AtomicConstraints, parsers, tools, LATTICE_TYPE_CONFIGS, DEFAULT_LATTICE_UNITS, };
export { coefficients, tolerance, units, ATOMIC_COORD_UNITS, Material, MaterialHashed, defaultMaterialConfig, Lattice, Cell, UnitCell, defaultNonPeriodicMinimumLatticeSize, diatomicLatticePaddingFactor, molecularLatticePaddingFactor, ReciprocalLattice, Basis, AtomicConstraints, parsers, tools, LATTICE_TYPE_CONFIGS, DEFAULT_LATTICE_UNITS, };
Loading
Loading