diff --git a/docs/source/install/installing_mala.rst b/docs/source/install/installing_mala.rst index 7ec2f25b9..d9d740a95 100644 --- a/docs/source/install/installing_mala.rst +++ b/docs/source/install/installing_mala.rst @@ -43,7 +43,7 @@ itself is subject to ongoing development as well. git clone https://github.com/mala-project/test-data ~/path/to/data/repo cd ~/path/to/data/repo - git checkout v1.8.0 + git checkout v1.8.1 * Export the path to that repo by ``export MALA_DATA_REPO=~/path/to/data/repo`` diff --git a/mala/interfaces/ase_calculator.py b/mala/interfaces/ase_calculator.py index bfc041788..4fecfcbce 100644 --- a/mala/interfaces/ase_calculator.py +++ b/mala/interfaces/ase_calculator.py @@ -199,7 +199,7 @@ def calculate_properties(self, atoms, properties): "e_ewald" ] - def save_calculator(self, filename, save_path="./"): + def save_calculator(self, filename, path="./"): """ Save parameters used for this calculator. @@ -210,10 +210,10 @@ def save_calculator(self, filename, save_path="./"): filename : string Name of the file in which to store the calculator. - save_path : string + path : string Path where the calculator should be saved. """ self.predictor.save_run( - filename, save_path=save_path, additional_calculation_data=True + filename, path=save_path, additional_calculation_data=True ) diff --git a/mala/network/runner.py b/mala/network/runner.py index fb5a99321..a67a79eb0 100644 --- a/mala/network/runner.py +++ b/mala/network/runner.py @@ -99,8 +99,7 @@ def _calculate_errors( target_calculator, LDOS ) and not isinstance(target_calculator, Density): raise Exception( - "Cannot calculate density from this " - "observable." + "Cannot calculate density from this " "observable." ) target_calculator.read_additional_calculation_data( self.data.get_snapshot_calculation_output( @@ -145,8 +144,7 @@ def _calculate_errors( target_calculator, LDOS ) and not isinstance(target_calculator, DOS): raise Exception( - "Cannot calculate the DOS from this " - "observable." + "Cannot calculate the DOS from this " "observable." ) target_calculator.read_additional_calculation_data( self.data.get_snapshot_calculation_output( @@ -299,10 +297,8 @@ def _calculate_energy_errors( ) try: target_calculator.read_from_array(predicted_outputs) - be_predicted_actual_fe = ( - target_calculator.get_band_energy( - fermi_energy=fe_actual - ) + be_predicted_actual_fe = target_calculator.get_band_energy( + fermi_energy=fe_actual ) be_error_actual_fe = ( be_predicted_actual_fe - be_actual @@ -386,9 +382,7 @@ def _calculate_energy_targets_and_predictions( snapshot_number ) if not output_file: - raise Exception( - "Output file needed for energy calculations." - ) + raise Exception("Output file needed for energy calculations.") target_calculator.read_additional_calculation_data(output_file) targets = {} @@ -400,12 +394,8 @@ def _calculate_energy_targets_and_predictions( actual_outputs ) except ValueError: - targets = { - energy_type: np.nan for energy_type in energy_types - } - predictions = { - energy_type: np.nan for energy_type in energy_types - } + targets = {energy_type: np.nan for energy_type in energy_types} + predictions = {energy_type: np.nan for energy_type in energy_types} printout( "CAUTION! LDOS ground truth is so wrong that the " "estimation of the self consistent Fermi energy fails." @@ -416,12 +406,8 @@ def _calculate_energy_targets_and_predictions( predicted_outputs ) except ValueError: - targets = { - energy_type: np.nan for energy_type in energy_types - } - predictions = { - energy_type: np.nan for energy_type in energy_types - } + targets = {energy_type: np.nan for energy_type in energy_types} + predictions = {energy_type: np.nan for energy_type in energy_types} printout( "CAUTION! LDOS prediction is so wrong that the " "estimation of the self consistent Fermi energy fails." @@ -447,8 +433,12 @@ def _calculate_energy_targets_and_predictions( be_predicted = target_calculator.get_band_energy( fermi_energy=fe_predicted ) - targets[energy_type] = be_actual * 1000 / len(target_calculator.atoms) - predictions[energy_type] = be_predicted * 1000 / len(target_calculator.atoms) + targets[energy_type] = ( + be_actual * 1000 / len(target_calculator.atoms) + ) + predictions[energy_type] = ( + be_predicted * 1000 / len(target_calculator.atoms) + ) except ValueError: targets[energy_type] = np.nan predictions[energy_type] = np.nan @@ -461,13 +451,17 @@ def _calculate_energy_targets_and_predictions( ) try: target_calculator.read_from_array(predicted_outputs) - be_predicted_actual_fe = ( - target_calculator.get_band_energy( - fermi_energy=fe_actual - ) + be_predicted_actual_fe = target_calculator.get_band_energy( + fermi_energy=fe_actual + ) + targets[energy_type] = ( + be_actual * 1000 / len(target_calculator.atoms) + ) + predictions[energy_type] = ( + be_predicted_actual_fe + * 1000 + / len(target_calculator.atoms) ) - targets[energy_type] = be_actual * 1000 / len(target_calculator.atoms) - predictions[energy_type] = be_predicted_actual_fe * 1000 / len(target_calculator.atoms) except ValueError: targets[energy_type] = np.nan predictions[energy_type] = np.nan @@ -491,8 +485,12 @@ def _calculate_energy_targets_and_predictions( te_predicted = target_calculator.get_total_energy( fermi_energy=fe_predicted ) - targets[energy_type] = te_actual * 1000 / len(target_calculator.atoms) - predictions[energy_type] = te_predicted * 1000 / len(target_calculator.atoms) + targets[energy_type] = ( + te_actual * 1000 / len(target_calculator.atoms) + ) + predictions[energy_type] = ( + te_predicted * 1000 / len(target_calculator.atoms) + ) except ValueError: targets[energy_type] = np.nan predictions[energy_type] = np.nan @@ -509,9 +507,15 @@ def _calculate_energy_targets_and_predictions( fermi_energy=fe_actual ) ) - - targets[energy_type] = te_actual * 1000 / len(target_calculator.atoms) - predictions[energy_type] = te_predicted_actual_fe * 1000 / len(target_calculator.atoms) + + targets[energy_type] = ( + te_actual * 1000 / len(target_calculator.atoms) + ) + predictions[energy_type] = ( + te_predicted_actual_fe + * 1000 + / len(target_calculator.atoms) + ) except ValueError: targets[energy_type] = np.nan predictions[energy_type] = np.nan @@ -524,7 +528,7 @@ def _calculate_energy_targets_and_predictions( def save_run( self, run_name, - save_path="./", + path="./", zip_run=True, save_runner=False, additional_calculation_data=None, @@ -537,7 +541,7 @@ def save_run( run_name : str Name under which the run should be saved. - save_path : str + path : str Path where to which the run. zip_run : bool @@ -567,20 +571,16 @@ def save_run( params_file = run_name + ".params.json" if save_runner: optimizer_file = run_name + ".optimizer.pth" - os.makedirs(save_path, exist_ok=True) - self.parameters_full.save(os.path.join(save_path, params_file)) + os.makedirs(path, exist_ok=True) + self.parameters_full.save(os.path.join(path, params_file)) if self.parameters_full.use_ddp: self.network.module.save_network( - os.path.join(save_path, model_file) + os.path.join(path, model_file) ) else: - self.network.save_network(os.path.join(save_path, model_file)) - self.data.input_data_scaler.save( - os.path.join(save_path, iscaler_file) - ) - self.data.output_data_scaler.save( - os.path.join(save_path, oscaler_file) - ) + self.network.save_network(os.path.join(path, model_file)) + self.data.input_data_scaler.save(os.path.join(path, iscaler_file)) + self.data.output_data_scaler.save(os.path.join(path, oscaler_file)) files = [model_file, iscaler_file, oscaler_file, params_file] if save_runner: @@ -593,27 +593,23 @@ def save_run( additional_calculation_data ) self.data.target_calculator.write_additional_calculation_data( - os.path.join( - save_path, additional_calculation_file - ) + os.path.join(path, additional_calculation_file) ) elif isinstance(additional_calculation_data, bool): if additional_calculation_data: self.data.target_calculator.write_additional_calculation_data( - os.path.join( - save_path, additional_calculation_file - ) + os.path.join(path, additional_calculation_file) ) files.append(additional_calculation_file) with ZipFile( - os.path.join(save_path, run_name + ".zip"), + os.path.join(path, run_name + ".zip"), "w", compression=ZIP_STORED, ) as zip_obj: for file in files: - zip_obj.write(os.path.join(save_path, file), file) - os.remove(os.path.join(save_path, file)) + zip_obj.write(os.path.join(path, file), file) + os.remove(os.path.join(path, file)) @classmethod def load_run( diff --git a/mala/network/trainer.py b/mala/network/trainer.py index 1d5adf5d2..92b2a3f7c 100644 --- a/mala/network/trainer.py +++ b/mala/network/trainer.py @@ -1046,7 +1046,7 @@ def __create_training_checkpoint(self): self.save_run( self.parameters.checkpoint_name, save_runner=True, - save_path=self.parameters.run_name, + path=self.parameters.run_name, ) else: self.save_run(self.parameters.checkpoint_name, save_runner=True) diff --git a/mala/targets/calculation_helpers.py b/mala/targets/calculation_helpers.py index 6b88dec21..1556a6509 100644 --- a/mala/targets/calculation_helpers.py +++ b/mala/targets/calculation_helpers.py @@ -21,8 +21,8 @@ def integrate_values_on_spacing(values, spacing, method, axis=0): method : string Integration method to be used. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. axis : int Axis along which the integration is performed. @@ -31,10 +31,10 @@ def integrate_values_on_spacing(values, spacing, method, axis=0): integral_values : float The value of the integral. """ - if method == "trapz": - return integrate.trapz(values, dx=spacing, axis=axis) - elif method == "simps": - return integrate.simps(values, dx=spacing, axis=axis) + if method == "trapezoid": + return integrate.trapezoid(values, dx=spacing, axis=axis) + elif method == "simpson": + return integrate.simpson(values, dx=spacing, axis=axis) else: raise Exception("Unknown integration method.") diff --git a/mala/targets/density.py b/mala/targets/density.py index fab7913d7..25464b40c 100644 --- a/mala/targets/density.py +++ b/mala/targets/density.py @@ -575,8 +575,8 @@ def get_number_of_electrons( Integration method used to integrate density on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) """ if density_data is None: diff --git a/mala/targets/dos.py b/mala/targets/dos.py index 6e4d82927..a6fcadf5d 100644 --- a/mala/targets/dos.py +++ b/mala/targets/dos.py @@ -558,8 +558,8 @@ def get_band_energy( integration_method : string Integration method to be used. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. Recommended. broadcast_band_energy : bool @@ -655,8 +655,8 @@ def get_number_of_electrons( integration_method : string Integration method to be used. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. Recommended. Returns @@ -723,8 +723,8 @@ def get_entropy_contribution( integration_method : string Integration method to be used. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. Recommended. broadcast_entropy : bool @@ -813,8 +813,8 @@ def get_self_consistent_fermi_energy( integration_method : string Integration method to be used. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. Recommended. broadcast_fermi_energy : bool @@ -913,12 +913,12 @@ def __number_of_electrons_from_dos( energy_grid, fermi_energy, temperature, suppress_overflow=True ) # Calculate the number of electrons. - if integration_method == "trapz": - number_of_electrons = integrate.trapz( + if integration_method == "trapezoid": + number_of_electrons = integrate.trapezoid( dos_data * fermi_vals, energy_grid, axis=-1 ) - elif integration_method == "simps": - number_of_electrons = integrate.simps( + elif integration_method == "simpson": + number_of_electrons = integrate.simpson( dos_data * fermi_vals, energy_grid, axis=-1 ) elif integration_method == "quad": @@ -954,11 +954,11 @@ def __band_energy_from_dos( # Calculate the band energy. if integration_method == "trapz": - band_energy = integrate.trapz( + band_energy = integrate.trapezoid( dos_data * (energy_grid * fermi_vals), energy_grid, axis=-1 ) - elif integration_method == "simps": - band_energy = integrate.simps( + elif integration_method == "simpson": + band_energy = integrate.simpson( dos_data * (energy_grid * fermi_vals), energy_grid, axis=-1 ) elif integration_method == "quad": @@ -999,19 +999,19 @@ def __entropy_contribution_from_dos( More specifically, this gives -\beta^-1*S_S """ # Calculate the entropy contribution to the energy. - if integration_method == "trapz": + if integration_method == "trapezoid": multiplicator = entropy_multiplicator( energy_grid, fermi_energy, temperature ) - entropy_contribution = integrate.trapz( + entropy_contribution = integrate.trapezoid( dos_data * multiplicator, energy_grid, axis=-1 ) entropy_contribution /= get_beta(temperature) - elif integration_method == "simps": + elif integration_method == "simpson": multiplicator = entropy_multiplicator( energy_grid, fermi_energy, temperature ) - entropy_contribution = integrate.simps( + entropy_contribution = integrate.simpson( dos_data * multiplicator, energy_grid, axis=-1 ) entropy_contribution /= get_beta(temperature) diff --git a/mala/targets/ldos.py b/mala/targets/ldos.py index e5d665278..a45ceaad2 100644 --- a/mala/targets/ldos.py +++ b/mala/targets/ldos.py @@ -618,15 +618,15 @@ def get_total_energy( Integration method used to integrate the density on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) energy_integration_method : string Integration method to integrate the DOS. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. (recommended) atoms_Angstrom : ase.Atoms @@ -811,15 +811,15 @@ def get_band_energy( Integration method used to integrate the LDOS on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) energy_integration_method : string Integration method to integrate the DOS. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. (recommended) voxel : ase.cell.Cell @@ -887,15 +887,15 @@ def get_entropy_contribution( Integration method used to integrate the LDOS on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) energy_integration_method : string Integration method to integrate the DOS. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. (recommended) voxel : ase.cell.Cell @@ -963,15 +963,15 @@ def get_number_of_electrons( Integration method used to integrate the LDOS on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) energy_integration_method : string Integration method to integrate the DOS. Currently supported: - "trapz" for trapezoid method - - "simps" for Simpson method. + - "simpson" for Simpson method. - "analytical" for analytical integration. (recommended) voxel : ase.cell.Cell @@ -1039,15 +1039,15 @@ def get_self_consistent_fermi_energy( Integration method used to integrate the LDOS on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) energy_integration_method : string Integration method to integrate the DOS. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. (recommended) voxel : ase.cell.Cell @@ -1113,8 +1113,8 @@ def get_density( integration_method : string Integration method to be used. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. Recommended. ldos_data : numpy.array @@ -1125,8 +1125,8 @@ def get_density( Integration method to integrate LDOS on energygrid. Currently supported: - - "trapz" for trapezoid method - - "simps" for Simpson method. + - "trapezoid" for trapezoid method + - "simpson" for Simpson method. - "analytical" for analytical integration. Recommended. gather_density : bool @@ -1193,12 +1193,12 @@ def get_density( ) # Calculate the number of electrons. - if integration_method == "trapz": - density_values = integrate.trapz( + if integration_method == "trapezoid": + density_values = integrate.trapezoid( ldos_data_used * fermi_values, energy_grid, axis=-1 ) - elif integration_method == "simps": - density_values = integrate.simps( + elif integration_method == "simpson": + density_values = integrate.simpson( ldos_data_used * fermi_values, energy_grid, axis=-1 ) elif integration_method == "analytical": @@ -1277,8 +1277,8 @@ def get_density_of_states( Integration method used to integrate LDOS on the grid. Currently supported: - - "trapz" for trapezoid method (only for cubic grids). - - "simps" for Simpson method (only for cubic grids). + - "trapezoid" for trapezoid method (only for cubic grids). + - "simpson" for Simpson method (only for cubic grids). - "summation" for summation and scaling of the values (recommended) gather_dos : bool diff --git a/mala/targets/target.py b/mala/targets/target.py index 4621c6542..12339c0d0 100644 --- a/mala/targets/target.py +++ b/mala/targets/target.py @@ -11,7 +11,7 @@ import ase.io import numpy as np from scipy.spatial import distance -from scipy.integrate import simps +from scipy.integrate import simpson from mala.common.parameters import Parameters, ParametersTargets from mala.common.parallelizer import printout, parallel_warn @@ -1032,7 +1032,7 @@ def static_structure_factor_from_atoms( kr = np.array(radii) * kpoints[-1] integrand = (rdf - 1) * radii * np.sin(kr) / kpoints[-1] structure_factor[i] = 1 + ( - 4 * np.pi * rho * simps(integrand, radii) + 4 * np.pi * rho * simpson(integrand, radii) ) return structure_factor[1:], np.array(kpoints)[1:]