Skip to content

Commit 68340e2

Browse files
Merge pull request #158 from bastonero/fix/aiida-ensemble
Fix: props not computed are not poped (AiiDA)
2 parents 0803ec9 + f5e18b9 commit 68340e2

6 files changed

Lines changed: 14805 additions & 23 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ scf_population*.dat
6464
frequencies*.*
6565
timer.json
6666
minim.dat
67+
otf_run*
68+
disp_*
69+
_data_tmp_
6770

6871
# Translations
6972
*.mo

Modules/aiida_ensemble.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,17 @@ def compute_ensemble(
5959
if self.force_computed is None:
6060
self.force_computed = np.array([False] * self.N, dtype=bool)
6161

62-
n_calcs = np.sum(self.force_computed.astype(int))
63-
computing_ensemble = self
64-
6562
self.has_stress = True # by default we calculate stresses with the `get_builder_from_protocol`
6663
if overrides:
6764
try:
6865
tstress = overrides['pw']['parameters']['CONTROL']['tstress']
6966
self.has_stress = tstress
7067
except KeyError:
7168
pass
72-
73-
# Check wheter compute the whole ensemble, or just a small part
74-
should_i_merge = False
75-
if n_calcs != self.N:
76-
should_i_merge = True
77-
computing_ensemble = self.get_noncomputed()
78-
self.remove_noncomputed()
7969

8070
# ============= AIIDA SECTION ============= #
8171
workchains = submit_and_get_workchains(
82-
structures=computing_ensemble.structures,
72+
structures=self.structures,
8373
pw_code=pw_code,
8474
temperature=self.current_T,
8575
protocol=protocol,
@@ -93,28 +83,33 @@ def compute_ensemble(
9383

9484
workchains_copy = copy(workchains)
9585
while(workchains_copy):
96-
workchains_copy = get_running_workchains(workchains_copy, computing_ensemble.force_computed)
86+
workchains_copy = get_running_workchains(workchains_copy, self.force_computed)
9787
if workchains_copy:
9888
time.sleep(60) # wait before checking again
9989

100-
for i, is_computed in enumerate(computing_ensemble.force_computed):
90+
for i, is_computed in enumerate(self.force_computed):
10191
if is_computed:
10292
out = workchains[i].outputs
103-
computing_ensemble.energies[i] = out.output_parameters.dict.energy / CONSTANTS.ry_to_ev
104-
computing_ensemble.forces[i] = out.output_trajectory.get_array('forces')[-1] / CONSTANTS.ry_to_ev
93+
self.energies[i] = out.output_parameters.dict.energy / CONSTANTS.ry_to_ev
94+
self.forces[i] = out.output_trajectory.get_array('forces')[-1] / CONSTANTS.ry_to_ev
10595
if self.has_stress:
106-
computing_ensemble.stresses[i] = out.output_trajectory.get_array('stress')[-1] * gpa_to_rybohr3
96+
self.stresses[i] = out.output_trajectory.get_array('stress')[-1] * gpa_to_rybohr3
10797
# ============= AIIDA SECTION ============= #
10898

10999
if self.has_stress:
110-
computing_ensemble.stress_computed = copy(computing_ensemble.force_computed)
100+
self.stress_computed = copy(self.force_computed)
111101

112-
print("CE BEFORE MERGE:", len(self.force_computed))
102+
self._clean_runs()
113103

114-
if should_i_merge:
115-
# Remove the noncomputed ensemble from here, and merge
116-
self.merge(computing_ensemble)
117-
print("CE AFTER MERGE:", len(self.force_computed))
104+
def _clean_runs(self) -> None:
105+
"""Clean the failed runs and print summary."""
106+
n_calcs = np.sum(self.force_computed.astype(int))
107+
print('=============== SUMMARY AIIDA CALCULATIONS =============== \n')
108+
print('Total structures included: ', n_calcs)
109+
print('Structures not included : ', self.N-n_calcs, '\n')
110+
print('===================== END OF SUMMARY ===================== \n')
111+
if n_calcs != self.N:
112+
self.remove_noncomputed()
118113

119114

120115
def get_running_workchains(workchains: list, success: list[bool]) -> list:

0 commit comments

Comments
 (0)