Skip to content

Commit 3e6629c

Browse files
authored
Merge pull request #77 from Exabyte-io/feat/SOF-7315
SOF-7315: accomodate constrained magnetization in CollinearMagnetizationContextProvider
2 parents ec60a93 + cf7e99f commit 3e6629c

9 files changed

+92
-72
lines changed

package-lock.json

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"underscore.string": "^3.3.4"
4747
},
4848
"devDependencies": {
49-
"@exabyte-io/ade.js": "2024.3.29-0",
50-
"@exabyte-io/application-flavors.js": "2024.3.29-0",
49+
"@exabyte-io/ade.js": "2024.4.5-0",
50+
"@exabyte-io/application-flavors.js": "2024.4.5-0",
5151
"@exabyte-io/eslint-config": "^2022.11.17-0",
5252
"@exabyte-io/ide.js": "2024.3.26-0",
5353
"@exabyte-io/mode.js": "2024.3.26-0",

src/context/providers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,6 @@ export const wodeProviders = {
105105
},
106106
CollinearMagnetizationDataManager: {
107107
providerCls: CollinearMagnetizationContextProvider,
108-
config: _makeImportant({ name: "starting_magnetization" }),
108+
config: _makeImportant({ name: "collinearMagnetization" }),
109109
},
110110
};

src/context/providers/CollinearMagnetizationContextProvider.js

+73-41
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import { JSONSchemaFormDataProvider, MaterialContextMixin } from "@mat3ra/code/dist/js/context";
22
import { Made } from "@mat3ra/made";
3+
import lodash from "lodash";
34
import { mix } from "mixwith";
45

