@mat3ra/wode 2026.8.26-1 → 2026.8.29-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.
@@ -8,7 +8,7 @@ import { type ComputedEntityMixin } from "@mat3ra/ide/dist/js/compute";
8
8
  import type { Material } from "@mat3ra/made";
9
9
  import { Model, ModelFactory } from "@mat3ra/mode";
10
10
  import type { MetaPropertyHolder } from "@mat3ra/prode";
11
- import type { WorkflowExternalContext } from "./context/providers/by_application/espresso/QEPWXInputDataManager";
11
+ import type { WorkflowExternalContext } from "./context/providers/base/ContextProvider";
12
12
  import { type SubworkflowSchemaMixin } from "./generated/SubworkflowSchemaMixin";
13
13
  import { SubworkflowUnit } from "./units";
14
14
  import type { AnySubworkflowUnit } from "./units/factory";
@@ -11,7 +11,7 @@ import type { MetaPropertyHolder } from "@mat3ra/prode";
11
11
  import type { MaterialExternalContext } from "./context/mixins/MaterialContextMixin";
12
12
  import type { MaterialsExternalContext } from "./context/mixins/MaterialsContextMixin";
13
13
  import type { MaterialsSetExternalContext } from "./context/mixins/MaterialsSetContextMixin";
14
- import type { JobExternalContext } from "./context/providers/by_application/espresso/QEPWXInputDataManager";
14
+ import type { JobExternalContext } from "./context/providers/base/ContextProvider";
15
15
  import { UnitType } from "./enums";
16
16
  import { type WorkflowSchemaMixin } from "./generated/WorkflowSchemaMixin";
17
17
  import Subworkflow from "./Subworkflow";
@@ -16,6 +16,13 @@ export type Domain = "executable" | "important";
16
16
  export type EntityName = "unit" | "subworkflow";
17
17
  /** Minimal bound for provider external context; the full contract is ExternalContext in context/providers/index.ts */
18
18
  export type BaseExternalContext = object;
