@mat3ra/mode 2026.3.4-0 → 2026.5.28-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.
@@ -1,6 +1,29 @@
1
- import { BaseMethod, BaseModel, SlugifiedEntry } from "@mat3ra/esse/dist/js/types";
2
- export declare const PseudopotentialMethodConfig: BaseMethod;
3
- export declare const LocalOrbitalMethodConfig: BaseMethod;
4
- export declare const UnknownMethodConfig: BaseMethod;
1
+ import { BaseModel, SlugifiedEntry } from "@mat3ra/esse/dist/js/types";
2
+ export declare const PseudopotentialMethodConfig: {
3
+ readonly type: "pseudopotential";
4
+ readonly subtype: "us";
5
+ };
6
+ export declare const LocalOrbitalMethodConfig: {
7
+ readonly type: "localorbital";
8
+ readonly subtype: "pople";
9
+ };
10
+ export declare const UnknownMethodConfig: {
11
+ readonly type: "unknown";
12
+ readonly subtype: "unknown";
13
+ };
14
+ export declare const methodConfigs: {
15
+ readonly pseudopotential: {
16
+ readonly type: "pseudopotential";
17
+ readonly subtype: "us";
18
+ };
19
+ readonly localorbital: {
20
+ readonly type: "localorbital";
21
+ readonly subtype: "pople";
22
+ };
23
+ readonly unknown: {
24
+ readonly type: "unknown";
25
+ readonly subtype: "unknown";
26
+ };
27
+ };
5
28
  export declare function allowedTypes(model: Pick<BaseModel, "type" | "subtype">): SlugifiedEntry[];
6
29
  export declare function allowedSubtypes(model: Pick<BaseModel, "type" | "subtype">, type: string): SlugifiedEntry[];
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.UnknownMethodConfig = exports.LocalOrbitalMethodConfig = exports.PseudopotentialMethodConfig = void 0;
6
+ exports.methodConfigs = exports.UnknownMethodConfig = exports.LocalOrbitalMethodConfig = exports.PseudopotentialMethodConfig = void 0;
7
7
  exports.allowedTypes = allowedTypes;
8
8
  exports.allowedSubtypes = allowedSubtypes;
9
9
  const lodash_1 = __importDefault(require("lodash"));
@@ -20,6 +20,11 @@ exports.UnknownMethodConfig = {
20
20
  type: "unknown",
21
21
  subtype: "unknown",
22
22
  };
