Skip to content

Commit

Permalink
Merge pull request #79 from Exabyte-io/feat/SOF-7298
Browse files Browse the repository at this point in the history
SOF-7298: non-collinear magnetization context provider
  • Loading branch information
pranabdas authored Apr 27, 2024
2 parents bdef079 + 4db1ee6 commit ab45660
Show file tree
Hide file tree
Showing 13 changed files with 296 additions and 20 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"underscore.string": "^3.3.4"
},
"devDependencies": {
"@exabyte-io/ade.js": "2024.4.19-0",
"@exabyte-io/application-flavors.js": "2024.4.19-0",
"@exabyte-io/ade.js": "2024.4.27-0",
"@exabyte-io/application-flavors.js": "2024.4.27-0",
"@exabyte-io/eslint-config": "^2022.11.17-0",
"@exabyte-io/ide.js": "2024.3.26-0",
"@exabyte-io/mode.js": "2024.4.19-0",
"@exabyte-io/mode.js": "2024.4.23-0",
"@mat3ra/code": "2024.3.25-3",
"@mat3ra/esse": "2024.4.19-1",
"@mat3ra/made": "2024.3.26-0",
Expand Down
2 changes: 2 additions & 0 deletions src/context/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IonDynamicsContextProvider } from "./providers/IonDynamicsContextProvid
import { MLSettingsContextProvider } from "./providers/MLSettingsContextProvider";
import { MLTrainTestSplitContextProvider } from "./providers/MLTrainTestSplitContextProvider";
import { NEBFormDataProvider } from "./providers/NEBFormDataProvider";
import { NonCollinearMagnetizationContextProvider } from "./providers/NonCollinearMagnetizationContextProvider";
import { PlanewaveCutoffsContextProvider } from "./providers/PlanewaveCutoffsContextProvider";
import { PointsGridFormDataProvider } from "./providers/PointsGridFormDataProvider";
import {
Expand All @@ -32,4 +33,5 @@ export default {
HubbardContextProviderLegacy,
IonDynamicsContextProvider,
CollinearMagnetizationContextProvider,
NonCollinearMagnetizationContextProvider,
};
5 changes: 5 additions & 0 deletions src/context/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
HubbardContextProviderLegacy,
IonDynamicsContextProvider,
CollinearMagnetizationContextProvider,
NonCollinearMagnetizationContextProvider,
} = context;

