1
1
import { JSONSchemaFormDataProvider , MaterialContextMixin } from "@mat3ra/code/dist/js/context" ;
2
2
import { Made } from "@mat3ra/made" ;
3
+ import lodash from "lodash" ;
3
4
import { mix } from "mixwith" ;
4
5
5
6
export class CollinearMagnetizationContextProvider extends mix ( JSONSchemaFormDataProvider ) . with (
6
7
MaterialContextMixin ,
7
8
) {
8
9
static Material = Made . Material ;
9
10
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
+
10
18
get uniqueElementsWithLabels ( ) {
11
19
const elementsWithLabelsArray = this . material ?. Basis ?. elementsWithLabelsArray || [ ] ;
12
20
return [ ...new Set ( elementsWithLabelsArray ) ] ;
@@ -16,69 +24,93 @@ export class CollinearMagnetizationContextProvider extends mix(JSONSchemaFormDat
16
24
return this . uniqueElementsWithLabels . indexOf ( element ) + 1 ;
17
25
} ;
18
26
19
- // eslint-disable-next-line class-methods-use-this
20
27
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
+ } ;
31
39
}
32
40
33
41
transformData = ( data ) => {
34
- return data . map ( ( row ) => ( {
42
+ const startingMagnetizationWithIndex = data . startingMagnetization . map ( ( row ) => ( {
35
43
...row ,
36
44
index : this . indexOfElement ( row . atomicSpecies ) ,
37
45
} ) ) ;
46
+
47
+ return {
48
+ ...data ,
49
+ startingMagnetization : startingMagnetizationWithIndex ,
50
+ } ;
38
51
} ;
39
52
53
+ // eslint-disable-next-line class-methods-use-this
40
54
get uiSchemaStyled ( ) {
41
55
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
+ } ,
51
64
} ,
65
+ "ui:readonly" : this . isTotalMagnetization ,
66
+ } ,
67
+ isTotalMagnetization : { } ,
68
+ totalMagnetization : {
69
+ "ui:classNames" : "col-xs-6" ,
70
+ "ui:readonly" : ! this . isTotalMagnetization ,
52
71
} ,
53
72
} ;
54
73
}
55
74
56
75
get jsonSchema ( ) {
57
76
return {
58
- $schema : "http://json-schema.org/draft-04 /schema#" ,
77
+ $schema : "http://json-schema.org/draft-07 /schema#" ,
59
78
title : "" ,
60
79
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
+ } ,
80
102
} ,
81
103
} ,
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
+ } ,
82
114
} ,
83
115
} ;
84
116
}
0 commit comments