Skip to content

Commit fac5c4d

Browse files
committed
refactor: adjust contextproviders to use static class variable
1 parent 37944e9 commit fac5c4d

File tree

3 files changed

+105
-78
lines changed

3 files changed

+105
-78
lines changed
Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
1-
import _ from "underscore";
2-
import lodash from "lodash";
3-
import { mix } from "mixwith";
4-
import s from "underscore.string";
5-
6-
import { Made } from "@exabyte-io/made.js";
7-
import { PERIODIC_TABLE } from "@exabyte-io/periodic-table.js";
8-
91
import {
10-
MaterialContextMixinBuilder,
11-
MaterialsContextMixinBuilder,
2+
JobContextMixin,
3+
MaterialContextMixin,
4+
MaterialsContextMixin,
125
MaterialsSetContextMixin,
136
MethodDataContextMixin,
147
WorkflowContextMixin,
15-
JobContextMixin
168
} from "@exabyte-io/code.js/dist/context";
9+
import { Made } from "@exabyte-io/made.js";
10+
import { PERIODIC_TABLE } from "@exabyte-io/periodic-table.js";
11+
import lodash from "lodash";
12+
import { mix } from "mixwith";
13+
import _ from "underscore";
14+
import s from "underscore.string";
15+
1716
import { ExecutableContextProvider } from "../../providers";
1817

1918
export class QEPWXContextProvider extends mix(ExecutableContextProvider).with(
20-
MaterialContextMixinBuilder(Made.Material),
19+
MaterialContextMixin,
2120
MethodDataContextMixin,
2221
WorkflowContextMixin,
2322
JobContextMixin,
2423
) {
24+
static materialCls = Made.Material;
2525

26-
get atomSymbols() {return this.material.Basis.uniqueElements}
26+
get atomSymbols() {
27+
return this.material.Basis.uniqueElements;
28+
}
2729

28-
get atomicPositionsWithoutConstraints() {return this.material.Basis.atomicPositions}
30+
get atomicPositionsWithoutConstraints() {
31+
return this.material.Basis.atomicPositions;
32+
}
2933

30-
get atomicPositions() {return this.material.Basis.atomicPositionsWithConstraints};
34+
get atomicPositions() {
35+
return this.material.Basis.atomicPositionsWithConstraints;
36+
}
3137

3238
/*
3339
* @NOTE: Overriding getData makes this provider "stateless", ie. delivering data from scratch each time and not
3440
* considering the content of `this.data`, and `this.isEdited` field(s).
3541
*/
3642
getData() {
37-
3843
// the below values are read from PlanewaveDataManager instead
3944
// ECUTWFC = 40;
4045
// ECUTRHO = 200;
@@ -46,67 +51,75 @@ export class QEPWXContextProvider extends mix(ExecutableContextProvider).with(
4651
RESTART_MODE: this.RESTART_MODE,
4752
NAT: this.atomicPositions.length,
4853
NTYP: this.atomSymbols.length,
49-
ATOMIC_POSITIONS: this.atomicPositions.join('\n'),
50-
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: this.atomicPositionsWithoutConstraints.join('\n'),
54+
ATOMIC_POSITIONS: this.atomicPositions.join("\n"),
55+
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: this.atomicPositionsWithoutConstraints.join("\n"),
5156
CELL_PARAMETERS: this.CELL_PARAMETERS,
5257
ATOMIC_SPECIES: this.ATOMIC_SPECIES,
53-
}
58+
};
5459
}
5560

5661
get RESTART_MODE() {
57-
return (this.job.parentJob || this.workflow.hasRelaxation) ? 'restart' : 'from_scratch';
62+
return this.job.parentJob || this.workflow.hasRelaxation ? "restart" : "from_scratch";
5863
}
5964

6065
getPseudoBySymbol(symbol) {
61-
return (this.methodData.pseudo || []).find(p => p.element === symbol);
66+
return (this.methodData.pseudo || []).find((p) => p.element === symbol);
6267
}
6368

6469
get ATOMIC_SPECIES() {
6570
// atomic species with pseudopotentials
6671
return _.map(this.atomSymbols, (symbol) => {
6772
const pseudo = this.getPseudoBySymbol(symbol);
6873
return QEPWXContextProvider.symbolToAtomicSpecie(symbol, pseudo);
69-
}).join('\n');
74+
}).join("\n");
7075
}
7176

7277
get CELL_PARAMETERS() {
73-
return this.material.Lattice.vectorArrays.map(x => {
74-
return x.map(y => {
75-
return s.sprintf('%14.9f', y).trim();
76-
}).join(' ');
77-
}).join('\n');
78-
78+
return this.material.Lattice.vectorArrays
79+
.map((x) => {
80+
return x
81+
.map((y) => {
82+
return s.sprintf("%14.9f", y).trim();
83+
})
84+
.join(" ");
85+
})
86+
.join("\n");
7987
}
8088

