From 014c988e319d1e17b7992b591b08d2fefab18de1 Mon Sep 17 00:00:00 2001 From: ElliottKasoar <45317199+ElliottKasoar@users.noreply.github.com> Date: Fri, 8 Nov 2024 10:44:29 +0000 Subject: [PATCH] Update docstrings (#348) --- janus_core/calculations/base.py | 46 +++++----- janus_core/calculations/descriptors.py | 36 ++++---- janus_core/calculations/eos.py | 48 +++++----- janus_core/calculations/geom_opt.py | 56 ++++++------ janus_core/calculations/md.py | 116 ++++++++++++------------ janus_core/calculations/phonons.py | 88 +++++++++--------- janus_core/calculations/single_point.py | 34 +++---- janus_core/helpers/log.py | 14 +-- janus_core/helpers/mlip_calculators.py | 8 +- janus_core/helpers/struct_io.py | 22 ++--- janus_core/helpers/utils.py | 6 +- janus_core/processing/post_process.py | 14 +-- janus_core/training/train.py | 6 +- tests/utils.py | 2 +- 14 files changed, 248 insertions(+), 248 deletions(-) diff --git a/janus_core/calculations/base.py b/janus_core/calculations/base.py index 7146ac5e..0797b1db 100644 --- a/janus_core/calculations/base.py +++ b/janus_core/calculations/base.py @@ -26,46 +26,46 @@ class BaseCalculation(FileNameMixin): ---------- calc_name : str Name of calculation being run, used for name of logger. Default is "base". - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. read_kwargs : ASEReadArgs Keyword arguments to pass to ase.io.read. Default is {}. sequence_allowed : bool Whether a sequence of Atoms objects is allowed. Default is True. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is None. - additional_prefix : Optional[str] + additional_prefix : str | None Component to add to default file_prefix (joined by hyphens). Default is None. - param_prefix : Optional[str] + param_prefix : str | None Additional parameters to add to default file_prefix. Default is None. Attributes ---------- - logger : Optional[logging.Logger] + logger : logging.Logger | None Logger if log file has been specified. - tracker : Optional[OfflineEmissionsTracker] + tracker : OfflineEmissionsTracker | None Tracker if logging is enabled. """ @@ -97,40 +97,40 @@ def __init__( ---------- calc_name : str Name of calculation being run, used for name of logger. Default is "base". - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. Default is {}. sequence_allowed : bool Whether a sequence of Atoms objects is allowed. Default is True. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is None. - additional_prefix : Optional[str] + additional_prefix : str | None Component to add to default file_prefix (joined by hyphens). Default is None. - param_prefix : Optional[str] + param_prefix : str | None Additional parameters to add to default file_prefix. Default is None. """ (read_kwargs, calc_kwargs, log_kwargs, tracker_kwargs) = none_to_dict( diff --git a/janus_core/calculations/descriptors.py b/janus_core/calculations/descriptors.py index 95425d15..f8fa98ad 100644 --- a/janus_core/calculations/descriptors.py +++ b/janus_core/calculations/descriptors.py @@ -28,32 +28,32 @@ class Descriptors(BaseCalculation): Parameters ---------- - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to calculate descriptors for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to calculate descriptors for. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. invariants_only : bool Whether only the invariant descriptors should be returned. Default is True. @@ -63,7 +63,7 @@ class Descriptors(BaseCalculation): Whether to calculate descriptors for each atom. Default is False. write_results : bool True to write out structure with results of calculations. Default is False. - write_kwargs : Optional[ASEWriteArgs], + write_kwargs : ASEWriteArgs | None Keyword arguments to pass to ase.io.write if saving structure with results of calculations. Default is {}. @@ -98,32 +98,32 @@ def __init__( Parameters ---------- - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to calculate descriptors for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to calculate descriptors for. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. invariants_only : bool Whether only the invariant descriptors should be returned. Default is True. @@ -133,7 +133,7 @@ def __init__( Whether to calculate descriptors for each atom. Default is False. write_results : bool True to write out structure with results of calculations. Default is False. - write_kwargs : Optional[ASEWriteArgs], + write_kwargs : ASEWriteArgs | None Keyword arguments to pass to ase.io.write if saving structure with results of calculations. Default is {}. """ diff --git a/janus_core/calculations/eos.py b/janus_core/calculations/eos.py index 1ddd3ee7..09926588 100644 --- a/janus_core/calculations/eos.py +++ b/janus_core/calculations/eos.py @@ -31,32 +31,32 @@ class EoS(BaseCalculation): Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to calculate equation of state for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to calculate equation of state for. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. min_volume : float Minimum volume scale factor. Default is 0.95. @@ -70,20 +70,20 @@ class EoS(BaseCalculation): Whether to minimize initial structure before calculations. Default is True. minimize_all : bool Whether to optimize geometry for all generated structures. Default is False. - minimize_kwargs : Optional[dict[str, Any]] + minimize_kwargs : dict[str, Any] | None Keyword arguments to pass to optimize. Default is None. write_results : bool True to write out results of equation of state calculations. Default is True. write_structures : bool True to write out all genereated structures. Default is False. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write to save generated structures. Default is {}. plot_to_file : bool Whether to save plot equation of state to svg. Default is False. - plot_kwargs : Optional[dict[str, Any]] + plot_kwargs : dict[str, Any] | None Keyword arguments to pass to EquationOfState.plot. Default is {}. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure name, or chemical formula of the structure. @@ -138,32 +138,32 @@ def __init__( Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to optimize geometry for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to optimize. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for optimization. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. min_volume : float Minimum volume scale factor. Default is 0.95. @@ -178,21 +178,21 @@ def __init__( minimize_all : bool Whether to optimize geometry for all generated structures. Default is False. - minimize_kwargs : Optional[dict[str, Any]] + minimize_kwargs : dict[str, Any] | None Keyword arguments to pass to optimize. Default is None. write_results : bool True to write out results of equation of state calculations. Default is True. write_structures : bool True to write out all genereated structures. Default is False. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write to save generated structures. Default is {}. plot_to_file : bool Whether to save plot equation of state to svg. Default is False. - plot_kwargs : Optional[dict[str, Any]] + plot_kwargs : dict[str, Any] | None Keyword arguments to pass to EquationOfState.plot. Default is {}. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure name, or chemical formula of the structure. """ diff --git a/janus_core/calculations/geom_opt.py b/janus_core/calculations/geom_opt.py index 3f4c155e..170ae3f8 100644 --- a/janus_core/calculations/geom_opt.py +++ b/janus_core/calculations/geom_opt.py @@ -32,31 +32,31 @@ class GeomOpt(BaseCalculation): Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to optimize geometry for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to optimize. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for optimization. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. fmax : float Set force convergence criteria for optimizer in units eV/Å. Default is 0.1. @@ -70,22 +70,22 @@ class GeomOpt(BaseCalculation): angle_tolerance : float Angle precision for spglib symmetry determination, in degrees. Default is -1.0, which means an internally optimized routine is used to judge symmetry. - filter_func : Optional[Union[Callable, str]] + filter_func : Callable | str | None Filter function, or name of function from ase.filters to apply constraints to atoms. Default is `FrechetCellFilter`. - filter_kwargs : Optional[dict[str, Any]] + filter_kwargs : dict[str, Any] | None Keyword arguments to pass to filter_func. Default is {}. - optimizer : Union[Callable, str] + optimizer : Callable | str Optimization function, or name of function from ase.optimize. Default is `LBFGS`. - opt_kwargs : Optional[ASEOptArgs] + opt_kwargs : ASEOptArgs | None Keyword arguments to pass to optimizer. Default is {}. write_results : bool True to write out optimized structure. Default is False. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write to save optimized structure. Default is {}. - traj_kwargs : Optional[OutputKwargs] + traj_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write to save optimization trajectory. Must include "filename" keyword. Default is {}. @@ -129,32 +129,32 @@ def __init__( Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to optimize geometry for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to optimize. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for optimization. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. fmax : float Set force convergence criteria for optimizer in units eV/Å. Default is 0.1. @@ -168,22 +168,22 @@ def __init__( angle_tolerance : float Angle precision for spglib symmetry determination, in degrees. Default is -1.0, which means an internally optimized routine is used to judge symmetry. - filter_func : Optional[Union[Callable, str]] + filter_func : Callable | str | None Filter function, or name of function from ase.filters to apply constraints to atoms. Default is `FrechetCellFilter`. - filter_kwargs : Optional[dict[str, Any]] + filter_kwargs : dict[str, Any] | None Keyword arguments to pass to filter_func. Default is {}. - optimizer : Union[Callable, str] + optimizer : Callable | str Optimization function, or name of function from ase.optimize. Default is `LBFGS`. - opt_kwargs : Optional[ASEOptArgs] + opt_kwargs : ASEOptArgs | None Keyword arguments to pass to optimizer. Default is {}. write_results : bool True to write out optimized structure. Default is False. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write to save optimized structure. Default is {}. - traj_kwargs : Optional[OutputKwargs] + traj_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write to save optimization trajectory. Must include "filename" keyword. Default is {}. """ diff --git a/janus_core/calculations/md.py b/janus_core/calculations/md.py index 4f17d883..3b691795 100644 --- a/janus_core/calculations/md.py +++ b/janus_core/calculations/md.py @@ -52,31 +52,31 @@ class MolecularDynamics(BaseCalculation): Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for simulation. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. struct : Atoms Structure to simulate. @@ -96,7 +96,7 @@ class MolecularDynamics(BaseCalculation): minimize_every : int Frequency of minimizations. Default is -1, which disables minimization after beginning dynamics. - minimize_kwargs : Optional[dict[str, Any]] + minimize_kwargs : dict[str, Any] | None Keyword arguments to pass to geometry optimizer. Default is {}. rescale_velocities : bool Whether to rescale velocities. Default is False. @@ -104,7 +104,7 @@ class MolecularDynamics(BaseCalculation): Whether to remove rotation. Default is False. rescale_every : int Frequency to rescale velocities. Default is 10. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure, ensemble, and temperature. restart : bool @@ -119,14 +119,14 @@ class MolecularDynamics(BaseCalculation): Whether to rotate restart files. Default is False. restarts_to_keep : int Restart files to keep if rotating. Default is 4. - final_file : Optional[PathLike] + final_file : PathLike | None File to save final configuration at each temperature of similation. Default inferred from `file_prefix`. - stats_file : Optional[PathLike] + stats_file : PathLike | None File to save thermodynamical statistics. Default inferred from `file_prefix`. stats_every : int Frequency to output statistics. Default is 100. - traj_file : Optional[PathLike] + traj_file : PathLike | None Trajectory file to save. Default inferred from `file_prefix`. traj_append : bool Whether to append trajectory. Default is False. @@ -134,23 +134,23 @@ class MolecularDynamics(BaseCalculation): Step to start saving trajectory. Default is 0. traj_every : int Frequency of steps to save trajectory. Default is 100. - temp_start : Optional[float] + temp_start : float | None Temperature to start heating, in K. Default is None, which disables heating. - temp_end : Optional[float] + temp_end : float | None Maximum temperature for heating, in K. Default is None, which disables heating. - temp_step : Optional[float] + temp_step : float | None Size of temperature steps when heating, in K. Default is None, which disables heating. - temp_time : Optional[float] + temp_time : float | None Time between heating steps, in fs. Default is None, which disables heating. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to `output_structs` when saving trajectory and final files. Default is {}. - post_process_kwargs : Optional[PostProcessKwargs] + post_process_kwargs : PostProcessKwargs | None Keyword arguments to control post-processing operations. - correlation_kwargs : Optional[CorrelationKwargs] + correlation_kwargs : CorrelationKwargs | None Keyword arguments to control on-the-fly correlations. - seed : Optional[int] + seed : int | None Random seed used by numpy.random and random functions, such as in Langevin. Default is None. @@ -228,32 +228,32 @@ def __init__( Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for simulation. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. ensemble : Ensembles Name for thermodynamic ensemble. Default is None. @@ -271,7 +271,7 @@ def __init__( minimize_every : int Frequency of minimizations. Default is -1, which disables minimization after beginning dynamics. - minimize_kwargs : Optional[dict[str, Any]] + minimize_kwargs : dict[str, Any] | None Keyword arguments to pass to geometry optimizer. Default is {}. rescale_velocities : bool Whether to rescale velocities. Default is False. @@ -279,7 +279,7 @@ def __init__( Whether to remove rotation. Default is False. rescale_every : int Frequency to rescale velocities. Default is 10. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure, ensemble, and temperature. restart : bool @@ -294,15 +294,15 @@ def __init__( Whether to rotate restart files. Default is False. restarts_to_keep : int Restart files to keep if rotating. Default is 4. - final_file : Optional[PathLike] + final_file : PathLike | None File to save final configuration at each temperature of similation. Default inferred from `file_prefix`. - stats_file : Optional[PathLike] + stats_file : PathLike | None File to save thermodynamical statistics. Default inferred from `file_prefix`. stats_every : int Frequency to output statistics. Default is 100. - traj_file : Optional[PathLike] + traj_file : PathLike | None Trajectory file to save. Default inferred from `file_prefix`. traj_append : bool Whether to append trajectory. Default is False. @@ -310,25 +310,25 @@ def __init__( Step to start saving trajectory. Default is 0. traj_every : int Frequency of steps to save trajectory. Default is 100. - temp_start : Optional[float] + temp_start : float | None Temperature to start heating, in K. Default is None, which disables heating. - temp_end : Optional[float] + temp_end : float | None Maximum temperature for heating, in K. Default is None, which disables heating. - temp_step : Optional[float] + temp_step : float | None Size of temperature steps when heating, in K. Default is None, which disables heating. - temp_time : Optional[float] + temp_time : float | None Time between heating steps, in fs. Default is None, which disables heating. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to `output_structs` when saving trajectory and final files. Default is {}. - post_process_kwargs : Optional[PostProcessKwargs] + post_process_kwargs : PostProcessKwargs | None Keyword arguments to control post-processing operations. - correlation_kwargs : Optional[list[CorrelationKwargs]] + correlation_kwargs : list[CorrelationKwargs] | None Keyword arguments to control on-the-fly correlations. - seed : Optional[int] + seed : int | None Random seed used by numpy.random and random functions, such as in Langevin. Default is None. """ @@ -641,7 +641,7 @@ def _set_param_prefix(self, file_prefix: PathLike | None = None) -> str: Parameters ---------- - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames on class init. If not None, param_prefix = "". Returns @@ -1136,10 +1136,10 @@ class NPT(MolecularDynamics): Pressure, in GPa. Default is 0.0. ensemble : Ensembles Name for thermodynamic ensemble. Default is "npt". - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure, ensemble, temperature, and pressure. - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1179,10 +1179,10 @@ def __init__( Pressure, in GPa. Default is 0.0. ensemble : Ensembles Name for thermodynamic ensemble. Default is "npt". - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure, ensemble, temperature, and pressure. - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1219,7 +1219,7 @@ def _set_param_prefix(self, file_prefix: PathLike | None = None) -> str: Parameters ---------- - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames on class init. If not None, param_prefix = "". Returns @@ -1283,7 +1283,7 @@ class NVT(MolecularDynamics): Friction coefficient in fs^-1. Default is 0.005. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nvt". - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1313,7 +1313,7 @@ def __init__( Friction coefficient in fs^-1. Default is 0.005. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nvt". - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1378,7 +1378,7 @@ class NVE(MolecularDynamics): Additional arguments. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nve". - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1405,7 +1405,7 @@ def __init__( Additional arguments. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nve". - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1433,7 +1433,7 @@ class NVT_NH(NPT): # noqa: N801 (invalid-class-name) Thermostat time, in fs. Default is 50.0. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nvt-nh". - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1458,7 +1458,7 @@ def __init__( Thermostat time, in fs. Default is 50.0. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nvt-nh". - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1527,10 +1527,10 @@ class NPH(NPT): Pressure, in GPa. Default is 0.0. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nph". - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure, ensemble, temperature, and pressure. - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. @@ -1567,10 +1567,10 @@ def __init__( Pressure, in GPa. Default is 0.0. ensemble : Ensembles Name for thermodynamic ensemble. Default is "nph". - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure, ensemble, temperature, and pressure. - ensemble_kwargs : Optional[dict[str, Any]] + ensemble_kwargs : dict[str, Any] | None Keyword arguments to pass to ensemble initialization. Default is {}. **kwargs Additional keyword arguments. diff --git a/janus_core/calculations/phonons.py b/janus_core/calculations/phonons.py index ffc3cfc5..b69c5ed6 100644 --- a/janus_core/calculations/phonons.py +++ b/janus_core/calculations/phonons.py @@ -31,34 +31,34 @@ class Phonons(BaseCalculation): Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to calculate phonons for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to calculate phonons for. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. - calcs : Optional[MaybeSequence[PhononCalcs]] + calcs : MaybeSequence[PhononCalcs] | None Phonon calculations to run. Default calculates force constants only. supercell : MaybeList[int] The size of a supercell for calculation, or the supercell itself. @@ -79,7 +79,7 @@ class Phonons(BaseCalculation): minimize : bool Whether to perform geometry optimisation before calculating phonons. Default is False. - minimize_kwargs : Optional[dict[str, Any]] + minimize_kwargs : dict[str, Any] | None Keyword arguments to pass to geometry optimizer. Default is {}. temp_min : float Start temperature for thermal properties calculations, in K. Default is 0.0. @@ -98,7 +98,7 @@ class Phonons(BaseCalculation): write_full : bool Whether to maximize information written in various output files. Default is True. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from chemical formula of the structure. enable_progress_bar : bool @@ -173,34 +173,34 @@ def __init__( Parameters ---------- - struct : Optional[Atoms] + struct : Atoms | None ASE Atoms structure to calculate phonons for. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to calculate phonons for. Required if `struct` is None. Default is None. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is -1. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. - calcs : Optional[MaybeSequence[PhononCalcs]] + calcs : MaybeSequence[PhononCalcs] | None Phonon calculations to run. Default calculates force constants only. supercell : MaybeList[int] The size of a supercell for calculation, or the supercell itself. @@ -221,7 +221,7 @@ def __init__( minimize : bool Whether to perform geometry optimisation before calculating phonons. Default is False. - minimize_kwargs : Optional[dict[str, Any]] + minimize_kwargs : dict[str, Any] | None Keyword arguments to pass to geometry optimizer. Default is {}. temp_min : float Start temperature for thermal calculations, in K. Default is 0.0. @@ -240,7 +240,7 @@ def __init__( write_full : bool Whether to maximize information written in various output files. Default is True. - file_prefix : Optional[PathLike] + file_prefix : PathLike | None Prefix for output filenames. Default is inferred from structure name, or chemical formula of the structure. enable_progress_bar : bool @@ -373,7 +373,7 @@ def calc_force_constants( Parameters ---------- - write_force_consts : Optional[bool] + write_force_consts : bool | None Whether to write out results to file. Default is self.write_results. **kwargs Additional keyword arguments to pass to `write_force_constants`. @@ -448,13 +448,13 @@ def write_force_constants( Parameters ---------- - phonopy_file : Optional[PathLike] + phonopy_file : PathLike | None Name of yaml file to save params of phonopy and optionally force constants. Default is inferred from `file_prefix`. - force_consts_to_hdf5 : Optional[bool] + force_consts_to_hdf5 : bool | None Whether to save the force constants separately to an hdf5 file. Default is self.force_consts_to_hdf5. - force_consts_file : Optional[PathLike] + force_consts_file : PathLike | None Name of hdf5 file to save force constants. Unused if `force_consts_to_hdf5` is False. Default is inferred from `file_prefix`. """ @@ -488,7 +488,7 @@ def calc_bands(self, write_bands: bool | None = None, **kwargs) -> None: Parameters ---------- - write_bands : Optional[bool] + write_bands : bool | None Whether to write out results to file. Default is self.write_results. **kwargs Additional keyword arguments to pass to `write_bands`. @@ -516,12 +516,12 @@ def write_bands( Parameters ---------- - bands_file : Optional[PathLike] + bands_file : PathLike | None Name of yaml file to save band structure. Default is inferred from `file_prefix`. - save_plots : Optional[bool] + save_plots : bool | None Whether to save plot to file. Default is self.plot_to_file. - plot_file : Optional[PathLike] + plot_file : PathLike | None Name of svg file if saving band structure plot. Default is inferred from `file_prefix`. """ @@ -558,9 +558,9 @@ def calc_thermal_props( Parameters ---------- - mesh : Optional[tuple[int, int, int]] + mesh : tuple[int, int, int] | None Mesh for sampling. Default is self.mesh. - write_thermal : Optional[bool] + write_thermal : bool | None Whether to write out thermal properties to file. Default is self.write_results. **kwargs @@ -606,7 +606,7 @@ def write_thermal_props(self, thermal_file: PathLike | None = None) -> None: Parameters ---------- - thermal_file : Optional[PathLike] + thermal_file : PathLike | None Name of data file to save thermal properties. Default is inferred from `file_prefix`. """ @@ -640,9 +640,9 @@ def calc_dos( Parameters ---------- - mesh : Optional[tuple[int, int, int]] + mesh : tuple[int, int, int] | None Mesh for sampling. Default is self.mesh. - write_dos : Optional[bool] + write_dos : bool | None Whether to write out results to file. Default is True. **kwargs Additional keyword arguments to pass to `write_dos`. @@ -690,17 +690,17 @@ def write_dos( Parameters ---------- - dos_file : Optional[PathLike] + dos_file : PathLike | None Name of data file to save the calculated DOS. Default is inferred from `file_prefix`. - plot_to_file : Optional[bool] + plot_to_file : bool | None Whether to save plot to file. Default is self.plot_to_file. - plot_file : Optional[PathLike] + plot_file : PathLike | None Name of svg file if saving plot of the DOS. Default is inferred from `file_prefix`. plot_bands : bool Whether to plot the band structure and DOS together. Default is True. - plot_bands_file : Optional[PathLike] + plot_bands_file : PathLike | None Name of svg file if saving plot of the band structure and DOS. Default is inferred from `file_prefix`. """ @@ -747,9 +747,9 @@ def calc_pdos( Parameters ---------- - mesh : Optional[tuple[int, int, int]] + mesh : tuple[int, int, int] | None Mesh for sampling. Default is self.mesh. - write_pdos : Optional[bool] + write_pdos : bool | None Whether to write out results to file. Default is self.write_results. **kwargs Additional keyword arguments to pass to `write_pdos`. @@ -797,12 +797,12 @@ def write_pdos( Parameters ---------- - pdos_file : Optional[PathLike] + pdos_file : PathLike | None Name of file to save the calculated PDOS. Default is inferred from `file_prefix`. - plot_to_file : Optional[bool] + plot_to_file : bool | None Whether to save plot to file. Default is self.plot_to_file. - plot_file : Optional[PathLike] + plot_file : PathLike | None Name of svg file if saving plot of the calculated PDOS. Default is inferred from `file_prefix`. """ diff --git a/janus_core/calculations/single_point.py b/janus_core/calculations/single_point.py index a182e530..0fcb1b95 100644 --- a/janus_core/calculations/single_point.py +++ b/janus_core/calculations/single_point.py @@ -31,10 +31,10 @@ class SinglePoint(BaseCalculation): Parameters ---------- - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. arch : Architectures @@ -42,29 +42,29 @@ class SinglePoint(BaseCalculation): Default is "mace_mp". device : Devices Device to run model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. read_kwargs : ASEReadArgs Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is ":". - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. properties : MaybeSequence[Properties] Physical properties to calculate. If not specified, "energy", "forces", and "stress" will be returned. write_results : bool True to write out structure with results of calculations. Default is False. - write_kwargs : Optional[OutputKwargs] + write_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write if saving structure with results of calculations. Default is {}. @@ -103,10 +103,10 @@ def __init__( Parameters ---------- - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. arch : Architectures @@ -114,29 +114,29 @@ def __init__( Default is "mace_mp". device : Devices Device to run MLIP model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - read_kwargs : Optional[ASEReadArgs] + read_kwargs : ASEReadArgs | None Keyword arguments to pass to ase.io.read. By default, read_kwargs["index"] is ":". - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is None. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. properties : MaybeSequence[Properties] Physical properties to calculate. If not specified, "energy", "forces", and "stress" will be returned. write_results : bool True to write out structure with results of calculations. Default is False. - write_kwargs : Optional[OutputKwargs], + write_kwargs : OutputKwargs | None Keyword arguments to pass to ase.io.write if saving structure with results of calculations. Default is {}. """ diff --git a/janus_core/helpers/log.py b/janus_core/helpers/log.py index cfa9845d..bd224327 100644 --- a/janus_core/helpers/log.py +++ b/janus_core/helpers/log.py @@ -18,10 +18,10 @@ class YamlFormatter(logging.Formatter): # numpydoc ignore=PR02 Parameters ---------- - fmt : Optional[str] + fmt : str | None A format string in the given style for the logged output as a whole. Default is defined by `FORMAT`. - datefmt : Optional[str] + datefmt : str | None A format string in the given style for the date/time portion of the logged output. Default is taken from logging.Formatter.formatTime(). style : Literal['%', '{', '$'] @@ -30,7 +30,7 @@ class YamlFormatter(logging.Formatter): # numpydoc ignore=PR02 validate : bool If True, incorrect or mismatched fmt and style will raise a ValueError. Default is True. - defaults : Optional[dict[str, logging.Any]] + defaults : dict[str, logging.Any] | None A dictionary with default values to use in custom fields. Default is None. *args Arguments to pass to logging.Formatter.__init__. @@ -113,7 +113,7 @@ def config_logger( ---------- name : str Name of logger. Default is None. - filename : Optional[str] + filename : str | None Name of log file if writing logs. Default is None. level : LogLevel Threshold for logger. Default is logging.INFO. @@ -127,7 +127,7 @@ def config_logger( Returns ------- - Optional[logging.Logger] + logging.Logger | None Configured logger if `filename` has been specified. """ if filename: @@ -166,7 +166,7 @@ def config_tracker( Parameters ---------- - janus_logger : Optional[logging.Logger] + janus_logger : logging.Logger | None Logger for codecarbon output. track_carbon : bool Whether to track carbon emissions for calculation. Default is True. @@ -179,7 +179,7 @@ def config_tracker( Returns ------- - Optional[OfflineEmissionsTracker] + OfflineEmissionsTracker | None Configured offline codecarbon tracker, if logger is specified. """ if janus_logger and track_carbon: diff --git a/janus_core/helpers/mlip_calculators.py b/janus_core/helpers/mlip_calculators.py index e8b48020..2308c3e5 100644 --- a/janus_core/helpers/mlip_calculators.py +++ b/janus_core/helpers/mlip_calculators.py @@ -29,14 +29,14 @@ def _set_model_path( Parameters ---------- - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP file. - kwargs : Optional[dict[str, Any]] + kwargs : dict[str, Any] | None Dictionary of additional keyword arguments passed to the selected calculator. Returns ------- - Optional[PathLike | torch.nn.Module] + PathLike | torch.nn.Module | None Path to MLIP model file, loaded model, or None. """ kwargs = kwargs if kwargs else {} @@ -83,7 +83,7 @@ def choose_calculator( MLIP architecture. Default is "mace". device : Devices Device to run calculator on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP file. **kwargs Additional keyword arguments passed to the selected calculator. diff --git a/janus_core/helpers/struct_io.py b/janus_core/helpers/struct_io.py index bf877610..9cdc04f4 100644 --- a/janus_core/helpers/struct_io.py +++ b/janus_core/helpers/struct_io.py @@ -77,15 +77,15 @@ def attach_calculator( Parameters ---------- - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to attach calculators to. arch : Architectures MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. """ calc_kwargs = calc_kwargs if calc_kwargs else {} @@ -122,10 +122,10 @@ def input_structs( Parameters ---------- - struct : Optional[MaybeSequence[Atoms]] + struct : MaybeSequence[Atoms] | None ASE Atoms structure(s) to simulate. Required if `struct_path` is None. Default is None. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure to simulate. Required if `struct` is None. Default is None. read_kwargs : ASEReadArgs Keyword arguments to pass to ase.io.read. Default is {}. @@ -135,15 +135,15 @@ def input_structs( MLIP architecture to use for calculations. Default is "mace_mp". device : Devices Device to run model on. Default is "cpu". - model_path : Optional[PathLike] + model_path : PathLike | None Path to MLIP model. Default is `None`. - calc_kwargs : Optional[dict[str, Any]] + calc_kwargs : dict[str, Any] | None Keyword arguments to pass to the selected calculator. Default is {}. - set_calc : Optional[bool] + set_calc : bool | None Whether to set (new) calculators for structures. Default is True if `struct_path` is specified or `struct` is missing calculators, else default is False. - logger : Optional[logging.Logger] + logger : logging.Logger | None Logger if log file has been specified. Default is None. Returns @@ -232,7 +232,7 @@ def output_structs( ---------- images : MaybeSequence[Atoms] Atoms object or a list of Atoms objects to interact with. - struct_path : Optional[PathLike] + struct_path : PathLike | None Path of structure being simulated. If specified, the file stem is added to the info dict under "system_name". Default is None. set_info : bool @@ -244,7 +244,7 @@ def output_structs( invalidate_calc : bool Whether to remove all calculator results after copying properties to info dict. Default is False. - write_kwargs : Optional[ASEWriteArgs] + write_kwargs : ASEWriteArgs | None Keyword arguments passed to ase.io.write. Default is {}. """ # Separate kwargs for output_structs from kwargs for ase.io.write diff --git a/janus_core/helpers/utils.py b/janus_core/helpers/utils.py index 46f140a1..3153fac4 100644 --- a/janus_core/helpers/utils.py +++ b/janus_core/helpers/utils.py @@ -130,7 +130,7 @@ def _build_filename( Extra components to add to suffix (joined with hyphens). filename : PathLike | None Filename to use, if specified. Default is None. - prefix_override : Optional[str] + prefix_override : str | None Replace file_prefix if not None. Returns @@ -157,7 +157,7 @@ def none_to_dict(dictionaries: Sequence[dict | None]) -> Generator[dict, None, N Parameters ---------- - dictionaries : Sequence[Optional[dict]] + dictionaries : Sequence[dict | None] Sequence of dictionaries that could be None. Yields @@ -222,7 +222,7 @@ def write_table( Returns ------- - Optional[StringIO] + StringIO | None If no file given write columns to StringIO. Notes diff --git a/janus_core/processing/post_process.py b/janus_core/processing/post_process.py index 08af0e8d..044b8d02 100644 --- a/janus_core/processing/post_process.py +++ b/janus_core/processing/post_process.py @@ -64,9 +64,9 @@ def compute_rdf( ---------- data : MaybeSequence[Atoms] Dataset to compute RDF of. - ana : Optional[Analysis] + ana : Analysis | None ASE Analysis object for data reuse. - filenames : Optional[MaybeSequence[PathLike]] + filenames : MaybeSequence[PathLike] | None Filenames to output data to. Must match number of RDFs computed. by_elements : bool Split RDF into pairwise by elements group. Default is False. @@ -76,7 +76,7 @@ def compute_rdf( Maximum distance of RDF. nbins : int Number of bins to divide RDF. - elements : Optional[MaybeSequence[Union[int, str]]] + elements : MaybeSequence[int | str] | None Make partial RDFs. If `by_elements` is true will filter to only display pairs in list. index : SliceLike @@ -84,13 +84,13 @@ def compute_rdf( `index` if `int`, `start`, `stop`, `step` if `tuple`, `slice` if `slice` or `range`. - volume : Optional[float] + volume : float | None Volume of cell for normalisation. Only needs to be provided if aperiodic cell. Default is (2*rmax)**3. Returns ------- - Union[NDArray[float64], dict[tuple[str, str], NDArray[float64]]] + NDArray[float64] | dict[tuple[str, str] | NDArray[float64]] If `by_elements` is true returns a `dict` of RDF by element pairs. Otherwise returns RDF of total system filtered by elements. """ @@ -200,7 +200,7 @@ def compute_vaf( ---------- data : Sequence[Atoms] Dataset to compute VAF of. - filenames : Optional[MaybeSequence[PathLike]] + filenames : MaybeSequence[PathLike] | None If present, dump resultant VAF to file. use_velocities : bool Compute VAF using velocities rather than momenta. @@ -211,7 +211,7 @@ def compute_vaf( index : SliceLike Images to analyze as `start`, `stop`, `step`. Default is all images. - filter_atoms : MaybeSequence[MaybeSequence[Optional[int]]] + filter_atoms : MaybeSequence[MaybeSequence[int | None]] Compute the VAF averaged over subsets of the system. Default is all atoms. time_step : float diff --git a/janus_core/training/train.py b/janus_core/training/train.py index 6962fce6..72bb5610 100644 --- a/janus_core/training/train.py +++ b/janus_core/training/train.py @@ -58,16 +58,16 @@ def train( ---------- mlip_config : PathLike Configuration file to pass to MLIP. - req_file_keys : Optional[list[PathLike]] + req_file_keys : list[PathLike] | None List of files that must exist if defined in the configuration file. Default is ["train_file", "test_file", "valid_file", "statistics_file"]. attach_logger : bool Whether to attach a logger. Default is False. - log_kwargs : Optional[dict[str, Any]] + log_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_logger`. Default is {}. track_carbon : bool Whether to track carbon emissions of calculation. Default is True. - tracker_kwargs : Optional[dict[str, Any]] + tracker_kwargs : dict[str, Any] | None Keyword arguments to pass to `config_tracker`. Default is {}. """ (log_kwargs, tracker_kwargs) = none_to_dict((log_kwargs, tracker_kwargs)) diff --git a/tests/utils.py b/tests/utils.py index acd0188b..0216be40 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -24,7 +24,7 @@ def read_atoms(path: Path) -> Atoms | None: Returns ------- - Union[Atoms, None] + Atoms | None Atoms structure read from file, or None is any Exception is thrown. """ assert path.exists()