From e72facfd023e8ebbed6568363f057a92be031e84 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Thu, 30 May 2024 15:28:58 +0200 Subject: [PATCH 1/5] Implemented basic timestamping of descriptor calculation --- mala/descriptors/atomic_density.py | 18 +++++++---- mala/descriptors/bispectrum.py | 19 +++++++---- mala/descriptors/descriptor.py | 41 +++++++++++++++++++++--- mala/descriptors/minterpy_descriptors.py | 19 +++++++---- mala/targets/target.py | 2 +- 5 files changed, 73 insertions(+), 26 deletions(-) diff --git a/mala/descriptors/atomic_density.py b/mala/descriptors/atomic_density.py index a81c1d384..f11252f94 100755 --- a/mala/descriptors/atomic_density.py +++ b/mala/descriptors/atomic_density.py @@ -134,9 +134,12 @@ def __calculate_lammps(self, outdir, **kwargs): use_fp64 = kwargs.get("use_fp64", False) return_directly = kwargs.get("return_directly", False) + keep_logs = kwargs.get("keep_logs", False) lammps_format = "lammps-data" - ase_out_path = os.path.join(outdir, "lammps_input.tmp") + ase_out_path = os.path.join( + outdir, "lammps_input_" + self.calculation_timestamp + ".tmp" + ) ase.io.write(ase_out_path, self.atoms, format=lammps_format) nx = self.grid_dimensions[0] @@ -155,14 +158,11 @@ def __calculate_lammps(self, outdir, **kwargs): lammps_dict["sigma"] = self.parameters.atomic_density_sigma lammps_dict["rcutfac"] = self.parameters.atomic_density_cutoff lammps_dict["atom_config_fname"] = ase_out_path - lmp = self._setup_lammps( - nx, - ny, - nz, + log_path = os.path.join( outdir, - lammps_dict, - log_file_name="lammps_ggrid_log.tmp", + "lammps_ggrid_log_" + self.calculation_timestamp + ".tmp", ) + lmp = self._setup_lammps(nx, ny, nz, lammps_dict, log_path) # For now the file is chosen automatically, because this is used # mostly under the hood anyway. @@ -176,6 +176,10 @@ def __calculate_lammps(self, outdir, **kwargs): runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") lmp.file(runfile) + if not keep_logs: + os.remove(ase_out_path) + os.remove(log_path) + # Extract the data. nrows_ggrid = extract_compute_np( lmp, diff --git a/mala/descriptors/bispectrum.py b/mala/descriptors/bispectrum.py index 3f75ecc8e..baac8fa13 100755 --- a/mala/descriptors/bispectrum.py +++ b/mala/descriptors/bispectrum.py @@ -138,9 +138,12 @@ def __calculate_lammps(self, outdir, **kwargs): from lammps import constants as lammps_constants use_fp64 = kwargs.get("use_fp64", False) + keep_logs = kwargs.get("keep_logs", False) lammps_format = "lammps-data" - ase_out_path = os.path.join(outdir, "lammps_input.tmp") + ase_out_path = os.path.join( + outdir, "lammps_input_" + self.calculation_timestamp + ".tmp" + ) ase.io.write(ase_out_path, self.atoms, format=lammps_format) nx = self.grid_dimensions[0] @@ -153,14 +156,12 @@ def __calculate_lammps(self, outdir, **kwargs): "rcutfac": self.parameters.bispectrum_cutoff, "atom_config_fname": ase_out_path, } - lmp = self._setup_lammps( - nx, - ny, - nz, + + log_path = os.path.join( outdir, - lammps_dict, - log_file_name="lammps_bgrid_log.tmp", + "lammps_bgrid_log_" + self.calculation_timestamp + ".tmp", ) + lmp = self._setup_lammps(nx, ny, nz, lammps_dict, log_path) # An empty string means that the user wants to use the standard input. # What that is differs depending on serial/parallel execution. @@ -183,6 +184,10 @@ def __calculate_lammps(self, outdir, **kwargs): # Do the LAMMPS calculation. lmp.file(self.parameters.lammps_compute_file) + if not keep_logs: + os.remove(ase_out_path) + os.remove(log_path) + # Set things not accessible from LAMMPS # First 3 cols are x, y, z, coords ncols0 = 3 diff --git a/mala/descriptors/descriptor.py b/mala/descriptors/descriptor.py index 131037ba8..b65cc5221 100644 --- a/mala/descriptors/descriptor.py +++ b/mala/descriptors/descriptor.py @@ -1,6 +1,8 @@ """Base class for all descriptor calculators.""" from abc import abstractmethod +from datetime import datetime +from functools import cached_property import os import ase @@ -155,6 +157,17 @@ def descriptors_contain_xyz(self): def descriptors_contain_xyz(self, value): self.parameters.descriptors_contain_xyz = value + @cached_property + def calculation_timestamp(self): + """ + Timestamp of calculation start. + + Used to distinguish multiple LAMMPS runs performed in the same + directory. Since the interface is file based, this timestamp prevents + problems with slightly + """ + return datetime.utcnow().strftime("%F-%H-%M-%S-%f")[:-3] + ############################## # Methods ############################## @@ -273,6 +286,17 @@ def calculate_from_qe_out( Usually the local directory should suffice, given that there are no multiple instances running in the same directory. + kwargs : dict + A collection of keyword arguments, that are mainly used for + debugging and development. Different types of descriptors + may support different keyword arguments. Commonly supported + are + + - "use_fp64": To use enforce floating point 64 precision for + descriptors. + - "keep_logs": To not delete temporary files created during + LAMMPS calculation of descriptors. + Returns ------- descriptors : numpy.array @@ -334,6 +358,17 @@ def calculate_from_atoms( Usually the local directory should suffice, given that there are no multiple instances running in the same directory. + kwargs : dict + A collection of keyword arguments, that are mainly used for + debugging and development. Different types of descriptors + may support different keyword arguments. Commonly supported + are + + - "use_fp64": To use enforce floating point 64 precision for + descriptors. + - "keep_logs": To not delete temporary files created during + LAMMPS calculation of descriptors. + Returns ------- descriptors : numpy.array @@ -542,9 +577,7 @@ def _feature_mask(self): else: return 0 - def _setup_lammps( - self, nx, ny, nz, outdir, lammps_dict, log_file_name="lammps_log.tmp" - ): + def _setup_lammps(self, nx, ny, nz, lammps_dict, log_file): """ Set up the lammps processor grid. @@ -564,7 +597,7 @@ def _setup_lammps( "-screen", "none", "-log", - os.path.join(outdir, log_file_name), + log_file, ] if self.parameters._configuration["mpi"]: diff --git a/mala/descriptors/minterpy_descriptors.py b/mala/descriptors/minterpy_descriptors.py index 3722260c3..b069ec20f 100755 --- a/mala/descriptors/minterpy_descriptors.py +++ b/mala/descriptors/minterpy_descriptors.py @@ -91,6 +91,8 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): # general LAMMPS import. from lammps import constants as lammps_constants + keep_logs = kwargs.get("keep_logs", False) + nx = grid_dimensions[0] ny = grid_dimensions[1] nz = grid_dimensions[2] @@ -161,7 +163,9 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): # The rest is the stanfard LAMMPS atomic density stuff. lammps_format = "lammps-data" - ase_out_path = os.path.join(outdir, "lammps_input.tmp") + ase_out_path = os.path.join( + outdir, "lammps_input_" + self.calculation_timestamp + ".tmp" + ) ase.io.write(ase_out_path, atoms_copied, format=lammps_format) # Create LAMMPS instance. @@ -169,14 +173,11 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): lammps_dict["sigma"] = self.parameters.atomic_density_sigma lammps_dict["rcutfac"] = self.parameters.atomic_density_cutoff lammps_dict["atom_config_fname"] = ase_out_path - lmp = self._setup_lammps( - nx, - ny, - nz, + log_path = os.path.join( outdir, - lammps_dict, - log_file_name="lammps_mgrid_log.tmp", + "lammps_mgrid_log_" + self.calculation_timestamp + ".tmp", ) + lmp = self._setup_lammps(nx, ny, nz, lammps_dict, log_path) # For now the file is chosen automatically, because this is used # mostly under the hood anyway. @@ -194,6 +195,10 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") lmp.file(runfile) + if not keep_logs: + os.remove(ase_out_path) + os.remove(log_path) + # Extract the data. nrows_ggrid = extract_compute_np( lmp, diff --git a/mala/targets/target.py b/mala/targets/target.py index 23212470b..4621c6542 100644 --- a/mala/targets/target.py +++ b/mala/targets/target.py @@ -649,7 +649,7 @@ def get_target(self): @abstractmethod def invalidate_target(self): """ - Invalidates the saved target wuantity. + Invalidates the saved target quantity. This is the generic interface for cached target quantities. It should work for all implemented targets. From 94ae81946b7ae11cb121fcc7d7ba76eb759e80c3 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Thu, 30 May 2024 15:52:39 +0200 Subject: [PATCH 2/5] Moved functionality to base class to get rid of redundancy --- mala/descriptors/atomic_density.py | 25 ++++++++++++------------ mala/descriptors/bispectrum.py | 18 ++++++++--------- mala/descriptors/descriptor.py | 20 +++++++++++++++++-- mala/descriptors/minterpy_descriptors.py | 18 ++++++++--------- 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/mala/descriptors/atomic_density.py b/mala/descriptors/atomic_density.py index f11252f94..537245d58 100755 --- a/mala/descriptors/atomic_density.py +++ b/mala/descriptors/atomic_density.py @@ -137,10 +137,12 @@ def __calculate_lammps(self, outdir, **kwargs): keep_logs = kwargs.get("keep_logs", False) lammps_format = "lammps-data" - ase_out_path = os.path.join( + self.lammps_temporary_input = os.path.join( outdir, "lammps_input_" + self.calculation_timestamp + ".tmp" ) - ase.io.write(ase_out_path, self.atoms, format=lammps_format) + ase.io.write( + self.lammps_temporary_input, self.atoms, format=lammps_format + ) nx = self.grid_dimensions[0] ny = self.grid_dimensions[1] @@ -154,15 +156,15 @@ def __calculate_lammps(self, outdir, **kwargs): ) # Create LAMMPS instance. - lammps_dict = {} - lammps_dict["sigma"] = self.parameters.atomic_density_sigma - lammps_dict["rcutfac"] = self.parameters.atomic_density_cutoff - lammps_dict["atom_config_fname"] = ase_out_path - log_path = os.path.join( + lammps_dict = { + "sigma": self.parameters.atomic_density_sigma, + "rcutfac": self.parameters.atomic_density_cutoff, + } + self.lammps_temporary_log = os.path.join( outdir, "lammps_ggrid_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. @@ -174,11 +176,10 @@ def __calculate_lammps(self, outdir, **kwargs): runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") else: runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") - lmp.file(runfile) - if not keep_logs: - os.remove(ase_out_path) - os.remove(log_path) + # 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( diff --git a/mala/descriptors/bispectrum.py b/mala/descriptors/bispectrum.py index baac8fa13..fc2bd522d 100755 --- a/mala/descriptors/bispectrum.py +++ b/mala/descriptors/bispectrum.py @@ -141,10 +141,12 @@ def __calculate_lammps(self, outdir, **kwargs): keep_logs = kwargs.get("keep_logs", False) lammps_format = "lammps-data" - ase_out_path = os.path.join( + self.lammps_temporary_input = os.path.join( outdir, "lammps_input_" + self.calculation_timestamp + ".tmp" ) - ase.io.write(ase_out_path, self.atoms, format=lammps_format) + ase.io.write( + self.lammps_temporary_input, self.atoms, format=lammps_format + ) nx = self.grid_dimensions[0] ny = self.grid_dimensions[1] @@ -154,14 +156,13 @@ def __calculate_lammps(self, outdir, **kwargs): lammps_dict = { "twojmax": self.parameters.bispectrum_twojmax, "rcutfac": self.parameters.bispectrum_cutoff, - "atom_config_fname": ase_out_path, } - log_path = os.path.join( + 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) # An empty string means that the user wants to use the standard input. # What that is differs depending on serial/parallel execution. @@ -181,12 +182,9 @@ def __calculate_lammps(self, outdir, **kwargs): filepath, "in.bgrid.python" ) - # Do the LAMMPS calculation. + # Do the LAMMPS calculation and clean up. lmp.file(self.parameters.lammps_compute_file) - - if not keep_logs: - os.remove(ase_out_path) - os.remove(log_path) + self._clean_calculation(keep_logs) # Set things not accessible from LAMMPS # First 3 cols are x, y, z, coords diff --git a/mala/descriptors/descriptor.py b/mala/descriptors/descriptor.py index b65cc5221..43bdf1e94 100644 --- a/mala/descriptors/descriptor.py +++ b/mala/descriptors/descriptor.py @@ -124,6 +124,12 @@ def __init__(self, parameters): self.atoms = None self.voxel = None + # If we ever have NON LAMMPS descriptors, these parameters have no + # meaning anymore and should probably be moved to an intermediate + # DescriptorsLAMMPS class, from which the LAMMPS descriptors inherit. + self.lammps_temporary_input = None + self.lammps_temporary_log = None + ############################## # Properties ############################## @@ -577,7 +583,7 @@ def _feature_mask(self): else: return 0 - def _setup_lammps(self, nx, ny, nz, lammps_dict, log_file): + def _setup_lammps(self, nx, ny, nz, lammps_dict): """ Set up the lammps processor grid. @@ -597,8 +603,9 @@ def _setup_lammps(self, nx, ny, nz, lammps_dict, log_file): "-screen", "none", "-log", - log_file, + self.lammps_temporary_log, ] + lammps_dict["atom_config_fname"] = self.lammps_temporary_input if self.parameters._configuration["mpi"]: size = get_size() @@ -811,6 +818,15 @@ def _setup_lammps(self, nx, ny, nz, lammps_dict, log_file): return lmp + def _clean_calculation(self, keep_logs): + if not keep_logs: + os.remove(self.lammps_temporary_log) + os.remove(self.lammps_temporary_input) + + # Reset timestamp for potential next calculation using same LAMMPS + # object. + del self.calculation_timestamp + def _setup_atom_list(self): """ Set up a list of atoms potentially relevant for descriptor calculation. diff --git a/mala/descriptors/minterpy_descriptors.py b/mala/descriptors/minterpy_descriptors.py index b069ec20f..aac268b7c 100755 --- a/mala/descriptors/minterpy_descriptors.py +++ b/mala/descriptors/minterpy_descriptors.py @@ -163,19 +163,20 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): # The rest is the stanfard LAMMPS atomic density stuff. lammps_format = "lammps-data" - ase_out_path = os.path.join( + self.lammps_temporary_input = os.path.join( outdir, "lammps_input_" + self.calculation_timestamp + ".tmp" ) - ase.io.write(ase_out_path, atoms_copied, format=lammps_format) + ase.io.write( + self.lammps_temporary_input, self.atoms, format=lammps_format + ) # Create LAMMPS instance. lammps_dict = {} lammps_dict["sigma"] = self.parameters.atomic_density_sigma lammps_dict["rcutfac"] = self.parameters.atomic_density_cutoff - lammps_dict["atom_config_fname"] = ase_out_path - log_path = os.path.join( + self.lammps_temporary_log = os.path.join( outdir, - "lammps_mgrid_log_" + self.calculation_timestamp + ".tmp", + "lammps_bgrid_log_" + self.calculation_timestamp + ".tmp", ) lmp = self._setup_lammps(nx, ny, nz, lammps_dict, log_path) @@ -193,11 +194,10 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): # runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") else: runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") - lmp.file(runfile) - if not keep_logs: - os.remove(ase_out_path) - os.remove(log_path) + # 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( From 8cee35970dff09dadc9d41b802ca59093a4e15a9 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Thu, 30 May 2024 16:30:14 +0200 Subject: [PATCH 3/5] Fixed timestamping in MPI case --- mala/descriptors/descriptor.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/mala/descriptors/descriptor.py b/mala/descriptors/descriptor.py index 43bdf1e94..5fa9a78d7 100644 --- a/mala/descriptors/descriptor.py +++ b/mala/descriptors/descriptor.py @@ -172,7 +172,16 @@ def calculation_timestamp(self): directory. Since the interface is file based, this timestamp prevents problems with slightly """ - return datetime.utcnow().strftime("%F-%H-%M-%S-%f")[:-3] + if get_rank() == 0: + timestamp = datetime.timestamp(datetime.utcnow()) + else: + timestamp = None + + if self.parameters._configuration["mpi"]: + timestamp = get_comm().bcast(timestamp, root=0) + return datetime.fromtimestamp(timestamp).strftime("%F-%H-%M-%S-%f")[ + :-3 + ] ############################## # Methods @@ -591,13 +600,6 @@ def _setup_lammps(self, nx, ny, nz, lammps_dict): """ from lammps import lammps - parallel_warn( - "Using LAMMPS for descriptor calculation. " - "Do not initialize more than one pre-processing " - "calculation in the same directory at the same time. " - "Data may be over-written." - ) - # Build LAMMPS arguments from the data we read. lmp_cmdargs = [ "-screen", @@ -820,8 +822,9 @@ def _setup_lammps(self, nx, ny, nz, lammps_dict): def _clean_calculation(self, keep_logs): if not keep_logs: - os.remove(self.lammps_temporary_log) - os.remove(self.lammps_temporary_input) + if get_rank() == 0: + os.remove(self.lammps_temporary_log) + os.remove(self.lammps_temporary_input) # Reset timestamp for potential next calculation using same LAMMPS # object. From 92831ff150cff5bf7791791c1ed55f2603d665f3 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Thu, 30 May 2024 17:09:35 +0200 Subject: [PATCH 4/5] Fixed copy and paste bug --- mala/descriptors/atomic_density.py | 12 +++++++++--- mala/descriptors/minterpy_descriptors.py | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mala/descriptors/atomic_density.py b/mala/descriptors/atomic_density.py index 537245d58..dd593111b 100755 --- a/mala/descriptors/atomic_density.py +++ b/mala/descriptors/atomic_density.py @@ -171,11 +171,17 @@ def __calculate_lammps(self, outdir, **kwargs): filepath = __file__.split("atomic_density")[0] if self.parameters._configuration["mpi"]: if self.parameters.use_z_splitting: - runfile = os.path.join(filepath, "in.ggrid.python") + self.parameters.lammps_compute_file = os.path.join( + filepath, "in.ggrid.python" + ) else: - runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") + self.parameters.lammps_compute_file = os.path.join( + filepath, "in.ggrid_defaultproc.python" + ) else: - runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") + self.parameters.lammps_compute_file = os.path.join( + filepath, "in.ggrid_defaultproc.python" + ) # Do the LAMMPS calculation and clean up. lmp.file(self.parameters.lammps_compute_file) diff --git a/mala/descriptors/minterpy_descriptors.py b/mala/descriptors/minterpy_descriptors.py index aac268b7c..3b694be16 100755 --- a/mala/descriptors/minterpy_descriptors.py +++ b/mala/descriptors/minterpy_descriptors.py @@ -193,7 +193,9 @@ def _calculate(self, atoms, outdir, grid_dimensions, **kwargs): # else: # runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") else: - runfile = os.path.join(filepath, "in.ggrid_defaultproc.python") + self.parameters.lammps_compute_file = os.path.join( + filepath, "in.ggrid_defaultproc.python" + ) # Do the LAMMPS calculation and clean up. lmp.file(self.parameters.lammps_compute_file) From fe911a2ab73ad75a0d3554dfa825a26aa13f2640 Mon Sep 17 00:00:00 2001 From: Lenz Fiedler Date: Fri, 31 May 2024 09:16:36 +0200 Subject: [PATCH 5/5] Log now only cleaned AFTER LAMMPS instance is closed --- mala/descriptors/atomic_density.py | 3 +-- mala/descriptors/bispectrum.py | 5 ++--- mala/descriptors/descriptor.py | 3 ++- mala/descriptors/minterpy_descriptors.py | 12 ++++++------ 4 files changed, 11 insertions(+), 12 deletions(-) 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( (