const CONTEXT_DOMAINS = {
Expand Down Expand Up @@ -107,4 +108,8 @@ export const wodeProviders = {
providerCls: CollinearMagnetizationContextProvider,
config: _makeImportant({ name: "collinearMagnetization" }),
},
NonCollinearMagnetizationDataManager: {
providerCls: NonCollinearMagnetizationContextProvider,
config: _makeImportant({ name: "nonCollinearMagnetization" }),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class BoundaryConditionsFormDataProvider extends mix(JSONSchemaFormDataPr

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
$schema: "http://json-schema.org/draft-07/schema#",
type: "object",
properties: {
type: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class CollinearMagnetizationContextProvider extends mix(JSONSchemaFormDat
};
};

// eslint-disable-next-line class-methods-use-this
get uiSchemaStyled() {
return {
startingMagnetization: {
Expand Down
2 changes: 1 addition & 1 deletion src/context/providers/MLSettingsContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MLSettingsContextProvider extends mix(ContextProvider).with(Applica

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
$schema: "http://json-schema.org/draft-07/schema#",
title: " ",
description: "Settings important to machine learning runs.",
type: "object",
Expand Down
2 changes: 1 addition & 1 deletion src/context/providers/MLTrainTestSplitContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class MLTrainTestSplitContextProvider extends mix(ContextProvider).with(

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
$schema: "http://json-schema.org/draft-07/schema#",
title: " ",
description:
"Fraction held as the test set. For example, a value of 0.2 corresponds to an 80/20 train/test split.",
Expand Down
2 changes: 1 addition & 1 deletion src/context/providers/NEBFormDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class NEBFormDataProvider extends JSONSchemaFormDataProvider {

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-04/schema#",
$schema: "http://json-schema.org/draft-07/schema#",
title: " ",
description: "Number of intermediate NEB images.",
type: "object",
Expand Down
270 changes: 270 additions & 0 deletions src/context/providers/NonCollinearMagnetizationContextProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
import { JSONSchemaFormDataProvider, MaterialContextMixin } from "@mat3ra/code/dist/js/context";
import { Made } from "@mat3ra/made";
import lodash from "lodash";
import { mix } from "mixwith";

export class NonCollinearMagnetizationContextProvider extends mix(JSONSchemaFormDataProvider).with(
MaterialContextMixin,
) {
static Material = Made.Material;

constructor(config) {
super(config);
this.isStartingMagnetization = lodash.get(this.data, "isStartingMagnetization", true);
this.isConstrainedMagnetization = lodash.get(
this.data,
"isConstrainedMagnetization",
false,
);
this.isExistingChargeDensity = lodash.get(this.data, "isExistingChargeDensity", false);
this.isArbitrarySpinDirection = lodash.get(this.data, "isArbitrarySpinDirection", false);
this.isFixedMagnetization = lodash.get(this.data, "isFixedMagnetization", false);
this.constrainedMagnetization = lodash.get(this.data, "constrainedMagnetization", {});
}

get uniqueElementsWithLabels() {
const elementsWithLabelsArray = this.material?.Basis?.elementsWithLabelsArray || [];
return [...new Set(elementsWithLabelsArray)];
}

get defaultData() {
const startingMagnetization = this.uniqueElementsWithLabels.map((element, index) => {
return {
index: index + 1,
atomicSpecies: element,
value: 0.0,
};
});

const spinAngles = this.uniqueElementsWithLabels.map((element, index) => {
return {
index: index + 1,
atomicSpecies: element,
angle1: 0.0,
angle2: 0.0,
};
});

return {
isExistingChargeDensity: false,
isStartingMagnetization: true,
isConstrainedMagnetization: false,
isArbitrarySpinAngle: false,
isFixedMagnetization: false,
lforcet: true,
spinAngles,
startingMagnetization,
constrainedMagnetization: {
lambda: 0.0,
constrainType: "atomic direction",
},
fixedMagnetization: {
x: 0.0,
y: 0.0,
z: 0.0,
},
};
}

get uiSchemaStyled() {
return {
isExistingChargeDensity: {},
lforcet: {
"ui:readonly": !this.isExistingChargeDensity,
"ui:widget": "radio",
"ui:options": {
inline: true,
},
},
isArbitrarySpinDirection: {},
spinAngles: {
items: {
atomicSpecies: {
...this.defaultFieldStyles,
"ui:readonly": true,
},
angle1: this.defaultFieldStyles,
angle2: this.defaultFieldStyles,
},
"ui:readonly": !this.isArbitrarySpinDirection,
"ui:options": {
addable: false,
orderable: false,
removable: false,
},
},
isStartingMagnetization: {},
startingMagnetization: {
items: {
atomicSpecies: {
...this.defaultFieldStyles,
"ui:readonly": true,
},
value: {
"ui:classNames": "col-xs-6",
},
},
"ui:readonly": !this.isStartingMagnetization,
"ui:options": {
addable: false,
orderable: false,
removable: false,
},
},
isConstrainedMagnetization: {},
constrainedMagnetization: {
constrainType: this.defaultFieldStyles,
lambda: this.defaultFieldStyles,
"ui:readonly": !this.isConstrainedMagnetization,
},
isFixedMagnetization: {
"ui:readonly": !(
this.isConstrainedMagnetization &&
this.constrainedMagnetization?.constrainType === "total"
),
},
fixedMagnetization: {
x: this.defaultFieldStyles,
y: this.defaultFieldStyles,
z: this.defaultFieldStyles,
"ui:readonly": !(
this.isFixedMagnetization &&
this.isConstrainedMagnetization &&
this.constrainedMagnetization?.constrainType === "total"
),
},
};
}

get jsonSchema() {
return {
$schema: "http://json-schema.org/draft-07/schema#",
title: "",
description:
"Set initial parameters for non-collinear spin magnetic (SOC) calculation.",
type: "object",
properties: {
isStartingMagnetization: {
type: "boolean",
title: "Set starting magnetization",
default: true,
},
startingMagnetization: {
type: "array",
minItems: this.uniqueElementsWithLabels.length,
maxItems: this.uniqueElementsWithLabels.length,
items: {
type: "object",
properties: {
atomicSpecies: {
type: "string",
title: "Atomic species",
},
value: {
type: "number",
title: "Starting magnetization",
default: 0.0,
minimum: -1.0,
maximum: 1.0,
},
},
},
},
isExistingChargeDensity: {
type: "boolean",
title: "Start calculation from existing charge density",
default: false,
},
lforcet: {
title: "Set lforcet to",
type: "boolean",
oneOf: [
{ const: true, title: "True" },
{ const: false, title: "False" },
],
},
isArbitrarySpinDirection: {
type: "boolean",
title: "Set spin directions",
default: false,
},
spinAngles: {
type: "array",
minItems: this.uniqueElementsWithLabels.length,
maxItems: this.uniqueElementsWithLabels.length,
items: {
type: "object",
properties: {
atomicSpecies: {
type: "string",
title: "Atomic species",
},
angle1: {
type: "number",
title: "Angle1 (deg)",
default: 0.0,
},
angle2: {
type: "number",
title: "Angle2 (deg)",
default: 0.0,
},
},
},
},
isConstrainedMagnetization: {
type: "boolean",
title: "Set constrained magnetization",
default: false,
},
constrainedMagnetization: {
type: "object",
properties: {
constrainType: {
type: "string",
title: "Constrain type",
enum: [
"none",
"total",
"atomic",
"total direction",
"atomic direction",
],
default: "atomic direction",
},
lambda: {
type: "number",
title: "lambda",
default: 0.0,
},
},
},
isFixedMagnetization: {
type: "boolean",
title: "Set Fixed magnetization (only applicable to constrained magnetization of 'total' type)",
default: true,
},
fixedMagnetization: {
type: "object",
properties: {
x: {
type: "number",
title: "X-component",
default: 0.0,
},
y: {
type: "number",
title: "Y-component",
default: 0.0,
},
z: {
type: "number",
title: "Z-component",
default: 0.0,
},
},
},
},
};
}
}
Loading

0 comments on commit ab45660

Please sign in to comment.