generated from Exabyte-io/template-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tree.js
226 lines (200 loc) · 6.33 KB
/
tree.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { deepClone, filterEntityList, mergeTerminalNodes } from "@mat3ra/code/dist/js/utils";
import lodash from "lodash";
import _ from "underscore";
import modelMethodMap from "./data/model_method_map";
// TODO: migrate to use manifest instead
export const METHODS = {
pseudopotential: "pseudopotential",
localorbital: "localorbital",
unknown: "unknown",
};
const methods = {
[METHODS.pseudopotential]: ["paw", "nc", "nc-fr", "us"],
// TODO: Add additional basis set options, once user choice of specific (i.e 3-21G vs cc-pVDZ) is implemented.
[METHODS.localorbital]: ["pople"],
[METHODS.unknown]: ["unknown"],
};
export const getPseudopotentialTypesFromTree = () => methods[METHODS.pseudopotential];
// DFT-specific
const DFTModelRefiners = ["hse", "g0w0"];
const DFTModelModifiers = ["soc", "magn"];
const DFTModelTree = {
gga: {
refiners: DFTModelRefiners,
modifiers: DFTModelModifiers,
methods,
functionals: ["pbe", "pbesol", "pw91", "other"],
},
lda: {
refiners: DFTModelRefiners,
modifiers: DFTModelModifiers,
methods,
functionals: ["pz", "pw", "vwn", "other"],
},
hybrid: {
methods,
functionals: ["b3lyp", "hse06"],
},
other: {
methods,
functionals: ["other"],
},
};
export const getDFTFunctionalsFromTree = () => Object.keys(DFTModelTree);
export const getDFTFunctionalsByApproximation = (approximation) => {
const branch = DFTModelTree[approximation];
return branch && branch.functionals;
};
// GENERAL
export const MODEL_TREE = {
dft: DFTModelTree,
ml: {
re: {
methods: {
linear: ["least_squares", "ridge"],
kernel_ridge: ["least_squares"],
},
},
},
unknown: {
unknown: {
methods: {
unknown: ["unknown"],
},
},
},
};
export const MODEL_NAMES = {
dft: "density functional theory",
lda: "local density approximation",
gga: "generalized gradient approximation",
hybrid: "hybrid functional",
ml: "machine learning",
re: "regression",
};
export const treeSlugToNamedObject = (modelSlug) => {
return {
slug: modelSlug,
name: lodash.get(MODEL_NAMES, modelSlug, modelSlug),
};
};
// TODO: find a better way to handle application-specific model-method combination
// must be a subset of the MODEL_TREE above
// demonstrate how tree can be modified
// VASP_MODELS_TREE.gga.functionals = _.omit(VASP_MODELS_TREE.gga.functionals);
const VASP_MODELS_TREE = deepClone(_.pick(MODEL_TREE, "dft"));
const ESPRESSO_MODELS_TREE = deepClone(_.pick(MODEL_TREE, "dft"));
const NWCHEM_MODELS_TREE = deepClone(_.pick(MODEL_TREE, "dft"));
["gga", "lda"].forEach((approximation) => {
// pick "paw" for vasp
VASP_MODELS_TREE.dft[approximation].methods.pseudopotential = VASP_MODELS_TREE.dft[
approximation
].methods.pseudopotential.splice(0, 1);
// assert "us" is the first option
ESPRESSO_MODELS_TREE.dft[approximation].methods.pseudopotential =
ESPRESSO_MODELS_TREE.dft[approximation].methods.pseudopotential.reverse();
});
const UNKNOWN_MODELS_TREE = _.pick(MODEL_TREE, "unknown");
const ML_MODELS_TREE = _.pick(MODEL_TREE, "ml");
const MODELS_TREE_CONFIGS_BY_APPLICATION_NAME_VERSION = [
{
name: "vasp",
tree: VASP_MODELS_TREE,
},
{
name: "espresso",
tree: ESPRESSO_MODELS_TREE,
},
{
name: "python",
tree: UNKNOWN_MODELS_TREE,
},
{
name: "shell",
tree: UNKNOWN_MODELS_TREE,
},
{
name: "exabyteml",
tree: ML_MODELS_TREE,
},
{
name: "jupyterLab",
tree: UNKNOWN_MODELS_TREE,
},
{
name: "nwchem",
tree: NWCHEM_MODELS_TREE,
},
{
name: "deepmd",
tree: UNKNOWN_MODELS_TREE,
},
];
export const getTreeByApplicationNameAndVersion = ({
name,
// eslint-disable-next-line no-unused-vars
version,
}) => {
// TODO: add logic to filter by version when necessary
const cfgs = MODELS_TREE_CONFIGS_BY_APPLICATION_NAME_VERSION.filter(
(cfg) => cfg.name === name,
).map((x) => x.tree);
return Object.assign({}, ...cfgs);
};
export const getDefaultModelTypeForApplication = (application) => {
return Object.keys(getTreeByApplicationNameAndVersion(application))[0];
};
function safelyGet(obj, ...args) {
return lodash.get(obj, args, undefined);
}
/**
* Create list of filter objects based on model categories.
* @param {Object} filterTree - filter tree constructed from assets
* @param {string} tier1 - Level 1 tier
* @param {string} tier2 - Level 2 tier
* @param {string} tier3 - Level 3 tier
* @param {string} type - Type
* @param {string} subtype - Subtype
* @return {*[]}
*/
function getMethodFilterObjects({ filterTree, tier1, tier2, tier3, type, subtype }) {
let filterList;
if (!tier1) {
filterList = mergeTerminalNodes(filterTree);
} else if (!tier2) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1));
} else if (!tier3) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1, tier2));
} else if (!type) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1, tier2, tier3));
} else if (!subtype) {
filterList = mergeTerminalNodes(safelyGet(filterTree, tier1, tier2, tier3, type));
} else {
filterList = safelyGet(filterTree, tier1, tier2, tier3, type, subtype);
}
const extractUniqueBy = (name) => {
return lodash
.chain(filterList)
.filter(Boolean)
.filter((o) => Boolean(o[name]))
.uniqBy(name)
.value();
};
return [].concat(extractUniqueBy("path"), extractUniqueBy("regex"));
}
/**
* Filter list of method configs based on model
* @param {Object[]} methodList - Array of method configs
* @param {Object} model - Model config for which methods should be filtered
* @return {Object[]}
*/
export function filterMethodsByModel({ methodList, model }) {
if (!model) return [];
const { categories } = model;
const filterObjects = getMethodFilterObjects({ filterTree: modelMethodMap, ...categories });
return filterEntityList({
entitiesOrPaths: methodList,
filterObjects,
multiPathSeparator: "::",
});
}