|
| 1 | +import { JSONSchemaFormDataProvider, MaterialContextMixin } from "@mat3ra/code/dist/js/context"; |
| 2 | +import { Made } from "@mat3ra/made"; |
| 3 | +import lodash from "lodash"; |
| 4 | +import { mix } from "mixwith"; |
| 5 | + |
| 6 | +export class NonCollinearMagnetizationContextProvider extends mix(JSONSchemaFormDataProvider).with( |
| 7 | + MaterialContextMixin, |
| 8 | +) { |
| 9 | + static Material = Made.Material; |
| 10 | + |
| 11 | + constructor(config) { |
| 12 | + super(config); |
| 13 | + this.isStartingMagnetization = lodash.get(this.data, "isStartingMagnetization", true); |
| 14 | + this.isConstrainedMagnetization = lodash.get( |
| 15 | + this.data, |
| 16 | + "isConstrainedMagnetization", |
| 17 | + false, |
| 18 | + ); |
| 19 | + this.isExistingChargeDensity = lodash.get(this.data, "isExistingChargeDensity", false); |
| 20 | + this.isArbitrarySpinDirection = lodash.get(this.data, "isArbitrarySpinDirection", false); |
| 21 | + this.isFixedMagnetization = lodash.get(this.data, "isFixedMagnetization", false); |
| 22 | + this.constrainedMagnetization = lodash.get(this.data, "constrainedMagnetization", {}); |
| 23 | + } |
| 24 | + |
| 25 | + get uniqueElementsWithLabels() { |
| 26 | + const elementsWithLabelsArray = this.material?.Basis?.elementsWithLabelsArray || []; |
| 27 | + return [...new Set(elementsWithLabelsArray)]; |
| 28 | + } |
| 29 | + |
| 30 | + get defaultData() { |
| 31 | + const startingMagnetization = this.uniqueElementsWithLabels.map((element, index) => { |
| 32 | + return { |
| 33 | + index: index + 1, |
| 34 | + atomicSpecies: element, |
| 35 | + value: 0.0, |
| 36 | + }; |
| 37 | + }); |
| 38 | + |
| 39 | + const spinAngles = this.uniqueElementsWithLabels.map((element, index) => { |
| 40 | + return { |
| 41 | + index: index + 1, |
| 42 | + atomicSpecies: element, |
| 43 | + angle1: 0.0, |
| 44 | + angle2: 0.0, |
| 45 | + }; |
| 46 | + }); |
| 47 | + |
| 48 | + return { |
| 49 | + isExistingChargeDensity: false, |
| 50 | + isStartingMagnetization: true, |
| 51 | + isConstrainedMagnetization: false, |
| 52 | + isArbitrarySpinAngle: false, |
| 53 | + isFixedMagnetization: false, |
| 54 | + lforcet: true, |
| 55 | + spinAngles, |
| 56 | + startingMagnetization, |
| 57 | + constrainedMagnetization: { |
| 58 | + lambda: 0.0, |
| 59 | + constrainType: "atomic direction", |
| 60 | + }, |
| 61 | + fixedMagnetization: { |
| 62 | + x: 0.0, |
| 63 | + y: 0.0, |
| 64 | + z: 0.0, |
| 65 | + }, |
| 66 | + }; |
| 67 | + } |
| 68 | + |
| 69 | + get uiSchemaStyled() { |
| 70 | + return { |
| 71 | + isExistingChargeDensity: {}, |
| 72 | + lforcet: { |
| 73 | + "ui:readonly": !this.isExistingChargeDensity, |
| 74 | + "ui:widget": "radio", |
| 75 | + "ui:options": { |
| 76 | + inline: true, |
| 77 | + }, |
| 78 | + }, |
| 79 | + isArbitrarySpinDirection: {}, |
| 80 | + spinAngles: { |
| 81 | + items: { |
| 82 | + atomicSpecies: { |
| 83 | + ...this.defaultFieldStyles, |
| 84 | + "ui:readonly": true, |
| 85 | + }, |
| 86 | + angle1: this.defaultFieldStyles, |
| 87 | + angle2: this.defaultFieldStyles, |
| 88 | + }, |
| 89 | + "ui:readonly": !this.isArbitrarySpinDirection, |
| 90 | + "ui:options": { |
| 91 | + addable: false, |
| 92 | + orderable: false, |
| 93 | + removable: false, |
| 94 | + }, |
| 95 | + }, |
| 96 | + isStartingMagnetization: {}, |
| 97 | + startingMagnetization: { |
| 98 | + items: { |
| 99 | + atomicSpecies: { |
| 100 | + ...this.defaultFieldStyles, |
| 101 | + "ui:readonly": true, |
| 102 | + }, |
| 103 | + value: { |
| 104 | + "ui:classNames": "col-xs-6", |
| 105 | + }, |
| 106 | + }, |
| 107 | + "ui:readonly": !this.isStartingMagnetization, |
| 108 | + "ui:options": { |
| 109 | + addable: false, |
| 110 | + orderable: false, |
| 111 | + removable: false, |
| 112 | + }, |
| 113 | + }, |
| 114 | + isConstrainedMagnetization: {}, |
| 115 | + constrainedMagnetization: { |
| 116 | + constrainType: this.defaultFieldStyles, |
| 117 | + lambda: this.defaultFieldStyles, |
| 118 | + "ui:readonly": !this.isConstrainedMagnetization, |
| 119 | + }, |
| 120 | + isFixedMagnetization: { |
| 121 | + "ui:readonly": !( |
| 122 | + this.isConstrainedMagnetization && |
| 123 | + this.constrainedMagnetization?.constrainType === "total" |
| 124 | + ), |
| 125 | + }, |
| 126 | + fixedMagnetization: { |
| 127 | + x: this.defaultFieldStyles, |
| 128 | + y: this.defaultFieldStyles, |
| 129 | + z: this.defaultFieldStyles, |
| 130 | + "ui:readonly": !( |
| 131 | + this.isFixedMagnetization && |
| 132 | + this.isConstrainedMagnetization && |
| 133 | + this.constrainedMagnetization?.constrainType === "total" |
| 134 | + ), |
| 135 | + }, |
| 136 | + }; |
| 137 | + } |
| 138 | + |
| 139 | + get jsonSchema() { |
| 140 | + return { |
| 141 | + $schema: "http://json-schema.org/draft-07/schema#", |
| 142 | + title: "", |
| 143 | + description: |
| 144 | + "Set initial parameters for non-collinear spin magnetic (SOC) calculation.", |
| 145 | + type: "object", |
| 146 | + properties: { |
| 147 | + isStartingMagnetization: { |
| 148 | + type: "boolean", |
| 149 | + title: "Set starting magnetization", |
| 150 | + default: true, |
| 151 | + }, |
| 152 | + startingMagnetization: { |
| 153 | + type: "array", |
| 154 | + minItems: this.uniqueElementsWithLabels.length, |
| 155 | + maxItems: this.uniqueElementsWithLabels.length, |
| 156 | + items: { |
| 157 | + type: "object", |
| 158 | + properties: { |
| 159 | + atomicSpecies: { |
| 160 | + type: "string", |
| 161 | + title: "Atomic species", |
| 162 | + }, |
| 163 | + value: { |
| 164 | + type: "number", |
| 165 | + title: "Starting magnetization", |
| 166 | + default: 0.0, |
| 167 | + minimum: -1.0, |
| 168 | + maximum: 1.0, |
| 169 | + }, |
| 170 | + }, |
| 171 | + }, |
| 172 | + }, |
| 173 | + isExistingChargeDensity: { |
| 174 | + type: "boolean", |
| 175 | + title: "Start calculation from existing charge density", |
| 176 | + default: false, |
| 177 | + }, |
| 178 | + lforcet: { |
| 179 | + title: "Set lforcet to", |
| 180 | + type: "boolean", |
| 181 | + oneOf: [ |
| 182 | + { const: true, title: "True" }, |
| 183 | + { const: false, title: "False" }, |
| 184 | + ], |
| 185 | + }, |
| 186 | + isArbitrarySpinDirection: { |
| 187 | + type: "boolean", |
| 188 | + title: "Set spin directions", |
| 189 | + default: false, |
| 190 | + }, |
| 191 | + spinAngles: { |
| 192 | + type: "array", |
| 193 | + minItems: this.uniqueElementsWithLabels.length, |
| 194 | + maxItems: this.uniqueElementsWithLabels.length, |
| 195 | + items: { |
| 196 | + type: "object", |
| 197 | + properties: { |
| 198 | + atomicSpecies: { |
| 199 | + type: "string", |
| 200 | + title: "Atomic species", |
| 201 | + }, |
| 202 | + angle1: { |
| 203 | + type: "number", |
| 204 | + title: "Angle1 (deg)", |
| 205 | + default: 0.0, |
| 206 | + }, |
| 207 | + angle2: { |
| 208 | + type: "number", |
| 209 | + title: "Angle2 (deg)", |
| 210 | + default: 0.0, |
| 211 | + }, |
| 212 | + }, |
| 213 | + }, |
| 214 | + }, |
| 215 | + isConstrainedMagnetization: { |
| 216 | + type: "boolean", |
| 217 | + title: "Set constrained magnetization", |
| 218 | + default: false, |
| 219 | + }, |
| 220 | + constrainedMagnetization: { |
| 221 | + type: "object", |
| 222 | + properties: { |
| 223 | + constrainType: { |
| 224 | + type: "string", |
| 225 | + title: "Constrain type", |
| 226 | + enum: [ |
| 227 | + "none", |
| 228 | + "total", |
| 229 | + "atomic", |
| 230 | + "total direction", |
| 231 | + "atomic direction", |
| 232 | + ], |
| 233 | + default: "atomic direction", |
| 234 | + }, |
| 235 | + lambda: { |
| 236 | + type: "number", |
| 237 | + title: "lambda", |
| 238 | + default: 0.0, |
| 239 | + }, |
| 240 | + }, |
| 241 | + }, |
| 242 | + isFixedMagnetization: { |
| 243 | + type: "boolean", |
| 244 | + title: "Set Fixed magnetization (only applicable to constrained magnetization of 'total' type)", |
| 245 | + default: true, |
| 246 | + }, |
| 247 | + fixedMagnetization: { |
| 248 | + type: "object", |
| 249 | + properties: { |
| 250 | + x: { |
| 251 | + type: "number", |
| 252 | + title: "X-component", |
| 253 | + default: 0.0, |
| 254 | + }, |
| 255 | + y: { |
| 256 | + type: "number", |
| 257 | + title: "Y-component", |
| 258 | + default: 0.0, |
| 259 | + }, |
| 260 | + z: { |
| 261 | + type: "number", |
| 262 | + title: "Z-component", |
| 263 | + default: 0.0, |
| 264 | + }, |
| 265 | + }, |
| 266 | + }, |
| 267 | + }, |
| 268 | + }; |
| 269 | + } |
| 270 | +} |
0 commit comments