1
1
import { JSONSchemaFormDataProvider , MaterialContextMixin } from "@exabyte-io/code.js/dist/context" ;
2
+ import { math } from "@exabyte-io/code.js/dist/math" ;
2
3
import { Made } from "@exabyte-io/made.js" ;
3
4
import lodash from "lodash" ;
4
5
import { mix } from "mixwith" ;
@@ -21,27 +22,21 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
21
22
this . preferKPPRA = lodash . get ( this . data , "preferKPPRA" , false ) ;
22
23
}
23
24
24
- getDefaultDimension ( ) {
25
- return this . _getGridFromKPPRA ( this . _defaultKPPRA ) . dimensions [ 0 ] ;
26
- }
27
-
28
25
// eslint-disable-next-line class-methods-use-this
29
26
getDefaultShift ( ) {
30
27
return 0 ;
31
28
}
32
29
33
- // eslint-disable-next-line class-methods-use-this
34
30
get _defaultDimensions ( ) {
35
- return Array ( 3 ) . fill ( this . getDefaultDimension ( ) ) ;
31
+ return this . _getGridFromKPPRA ( this . _defaultKPPRA ) . dimensions ;
36
32
}
37
33
38
- // eslint-disable-next-line class-methods-use-this
39
34
get _defaultShifts ( ) {
40
35
return Array ( 3 ) . fill ( this . getDefaultShift ( ) ) ;
41
36
}
42
37
43
38
get _defaultKPPRA ( ) {
44
- return Math . floor ( 10 / this . _divisor ) ;
39
+ return Math . floor ( 5 / this . _divisor ) ;
45
40
}
46
41
47
42
get jsonSchema ( ) {
@@ -56,12 +51,14 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
56
51
} ;
57
52
58
53
const vector_ = ( defaultValue ) => {
54
+ const isArray = Array . isArray ( defaultValue ) ;
59
55
return {
60
56
...vector ,
61
57
items : {
62
58
type : this . isUsingJinjaVariables ? "string" : "number" ,
63
- default : defaultValue ,
59
+ ... ( isArray ? { } : { default : defaultValue } ) ,
64
60
} ,
61
+ ...( isArray ? { default : defaultValue } : { } ) ,
65
62
} ;
66
63
} ;
67
64
@@ -72,7 +69,7 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
72
69
} .`,
73
70
type : "object" ,
74
71
properties : {
75
- dimensions : vector_ ( this . getDefaultDimension ( ) ) ,
72
+ dimensions : vector_ ( this . _defaultDimensions ) ,
76
73
shifts : vector_ ( this . getDefaultShift ( ) ) ,
77
74
KPPRA : {
78
75
type : "integer" ,
@@ -116,6 +113,7 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
116
113
preferKPPRA : {
117
114
...this . fieldStyles ( "p-t-20" ) , // add padding top to level with other elements
118
115
"ui:emptyValue" : true ,
116
+ "ui:disabled" : this . isUsingJinjaVariables ,
119
117
} ,
120
118
} ;
121
119
}
@@ -140,11 +138,28 @@ export class PointsGridFormDataProvider extends mix(JSONSchemaFormDataProvider).
140
138
return this . material ? this . _defaultDataWithMaterial : this . _defaultData ;
141
139
}
142
140
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
+
143
159
_getGridFromKPPRA ( KPPRA ) {
144
160
const nAtoms = this . material ? this . material . Basis . nAtoms : 1 ;
145
- const dimension = Math . ceil ( ( KPPRA / nAtoms ) ** ( 1 / 3 ) ) ;
146
161
return {
147
- dimensions : Array ( 3 ) . fill ( dimension ) ,
162
+ dimensions : this . _calculateDimensions ( KPPRA / nAtoms ) ,
148
163
shifts : this . _defaultShifts ,
149
164
} ;
150
165
}
0 commit comments