19
+ /** Application-agnostic external context, set by Workflow / Subworkflow for any provider to consume. */
20
+ export type JobExternalContext = {
21
+ jobHasParent: boolean;
22
+ };
23
+ export type WorkflowExternalContext = {
24
+ workflowHasRelaxation: boolean;
25
+ };
19
26
  /**
20
27
  * Context providers expose three data layers. Keep them separate.
21
28
  *
@@ -3,9 +3,9 @@ import type { JSONSchema7 } from "json-schema";
3
3
  import { type MaterialContextMixin, type MaterialExternalContext } from "../../../mixins/MaterialContextMixin";
4
4
  import { type MaterialsContextMixin, type MaterialsExternalContext } from "../../../mixins/MaterialsContextMixin";
5
5
  import { type MaterialsSetContextMixin, type MaterialsSetExternalContext } from "../../../mixins/MaterialsSetContextMixin";
6
- import type { UnitContext } from "../../base/ContextProvider";
6
+ import type { JobExternalContext, UnitContext, WorkflowExternalContext } from "../../base/ContextProvider";
7
7
  import JSONSchemaDataProvider, { type JinjaExternalContext } from "../../base/JSONSchemaDataProvider";
8
- import { type JobExternalContext, type MethodDataExternalContext, type WorkflowExternalContext } from "./QEPWXInputDataManager";
8
+ import { type MethodDataExternalContext } from "./QEPWXInputDataManager";
9
9
  type Data = QENEBContextProviderSchema;
10
10
  type Schema = InputContextItemSchema & {
11
11
  data: Data;
@@ -3,7 +3,7 @@ import type { AtomicElementValue } from "@mat3ra/made/dist/js/basis/elements";
3
3
  import type { JSONSchema7 } from "json-schema";
4
4
  import { type MaterialContextMixin, type MaterialExternalContext } from "../../../mixins/MaterialContextMixin";
5
5
  import { type MaterialsContextMixin, type MaterialsExternalContext } from "../../../mixins/MaterialsContextMixin";
6
- import type { UnitContext } from "../../base/ContextProvider";
6
+ import type { JobExternalContext, UnitContext, WorkflowExternalContext } from "../../base/ContextProvider";
7
7
  import JSONSchemaDataProvider, { type JinjaExternalContext } from "../../base/JSONSchemaDataProvider";
8
8
  type MethodData = BaseMethod["data"] & {
9
9
  pseudo?: {
@@ -15,12 +15,6 @@ type MethodData = BaseMethod["data"] & {
15
15
  export type MethodDataExternalContext = {
16
16
  methodData?: MethodData;
17
17
  };
18
- export type JobExternalContext = {
19
- jobHasParent: boolean;
20
- };
21
- export type WorkflowExternalContext = {
22
- workflowHasRelaxation: boolean;
23
- };
24
18
  type Data = QEPwxContextProviderSchema;
25
19
  type Schema = InputContextItemSchema & {
26
20
  data: Data;
@@ -1,13 +1,13 @@
1
1
  import type { InputContextItemSchema, NWChemTotalEnergyContextProviderSchema } from "@mat3ra/esse/dist/js/types";
2
2
  import type { JSONSchema7 } from "json-schema";
3
3
  import { type MaterialContextMixin, type MaterialExternalContext } from "../../../mixins/MaterialContextMixin";
4
- import type { UnitContext } from "../../base/ContextProvider";
4
+ import type { JobExternalContext, UnitContext, WorkflowExternalContext } from "../../base/ContextProvider";
5
5
  import JSONSchemaDataProvider, { type JinjaExternalContext } from "../../base/JSONSchemaDataProvider";
6
6
  type Data = NWChemTotalEnergyContextProviderSchema;
7
7
  type Schema = InputContextItemSchema & {
8
8
  data: Data;
9
9
  };
10
- type ExternalContext = JinjaExternalContext & MaterialExternalContext;
10
+ type ExternalContext = JinjaExternalContext & MaterialExternalContext & WorkflowExternalContext & JobExternalContext;
11
11
  interface NWChemInputDataManager extends MaterialContextMixin {
12
12
  }
13
13
  declare class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, ExternalContext> {
@@ -15,6 +15,7 @@ declare class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, Exte
15
15
  readonly domain: "executable";
16
16
  readonly entityName: "unit";
17
17
  isEdited: boolean;
18
+ workflowHasRelaxation: boolean;
18
19
  static createFromUnitContext(unitContext: UnitContext, externalContext: ExternalContext): NWChemInputDataManager;
19
20
  readonly contextProviderName: "nwchem-total-energy";
20
21
  readonly jsonSchema: JSONSchema7;
@@ -30,6 +31,7 @@ declare class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, Exte
30
31
  ATOMIC_SPECIES: string;
31
32
  FUNCTIONAL: string;
32
33
  CARTESIAN: boolean;
34
+ RESTART: boolean;
33
35
  contextProviderName: "nwchem-total-energy";
34
36
  };
35
37
  }
@@ -21,6 +21,7 @@ class NWChemInputDataManager extends JSONSchemaDataProvider_1.default {
21
21
  this.isEdited = false;
22
22
  this.contextProviderName = "nwchem-total-energy";
23
23
  this.initMaterialContextMixin(externalContext);
24
+ this.workflowHasRelaxation = externalContext.workflowHasRelaxation;
24
25
  const jsonSchema = JSONSchemasInterface_1.default.getSchemaById(jsonSchemaId);
25
26
  if (!jsonSchema) {
26
27
  throw new Error("Failed to get JSON schema");
@@ -32,6 +33,7 @@ class NWChemInputDataManager extends JSONSchemaDataProvider_1.default {
32
33
  */
