Skip to content

Commit 845a5f5

Browse files
authored
Feature/sof 1547 (#29)
* feat: calculate dimensions from reciprocal lattice * chore: add made.js to peerDependencies * fix: import of ReciprocalLattice * fix: undefined indices * chore: adjust complementary indices * chore: add isUsingJinjaVariable logic * chore: disable preferKPPRA when using Jinja variables * chore: adjust default dimensions * chore: decrease default KPPRA * chore: remove duplicate dependency
1 parent c8811c1 commit 845a5f5

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/context/providers/PointsGridFormDataProvider.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JSONSchemaFormDataProvider, MaterialContextMixin } from "@exabyte-io/code.js/dist/context";
2+
import { math } from "@exabyte-io/code.js/dist/math";
23
import { Made } from "@exabyte-io/made.js";
34
import lodash from "lodash";
45
import { mix } from "mixwith";
@@ -21,27 +22,21 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
2122
this.preferKPPRA = lodash.get(this.data, "preferKPPRA", false);
2223
}
2324

24-
getDefaultDimension() {
25-
return this._getGridFromKPPRA(this._defaultKPPRA).dimensions[0];
26-
}
27-
2825
// eslint-disable-next-line class-methods-use-this
2926
getDefaultShift() {
3027
return 0;
3128
}
3229

33-
// eslint-disable-next-line class-methods-use-this
3430
get _defaultDimensions() {
35-
return Array(3).fill(this.getDefaultDimension());
31+
return this._getGridFromKPPRA(this._defaultKPPRA).dimensions;
3632
}
3733

38-
// eslint-disable-next-line class-methods-use-this
3934
get _defaultShifts() {
4035
return Array(3).fill(this.getDefaultShift());
4136
}
4237

4338
get _defaultKPPRA() {
44-
return Math.floor(10 / this._divisor);
39+
return Math.floor(5 / this._divisor);
4540
}
4641

4742
get jsonSchema() {
@@ -56,12 +51,14 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
5651
};
5752

5853
const vector_ = (defaultValue) => {
54+
const isArray = Array.isArray(defaultValue);
5955
return {
6056
...vector,
6157
items: {
6258
type: this.isUsingJinjaVariables ? "string" : "number",
63-
default: defaultValue,
59+
...(isArray ? {} : { default: defaultValue }),
6460
},
61+
...(isArray ? { default: defaultValue } : {}),
6562
};
6663
};
6764

@@ -72,7 +69,7 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
7269
}.`,
7370
type: "object",
7471
properties: {
75-
dimensions: vector_(this.getDefaultDimension()),
72+
dimensions: vector_(this._defaultDimensions),
7673
shifts: vector_(this.getDefaultShift()),
7774
KPPRA: {
7875
type: "integer",
@@ -116,6 +113,7 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
116113
preferKPPRA: {
117114
...this.fieldStyles("p-t-20"), // add padding top to level with other elements
118115
"ui:emptyValue": true,
116+
"ui:disabled": this.isUsingJinjaVariables,
119117
},
120118
};
121119
}
@@ -140,11 +138,28 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
140138
return this.material ? this._defaultDataWithMaterial : this._defaultData;
141139
}
142140

141+
_getReciprocalLatticeNorms() {
142+
const reciprocalLattice = new Made.ReciprocalLattice(this.material.lattice);
143+
const bVectors = reciprocalLattice.reciprocalVectors;
144+
return bVectors.map((vec) => math.norm(vec));
145+
}
146+
147+
static _calculateDimension(nPoints, norms, index) {
148+
const [j, k] = [0, 1, 2].filter((i) => i !== index); // get indices of other two dimensions
149+
const N = Math.cbrt((nPoints * norms[index] ** 2) / (norms[j] * norms[k]));
150+
return Math.max(1, Math.ceil(N));
151+
}
152+
153+
_calculateDimensions(nKpoints) {
154+
const norms = this._getReciprocalLatticeNorms();
155+
const indices = [0, 1, 2];
156+
return indices.map((i) => this.constructor._calculateDimension(nKpoints, norms, i));
157+
}
158+
143159
_getGridFromKPPRA(KPPRA) {
144160
const nAtoms = this.material ? this.material.Basis.nAtoms : 1;
145-
const dimension = Math.ceil((KPPRA / nAtoms) ** (1 / 3));
146161
return {
147-
dimensions: Array(3).fill(dimension),
162+
dimensions: this._calculateDimensions(KPPRA / nAtoms),
148163
shifts: this._defaultShifts,
149164
};
150165
}

0 commit comments

Comments
 (0)