23
+ exports.methodConfigs = {
24
+ pseudopotential: exports.PseudopotentialMethodConfig,
25
+ localorbital: exports.LocalOrbitalMethodConfig,
26
+ unknown: exports.UnknownMethodConfig,
27
+ };
23
28
  const mapSlugToNamedObject = (slug) => {
24
29
  return {
25
30
  slug,
@@ -1,3 +1,8 @@
1
- import type { ModelConfig } from "./types";
2
- export declare const DFTModelConfig: ModelConfig;
3
- export declare const UnknownModelConfig: ModelConfig;
1
+ export declare const DFTModelConfig: {
2
+ readonly type: "dft";
3
+ readonly subtype: "gga";
4
+ };
5
+ export declare const UnknownModelConfig: {
6
+ readonly type: "unknown";
7
+ readonly subtype: "unknown";
8
+ };
@@ -2,4 +2,4 @@ import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
2
  import type { BaseMethod } from "@mat3ra/esse/dist/js/types";
3
3
  export type MethodSchemaMixin = BaseMethod;
4
4
  export type MethodInMemoryEntity = InMemoryEntity & MethodSchemaMixin;
5
- export declare function methodSchemaMixin(item: InMemoryEntity): void;
5
+ export declare function methodSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & MethodSchemaMixin;
@@ -7,15 +7,27 @@ function methodSchemaMixin(item) {
7
7
  get type() {
8
8
  return this.requiredProp("type");
9
9
  },
10
+ set type(value) {
11
+ this.setProp("type", value);
12
+ },
10
13
  get subtype() {
11
14
  return this.requiredProp("subtype");
12
15
  },
16
+ set subtype(value) {
17
+ this.setProp("subtype", value);
18
+ },
13
19
  get precision() {
14
20
  return this.prop("precision");
15
21
  },
22
+ set precision(value) {
23
+ this.setProp("precision", value);
24
+ },
16
25
  get data() {
17
26
  return this.prop("data");
18
27
  },
28
+ set data(value) {
29
+ this.setProp("data", value);
30
+ },
19
31
  };
20
32
  Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
21
33
  }
@@ -2,4 +2,4 @@ import type { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
2
  import type { BaseModel } from "@mat3ra/esse/dist/js/types";
3
3
  export type ModelSchemaMixin = BaseModel;
4
4
  export type ModelInMemoryEntity = InMemoryEntity & ModelSchemaMixin;
5
- export declare function modelSchemaMixin(item: InMemoryEntity): void;
5
+ export declare function modelSchemaMixin<T extends InMemoryEntity>(item: InMemoryEntity): asserts item is T & ModelSchemaMixin;
@@ -7,12 +7,21 @@ function modelSchemaMixin(item) {
7
7
  get type() {
8
8
  return this.requiredProp("type");
9
9
  },
10
+ set type(value) {
11
+ this.setProp("type", value);
12
+ },
10
13
  get subtype() {
11
14
  return this.requiredProp("subtype");
12
15
  },
16
+ set subtype(value) {
17
+ this.setProp("subtype", value);
18
+ },
13
19
  get method() {
14
20
  return this.requiredProp("method");
15
21
  },
22
+ set method(value) {
23
+ this.setProp("method", value);
24
+ },
16
25
  };
17
26
  Object.defineProperties(item, Object.getOwnPropertyDescriptors(properties));
18
27
  }
@@ -1,5 +1,6 @@
1
1
  import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
2
  import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
3
+ import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
3
4
  import type { BaseMethod, SlugifiedEntry } from "@mat3ra/esse/dist/js/types";
4
5
  import { type MethodSchemaMixin } from "./generated/MethodSchemaMixin";
5
6
  type Base = typeof InMemoryEntity & Constructor<MethodSchemaMixin>;
@@ -9,9 +10,13 @@ interface MethodData extends Record<string, unknown> {
9
10
  declare const Method_base: Base;
10
11
  export declare class Method extends Method_base implements BaseMethod {
11
12
  constructor(config: BaseMethod);
13
+ toJSON: () => BaseMethod & AnyObject;
12
14
  cloneWithoutData(): Method;
13
15
  setSubtype(subtype: SlugifiedEntry): void;
14
- static get defaultConfig(): BaseMethod;
16
+ static get defaultConfig(): {
17
+ readonly type: "pseudopotential";
18
+ readonly subtype: "us";
19
+ };
15
20
  get searchText(): string;
16
21
  setSearchText(searchText: string): void;
17
22
  setData(data?: MethodData): void;
@@ -1,21 +1,22 @@
1
- import { BaseMethod } from "@mat3ra/esse/dist/js/types";
1
+ import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
2
+ import { type BaseMethod, type FileDataItem } from "@mat3ra/esse/dist/js/types";
3
+ import { PseudopotentialFilter, PseudopotentialMetaProperty } from "@mat3ra/prode";
2
4
  import { Method } from "../method";
3
- import type { PseudopotentialCtor, PseudopotentialLike } from "../types";
5
+ export type ExchangeCorrelation = {
6
+ approximation: string;
7
+ functional: string;
8
+ };
4
9
  export declare class PseudopotentialMethod extends Method {
5
- PseudopotentialCls: PseudopotentialCtor | null;
6
- constructor(config: BaseMethod);
7
- get pseudo(): Record<string, unknown>[];
8
- get allPseudo(): Record<string, unknown>[];
9
- get pseudopotentials(): PseudopotentialLike[];
10
- get allPseudopotentials(): PseudopotentialLike[];
11
- static extractExchangeCorrelationFromSubworkflow(subworkflow: any): {
12
- approximation: string;
13
- functional: string;
14
- };
10
+ toJSON: () => BaseMethod & AnyObject;
11
+ get pseudo(): FileDataItem[];
12
+ get allPseudo(): FileDataItem[];
13
+ get pseudopotentials(): PseudopotentialMetaProperty[];
14
+ get allPseudopotentials(): PseudopotentialMetaProperty[];
15
15
  hasPseudopotentialFor(element: string): boolean;
16
- setPseudopotentialPerElement(pseudo: PseudopotentialLike | undefined): void;
17
- addToAllPseudos(pseudos: PseudopotentialLike | PseudopotentialLike[]): void;
18
- setPseudopotentials(pseudopotentials: PseudopotentialLike[]): void;
19
- setAllPseudopotentials(pseudopotentials: PseudopotentialLike[]): void;
16
+ setPseudopotentialPerElement(pseudo?: PseudopotentialMetaProperty): void;
17
+ addToAllPseudos(pseudos: PseudopotentialMetaProperty | PseudopotentialMetaProperty[]): void;
18
+ setPseudopotentials(pseudopotentials: PseudopotentialMetaProperty[]): void;
19
+ setAllPseudopotentials(pseudopotentials: PseudopotentialMetaProperty[]): void;
20
20
  toJSONWithCleanData(exclude?: string[]): BaseMethod;
21
+ updateMethodDataByApplicationAndMaterials(methodDataItems: PseudopotentialMetaProperty[], pseudoFilter: Pick<PseudopotentialFilter, "elements" | "appName" | "exchangeCorrelation">): this;
21
22
  }
@@ -4,14 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.PseudopotentialMethod = void 0;
7
- const utils_1 = require("@mat3ra/code/dist/js/utils");
7
+ const prode_1 = require("@mat3ra/prode");
8
8
  const underscore_1 = __importDefault(require("underscore"));
9
9
  const method_1 = require("../method");
10
10
  class PseudopotentialMethod extends method_1.Method {
11
- constructor(config) {
12
- super(config);
13
- this.PseudopotentialCls = null;
14
- }
15
11
  get pseudo() {
16
12
  return this.prop("data.pseudo", []);
17
13
  }
@@ -19,24 +15,10 @@ class PseudopotentialMethod extends method_1.Method {
19
15
  return this.prop("data.allPseudo", []);
20
16
  }
21
17
  get pseudopotentials() {
22
- if (!this.PseudopotentialCls)
23
- return [];
24
- return this.pseudo.map((config) => new this.PseudopotentialCls(config));
18
+ return this.pseudo.map((config) => new prode_1.PseudopotentialMetaProperty(config));
25
19
  }
26
20
  get allPseudopotentials() {
27
- if (!this.PseudopotentialCls)
28
- return [];
29
- return this.allPseudo.map((config) => new this.PseudopotentialCls(config));
30
- }
31
- static extractExchangeCorrelationFromSubworkflow(subworkflow) {
32
- const { model } = subworkflow;
33
- const approximation = model.subtype;
34
- const functionalValue = model.functional;
35
- const functional = functionalValue && (functionalValue.slug || functionalValue);
36
- return {
37
- approximation,
38
- functional: functional || "",
39
- };
21
+ return this.allPseudo.map((config) => new prode_1.PseudopotentialMetaProperty(config));
40
22
  }
41
23
  hasPseudopotentialFor(element) {
42
24
  return Boolean(this.pseudopotentials.find((pseudo) => pseudo.element === element));
@@ -47,14 +29,11 @@ class PseudopotentialMethod extends method_1.Method {
47
29
  return;
48
30
  }
49
31
  const filtered = this.pseudopotentials.filter((item) => item.element !== pseudo.element);
50
- filtered.push(pseudo);
51
- this.setPseudopotentials(filtered);
32
+ this.setPseudopotentials([...filtered, pseudo]);
52
33
  }
53
34
  addToAllPseudos(pseudos) {
54
- const list = (0, utils_1.safeMakeArray)(pseudos);
55
- const all = this.allPseudopotentials;
56
- all.push(...list);
57
- this.setAllPseudopotentials(all);
35
+ const list = Array.isArray(pseudos) ? pseudos : [pseudos];
36
+ this.setAllPseudopotentials([...this.allPseudopotentials, ...list]);
58
37
  }
59
38
  setPseudopotentials(pseudopotentials) {
60
39
  this.setData({
@@ -71,5 +50,40 @@ class PseudopotentialMethod extends method_1.Method {
71
50
  toJSONWithCleanData(exclude = []) {
72
51
  return super.toJSONWithCleanData(exclude.concat(["allPseudo"]));
73
52
  }
53
+ updateMethodDataByApplicationAndMaterials(methodDataItems, pseudoFilter) {
54
+ var _a;
55
+ const typeFilter = { type: this.subtype };
56
+ let pseudos = prode_1.PseudopotentialMetaProperty.applyPseudoFilters(methodDataItems, {
57
+ ...pseudoFilter,
58
+ ...typeFilter,
59
+ });
60
+ // sorting pseudos, this is very hacky! TODO: find better approach for default pseudos per application
61
+ if (this.subtype === "us") {
62
+ pseudos = prode_1.PseudopotentialMetaProperty.sortPseudosByPattern(pseudos);
63
+ }
64
+ pseudos = prode_1.PseudopotentialMetaProperty.sortByPathApplicationSpecific(pseudos, pseudoFilter.appName);
65
+ pseudos = prode_1.PseudopotentialMetaProperty.filterUnique(pseudos);
66
+ this.setAllPseudopotentials(pseudos);
67
+ this.setSearchText(this.searchText);
68
+ // if searchText is present => use it to filter the pseudos before selecting one per element
69
+ pseudos = prode_1.PseudopotentialMetaProperty.safelyFilterRawDataBySearchText(pseudos, this.searchText);
70
+ const newFilter = {
71
+ elements: pseudoFilter.elements,
72
+ appName: pseudoFilter.appName,
73
+ exchangeCorrelation: pseudoFilter.exchangeCorrelation,
74
+ searchText: this.searchText,
75
+ ...typeFilter,
76
+ };
77
+ // try to keep previously selected pseudos
78
+ // TODO: rework creating/updating method data items once methodData has been removed from store
79
+ const filteredSelected = prode_1.PseudopotentialMetaProperty.applyPseudoFilters(this.pseudopotentials, newFilter);
80
+ // set first pseudopotentials as selected per element, prioritize already selected
81
+ (_a = pseudoFilter.elements) === null || _a === void 0 ? void 0 : _a.forEach((el) => {
82
+ const selected = filteredSelected.find((p) => p.element === el);
83
+ const pseudo = selected || pseudos.find((p) => p.element === el);
84
+ this.setPseudopotentialPerElement(pseudo);
85
+ });
86
+ return this;
87
+ }
74
88
  }
75
89
  exports.PseudopotentialMethod = PseudopotentialMethod;
@@ -1,6 +1,7 @@
1
1
  import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
2
2
  import type { Constructor } from "@mat3ra/code/dist/js/utils/types";
3
- import type { ApplicationSchemaBase, BaseMethod, BaseModel, SlugifiedEntry, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
3
+ import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
4
+ import type { AnyModelSchema, ApplicationSchema, BaseMethod, BaseModel, SlugifiedEntry, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
4
5
  import { type ModelSchemaMixin } from "./generated/ModelSchemaMixin";
5
6
  import { Method } from "./method";
6
7
  import { MethodFactory } from "./methods/factory";
@@ -8,7 +9,7 @@ import type { MethodTreeBranch, ModelConfig, ModelTree } from "./types";
8
9
  type Base = typeof InMemoryEntity & Constructor<ModelSchemaMixin>;
9
10
  declare const Model_base: Base;
10
11
  export declare class Model extends Model_base implements BaseModel {
11
- protected _application?: ApplicationSchemaBase;
12
+ protected _application?: ApplicationSchema;
12
13
  protected _MethodFactory: typeof MethodFactory;
13
14
  protected _method?: Method;
14
15
  constructor(config: ModelConfig);
@@ -28,9 +29,17 @@ export declare class Model extends Model_base implements BaseModel {
28
29
  get methodTypes(): SlugifiedEntry[];
29
30
  get methodSubtypes(): SlugifiedEntry[];
30
31
  get defaultMethodConfig(): BaseMethod;
31
- static get defaultConfig(): ModelConfig;
32
+ static get defaultConfig(): {
33
+ method: {
34
+ readonly type: "pseudopotential";
35
+ readonly subtype: "us";
36
+ };
37
+ type: "dft";
38
+ subtype: "gga";
39
+ };
32
40
  static get allTypes(): SlugifiedEntry[];
33
- toJSON(): Record<string, unknown>;
41
+ _json: AnyModelSchema & AnyObject;
42
+ toJSON(): AnyModelSchema & AnyObject;
34
43
  protected _stringToSlugifiedObject(slug: SlugifiedEntryOrSlug): SlugifiedEntry;
35
44
  get isUnknown(): boolean;
36
45
  protected get subtypeSlug(): string;
package/dist/js/model.js CHANGED
@@ -19,11 +19,10 @@ class Model extends entity_1.InMemoryEntity {
19
19
  super(entityConfig);
20
20
  this._application = application;
21
21
  this._MethodFactory = factory_1.MethodFactory;
22
- if (method) {
23
- this.setProp("method", method);
24
- }
22
+ this.method = method || this.method;
25
23
  }
26
24
  setSubtype(subtype) {
25
+ // TODO-question: subtype is a string, but we're setting it to a SlugifiedEntryOrSlug
27
26
  this.setProp("subtype", subtype);
28
27
  this.setMethod(this._MethodFactory.create(this.defaultMethodConfig));
29
28
  }
@@ -109,9 +108,8 @@ class Model extends entity_1.InMemoryEntity {
109
108
  return Object.keys(tree_1.MODEL_TREE).map((modelSlug) => (0, tree_1.treeSlugToNamedObject)(modelSlug));
110
109
  }
111
110
  toJSON() {
112
- const json = super.toJSON();
113
111
  return {
114
- ...json,
112
+ ...super.toJSON(),
115
113
  type: this.type,
116
114
  subtype: this.subtype,
117
115
  method: this.Method.toJSONWithCleanData(),
@@ -1,12 +1,44 @@
1
- import { CategorizedModel, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
2
- import type { ModelConfig, SimplifiedCategorizedModel } from "./types";
1
+ import { type AnyModelSchema, type DFTModelSchema, type MLModelSchema, CategorizedModel, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
2
+ import type { DFTModelConfig, SimplifiedCategorizedModel, UnknownModelConfig } from "./types";
3
3
  export declare function safelyGetSlug(slugObj: SlugifiedEntryOrSlug): string;
4
4
  export declare class ModelConversionHandler {
5
- static convertToSimple(categorizedModel: CategorizedModel | undefined): ModelConfig;
6
- static convertDftToSimple(categorizedModel: CategorizedModel): ModelConfig;
7
- static convertMlToSimple(): ModelConfig;
8
- static convertUnknownToSimple(): ModelConfig;
9
- static convertToCategorized(simpleModel: ModelConfig | undefined, allModels?: CategorizedModel[]): SimplifiedCategorizedModel | undefined;
10
- static convertDftToCategorized(simpleModel: ModelConfig, allModels?: CategorizedModel[]): SimplifiedCategorizedModel | undefined;
11
- static convertMlToCategorized(simpleModel: ModelConfig): SimplifiedCategorizedModel;
5
+ static convertToSimple(categorizedModel?: CategorizedModel): DFTModelConfig | {
6
+ readonly type: "unknown";
7
+ readonly subtype: "unknown";
8
+ } | {
9
+ readonly type: "ml";
10
+ readonly subtype: "re";
11
+ };
12
+ static convertDftToSimple(categorizedModel: CategorizedModel): DFTModelConfig | UnknownModelConfig;
13
+ static convertMlToSimple(): {
14
+ readonly type: "ml";
15
+ readonly subtype: "re";
16
+ };
17
+ static convertUnknownToSimple(): {
18
+ readonly type: "unknown";
19
+ readonly subtype: "unknown";
20
+ };
21
+ static convertToCategorized(simpleModel?: AnyModelSchema, allModels?: CategorizedModel[]): SimplifiedCategorizedModel | {
22
+ readonly name: "Regression";
23
+ readonly path: "/st/det/ml/re/none";
24
+ readonly categories: {
25
+ readonly tier1: "st";
26
+ readonly tier2: "det";
27
+ readonly tier3: "ml";
28
+ readonly type: string;
29
+ };
30
+ readonly parameters: {};
31
+ } | undefined;
32
+ static convertDftToCategorized(simpleModel: DFTModelSchema, allModels?: CategorizedModel[]): SimplifiedCategorizedModel | undefined;
33
+ static convertMlToCategorized(simpleModel: MLModelSchema): {
34
+ readonly name: "Regression";
35
+ readonly path: "/st/det/ml/re/none";
36
+ readonly categories: {
37
+ readonly tier1: "st";
38
+ readonly tier2: "det";
39
+ readonly tier3: "ml";
40
+ readonly type: string;
41
+ };
42
+ readonly parameters: {};
43
+ };
12
44
  }
@@ -1,41 +1,7 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.ModelConversionHandler = void 0;
37
4
  exports.safelyGetSlug = safelyGetSlug;
38
- const tree = __importStar(require("./tree"));
39
5
  function safelyGetSlug(slugObj) {
40
6
  return typeof slugObj === "string" ? slugObj : slugObj.slug;
41
7
  }
@@ -53,19 +19,20 @@ class ModelConversionHandler {
53
19
  }
54
20
  }
55
21
  static convertDftToSimple(categorizedModel) {
56
- var _a, _b;
57
- if (!((_a = categorizedModel.categories) === null || _a === void 0 ? void 0 : _a.subtype))
22
+ var _a;
23
+ if (!((_a = categorizedModel.categories) === null || _a === void 0 ? void 0 : _a.subtype)) {
58
24
  return this.convertUnknownToSimple();
59
- const subtypeCategory = categorizedModel.categories.subtype;
60
- const subtype = safelyGetSlug(subtypeCategory);
61
- const functionalParam = (_b = categorizedModel.parameters) === null || _b === void 0 ? void 0 : _b.functional;
62
- const functionalSlug = functionalParam
25
+ }
26
+ const model = categorizedModel;
27
+ const subtype = safelyGetSlug(model.categories.subtype);
28
+ const functionalParam = model.parameters.functional;
29
+ const functional = functionalParam
63
30
  ? safelyGetSlug(functionalParam)
64
- : "";
31
+ : undefined;
65
32
  return {
66
33
  type: "dft",
67
34
  subtype,
68
- functional: tree.treeSlugToNamedObject(functionalSlug),
35
+ functional, // old: tree.treeSlugToNamedObject(functional),
69
36
  };
70
37
  }
71
38
  static convertMlToSimple() {
@@ -80,7 +47,7 @@ class ModelConversionHandler {
80
47
  subtype: "unknown",
81
48
  };
82
49
  }
83
- static convertToCategorized(simpleModel, allModels = []) {
50
+ static convertToCategorized(simpleModel, allModels) {
84
51
  switch (simpleModel === null || simpleModel === void 0 ? void 0 : simpleModel.type) {
85
52
  case "dft":
86
53
  return this.convertDftToCategorized(simpleModel, allModels);
@@ -1,4 +1,5 @@
1
- import { SlugifiedEntry, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
1
+ import type { AnyObject } from "@mat3ra/esse/dist/js/esse/types";
2
+ import { type DFTModelSchema, SlugifiedEntry, SlugifiedEntryOrSlug } from "@mat3ra/esse/dist/js/types";
2
3
  import { MethodFactory } from "../methods/factory";
3
4
  import { Model } from "../model";
4
5
  import type { ModelConfig } from "../types";
@@ -6,19 +7,24 @@ export declare class DFTModel extends Model {
6
7
  constructor(config: ModelConfig & {
7
8
  MethodFactory?: typeof MethodFactory;
8
9
  });
10
+ type: DFTModelSchema["type"];
11
+ subtype: DFTModelSchema["subtype"];
9
12
  get groupSlug(): string;
10
- get defaultFunctional(): SlugifiedEntry;
11
- get defaultRefiners(): SlugifiedEntry[];
12
- get defaultModifiers(): SlugifiedEntry[];
13
- get functional(): SlugifiedEntry;
13
+ private get defaultFunctional();
14
+ readonly defaultRefiners: SlugifiedEntry[];
15
+ readonly defaultModifiers: SlugifiedEntry[];
16
+ get slugifiedFunctional(): SlugifiedEntry;
17
+ get functional(): "pz" | "pw" | "vwn" | "other" | "pbe" | "pbesol" | "pw91" | "b3lyp" | "hse06";
18
+ set functional(functional: "pz" | "pw" | "vwn" | "other" | "pbe" | "pbesol" | "pw91" | "b3lyp" | "hse06");
14
19
  get refiners(): SlugifiedEntry[];
15
20
  get modifiers(): SlugifiedEntry[];
16
21
  setSubtype(subtype: SlugifiedEntryOrSlug): void;
17
- setFunctional(functional: SlugifiedEntryOrSlug): void;
22
+ setFunctional(functional: string): void;
18
23
  private _setArrayProp;
19
24
  setRefiners(refiners: SlugifiedEntryOrSlug | SlugifiedEntryOrSlug[]): void;
20
25
  setModifiers(modifiers: SlugifiedEntryOrSlug | SlugifiedEntryOrSlug[]): void;
21
- toJSON(): Record<string, unknown>;
26
+ _json: DFTModelSchema & AnyObject;
27
+ toJSON(): DFTModelSchema & AnyObject;
22
28
  get allFunctionals(): SlugifiedEntry[];
23
29
  get allRefiners(): SlugifiedEntry[];
24
30
  get allModifiers(): SlugifiedEntry[];
@@ -1,29 +1,28 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.DFTModel = void 0;
7
4
  const utils_1 = require("@mat3ra/code/dist/js/utils");
8
- const underscore_1 = __importDefault(require("underscore"));
9
5
  const factory_1 = require("../methods/factory");
10
6
  const model_1 = require("../model");
11
7
  const tree_1 = require("../tree");
12
8
  class DFTModel extends model_1.Model {
13
9
  constructor(config) {
14
10
  super(config);
11
+ this.defaultRefiners = [];
12
+ this.defaultModifiers = [];
15
13
  this._MethodFactory = config.MethodFactory || factory_1.MethodFactory;
14
+ this.functional =
15
+ this.prop("functional") || this.defaultFunctional.slug;
16
16
  }
17
17
  get groupSlug() {
18
18
  var _a;
19
- const functionalSlug = this.functional.slug;
20
19
  const refinersSlug = this.refiners.map((o) => o.slug).join("+");
21
20
  const modifiersSlug = this.modifiers.map((o) => o.slug).join("+");
22
21
  const slugs = [
23
22
  (_a = this._application) === null || _a === void 0 ? void 0 : _a.shortName,
24
23
  this.type,
25
24
  this.subtype,
26
- functionalSlug,
25
+ this.functional,
27
26
  refinersSlug,
28
27
  modifiersSlug,
29
28
  ].filter(Boolean);
@@ -33,16 +32,14 @@ class DFTModel extends model_1.Model {
33
32
  const [slug] = this.treeBranchForSubType.functionals || [];
34
33
  return (0, tree_1.treeSlugToNamedObject)(slug);
35
34
  }
36
- // eslint-disable-next-line class-methods-use-this
37
- get defaultRefiners() {
38
- return [];
39
- }
40
- // eslint-disable-next-line class-methods-use-this
41
- get defaultModifiers() {
42
- return [];
35
+ get slugifiedFunctional() {
36
+ return this._stringToSlugifiedObject(this.functional);
43
37
  }
44
38
  get functional() {
45
- return this.prop("functional", this.defaultFunctional);
39
+ return this.requiredProp("functional");
40
+ }
41
+ set functional(functional) {
42
+ this.setProp("functional", functional);
46
43
  }
47
44
  get refiners() {
48
45
  return this.prop("refiners", this.defaultRefiners);
@@ -52,10 +49,10 @@ class DFTModel extends model_1.Model {
52
49
  }
53
50
  setSubtype(subtype) {
54
51
  this.setProp("subtype", subtype);
55
- this.setFunctional(this.defaultFunctional);
52
+ this.setFunctional(this.defaultFunctional.slug);
56
53
  }
57
54
  setFunctional(functional) {
58
- this.setProp("functional", this._stringToSlugifiedObject(functional));
55
+ this.setProp("functional", functional);
59
56
  this.setMethod(this._MethodFactory.create(this.defaultMethodConfig));
60
57
  }
61
58
  _setArrayProp(name, data) {
@@ -70,7 +67,6 @@ class DFTModel extends model_1.Model {
70
67
  this._setArrayProp("modifiers", modifiers);
71
68
  }
72
69
  toJSON() {
73
- const pickSlugFromObject = (item) => underscore_1.default.pick(item, "slug");
74
70
  const baseJson = super.toJSON();
75
71
  const keysToExclude = ["type", "subtype", "functional", "refiners", "modifiers", "method"];
76
72
  const restJson = Object.fromEntries(Object.entries(baseJson).filter(([key]) => !keysToExclude.includes(key)));
@@ -78,7 +74,7 @@ class DFTModel extends model_1.Model {
78
74
  type: this.type,
79
75
  subtype: this.subtype,
80
76
  method: this.Method.toJSONWithCleanData(),
81
- functional: pickSlugFromObject(this.functional),
77
+ functional: this.functional,
82
78
  refiners: this.refiners,
83
79
  modifiers: this.modifiers,
84
80
  ...restJson,
@@ -1,9 +1,9 @@
1
1
  import { Model } from "../model";
2
- import type { ModelConfig } from "../types";
2
+ import type { ModelConfig, RequireFields } from "../types";
3
3
  import { DFTModel } from "./dft";
4
4
  export declare class ModelFactory {
5
5
  static DFTModel: typeof DFTModel;
6
6
  static Model: typeof Model;
7
7
  static create(config: ModelConfig): Model;
8
- static createFromApplication(config: ModelConfig): Model;
8
+ static createFromApplication(config: RequireFields<ModelConfig, "application">): Model;
9
9
  }
@@ -19,12 +19,11 @@ class ModelFactory {
19
19
  throw new Error("ModelFactory.createFromApplication: application is required");
20
20
  }
21
21
  const tree = (0, tree_1.getTreeByApplicationNameAndVersion)(application);
22
- if (Object.keys(tree).length === 0) {
22
+ if (!tree || Object.keys(tree).length === 0) {
23
23
  return this.create({ ...config, type: "unknown", subtype: "unknown" });
24
24
  }
25
- const type = (0, tree_1.getDefaultModelTypeForApplication)(application);
26
- const subtype = (0, tree_1.getDefaultModelSubtypeForApplicationAndType)(application, type) || "unknown";
27
- return this.create({ ...config, type, subtype });
25
+ const typeSubtype = (0, tree_1.getDefaultModelTypeSubtypeForApplication)(application);
26
+ return this.create({ ...config, ...typeSubtype });
28
27
  }
29
28
  }
30
29
  exports.ModelFactory = ModelFactory;