8189
static symbolToAtomicSpecie(symbol, pseudo) {
8290
const el = PERIODIC_TABLE[symbol];
83-
const filename = pseudo ? lodash.get(pseudo, 'filename', s.strRightBack(pseudo.path, '/')) : '';
84-
return el ? s.sprintf('%s %f %s', symbol, el.atomic_mass, filename) : undefined;
91+
const filename = pseudo
92+
? lodash.get(pseudo, "filename", s.strRightBack(pseudo.path, "/"))
93+
: "";
94+
return el ? s.sprintf("%s %f %s", symbol, el.atomic_mass, filename) : undefined;
8595
}
8696
}
8797

8898
export class QENEBContextProvider extends mix(ExecutableContextProvider).with(
89-
MaterialContextMixinBuilder(Made.Material),
90-
MaterialsContextMixinBuilder(Made.Material),
99+
MaterialContextMixin,
100+
MaterialsContextMixin,
91101
MaterialsSetContextMixin,
92102
MethodDataContextMixin,
93103
WorkflowContextMixin,
94104
JobContextMixin,
95105
) {
106+
static materialCls = Made.Material;
96107

97108
getData() {
98109
const sortedMaterials = this.sortMaterialsByIndexInSet(this.materials);
99-
const PWXContexts = sortedMaterials.map(material => {
100-
const context = Object.assign({}, this.config.context, {material: material});
101-
const config = Object.assign({}, this.config, {context});
110+
const PWXContexts = sortedMaterials.map((material) => {
111+
const context = { ...this.config.context, material };
112+
const config = { ...this.config, context };
102113
return new QEPWXContextProvider(config).getData();
103114
});
104115

105116
return {
106117
..._.omit(PWXContexts[0], ["ATOMIC_POSITIONS", "ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS"]),
107118
FIRST_IMAGE: PWXContexts[0].ATOMIC_POSITIONS,
108119
LAST_IMAGE: PWXContexts[PWXContexts.length - 1].ATOMIC_POSITIONS,
109-
INTERMEDIATE_IMAGES: PWXContexts.slice(1, PWXContexts.length - 1).map(data => data.ATOMIC_POSITIONS),
110-
}
120+
INTERMEDIATE_IMAGES: PWXContexts.slice(1, PWXContexts.length - 1).map(
121+
(data) => data.ATOMIC_POSITIONS,
122+
),
123+
};
111124
}
112125
}
Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
import _ from "underscore";
2-
import lodash from "lodash";
3-
import {mix} from "mixwith";
4-
import s from "underscore.string";
5-
import { Made } from "@exabyte-io/made.js";
6-
import { PERIODIC_TABLE } from "@exabyte-io/periodic-table.js";
7-
81
import {
9-
MaterialContextMixinBuilder,
2+
JobContextMixin,
3+
MaterialContextMixin,
104
MethodDataContextMixin,
115
WorkflowContextMixin,
12-
JobContextMixin
136
} from "@exabyte-io/code.js/dist/context";
7+
import { Made } from "@exabyte-io/made.js";
8+
import { PERIODIC_TABLE } from "@exabyte-io/periodic-table.js";
9+
import lodash from "lodash";
10+
import { mix } from "mixwith";
11+
import _ from "underscore";
12+
import s from "underscore.string";
13+
1414
import { ExecutableContextProvider } from "../../providers";
1515

1616
export class NWChemTotalEnergyContextProvider extends mix(ExecutableContextProvider).with(
17-
MaterialContextMixinBuilder(Made.Material),
17+
MaterialContextMixin,
1818
MethodDataContextMixin,
1919
WorkflowContextMixin,
2020
JobContextMixin,
2121
) {
22+
static materialCls = Made.Material;
2223

23-
get atomSymbols() {return this.material.Basis.uniqueElements}
24+
get atomSymbols() {
25+
return this.material.Basis.uniqueElements;
26+
}
2427

25-
get atomicPositionsWithoutConstraints() {return this.material.Basis.atomicPositions}
28+
get atomicPositionsWithoutConstraints() {
29+
return this.material.Basis.atomicPositions;
30+
}
2631

27-
get atomicPositions() {return this.material.Basis.atomicPositionsWithConstraints};
32+
get atomicPositions() {
33+
return this.material.Basis.atomicPositionsWithConstraints;
34+
}
2835

29-
get cartesianAtomicPositions() {return this.material.toCartesian()};
36+
get cartesianAtomicPositions() {
37+
return this.material.toCartesian();
38+
}
3039

3140
/*
3241
* @NOTE: Overriding getData makes this provider "stateless", ie. delivering data from scratch each time and not
@@ -38,32 +47,34 @@ export class NWChemTotalEnergyContextProvider extends mix(ExecutableContextProvi
3847
*/
3948
const CHARGE = 0;
4049
const MULT = 1;
41-
const BASIS = '6-31G';
42-
const FUNCTIONAL = 'B3LYP';
50+
const BASIS = "6-31G";
51+
const FUNCTIONAL = "B3LYP";
4352

4453
return {
45-
CHARGE: CHARGE,
46-
MULT: MULT,
47-
BASIS: BASIS,
54+
CHARGE,
55+
MULT,
56+
BASIS,
4857
NAT: this.atomicPositions.length,
4958
NTYP: this.atomSymbols.length,
50-
ATOMIC_POSITIONS: this.atomicPositions.join('\n'),
51-
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: this.atomicPositionsWithoutConstraints.join('\n'),
59+
ATOMIC_POSITIONS: this.atomicPositions.join("\n"),
60+
ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS: this.atomicPositionsWithoutConstraints.join("\n"),
5261
ATOMIC_SPECIES: this.ATOMIC_SPECIES,
53-
FUNCTIONAL: FUNCTIONAL,
62+
FUNCTIONAL,
5463
CARTESIAN: this.cartesianAtomicPositions,
55-
}
64+
};
5665
}
5766

