@mat3ra/mode 2025.10.2-0 → 2025.11.3-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +16 -9
- package/dist/methodConversionHandler.js +128 -0
- package/dist/modelConversionHandler.js +102 -0
- package/dist/tree.js +2 -20
- package/package.json +1 -1
- package/src/index.js +4 -10
- package/src/methodConversionHandler.js +125 -0
- package/src/modelConversionHandler.js +91 -0
- package/src/tree.js +0 -13
package/dist/index.js
CHANGED
|
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "Method", {
|
|
|
15
15
|
return _method.Method;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "MethodConversionHandler", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _methodConversionHandler.MethodConversionHandler;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
18
24
|
Object.defineProperty(exports, "MethodFactory", {
|
|
19
25
|
enumerable: true,
|
|
20
26
|
get: function () {
|
|
@@ -27,6 +33,12 @@ Object.defineProperty(exports, "Model", {
|
|
|
27
33
|
return _model.Model;
|
|
28
34
|
}
|
|
29
35
|
});
|
|
36
|
+
Object.defineProperty(exports, "ModelConversionHandler", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _modelConversionHandler.ModelConversionHandler;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
30
42
|
Object.defineProperty(exports, "ModelFactory", {
|
|
31
43
|
enumerable: true,
|
|
32
44
|
get: function () {
|
|
@@ -39,24 +51,19 @@ Object.defineProperty(exports, "PseudopotentialMethod", {
|
|
|
39
51
|
return _pseudopotential.PseudopotentialMethod;
|
|
40
52
|
}
|
|
41
53
|
});
|
|
42
|
-
exports.tree = exports.default_models = exports.default_methods =
|
|
43
|
-
var _standata = require("@mat3ra/standata");
|
|
54
|
+
exports.tree = exports.default_models = exports.default_methods = void 0;
|
|
44
55
|
var default_methods = _interopRequireWildcard(require("./default_methods"));
|
|
45
56
|
exports.default_methods = default_methods;
|
|
46
57
|
var default_models = _interopRequireWildcard(require("./default_models"));
|
|
47
58
|
exports.default_models = default_models;
|
|
48
59
|
var _method = require("./method");
|
|
60
|
+
var _methodConversionHandler = require("./methodConversionHandler");
|
|
49
61
|
var _factory = require("./methods/factory");
|
|
50
62
|
var _pseudopotential = require("./methods/pseudopotential");
|
|
51
63
|
var _model = require("./model");
|
|
64
|
+
var _modelConversionHandler = require("./modelConversionHandler");
|
|
52
65
|
var _dft = require("./models/dft");
|
|
53
66
|
var _factory2 = require("./models/factory");
|
|
54
67
|
var tree = _interopRequireWildcard(require("./tree"));
|
|
55
68
|
exports.tree = tree;
|
|
56
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
57
|
-
// TODO : can replace these with subpackages in exports in package.json
|
|
58
|
-
|
|
59
|
-
const methodStandata = new _standata.MethodStandata();
|
|
60
|
-
const modelStandata = new _standata.ModelStandata();
|
|
61
|
-
const categorizedMethodList = exports.categorizedMethodList = methodStandata.getAll();
|
|
62
|
-
const categorizedModelList = exports.categorizedModelList = modelStandata.getAll();
|
|
69
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MethodConversionHandler = void 0;
|
|
7
|
+
exports.safelyGetSlug = safelyGetSlug;
|
|
8
|
+
var _default_methods = require("./default_methods");
|
|
9
|
+
function safelyGetSlug(slugObj) {
|
|
10
|
+
return typeof slugObj === "string" ? slugObj : slugObj.slug;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The method interface converts between the legacy method data structure (type, subtype)
|
|
15
|
+
* and the categorized method data structure (units with tier1, tier2, ...).
|
|
16
|
+
*/
|
|
17
|
+
class MethodConversionHandler {
|
|
18
|
+
static convertToSimple(cm) {
|
|
19
|
+
if (!cm) return this.convertUnknownToSimple();
|
|
20
|
+
const pspUnits = cm.units.filter(u => u.categories.type === "psp");
|
|
21
|
+
const aoUnit = cm.units.find(u => u.categories.type === "ao");
|
|
22
|
+
const reUnit = cm.units.find(u => u.name && u.name.includes("regression"));
|
|
23
|
+
if (pspUnits.length) return this.convertPspUnitsToSimple(pspUnits);
|
|
24
|
+
if (aoUnit) return this.convertAoUnitToSimple();
|
|
25
|
+
if (reUnit) return this.convertRegressionUnitToSimple(reUnit);
|
|
26
|
+
return this.convertRegressionUnitToSimple(reUnit);
|
|
27
|
+
}
|
|
28
|
+
static convertUnknownToSimple() {
|
|
29
|
+
return _default_methods.UnknownMethodConfig;
|
|
30
|
+
}
|
|
31
|
+
static convertPspUnitsToSimple(cm) {
|
|
32
|
+
const [firstPspUnit, ...otherUnits] = cm;
|
|
33
|
+
if (!firstPspUnit || !firstPspUnit.categories?.subtype) return this.convertUnknownToSimple();
|
|
34
|
+
const subtype = otherUnits?.length ? "any" : firstPspUnit.categories.subtype;
|
|
35
|
+
return {
|
|
36
|
+
type: "pseudopotential",
|
|
37
|
+
subtype
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
static convertAoUnitToSimple() {
|
|
41
|
+
return _default_methods.LocalOrbitalMethodConfig;
|
|
42
|
+
}
|
|
43
|
+
static convertRegressionUnitToSimple(cm) {
|
|
44
|
+
const type = cm.categories.type || "linear";
|
|
45
|
+
const subtype = cm.categories.subtype || "least_squares";
|
|
46
|
+
return {
|
|
47
|
+
type: safelyGetSlug(type),
|
|
48
|
+
subtype: safelyGetSlug(subtype),
|
|
49
|
+
data: cm.data,
|
|
50
|
+
precision: cm.precision
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
static convertToCategorized(sm, allMethods = []) {
|
|
54
|
+
switch (sm?.type) {
|
|
55
|
+
case "pseudopotential":
|
|
56
|
+
return this.convertPspToCategorized(sm, allMethods);
|
|
57
|
+
case "localorbital":
|
|
58
|
+
return this.convertAoToCategorized(sm);
|
|
59
|
+
case "linear":
|
|
60
|
+
return this.convertRegressionToCategorized(sm);
|
|
61
|
+
case "kernel_ridge":
|
|
62
|
+
return this.convertRegressionToCategorized(sm);
|
|
63
|
+
default:
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
static convertPspToCategorized(sm, allMethods = []) {
|
|
68
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
69
|
+
// the "any" subtype is equivalent to the method representing all planewave-pseudopotential
|
|
70
|
+
// methods. All other subtypes are equivalent to using a specific PW-PSP method.
|
|
71
|
+
const path = subtype === "any" ? "/qm/wf/none/psp/us::/qm/wf/none/psp/nc::/qm/wf/none/psp/nc-fr::/qm/wf/none/psp/paw::/qm/wf/none/pw/none" : `/qm/wf/none/smearing/gaussian::/linalg/diag/none/davidson/none::/qm/wf/none/psp/${subtype}::/qm/wf/none/pw/none`;
|
|
72
|
+
return allMethods.find(catMethod => {
|
|
73
|
+
return catMethod.path === path;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
static convertAoToCategorized(sm) {
|
|
77
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
78
|
+
return {
|
|
79
|
+
units: [{
|
|
80
|
+
parameters: {
|
|
81
|
+
basisSlug: "6-31G"
|
|
82
|
+
},
|
|
83
|
+
categories: {
|
|
84
|
+
tier1: "qm",
|
|
85
|
+
tier2: "wf",
|
|
86
|
+
type: "ao",
|
|
87
|
+
subtype
|
|
88
|
+
},
|
|
89
|
+
tags: ["atomic orbital"],
|
|
90
|
+
name: "Wave function: LCAO - Pople basis set (6-31G)",
|
|
91
|
+
path: "/qm/wf/none/ao/pople?basisSlug=6-31G"
|
|
92
|
+
}],
|
|
93
|
+
name: "Wave function: LCAO - Pople basis set (6-31G)",
|
|
94
|
+
path: "/qm/wf/none/ao/pople?basisSlug=6-31G"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
static convertRegressionToCategorized(sm) {
|
|
98
|
+
const type = safelyGetSlug(sm.type);
|
|
99
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
100
|
+
const {
|
|
101
|
+
precision,
|
|
102
|
+
data
|
|
103
|
+
} = sm;
|
|
104
|
+
const path = `/none/none/none/${type}/${subtype}`;
|
|
105
|
+
const nameMap = {
|
|
106
|
+
kernel_ridge: "Kernel ridge",
|
|
107
|
+
linear: "Linear",
|
|
108
|
+
least_squares: "least squares",
|
|
109
|
+
ridge: "ridge"
|
|
110
|
+
};
|
|
111
|
+
const name = `${nameMap[type]} ${nameMap[subtype]} regression`;
|
|
112
|
+
return {
|
|
113
|
+
units: [{
|
|
114
|
+
categories: {
|
|
115
|
+
type,
|
|
116
|
+
subtype
|
|
117
|
+
},
|
|
118
|
+
name,
|
|
119
|
+
path,
|
|
120
|
+
precision,
|
|
121
|
+
data
|
|
122
|
+
}],
|
|
123
|
+
name,
|
|
124
|
+
path
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.MethodConversionHandler = MethodConversionHandler;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ModelConversionHandler = void 0;
|
|
7
|
+
exports.safelyGetSlug = safelyGetSlug;
|
|
8
|
+
var tree = _interopRequireWildcard(require("./tree"));
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
function safelyGetSlug(slugObj) {
|
|
11
|
+
return typeof slugObj === "string" ? slugObj : slugObj.slug;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The model interface converts between the legacy model data structure (type, subtype, functional)
|
|
16
|
+
* and the categorized model data structure (tier1, tier2, ...).
|
|
17
|
+
*/
|
|
18
|
+
class ModelConversionHandler {
|
|
19
|
+
static convertToSimple(cm) {
|
|
20
|
+
if (!cm) return this.convertUnknownToSimple();
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line default-case
|
|
23
|
+
switch (cm.categories.tier3) {
|
|
24
|
+
case "dft":
|
|
25
|
+
return this.convertDftToSimple(cm);
|
|
26
|
+
case "ml":
|
|
27
|
+
return this.convertMlToSimple();
|
|
28
|
+
default:
|
|
29
|
+
return this.convertUnknownToSimple();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
static convertDftToSimple(cm) {
|
|
33
|
+
if (!cm.categories?.subtype) return this.convertUnknownToSimple();
|
|
34
|
+
const {
|
|
35
|
+
subtype
|
|
36
|
+
} = cm.categories;
|
|
37
|
+
const functional = cm.parameters?.functional;
|
|
38
|
+
return {
|
|
39
|
+
type: "dft",
|
|
40
|
+
subtype,
|
|
41
|
+
functional: tree.treeSlugToNamedObject(functional)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
static convertMlToSimple() {
|
|
45
|
+
return {
|
|
46
|
+
type: "ml",
|
|
47
|
+
subtype: "re"
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
static convertUnknownToSimple() {
|
|
51
|
+
return {
|
|
52
|
+
type: "unknown",
|
|
53
|
+
subtype: "unknown"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
static convertToCategorized(sm, allModels = []) {
|
|
57
|
+
switch (sm?.type) {
|
|
58
|
+
case "dft":
|
|
59
|
+
return this.convertDftToCategorized(sm, allModels);
|
|
60
|
+
case "ml":
|
|
61
|
+
return this.convertMlToCategorized(sm);
|
|
62
|
+
case "unknown":
|
|
63
|
+
return undefined;
|
|
64
|
+
default:
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
static convertDftToCategorized(sm, allModels = []) {
|
|
69
|
+
const {
|
|
70
|
+
subtype,
|
|
71
|
+
functional: functionalStringOrObject
|
|
72
|
+
} = sm;
|
|
73
|
+
const defaultFunctionals = {
|
|
74
|
+
lda: "pz",
|
|
75
|
+
gga: "pbe",
|
|
76
|
+
hybrid: "b3lyp"
|
|
77
|
+
};
|
|
78
|
+
let functional;
|
|
79
|
+
if (!functionalStringOrObject) {
|
|
80
|
+
functional = defaultFunctionals[subtype];
|
|
81
|
+
} else {
|
|
82
|
+
functional = safelyGetSlug(functionalStringOrObject);
|
|
83
|
+
}
|
|
84
|
+
const path = `/pb/qm/dft/ksdft/${subtype}?functional=${functional}`;
|
|
85
|
+
return allModels.find(cm => cm.path === path);
|
|
86
|
+
}
|
|
87
|
+
static convertMlToCategorized(sm) {
|
|
88
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
89
|
+
return {
|
|
90
|
+
name: "Regression",
|
|
91
|
+
path: "/st/det/ml/re/none",
|
|
92
|
+
categories: {
|
|
93
|
+
tier1: "st",
|
|
94
|
+
tier2: "det",
|
|
95
|
+
tier3: "ml",
|
|
96
|
+
type: subtype
|
|
97
|
+
},
|
|
98
|
+
parameters: {}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.ModelConversionHandler = ModelConversionHandler;
|
package/dist/tree.js
CHANGED
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.MODEL_TREE = exports.MODEL_NAMES = exports.METHODS = void 0;
|
|
7
|
-
exports.filterMethodsByModel = filterMethodsByModel;
|
|
8
|
-
exports.treeSlugToNamedObject = exports.getTreeByApplicationNameAndVersion = exports.getPseudopotentialTypesFromTree = exports.getDefaultModelTypeForApplication = exports.getDFTFunctionalsFromTree = exports.getDFTFunctionalsByApproximation = void 0;
|
|
6
|
+
exports.treeSlugToNamedObject = exports.getTreeByApplicationNameAndVersion = exports.getPseudopotentialTypesFromTree = exports.getDefaultModelTypeForApplication = exports.getDFTFunctionalsFromTree = exports.getDFTFunctionalsByApproximation = exports.MODEL_TREE = exports.MODEL_NAMES = exports.METHODS = void 0;
|
|
9
7
|
var _utils = require("@mat3ra/code/dist/js/utils");
|
|
10
|
-
var _standata = require("@mat3ra/standata");
|
|
11
8
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
12
9
|
var _underscore = _interopRequireDefault(require("underscore"));
|
|
13
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -147,19 +144,4 @@ exports.getTreeByApplicationNameAndVersion = getTreeByApplicationNameAndVersion;
|
|
|
147
144
|
const getDefaultModelTypeForApplication = application => {
|
|
148
145
|
return Object.keys(getTreeByApplicationNameAndVersion(application))[0];
|
|
149
146
|
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Filter list of method configs based on model
|
|
153
|
-
* @param {Object[]} methodList - Array of method configs
|
|
154
|
-
* @param {Object} model - Model config for which methods should be filtered
|
|
155
|
-
* @return {Object[]}
|
|
156
|
-
*/
|
|
157
|
-
exports.getDefaultModelTypeForApplication = getDefaultModelTypeForApplication;
|
|
158
|
-
function filterMethodsByModel({
|
|
159
|
-
methodList,
|
|
160
|
-
model
|
|
161
|
-
}) {
|
|
162
|
-
if (!model) return [];
|
|
163
|
-
const modelMethodFilter = new _standata.ModelMethodFilter();
|
|
164
|
-
return modelMethodFilter.getCompatibleMethods(model, methodList);
|
|
165
|
-
}
|
|
147
|
+
exports.getDefaultModelTypeForApplication = getDefaultModelTypeForApplication;
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import { MethodStandata, ModelStandata } from "@mat3ra/standata";
|
|
2
|
-
|
|
3
1
|
import * as default_methods from "./default_methods";
|
|
4
2
|
import * as default_models from "./default_models";
|
|
5
3
|
import { Method } from "./method";
|
|
4
|
+
import { MethodConversionHandler } from "./methodConversionHandler";
|
|
6
5
|
import { MethodFactory } from "./methods/factory";
|
|
7
6
|
import { PseudopotentialMethod } from "./methods/pseudopotential";
|
|
8
7
|
import { Model } from "./model";
|
|
8
|
+
import { ModelConversionHandler } from "./modelConversionHandler";
|
|
9
9
|
import { DFTModel } from "./models/dft";
|
|
10
10
|
import { ModelFactory } from "./models/factory";
|
|
11
11
|
// TODO : can replace these with subpackages in exports in package.json
|
|
12
12
|
import * as tree from "./tree";
|
|
13
13
|
|
|
14
|
-
const methodStandata = new MethodStandata();
|
|
15
|
-
const modelStandata = new ModelStandata();
|
|
16
|
-
|
|
17
|
-
const categorizedMethodList = methodStandata.getAll();
|
|
18
|
-
const categorizedModelList = modelStandata.getAll();
|
|
19
|
-
|
|
20
14
|
export {
|
|
21
15
|
Method,
|
|
22
16
|
Model,
|
|
@@ -24,9 +18,9 @@ export {
|
|
|
24
18
|
ModelFactory,
|
|
25
19
|
PseudopotentialMethod,
|
|
26
20
|
DFTModel,
|
|
21
|
+
MethodConversionHandler,
|
|
22
|
+
ModelConversionHandler,
|
|
27
23
|
tree,
|
|
28
24
|
default_models,
|
|
29
25
|
default_methods,
|
|
30
|
-
categorizedModelList,
|
|
31
|
-
categorizedMethodList,
|
|
32
26
|
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { LocalOrbitalMethodConfig, UnknownMethodConfig } from "./default_methods";
|
|
2
|
+
|
|
3
|
+
export function safelyGetSlug(slugObj) {
|
|
4
|
+
return typeof slugObj === "string" ? slugObj : slugObj.slug;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The method interface converts between the legacy method data structure (type, subtype)
|
|
9
|
+
* and the categorized method data structure (units with tier1, tier2, ...).
|
|
10
|
+
*/
|
|
11
|
+
export class MethodConversionHandler {
|
|
12
|
+
static convertToSimple(cm) {
|
|
13
|
+
if (!cm) return this.convertUnknownToSimple();
|
|
14
|
+
const pspUnits = cm.units.filter((u) => u.categories.type === "psp");
|
|
15
|
+
const aoUnit = cm.units.find((u) => u.categories.type === "ao");
|
|
16
|
+
const reUnit = cm.units.find((u) => u.name && u.name.includes("regression"));
|
|
17
|
+
if (pspUnits.length) return this.convertPspUnitsToSimple(pspUnits);
|
|
18
|
+
if (aoUnit) return this.convertAoUnitToSimple();
|
|
19
|
+
if (reUnit) return this.convertRegressionUnitToSimple(reUnit);
|
|
20
|
+
return this.convertRegressionUnitToSimple(reUnit);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static convertUnknownToSimple() {
|
|
24
|
+
return UnknownMethodConfig;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static convertPspUnitsToSimple(cm) {
|
|
28
|
+
const [firstPspUnit, ...otherUnits] = cm;
|
|
29
|
+
if (!firstPspUnit || !firstPspUnit.categories?.subtype)
|
|
30
|
+
return this.convertUnknownToSimple();
|
|
31
|
+
const subtype = otherUnits?.length ? "any" : firstPspUnit.categories.subtype;
|
|
32
|
+
return {
|
|
33
|
+
type: "pseudopotential",
|
|
34
|
+
subtype,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static convertAoUnitToSimple() {
|
|
39
|
+
return LocalOrbitalMethodConfig;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static convertRegressionUnitToSimple(cm) {
|
|
43
|
+
const type = cm.categories.type || "linear";
|
|
44
|
+
const subtype = cm.categories.subtype || "least_squares";
|
|
45
|
+
return {
|
|
46
|
+
type: safelyGetSlug(type),
|
|
47
|
+
subtype: safelyGetSlug(subtype),
|
|
48
|
+
data: cm.data,
|
|
49
|
+
precision: cm.precision,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static convertToCategorized(sm, allMethods = []) {
|
|
54
|
+
switch (sm?.type) {
|
|
55
|
+
case "pseudopotential":
|
|
56
|
+
return this.convertPspToCategorized(sm, allMethods);
|
|
57
|
+
case "localorbital":
|
|
58
|
+
return this.convertAoToCategorized(sm);
|
|
59
|
+
case "linear":
|
|
60
|
+
return this.convertRegressionToCategorized(sm);
|
|
61
|
+
case "kernel_ridge":
|
|
62
|
+
return this.convertRegressionToCategorized(sm);
|
|
63
|
+
default:
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static convertPspToCategorized(sm, allMethods = []) {
|
|
69
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
70
|
+
// the "any" subtype is equivalent to the method representing all planewave-pseudopotential
|
|
71
|
+
// methods. All other subtypes are equivalent to using a specific PW-PSP method.
|
|
72
|
+
const path =
|
|
73
|
+
subtype === "any"
|
|
74
|
+
? "/qm/wf/none/psp/us::/qm/wf/none/psp/nc::/qm/wf/none/psp/nc-fr::/qm/wf/none/psp/paw::/qm/wf/none/pw/none"
|
|
75
|
+
: `/qm/wf/none/smearing/gaussian::/linalg/diag/none/davidson/none::/qm/wf/none/psp/${subtype}::/qm/wf/none/pw/none`;
|
|
76
|
+
|
|
77
|
+
return allMethods.find((catMethod) => {
|
|
78
|
+
return catMethod.path === path;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static convertAoToCategorized(sm) {
|
|
83
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
84
|
+
return {
|
|
85
|
+
units: [
|
|
86
|
+
{
|
|
87
|
+
parameters: { basisSlug: "6-31G" },
|
|
88
|
+
categories: { tier1: "qm", tier2: "wf", type: "ao", subtype },
|
|
89
|
+
tags: ["atomic orbital"],
|
|
90
|
+
name: "Wave function: LCAO - Pople basis set (6-31G)",
|
|
91
|
+
path: "/qm/wf/none/ao/pople?basisSlug=6-31G",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
name: "Wave function: LCAO - Pople basis set (6-31G)",
|
|
95
|
+
path: "/qm/wf/none/ao/pople?basisSlug=6-31G",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
static convertRegressionToCategorized(sm) {
|
|
100
|
+
const type = safelyGetSlug(sm.type);
|
|
101
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
102
|
+
const { precision, data } = sm;
|
|
103
|
+
const path = `/none/none/none/${type}/${subtype}`;
|
|
104
|
+
const nameMap = {
|
|
105
|
+
kernel_ridge: "Kernel ridge",
|
|
106
|
+
linear: "Linear",
|
|
107
|
+
least_squares: "least squares",
|
|
108
|
+
ridge: "ridge",
|
|
109
|
+
};
|
|
110
|
+
const name = `${nameMap[type]} ${nameMap[subtype]} regression`;
|
|
111
|
+
return {
|
|
112
|
+
units: [
|
|
113
|
+
{
|
|
114
|
+
categories: { type, subtype },
|
|
115
|
+
name,
|
|
116
|
+
path,
|
|
117
|
+
precision,
|
|
118
|
+
data,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
name,
|
|
122
|
+
path,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as tree from "./tree";
|
|
2
|
+
|
|
3
|
+
export function safelyGetSlug(slugObj) {
|
|
4
|
+
return typeof slugObj === "string" ? slugObj : slugObj.slug;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The model interface converts between the legacy model data structure (type, subtype, functional)
|
|
9
|
+
* and the categorized model data structure (tier1, tier2, ...).
|
|
10
|
+
*/
|
|
11
|
+
export class ModelConversionHandler {
|
|
12
|
+
static convertToSimple(cm) {
|
|
13
|
+
if (!cm) return this.convertUnknownToSimple();
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line default-case
|
|
16
|
+
switch (cm.categories.tier3) {
|
|
17
|
+
case "dft":
|
|
18
|
+
return this.convertDftToSimple(cm);
|
|
19
|
+
case "ml":
|
|
20
|
+
return this.convertMlToSimple();
|
|
21
|
+
default:
|
|
22
|
+
return this.convertUnknownToSimple();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static convertDftToSimple(cm) {
|
|
27
|
+
if (!cm.categories?.subtype) return this.convertUnknownToSimple();
|
|
28
|
+
const { subtype } = cm.categories;
|
|
29
|
+
const functional = cm.parameters?.functional;
|
|
30
|
+
return {
|
|
31
|
+
type: "dft",
|
|
32
|
+
subtype,
|
|
33
|
+
functional: tree.treeSlugToNamedObject(functional),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static convertMlToSimple() {
|
|
38
|
+
return {
|
|
39
|
+
type: "ml",
|
|
40
|
+
subtype: "re",
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static convertUnknownToSimple() {
|
|
45
|
+
return {
|
|
46
|
+
type: "unknown",
|
|
47
|
+
subtype: "unknown",
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static convertToCategorized(sm, allModels = []) {
|
|
52
|
+
switch (sm?.type) {
|
|
53
|
+
case "dft":
|
|
54
|
+
return this.convertDftToCategorized(sm, allModels);
|
|
55
|
+
case "ml":
|
|
56
|
+
return this.convertMlToCategorized(sm);
|
|
57
|
+
case "unknown":
|
|
58
|
+
return undefined;
|
|
59
|
+
default:
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static convertDftToCategorized(sm, allModels = []) {
|
|
65
|
+
const { subtype, functional: functionalStringOrObject } = sm;
|
|
66
|
+
const defaultFunctionals = { lda: "pz", gga: "pbe", hybrid: "b3lyp" };
|
|
67
|
+
let functional;
|
|
68
|
+
if (!functionalStringOrObject) {
|
|
69
|
+
functional = defaultFunctionals[subtype];
|
|
70
|
+
} else {
|
|
71
|
+
functional = safelyGetSlug(functionalStringOrObject);
|
|
72
|
+
}
|
|
73
|
+
const path = `/pb/qm/dft/ksdft/${subtype}?functional=${functional}`;
|
|
74
|
+
return allModels.find((cm) => cm.path === path);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static convertMlToCategorized(sm) {
|
|
78
|
+
const subtype = safelyGetSlug(sm.subtype);
|
|
79
|
+
return {
|
|
80
|
+
name: "Regression",
|
|
81
|
+
path: "/st/det/ml/re/none",
|
|
82
|
+
categories: {
|
|
83
|
+
tier1: "st",
|
|
84
|
+
tier2: "det",
|
|
85
|
+
tier3: "ml",
|
|
86
|
+
type: subtype,
|
|
87
|
+
},
|
|
88
|
+
parameters: {},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
package/src/tree.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { deepClone } from "@mat3ra/code/dist/js/utils";
|
|
2
|
-
import { ModelMethodFilter } from "@mat3ra/standata";
|
|
3
2
|
import lodash from "lodash";
|
|
4
3
|
import _ from "underscore";
|
|
5
4
|
|
|
@@ -161,15 +160,3 @@ export const getTreeByApplicationNameAndVersion = ({
|
|
|
161
160
|
export const getDefaultModelTypeForApplication = (application) => {
|
|
162
161
|
return Object.keys(getTreeByApplicationNameAndVersion(application))[0];
|
|
163
162
|
};
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Filter list of method configs based on model
|
|
167
|
-
* @param {Object[]} methodList - Array of method configs
|
|
168
|
-
* @param {Object} model - Model config for which methods should be filtered
|
|
169
|
-
* @return {Object[]}
|
|
170
|
-
*/
|
|
171
|
-
export function filterMethodsByModel({ methodList, model }) {
|
|
172
|
-
if (!model) return [];
|
|
173
|
-
const modelMethodFilter = new ModelMethodFilter();
|
|
174
|
-
return modelMethodFilter.getCompatibleMethods(model, methodList);
|
|
175
|
-
}
|