56
export class CollinearMagnetizationContextProvider extends mix(JSONSchemaFormDataProvider).with(
67
MaterialContextMixin,
78
) {
89
static Material = Made.Material;
910

11+
constructor(config) {
12+
super(config);
13+
this.firstElement =
14+
this.uniqueElementsWithLabels?.length > 0 ? this.uniqueElementsWithLabels[0] : "";
15+
this.isTotalMagnetization = lodash.get(this.data, "isTotalMagnetization", false);
16+
}
17+
1018
get uniqueElementsWithLabels() {
1119
const elementsWithLabelsArray = this.material?.Basis?.elementsWithLabelsArray || [];
1220
return [...new Set(elementsWithLabelsArray)];
@@ -16,69 +24,93 @@ export class CollinearMagnetizationContextProvider extends mix(JSONSchemaFormDat
1624
return this.uniqueElementsWithLabels.indexOf(element) + 1;
1725
};
1826

19-
// eslint-disable-next-line class-methods-use-this
2027
get defaultData() {
21-
return [
22-
{
23-
index: 1,
24-
atomicSpecies:
25-
this.uniqueElementsWithLabels?.length > 0
26-
? this.uniqueElementsWithLabels[0]
27-
: "",
28-
value: 0.0,
29-
},
30-
];
28+
return {
29+
startingMagnetization: [
30+
{
31+
index: 1,
32+
atomicSpecies: this.firstElement,
33+
value: 0.0,
34+
},
35+
],
36+
isTotalMagnetization: false,
37+
totalMagnetization: 0.0,
38+
};
3139
}
3240

3341
transformData = (data) => {
34-
return data.map((row) => ({
42+
const startingMagnetizationWithIndex = data.startingMagnetization.map((row) => ({
3543
...row,
3644
index: this.indexOfElement(row.atomicSpecies),
3745
}));
46+
47+
return {
48+
...data,
49+
startingMagnetization: startingMagnetizationWithIndex,
50+
};
3851
};
3952

53+
// eslint-disable-next-line class-methods-use-this
4054
get uiSchemaStyled() {
4155
return {
42-
"ui:options": {
43-
addable: true,
44-
orderable: false,
45-
removable: true,
46-
},
47-
items: {
48-
atomicSpecies: this.defaultFieldStyles,
49-
value: {
50-
"ui:classNames": "col-xs-6 ",
56+
startingMagnetization: {
57+
items: {
58+
atomicSpecies: {
59+
"ui:classNames": "col-xs-3",
60+
},
61+
value: {
62+
"ui:classNames": "col-xs-6",
63+
},
5164
},
65+
"ui:readonly": this.isTotalMagnetization,
66+
},
67+
isTotalMagnetization: {},
68+
totalMagnetization: {
69+
"ui:classNames": "col-xs-6",
70+
"ui:readonly": !this.isTotalMagnetization,
5271
},
5372
};
5473
}
5574

5675
get jsonSchema() {
5776
return {
58-
$schema: "http://json-schema.org/draft-04/schema#",
77+
$schema: "http://json-schema.org/draft-07/schema#",
5978
title: "",
6079
description: "Set starting magnetization, can have values in the range [-1, +1].",
61-
type: "array",
62-
items: {
63-
type: "object",
64-
properties: {
65-
atomicSpecies: {
66-
type: "string",
67-
title: "Atomic species",
68-
enum: this.uniqueElementsWithLabels,
69-
default:
70-
this.uniqueElementsWithLabels?.length > 0
71-
? this.uniqueElementsWithLabels[0]
72-
: "",
73-
},
74-
value: {
75-
type: "number",
76-
title: "Starting magnetization",
77-
default: 0.0,
78-
minimum: -1.0,
79-
maximum: 1.0,
80+
type: "object",
81+
properties: {
82+
startingMagnetization: {
83+
type: "array",
84+
maxItems: this.uniqueElementsWithLabels.length,
85+
items: {
86+
type: "object",
87+
properties: {
88+
atomicSpecies: {
89+
type: "string",
90+
title: "Atomic species",
91+
enum: this.uniqueElementsWithLabels,
92+
default: this.firstElement,
93+
},
94+
value: {
95+
type: "number",
96+
title: "Starting magnetization",
97+
default: 0.0,
98+
minimum: -1.0,
99+
maximum: 1.0,
100+
},
101+
},
80102
},
81103
},
104+
isTotalMagnetization: {
105+
type: "boolean",
106+
title: "Set total magnetization instead",
107+
default: false,
108+
},
109+
totalMagnetization: {
110+
type: "number",
111+
title: "Total magnetization",
112+
default: 0.0,
113+
},
82114
},
83115
};
84116
}

src/context/providers/HubbardContextProviderLegacy.js

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ export class HubbardContextProviderLegacy extends HubbardUContextProvider {
3535
orderable: false,
3636
removable: true,
3737
},
38-
title: {
39-
"ui:classNames": "col-xs-12",
40-
},
4138
items: {
4239
atomicSpecies: this.defaultFieldStyles,
4340
atomicSpeciesIndex: { ...this.defaultFieldStyles, "ui:readonly": true },

src/context/providers/HubbardJContextProvider.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ export class HubbardJContextProvider extends HubbardUContextProvider {
2424
orderable: true,
2525
removable: true,
2626
},
27-
title: {
28-
"ui:classNames": "col-xs-12",
29-
},
3027
items: {
3128
paramType: this.defaultFieldStyles,
3229
atomicSpecies: this.defaultFieldStyles,
@@ -38,7 +35,7 @@ export class HubbardJContextProvider extends HubbardUContextProvider {
3835

3936
get jsonSchema() {
4037
return {
41-
$schema: "http://json-schema.org/draft-04/schema#",
38+
$schema: "http://json-schema.org/draft-07/schema#",
4239
title: "",
4340
description: "Hubbard parameters for DFT+U+J calculation.",
4441
type: "array",

src/context/providers/HubbardUContextProvider.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ export class HubbardUContextProvider extends mix(JSONSchemaFormDataProvider).wit
5858
orderable: false,
5959
removable: true,
6060
},
61-
title: {
62-
"ui:classNames": "col-xs-12",
63-
},
6461
items: {
6562
atomicSpecies: this.defaultFieldStyles,
6663
atomicOrbital: this.defaultFieldStyles,
@@ -71,7 +68,7 @@ export class HubbardUContextProvider extends mix(JSONSchemaFormDataProvider).wit
7168

7269
get jsonSchema() {
7370
return {
74-
$schema: "http://json-schema.org/draft-04/schema#",
71+
$schema: "http://json-schema.org/draft-07/schema#",
7572
title: "",
7673
description: "Hubbard U parameters for DFT+U or DFT+U+V calculation.",
7774
type: "array",

src/context/providers/HubbardVContextProvider.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export class HubbardVContextProvider extends HubbardUContextProvider {
4040
orderable: true,
4141
removable: true,
4242
},
43-
title: {
44-
"ui:classNames": "col-xs-12",
45-
},
4643
items: {
4744
atomicSpecies: this.defaultFieldStyles,
4845
atomicOrbital: this.defaultFieldStyles,
@@ -57,7 +54,7 @@ export class HubbardVContextProvider extends HubbardUContextProvider {
5754

5855
get jsonSchema() {
5956
return {
60-
$schema: "http://json-schema.org/draft-04/schema#",
57+
$schema: "http://json-schema.org/draft-07/schema#",
6158
title: "",
6259
description: "Hubbard V parameters for DFT+U+V calculation.",
6360
type: "array",

src/context/providers/IonDynamicsContextProvider.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class IonDynamicsContextProvider extends JSONSchemaFormDataProvider {
2626
// eslint-disable-next-line class-methods-use-this
2727
get jsonSchema() {
2828
return {
29-
$schema: "http://json-schema.org/draft-04/schema#",
29+
$schema: "http://json-schema.org/draft-07/schema#",
3030
type: "object",
3131
description: "Important parameters for molecular dynamics calculation",
3232
properties: {

0 commit comments

Comments
 (0)