5867
get ATOMIC_SPECIES() {
5968
return _.map(this.atomSymbols, (symbol) => {
6069
return NWChemTotalEnergyContextProvider.symbolToAtomicSpecies(symbol);
61-
}).join('\n');
70+
}).join("\n");
6271
}
6372

6473
static symbolToAtomicSpecies(symbol, pseudo) {
6574
const el = PERIODIC_TABLE[symbol];
66-
const filename = pseudo ? lodash.get(pseudo, 'filename', s.strRightBack(pseudo.path, '/')) : '';
67-
return el ? s.sprintf('%s %f %s', symbol, el.atomic_mass, filename) : undefined;
75+
const filename = pseudo
76+
? lodash.get(pseudo, "filename", s.strRightBack(pseudo.path, "/"))
77+
: "";
78+
return el ? s.sprintf("%s %f %s", symbol, el.atomic_mass, filename) : undefined;
6879
}
6980
}
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
import { mix } from "mixwith";
21
import {
3-
MaterialContextMixinBuilder,
4-
MaterialsContextMixinBuilder,
2+
JobContextMixin,
3+
MaterialContextMixin,
4+
MaterialsContextMixin,
55
MaterialsSetContextMixin,
66
MethodDataContextMixin,
77
WorkflowContextMixin,
8-
JobContextMixin
98
} from "@exabyte-io/code.js/dist/context";
109
import { Made } from "@exabyte-io/made.js";
10+
import { mix } from "mixwith";
11+
1112
import { ExecutableContextProvider } from "../../providers";
1213

1314
export class VASPContextProvider extends mix(ExecutableContextProvider).with(
14-
MaterialContextMixinBuilder(Made.Material),
15+
MaterialContextMixin,
1516
MethodDataContextMixin,
1617
WorkflowContextMixin,
1718
JobContextMixin,
1819
) {
20+
static materialCls = Made.Material;
1921

2022
/*
2123
* @NOTE: Overriding getData makes this provider "stateless", ie. delivering data from scratch each time and not
2224
* considering the content of `this.data`, and `this.isEdited` field(s).
2325
*/
2426
getData() {
25-
2627
// consider adjusting so that below values are read from PlanewaveDataManager
2728
// ECUTWFC;
2829
// ECUTRHO;
@@ -31,32 +32,34 @@ export class VASPContextProvider extends mix(ExecutableContextProvider).with(
3132
// TODO: figure out whether we need two separate POSCARS, maybe one is enough
3233
POSCAR: this.material.getAsPOSCAR(true, true),
3334
POSCAR_WITH_CONSTRAINTS: this.material.getAsPOSCAR(true),
34-
}
35+
};
3536
}
36-
3737
}
3838

3939
export class VASPNEBContextProvider extends mix(ExecutableContextProvider).with(
40-
MaterialContextMixinBuilder(Made.Material),
41-
MaterialsContextMixinBuilder(Made.Material),
40+
MaterialContextMixin,
41+
MaterialsContextMixin,
4242
MaterialsSetContextMixin,
4343
MethodDataContextMixin,
4444
WorkflowContextMixin,
4545
JobContextMixin,
4646
) {
47+
static materialCls = Made.Material;
4748

4849
getData() {
4950
const sortedMaterials = this.sortMaterialsByIndexInSet(this.materials);
50-
const VASPContexts = sortedMaterials.map(material => {
51-
const context = Object.assign({}, this.config.context, {material: material});
52-
const config = Object.assign({}, this.config, {context});
51+
const VASPContexts = sortedMaterials.map((material) => {
52+
const context = { ...this.config.context, material };
53+
const config = { ...this.config, context };
5354
return new VASPContextProvider(config).getData();
5455
});
5556

5657
return {
5758
FIRST_IMAGE: VASPContexts[0].POSCAR_WITH_CONSTRAINTS,
5859
LAST_IMAGE: VASPContexts[VASPContexts.length - 1].POSCAR_WITH_CONSTRAINTS,
59-
INTERMEDIATE_IMAGES: VASPContexts.slice(1, VASPContexts.length - 1).map(data => data.POSCAR_WITH_CONSTRAINTS),
60-
}
60+
INTERMEDIATE_IMAGES: VASPContexts.slice(1, VASPContexts.length - 1).map(
61+
(data) => data.POSCAR_WITH_CONSTRAINTS,
62+
),
63+
};
6164
}
6265
}

0 commit comments

Comments
 (0)