Skip to content

Commit 4bf8812

Browse files
committed
Added a new way to compute the energy and forces using calculators with CellConstructor
This has the big advantage of enabling the MPI run from a python script. And avoid messing with ASE MPI parallel reading
1 parent d1092d2 commit 4bf8812

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

Modules/Ensemble.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2958,6 +2958,7 @@ def get_energy_forces(self, ase_calculator, compute_stress = True, stress_numeri
29582958
----------
29592959
ase_calculator : ase.calculator
29602960
The ASE interface to the calculator to run the calculation.
2961+
also a CellConstructor calculator is accepted
29612962
compute_stress : bool
29622963
If true, the stress is requested from the ASE calculator. Be shure
29632964
that the calculator you provide supports stress calculation
@@ -3052,10 +3053,10 @@ def get_energy_forces(self, ase_calculator, compute_stress = True, stress_numeri
30523053

30533054

30543055
struct = structures[i]
3055-
atms = struct.get_ase_atoms()
3056+
#atms = struct.get_ase_atoms()
30563057

30573058
# Setup the ASE calculator
3058-
atms.set_calculator(ase_calculator)
3059+
#atms.set_calculator(ase_calculator)
30593060

30603061

30613062
# Print the status
@@ -3068,15 +3069,21 @@ def get_energy_forces(self, ase_calculator, compute_stress = True, stress_numeri
30683069
count_fails = 0
30693070
while run:
30703071
try:
3071-
energy = atms.get_total_energy() / Rydberg # eV => Ry
3072-
# Get energy, forces (and stress)
3073-
energy = atms.get_total_energy() / Rydberg # eV => Ry
3074-
forces_ = atms.get_forces() / Rydberg # eV / A => Ry / A
3072+
results = CC.calculators.get_results(ase_calculator, struct, get_stress = compute_stress)
3073+
energy = results["energy"] / Rydberg # eV => Ry
3074+
forces_ = results["forces"] / Rydberg
3075+
30753076
if compute_stress:
3076-
if not stress_numerical:
3077-
stress[9*i0 : 9*i0 + 9] = -atms.get_stress(False).reshape(9) * Bohr**3 / Rydberg # ev/A^3 => Ry/bohr
3078-
else:
3079-
stress[9*i0 : 9*i0 + 9] = -ase_calculator.calculate_numerical_stress(atms, voigt = False).ravel()* Bohr**3 / Rydberg
3077+
stress[9*i0 : 9*i0 + 9] = -results["stress"].reshape(9)* Bohr**3 / Rydberg
3078+
#energy = atms.get_total_energy() / Rydberg # eV => Ry
3079+
# Get energy, forces (and stress)
3080+
#energy = atms.get_total_energy() / Rydberg # eV => Ry
3081+
#forces_ = atms.get_forces() / Rydberg # eV / A => Ry / A
3082+
#if compute_stress:
3083+
# if not stress_numerical:
3084+
# stress[9*i0 : 9*i0 + 9] = -atms.get_stress(False).reshape(9) * Bohr**3 / Rydberg # ev/A^3 => Ry/bohr
3085+
# else:
3086+
# stress[9*i0 : 9*i0 + 9] = -ase_calculator.calculate_numerical_stress(atms, voigt = False).ravel()* Bohr**3 / Rydberg
30803087

30813088
# Copy into the ensemble array
30823089
energies[i0] = energy

0 commit comments

Comments
 (0)