33
34
  getDefaultData() {
34
35
  const basis = this.material.getBasis();
36
+ const { workflowHasRelaxation } = this;
35
37
  const NTYP = basis.uniqueElements.length;
36
38
  const ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS = basis.atomicPositions.join("\n") || "";
37
39
  const ATOMIC_SPECIES = basis.uniqueElements
@@ -50,6 +52,12 @@ class NWChemInputDataManager extends JSONSchemaDataProvider_1.default {
50
52
  ATOMIC_SPECIES,
51
53
  FUNCTIONAL: "B3LYP",
52
54
  CARTESIAN: basis.toCartesian !== undefined,
55
+ // Continue from the previous unit's RTDB, which carries its optimized geometry. Units of
56
+ // one job share a work_dir, so nwchem.db is already there. Deliberately NOT
57
+ // `jobHasParent || ...` as espresso does: rupy's nwchem prepare_restart symlinks only the
58
+ // parent's perm/, while nwchem.db sits at the work-dir root, so a child job would render
59
+ // `restart` with no database to restart from.
60
+ RESTART: Boolean(workflowHasRelaxation),
53
61
  contextProviderName: this.contextProviderName,
54
62
  };
55
63
  }
@@ -3,11 +3,11 @@ import type { ApplicationExternalContext } from "../mixins/ApplicationContextMix
3
3
  import type { MaterialExternalContext } from "../mixins/MaterialContextMixin";
4
4
  import type { MaterialsExternalContext } from "../mixins/MaterialsContextMixin";
5
5
  import type { MaterialsSetExternalContext } from "../mixins/MaterialsSetContextMixin";
6
- import type { UnitContext } from "./base/ContextProvider";
6
+ import type { JobExternalContext, UnitContext, WorkflowExternalContext } from "./base/ContextProvider";
7
7
  import type { JinjaExternalContext } from "./base/JSONSchemaDataProvider";
8
8
  import BoundaryConditionsFormDataManager from "./BoundaryConditionsFormDataManager";
9
9
  import QENEBInputDataManager from "./by_application/espresso/QENEBInputDataManager";
10
- import QEPWXInputDataManager, { type JobExternalContext, type MethodDataExternalContext, type WorkflowExternalContext } from "./by_application/espresso/QEPWXInputDataManager";
10
+ import QEPWXInputDataManager, { type MethodDataExternalContext } from "./by_application/espresso/QEPWXInputDataManager";
11
11
  import NWChemInputDataManager from "./by_application/nwchem/NWChemInputDataManager";
12
12
  import VASPInputDataManager from "./by_application/vasp/VASPInputDataManager";
13
13
  import VASPNEBInputDataManager from "./by_application/vasp/VASPNEBInputDataManager";
