diff --git a/examples/advanced/ex09_convert_numpy_openpmd.py b/examples/advanced/ex09_convert_numpy_openpmd.py new file mode 100644 index 000000000..babaff191 --- /dev/null +++ b/examples/advanced/ex09_convert_numpy_openpmd.py @@ -0,0 +1,24 @@ +import mala + +parameters = mala.Parameters() +data_converter = mala.DataConverter(parameters) + +for snapshot in range(2): + data_converter.add_snapshot( + descriptor_input_type="openpmd", + descriptor_input_path="Be_shuffled{}.in.bp4".format(snapshot), + target_input_type=None, # "openpmd", + target_input_path=None, # "Be_shuffled{}.out.bp4".format(snapshot), + additional_info_input_type=None, + additional_info_input_path=None, + target_units=None, + ) + +# data_handler.descriptor_calculator.write_to_openpmd_file("descriptor_*.bp") +data_converter.convert_snapshots( + descriptor_save_path="./", + target_save_path="./", + additional_info_save_path="./", + naming_scheme="Be_snapshot*.bp", + descriptor_calculation_kwargs={"working_directory": "./"}, +) diff --git a/examples/basic/ex03_preprocess_data.py b/examples/basic/ex03_preprocess_data.py index 72ec9490a..738114b20 100644 --- a/examples/basic/ex03_preprocess_data.py +++ b/examples/basic/ex03_preprocess_data.py @@ -8,7 +8,7 @@ """ Shows how this framework can be used to preprocess -data. Preprocessing here means converting raw DFT calculation output into +data. Preprocessing here means converting raw DFT calculation output into numpy arrays of the correct size. For the input data, this means descriptor calculation. diff --git a/mala/common/physical_data.py b/mala/common/physical_data.py index e756e96d1..16ed6b34e 100644 --- a/mala/common/physical_data.py +++ b/mala/common/physical_data.py @@ -555,6 +555,11 @@ def write_to_openpmd_iteration( atoms_openpmd["position"][str(atom)].unit_SI = 1.0e-10 atoms_openpmd["positionOffset"][str(atom)].unit_SI = 1.0e-10 + if any(i == 0 for i in self.grid_dimensions) and not isinstance( + array, self.SkipArrayWriting + ): + self.grid_dimensions = array.shape[0:-1] + dataset = ( array.dataset if isinstance(array, self.SkipArrayWriting) @@ -564,8 +569,12 @@ def write_to_openpmd_iteration( # Global feature sizes: feature_global_from = 0 feature_global_to = self.feature_size - if feature_global_to == 0 and isinstance(array, self.SkipArrayWriting): - feature_global_to = array.feature_size + if feature_global_to == 0: + feature_global_to = ( + array.feature_size + if isinstance(array, self.SkipArrayWriting) + else array.shape[-1] + ) # First loop: Only metadata, write metadata equivalently across ranks for current_feature in range(feature_global_from, feature_global_to): diff --git a/mala/datahandling/data_converter.py b/mala/datahandling/data_converter.py index 5a97ec06c..f7f50bc2d 100644 --- a/mala/datahandling/data_converter.py +++ b/mala/datahandling/data_converter.py @@ -10,8 +10,8 @@ from mala.targets.target import Target from mala.version import __version__ as mala_version -descriptor_input_types = ["espresso-out"] -target_input_types = [".cube", ".xsf"] +descriptor_input_types = ["espresso-out", "openpmd"] +target_input_types = [".cube", ".xsf", "openpmd"] additional_info_input_types = ["espresso-out"] @@ -546,6 +546,16 @@ def __convert_single_snapshot( snapshot["input"], **descriptor_calculation_kwargs ) ) + print(tmp_input) + print(tmp_input.shape) + print(local_size) + + elif description["input"] == "openpmd": + tmp_input = self.descriptor_calculator.read_from_openpmd_file( + snapshot["input"] + ) + print(tmp_input) + print(tmp_input.shape) elif description["input"] is None: # In this case, only the output is processed. @@ -617,6 +627,9 @@ def __convert_single_snapshot( snapshot["output"], **target_calculator_kwargs ) + elif description["output"] == "openpmd": + raise RuntimeError("unimplemented!") + elif description["output"] is None: # In this case, only the input is processed. pass