diff --git a/mala/descriptors/atomic_density.py b/mala/descriptors/atomic_density.py index dd593111b..cda944b13 100755 --- a/mala/descriptors/atomic_density.py +++ b/mala/descriptors/atomic_density.py @@ -185,7 +185,6 @@ def __calculate_lammps(self, outdir, **kwargs): # Do the LAMMPS calculation and clean up. lmp.file(self.parameters.lammps_compute_file) - self._clean_calculation(keep_logs) # Extract the data. nrows_ggrid = extract_compute_np( @@ -209,7 +208,7 @@ def __calculate_lammps(self, outdir, **kwargs): array_shape=(nrows_ggrid, ncols_ggrid), use_fp64=use_fp64, ) - lmp.close() + self._clean_calculation(lmp, keep_logs) # In comparison to SNAP, the atomic density always returns # in the "local mode". Thus we have to make some slight adjustments diff --git a/mala/descriptors/bispectrum.py b/mala/descriptors/bispectrum.py index fc2bd522d..66860b29b 100755 --- a/mala/descriptors/bispectrum.py +++ b/mala/descriptors/bispectrum.py @@ -184,7 +184,6 @@ def __calculate_lammps(self, outdir, **kwargs): # Do the LAMMPS calculation and clean up. lmp.file(self.parameters.lammps_compute_file) - self._clean_calculation(keep_logs) # Set things not accessible from LAMMPS # First 3 cols are x, y, z, coords @@ -228,7 +227,7 @@ def __calculate_lammps(self, outdir, **kwargs): array_shape=(nrows_local, ncols_local), use_fp64=use_fp64, ) - lmp.close() + self._clean_calculation(lmp, keep_logs) # Copy the grid dimensions only at the end. self.grid_dimensions = [nx, ny, nz] @@ -244,7 +243,7 @@ def __calculate_lammps(self, outdir, **kwargs): (nz, ny, nx, self.fingerprint_length), use_fp64=use_fp64, ) - lmp.close() + self._clean_calculation(lmp, keep_logs) # switch from x-fastest to z-fastest order (swaps 0th and 2nd # dimension) diff --git a/mala/descriptors/descriptor.py b/mala/descriptors/descriptor.py index 5fa9a78d7..bf74f9ca5 100644 --- a/mala/descriptors/descriptor.py +++ b/mala/descriptors/descriptor.py @@ -820,7 +820,8 @@ def _setup_lammps(self, nx, ny, nz, lammps_dict): return lmp - def _clean_calculation(self, keep_logs): + def _clean_calculation(self, lmp, keep_logs): + lmp.close() if not keep_logs: if get_rank() == 0: os.remove(self.lammps_temporary_log) diff --git a/mala/descriptors/minterpy_descriptors.py b/mala/descriptors/minterpy_descriptors.py index 3b694be16..2964fb494 100755 --- a/mala/descriptors/minterpy_descriptors.py +++ b/mala/descriptors/minterpy_descriptors.py @@ -171,14 +171,15 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): ) # Create LAMMPS instance. - lammps_dict = {} - lammps_dict["sigma"] = self.parameters.atomic_density_sigma - lammps_dict["rcutfac"] = self.parameters.atomic_density_cutoff + lammps_dict = { + "sigma": self.parameters.atomic_density_sigma, + "rcutfac": self.parameters.atomic_density_cutoff, + } self.lammps_temporary_log = os.path.join( outdir, "lammps_bgrid_log_" + self.calculation_timestamp + ".tmp", ) - lmp = self._setup_lammps(nx, ny, nz, lammps_dict, log_path) + lmp = self._setup_lammps(nx, ny, nz, lammps_dict) # For now the file is chosen automatically, because this is used # mostly under the hood anyway. @@ -199,7 +200,6 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): # Do the LAMMPS calculation and clean up. lmp.file(self.parameters.lammps_compute_file) - self._clean_calculation(keep_logs) # Extract the data. nrows_ggrid = extract_compute_np( @@ -223,7 +223,7 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): array_shape=(nrows_ggrid, ncols_ggrid), ) - lmp.close() + self._clean_calculation(lmp, keep_logs) gaussian_descriptors_np = gaussian_descriptors_np.reshape( (