@@ -29,14 +29,25 @@ declare class ExecutionUnit extends BaseUnit<Schema> implements Schema {
29
29
  * ApplicationRegistry.
30
30
  */
31
31
  private isPersistedInputItemCompatible;
32
+ /**
33
+ * Pair each input slot of the current flavor with a row persisted in saved workflow JSON. A slot
34
+ * first claims the persisted row carrying the same `template.name`; slots still unpaired then fall
35
+ * back to the row in the same position, which is how a row the user renamed in the UI is still
36
+ * recognized. Every persisted row is claimed by at most one slot, so a flavor with more input files
37
+ * than the saved JSON has rows cannot end up with the same file twice.
38
+ */
39
+ private matchPersistedInput;
32
40
  /**
33
41
  * Build `inputInstances` from the current flavor’s defaults (`ApplicationRegistry#getInput(application, flavor)`),
34
- * merged with persisted `this.input` from saved workflow JSON. For each input slot from the registry we
35
- * prefer a compatible persisted row matched by `template.name`, else by index; incompatible or missing
36
- * rows use the registry template. `render()` then serializes from these instances into `this.input`, so UI
37
- * and saved JSON stay aligned when Subworkflow re-serializes units after render.
42
+ * merged with persisted `this.input` from saved workflow JSON (see `matchPersistedInput`); incompatible or
43
+ * missing rows use the registry template. `render()` then serializes from these instances into `this.input`,
44
+ * so UI and saved JSON stay aligned when Subworkflow re-serializes units after render. Pass
45
+ * `reusePersistedInput: false` to ignore `this.input` and take every slot from the registry, as `setFlavor`
46
+ * does when the flavor changes and the persisted rows describe the previous flavor's files.
38
47
  */
39
- setDefaultInput(): void;
48
+ setDefaultInput({ reusePersistedInput }?: {
49
+ reusePersistedInput?: boolean;
50
+ }): void;
40
51
  render(externalContext: ExternalContext, convergence?: ConvergenceParameter): void;
41
52
  private getContextProvidersInstances;
42
53
  savePersistentContext(): void;
@@ -69,14 +69,21 @@ class ExecutionUnit extends BaseUnit_1.default {
69
69
  this.defaultPostProcessors = flavor.postProcessors;
70
70
  // flavor is missing on the first run, so do not use getter this.flavor with requiredProperty
71
71
  const previousFlavor = this._json.flavor;
72
- if ((previousFlavor === null || previousFlavor === void 0 ? void 0 : previousFlavor.name) !== flavor.name) {
72
+ const isSameFlavor = (previousFlavor === null || previousFlavor === void 0 ? void 0 : previousFlavor.name) === flavor.name;
73
+ if (!isSameFlavor) {
73
74
  this.results = flavor.results;
74
75
  this.monitors = flavor.monitors;
75
76
  this.preProcessors = flavor.preProcessors;
76
77
  this.postProcessors = flavor.postProcessors;
77
78
  }
78
79
  this.flavor = flavor;
79
- this.setDefaultInput();
80
+ // Persisted input belongs to the flavor it was saved with: another flavor's files are a
81
+ // different set of templates under names that often collide (`script.py`,
82
+ // `requirements.txt`), so keeping them would silently serve the previous flavor's content
83
+ // - and leave slots the new flavor adds (e.g. `utils.py`) to be filled by whatever row sits
84
+ // in the same position. Reuse persisted rows only when the flavor is unchanged, i.e. when
85
+ // reconstructing a unit from saved JSON rather than switching flavor in the UI.
86
+ this.setDefaultInput({ reusePersistedInput: isSameFlavor });
80
87
  }
81
88
  /**
82
89
  * Persisted `input[].template` must match the current application/executable (and optional
@@ -95,19 +102,44 @@ class ExecutionUnit extends BaseUnit_1.default {
95
102
  }
96
103
  return true;
97
104
  }
105
+ /**
106
+ * Pair each input slot of the current flavor with a row persisted in saved workflow JSON. A slot
107
+ * first claims the persisted row carrying the same `template.name`; slots still unpaired then fall
108
+ * back to the row in the same position, which is how a row the user renamed in the UI is still
109
+ * recognized. Every persisted row is claimed by at most one slot, so a flavor with more input files
110
+ * than the saved JSON has rows cannot end up with the same file twice.
111
+ */
112
+ matchPersistedInput(driverTemplates) {
113
+ const persisted = Array.isArray(this.input) ? this.input : [];
114
+ const claimedIndices = new Set();
115
+ const matchedIndices = driverTemplates.map((driverTemplate) => {
116
+ const index = persisted.findIndex((item, i) => { var _a; return !claimedIndices.has(i) && ((_a = item === null || item === void 0 ? void 0 : item.template) === null || _a === void 0 ? void 0 : _a.name) === driverTemplate.name; });
117
+ if (index !== -1)
118
+ claimedIndices.add(index);
119
+ return index;
120
+ });
121
+ return matchedIndices.map((matchedIndex, index) => {
122
+ if (matchedIndex !== -1)
123
+ return persisted[matchedIndex];
124
+ if (claimedIndices.has(index))
125
+ return undefined;
126
+ claimedIndices.add(index);
127
+ return persisted[index];
128
+ });
129
+ }
98
130
  /**
99
131
  * Build `inputInstances` from the current flavor’s defaults (`ApplicationRegistry#getInput(application, flavor)`),
100
- * merged with persisted `this.input` from saved workflow JSON. For each input slot from the registry we
101
- * prefer a compatible persisted row matched by `template.name`, else by index; incompatible or missing
102
- * rows use the registry template. `render()` then serializes from these instances into `this.input`, so UI
103
- * and saved JSON stay aligned when Subworkflow re-serializes units after render.
132
+ * merged with persisted `this.input` from saved workflow JSON (see `matchPersistedInput`); incompatible or
133
+ * missing rows use the registry template. `render()` then serializes from these instances into `this.input`,
134
+ * so UI and saved JSON stay aligned when Subworkflow re-serializes units after render. Pass
135
+ * `reusePersistedInput: false` to ignore `this.input` and take every slot from the registry, as `setFlavor`
136
+ * does when the flavor changes and the persisted rows describe the previous flavor's files.
104
137
  */
105
- setDefaultInput() {
138
+ setDefaultInput({ reusePersistedInput = true } = {}) {
106
139
  const driverTemplates = new standata_1.ApplicationRegistry().getInput(this.application, this.flavor);
107
- const persisted = Array.isArray(this.input) ? this.input : [];
140
+ const persistedItems = reusePersistedInput ? this.matchPersistedInput(driverTemplates) : [];
108
141
  this.inputInstances = driverTemplates.map((driverTemplate, index) => {
109
- var _a;
110
- const persistedItem = (_a = persisted.find((item) => { var _a; return ((_a = item === null || item === void 0 ? void 0 : item.template) === null || _a === void 0 ? void 0 : _a.name) === driverTemplate.name; })) !== null && _a !== void 0 ? _a : persisted[index];
142
+ const persistedItem = persistedItems[index];
111
143
  if (persistedItem && this.isPersistedInputItemCompatible(persistedItem)) {
112
144
  return new ExecutionUnitInput_1.default(persistedItem);
113
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mat3ra/wode",
3
- "version": "2026.8.26-1",
3
+ "version": "2026.8.29-0",
4
4
  "description": "WOrkflow DEfinitions",
5
5
  "scripts": {
6
6
  "test": "mocha --recursive --bail --require ts-node/register 'tests/js/**/*.ts'",
@@ -27,7 +27,7 @@ import { ApplicationRegistry, setUnitLinks } from "@mat3ra/standata";
27
27
  import { Utils } from "@mat3ra/utils";
28
28
 
29
29
  import type { AssignmentContext, ExternalContext } from "./context/providers";
30
- import type { WorkflowExternalContext } from "./context/providers/by_application/espresso/QEPWXInputDataManager";
30
+ import type { WorkflowExternalContext } from "./context/providers/base/ContextProvider";
31
31
  import { createConvergenceParameter } from "./convergence/factory";
32
32
  import { UnitTag, UnitType } from "./enums";
33
33
  import {
@@ -31,7 +31,7 @@ import { Utils } from "@mat3ra/utils";
31
31
  import type { MaterialExternalContext } from "./context/mixins/MaterialContextMixin";
32
32
  import type { MaterialsExternalContext } from "./context/mixins/MaterialsContextMixin";
33
33
  import type { MaterialsSetExternalContext } from "./context/mixins/MaterialsSetContextMixin";
34
- import type { JobExternalContext } from "./context/providers/by_application/espresso/QEPWXInputDataManager";
34
+ import type { JobExternalContext } from "./context/providers/base/ContextProvider";
35
35
  import { UnitType } from "./enums";
36
36
  import { type WorkflowSchemaMixin, workflowSchemaMixin } from "./generated/WorkflowSchemaMixin";
37
37
  import Subworkflow from "./Subworkflow";
@@ -30,6 +30,15 @@ export type EntityName = "unit" | "subworkflow";
30
30
  /** Minimal bound for provider external context; the full contract is ExternalContext in context/providers/index.ts */
31
31
  export type BaseExternalContext = object;
32
32
 
33
+ /** Application-agnostic external context, set by Workflow / Subworkflow for any provider to consume. */
34
+ export type JobExternalContext = {
35
+ jobHasParent: boolean;
36
+ };
37
+
38
+ export type WorkflowExternalContext = {
39
+ workflowHasRelaxation: boolean;
40
+ };
41
+
33
42
  const nunjucksEnvironment = setupNunjucksEnvironment(new nunjucks.Environment());
34
43
 
35
44
  const parseNumericStrings = (_key: string, value: unknown) => {
@@ -17,15 +17,15 @@ import materialsSetContextMixin, {
17
17
  type MaterialsSetContextMixin,
18
18
  type MaterialsSetExternalContext,
19
19
  } from "../../../mixins/MaterialsSetContextMixin";
20
- import type { UnitContext } from "../../base/ContextProvider";
20
+ import type {
21
+ JobExternalContext,
22
+ UnitContext,
23
+ WorkflowExternalContext,
24
+ } from "../../base/ContextProvider";
21
25
  import JSONSchemaDataProvider, {
22
26
  type JinjaExternalContext,
23
27
  } from "../../base/JSONSchemaDataProvider";
24
- import QEPWXInputDataManager, {
25
- type JobExternalContext,
26
- type MethodDataExternalContext,
27
- type WorkflowExternalContext,
28
- } from "./QEPWXInputDataManager";
28
+ import QEPWXInputDataManager, { type MethodDataExternalContext } from "./QEPWXInputDataManager";
29
29
 
30
30
  const jsonSchemaId = "context-providers-directory/by-application/qe-neb-context-provider";
31
31
 
@@ -18,7 +18,11 @@ import materialsContextMixin, {
18
18
  type MaterialsContextMixin,
19
19
  type MaterialsExternalContext,
20
20
  } from "../../../mixins/MaterialsContextMixin";
21
- import type { UnitContext } from "../../base/ContextProvider";
21
+ import type {
22
+ JobExternalContext,
23
+ UnitContext,
24
+ WorkflowExternalContext,
25
+ } from "../../base/ContextProvider";
22
26
  import JSONSchemaDataProvider, {
23
27
  type JinjaExternalContext,
24
28
  } from "../../base/JSONSchemaDataProvider";
@@ -32,14 +36,6 @@ export type MethodDataExternalContext = {
32
36
  methodData?: MethodData;
33
37
  };
34
38
 
35
- export type JobExternalContext = {
36
- jobHasParent: boolean;
37
- };
38
-
39
- export type WorkflowExternalContext = {
40
- workflowHasRelaxation: boolean;
41
- };
42
-
43
39
  type Data = QEPwxContextProviderSchema;
44
40
  type Schema = InputContextItemSchema & { data: Data };
45
41
  type ExternalContext = JinjaExternalContext &
@@ -10,14 +10,21 @@ import materialContextMixin, {
10
10
  type MaterialContextMixin,
11
11
  type MaterialExternalContext,
12
12
  } from "../../../mixins/MaterialContextMixin";
13
- import type { UnitContext } from "../../base/ContextProvider";
13
+ import type {
14
+ JobExternalContext,
15
+ UnitContext,
16
+ WorkflowExternalContext,
17
+ } from "../../base/ContextProvider";
14
18
  import JSONSchemaDataProvider, {
15
19
  type JinjaExternalContext,
16
20
  } from "../../base/JSONSchemaDataProvider";
17
21
 
18
22
  type Data = NWChemTotalEnergyContextProviderSchema;
19
23
  type Schema = InputContextItemSchema & { data: Data };
20
- type ExternalContext = JinjaExternalContext & MaterialExternalContext;
24
+ type ExternalContext = JinjaExternalContext &
25
+ MaterialExternalContext &
26
+ WorkflowExternalContext &
27
+ JobExternalContext;
21
28
 
22
29
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
23
30
  interface NWChemInputDataManager extends MaterialContextMixin {}
@@ -34,6 +41,8 @@ class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, ExternalCont
34
41
 
35
42
  isEdited = false;
36
43
 
44
+ workflowHasRelaxation: boolean;
45
+
37
46
  static createFromUnitContext(unitContext: UnitContext, externalContext: ExternalContext) {
38
47
  const contextItem = this.findContextItem<Schema>(unitContext, "input");
39
48
 
@@ -48,6 +57,8 @@ class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, ExternalCont
48
57
  super(config, externalContext);
49
58
  this.initMaterialContextMixin(externalContext);
50
59
 
60
+ this.workflowHasRelaxation = externalContext.workflowHasRelaxation;
61
+
51
62
  const jsonSchema = JSONSchemasInterface.getSchemaById(jsonSchemaId);
52
63
 
53
64
  if (!jsonSchema) {
@@ -62,6 +73,7 @@ class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, ExternalCont
62
73
  */
63
74
  getDefaultData() {
64
75
  const basis = this.material.getBasis();
76
+ const { workflowHasRelaxation } = this;
65
77
 
66
78
  const NTYP = basis.uniqueElements.length;
67
79
  const ATOMIC_POSITIONS_WITHOUT_CONSTRAINTS = basis.atomicPositions.join("\n") || "";
@@ -83,6 +95,12 @@ class NWChemInputDataManager extends JSONSchemaDataProvider<Schema, ExternalCont
83
95
  ATOMIC_SPECIES,
84
96
  FUNCTIONAL: "B3LYP",
85
97
  CARTESIAN: basis.toCartesian !== undefined,
98
+ // Continue from the previous unit's RTDB, which carries its optimized geometry. Units of
99
+ // one job share a work_dir, so nwchem.db is already there. Deliberately NOT
100
+ // `jobHasParent || ...` as espresso does: rupy's nwchem prepare_restart symlinks only the
101
+ // parent's perm/, while nwchem.db sits at the work-dir root, so a child job would render
102
+ // `restart` with no database to restart from.
103
+ RESTART: Boolean(workflowHasRelaxation),
86
104
  contextProviderName: this.contextProviderName,
87
105
  };
88
106
  }
@@ -4,14 +4,16 @@ import type { ApplicationExternalContext } from "../mixins/ApplicationContextMix
4
4
  import type { MaterialExternalContext } from "../mixins/MaterialContextMixin";
5
5
  import type { MaterialsExternalContext } from "../mixins/MaterialsContextMixin";
6
6
  import type { MaterialsSetExternalContext } from "../mixins/MaterialsSetContextMixin";
7
- import type { UnitContext } from "./base/ContextProvider";
7
+ import type {
8
+ JobExternalContext,
9
+ UnitContext,
10
+ WorkflowExternalContext,
11
+ } from "./base/ContextProvider";
8
12
  import type { JinjaExternalContext } from "./base/JSONSchemaDataProvider";
9
13
  import BoundaryConditionsFormDataManager from "./BoundaryConditionsFormDataManager";
10
14
  import QENEBInputDataManager from "./by_application/espresso/QENEBInputDataManager";
11
15
  import QEPWXInputDataManager, {
12
- type JobExternalContext,
13
16
  type MethodDataExternalContext,
14
- type WorkflowExternalContext,
15
17
  } from "./by_application/espresso/QEPWXInputDataManager";
16
18
  import NWChemInputDataManager from "./by_application/nwchem/NWChemInputDataManager";
17
19
  import VASPInputDataManager from "./by_application/vasp/VASPInputDataManager";
@@ -1,6 +1,10 @@
1
1
  import { type Taggable } from "@mat3ra/code/dist/js/entity/mixins/TaggableMixin";
2
2
  import JSONSchemasInterface from "@mat3ra/esse/dist/js/esse/JSONSchemasInterface";
3
- import type { ExecutionUnitInputItemSchema, ExecutionUnitSchema } from "@mat3ra/esse/dist/js/types";
3
+ import type {
4
+ ExecutionUnitInputItemSchema,
5
+ ExecutionUnitSchema,
6
+ TemplateSchema,
7
+ } from "@mat3ra/esse/dist/js/types";
4
8
  import { ApplicationRegistry, applicationVersionSatisfiesSupportedRange } from "@mat3ra/standata";
5
9
  import { Utils } from "@mat3ra/utils";
6
10
 
@@ -111,8 +115,9 @@ class ExecutionUnit extends BaseUnit<Schema> implements Schema {
111
115
 
112
116
  // flavor is missing on the first run, so do not use getter this.flavor with requiredProperty
113
117
  const previousFlavor = this._json.flavor;
118
+ const isSameFlavor = previousFlavor?.name === flavor.name;
114
119
 
115
- if (previousFlavor?.name !== flavor.name) {
120
+ if (!isSameFlavor) {
116
121
  this.results = flavor.results;
117
122
  this.monitors = flavor.monitors;
118
123
  this.preProcessors = flavor.preProcessors;
@@ -120,7 +125,13 @@ class ExecutionUnit extends BaseUnit<Schema> implements Schema {
120
125
  }
121
126
 
122
127
  this.flavor = flavor;
123
- this.setDefaultInput();
128
+ // Persisted input belongs to the flavor it was saved with: another flavor's files are a
129
+ // different set of templates under names that often collide (`script.py`,
130
+ // `requirements.txt`), so keeping them would silently serve the previous flavor's content
131
+ // - and leave slots the new flavor adds (e.g. `utils.py`) to be filled by whatever row sits
132
+ // in the same position. Reuse persisted rows only when the flavor is unchanged, i.e. when
133
+ // reconstructing a unit from saved JSON rather than switching flavor in the UI.
134
+ this.setDefaultInput({ reusePersistedInput: isSameFlavor });
124
135
  }
125
136
 
126
137
  /**
@@ -150,21 +161,53 @@ class ExecutionUnit extends BaseUnit<Schema> implements Schema {
150
161
  return true;
151
162
  }
152
163
 
164
+ /**
165
+ * Pair each input slot of the current flavor with a row persisted in saved workflow JSON. A slot
166
+ * first claims the persisted row carrying the same `template.name`; slots still unpaired then fall
167
+ * back to the row in the same position, which is how a row the user renamed in the UI is still
168
+ * recognized. Every persisted row is claimed by at most one slot, so a flavor with more input files
169
+ * than the saved JSON has rows cannot end up with the same file twice.
170
+ */
171
+ private matchPersistedInput(
172
+ driverTemplates: TemplateSchema[],
173
+ ): (ExecutionUnitInputItemSchema | undefined)[] {
174
+ const persisted = Array.isArray(this.input) ? this.input : [];
175
+ const claimedIndices = new Set<number>();
176
+
177
+ const matchedIndices = driverTemplates.map((driverTemplate) => {
178
+ const index = persisted.findIndex(
179
+ (item, i) => !claimedIndices.has(i) && item?.template?.name === driverTemplate.name,
180
+ );
181
+
182
+ if (index !== -1) claimedIndices.add(index);
183
+
184
+ return index;
185
+ });
186
+
187
+ return matchedIndices.map((matchedIndex, index) => {
188
+ if (matchedIndex !== -1) return persisted[matchedIndex];
189
+ if (claimedIndices.has(index)) return undefined;
190
+
191
+ claimedIndices.add(index);
192
+
193
+ return persisted[index];
194
+ });
195
+ }
196
+
153
197
  /**
154
198
  * Build `inputInstances` from the current flavor’s defaults (`ApplicationRegistry#getInput(application, flavor)`),
155
- * merged with persisted `this.input` from saved workflow JSON. For each input slot from the registry we
156
- * prefer a compatible persisted row matched by `template.name`, else by index; incompatible or missing
157
- * rows use the registry template. `render()` then serializes from these instances into `this.input`, so UI
158
- * and saved JSON stay aligned when Subworkflow re-serializes units after render.
199
+ * merged with persisted `this.input` from saved workflow JSON (see `matchPersistedInput`); incompatible or
200
+ * missing rows use the registry template. `render()` then serializes from these instances into `this.input`,
201
+ * so UI and saved JSON stay aligned when Subworkflow re-serializes units after render. Pass
202
+ * `reusePersistedInput: false` to ignore `this.input` and take every slot from the registry, as `setFlavor`
203
+ * does when the flavor changes and the persisted rows describe the previous flavor's files.
159
204
  */
160
- setDefaultInput() {
205
+ setDefaultInput({ reusePersistedInput = true }: { reusePersistedInput?: boolean } = {}) {
161
206
  const driverTemplates = new ApplicationRegistry().getInput(this.application, this.flavor);
162
- const persisted = Array.isArray(this.input) ? this.input : [];
207
+ const persistedItems = reusePersistedInput ? this.matchPersistedInput(driverTemplates) : [];
163
208
 
164
209
  this.inputInstances = driverTemplates.map((driverTemplate, index) => {
165
- const persistedItem =
166
- persisted.find((item) => item?.template?.name === driverTemplate.name) ??
167
- persisted[index];
210
+ const persistedItem = persistedItems[index];
168
211
 
169
212
  if (persistedItem && this.isPersistedInputItemCompatible(persistedItem)) {
170
213
  return new ExecutionUnitInput(persistedItem);