Skip to content

Commit 172f004

Browse files
committed
move get cutoffs from pseudo method to method data context mixin
1 parent 4553c96 commit 172f004

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

src/context/mixins/MethodDataContextMixin.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,50 @@ export function methodDataContextMixin(item) {
4242
get isMethodDataUpdated() {
4343
return Boolean(this.extraData && this.extraData.methodDataHash !== this.methodDataHash);
4444
},
45+
46+
/**
47+
* @summary Find cutoff values corresponding to wavefunction or charge
48+
* density with accuracy level in the pseudo method data
49+
* @param data {Object}: the data object from pseudo method data
50+
* @param cutoffEntity {String}: "wavefunction", or "density"
51+
* @param accuracyLevel {String}: "standard", "high", or "low"
52+
* @return {number}: if cutoff value present returns value else return 0
53+
*/
54+
_cutoffFromPseudoData(data, cutoffEntity, accuracyLevel = "standard") {
55+
const cutoff = data?.cutoffs?.[cutoffEntity] || [];
56+
return cutoff.find((obj) => obj.accuracy_level === accuracyLevel)?.value ?? 0;
57+
},
58+
59+
/**
60+
* @summary Set highest cutoff of all elements present, in case wavefunction
61+
* cutoff is present but no charge density cutoff, set charge density cutoff
62+
* to 4 or 8 times that of wavefunction cutoff
63+
* @return {Array<number>}: tuple of wavefunction and density cutoffs
64+
*/
65+
get highestCutoffsFromPseudos() {
66+
let ecutwfc = 0;
67+
let ecutrho = 0;
68+
const pseudos = this.methodData?.pseudo || [];
69+
70+
pseudos.forEach((data) => {
71+
const ecutwfcStandard = this._cutoffFromPseudoData(data, "wavefunction");
72+
const ecutrhoStandard = this._cutoffFromPseudoData(data, "density");
73+
// set the highest cutoff of all elements
74+
ecutwfc = Math.max(ecutwfc, ecutwfcStandard);
75+
76+
if (ecutrhoStandard > ecutrho) {
77+
ecutrho = ecutrhoStandard;
78+
} else {
79+
// if rho cutoff is not present, set it based on wfc cutoff
80+
// if it is ultrasoft pseudopotential set rho cutoff 8 times
81+
// that of wfc cutoff, otherwise 4 times that of wfc cutoff
82+
const rhoMultiplier = data?.type === "us" ? 8 : 4;
83+
ecutrho = Math.max(ecutrho, ecutwfc * rhoMultiplier);
84+
}
85+
});
86+
87+
return [ecutwfc, ecutrho];
88+
},
4589
};
4690

4791
Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));

src/context/providers/PlanewaveCutoffsContextProvider.js

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,8 @@ export class PlanewaveCutoffsContextProvider extends ContextProvider {
3838
return cutoffConfig[this.application.name];
3939
}
4040

41-
/**
42-
* @summary Find cutoff values corresponding to wavefunction or charge
43-
* density with accuracy level in the pseudo method data
44-
* @param data {Object}: the data object from pseudo method data
45-
* @param cutoffEntity {String}: "wavefunction", or "density"
46-
* @param accuracyLevel {String}: "standard", "high", or "low"
47-
* @return {number}: if cutoff value present returns value else return 0
48-
*/
49-
_cutoffFromPseudoData = (data, cutoffEntity, accuracyLevel = "standard") => {
50-
const cutoff = data?.cutoffs?.[cutoffEntity] || [];
51-
return cutoff.find((obj) => obj.accuracy_level === accuracyLevel)?.value ?? 0;
52-
};
53-
54-
/**
55-
* @summary Set highest cutoff of all elements present, in case wavefunction
56-
* cutoff is present but no charge density cutoff, set charge density cutoff
57-
* to 4 or 8 times that of wavefunction cutoff
58-
* @return {Array<number>}: tuple of wavefunction and density cutoffs
59-
*/
60-
get _cutoffsFromPseudos() {
61-
let ecutwfc = 0;
62-
let ecutrho = 0;
63-
const pseudos = this.methodData?.pseudo || [];
64-
65-
pseudos.forEach((data) => {
66-
const ecutwfcStandard = this._cutoffFromPseudoData(data, "wavefunction");
67-
const ecutrhoStandard = this._cutoffFromPseudoData(data, "density");
68-
// set the highest cutoff of all elements
69-
ecutwfc = Math.max(ecutwfc, ecutwfcStandard);
70-
71-
if (ecutrhoStandard > ecutrho) {
72-
ecutrho = ecutrhoStandard;
73-
} else {
74-
// if rho cutoff is not present, set it based on wfc cutoff
75-
// if it is ultrasoft pseudopotential set rho cutoff 8 times
76-
// that of wfc cutoff, otherwise 4 times that of wfc cutoff
77-
const rhoMultiplier = data?.type === "us" ? 8 : 4;
78-
ecutrho = Math.max(ecutrho, ecutwfc * rhoMultiplier);
79-
}
80-
});
81-
82-
return [ecutwfc, ecutrho];
83-
}
84-
8541
get defaultECUTWFC() {
86-
const [ecutwfc] = this._cutoffsFromPseudos;
42+
const [ecutwfc] = this.highestCutoffsFromPseudos;
8743

8844
if (ecutwfc > 0) {
8945
return ecutwfc;
@@ -93,7 +49,7 @@ export class PlanewaveCutoffsContextProvider extends ContextProvider {
9349
}
9450

9551
get defaultECUTRHO() {
96-
const [, ecutrho] = this._cutoffsFromPseudos; // destructure and select second item
52+
const [, ecutrho] = this.highestCutoffsFromPseudos; // destructure and select second item
9753

9854
if (ecutrho > 0) {
9955
return ecutrho;

0 commit comments

Comments
 (0)