From 53e1f41564342032f4e35cd173e23f9dc49d92e5 Mon Sep 17 00:00:00 2001
From: Sean Kavanagh <s.kavanagh19@imperial.ac.uk>
Date: Wed, 29 Jan 2025 23:41:31 -0500
Subject: [PATCH] More docstring formatting

---
 shakenbreak/analysis.py                    |  40 ++++----
 shakenbreak/cli.py                         |  10 +-
 shakenbreak/distortions.py                 |  10 +-
 shakenbreak/energy_lowering_distortions.py |  24 ++---
 shakenbreak/input.py                       | 103 +++++++++++----------
 shakenbreak/io.py                          |   4 +-
 shakenbreak/plotting.py                    |  38 ++++----
 tests/test_input.py                        |   2 +-
 8 files changed, 116 insertions(+), 115 deletions(-)

diff --git a/shakenbreak/analysis.py b/shakenbreak/analysis.py
index c4eb7e53..1cbc6f98 100644
--- a/shakenbreak/analysis.py
+++ b/shakenbreak/analysis.py
@@ -63,7 +63,7 @@ def _read_distortion_metadata(output_path: str) -> dict:
 
     Args:
         output_path (:obj:`str`):
-            Path to directory containing ``distortion_metadata.json`
+            Path to directory containing ``distortion_metadata.json``
             (Default: '.', current directory)
 
     Returns:
@@ -155,14 +155,14 @@ def get_gs_distortion(defect_energies_dict: dict) -> tuple:
     """
     Calculate energy difference between ``Unperturbed`` structure and
     lowest energy distortion. Returns the energy (in eV) and bond
-    distortion of the ground-state relative to ``Unperturbed`. If
+    distortion of the ground-state relative to ``Unperturbed``. If
     ``Unperturbed`` not present, returns (None, ground-state bond
     distortion).
 
     Args:
         defect_energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy, as
-            produced by ``get_energies()`` or ``_sort_data`.
+            produced by ``get_energies()`` or ``_sort_data``.
 
     Returns:
         :obj:`tuple`:
@@ -211,7 +211,7 @@ def _sort_data(energies_file: str, verbose: bool = True, min_e_diff: float = 0.0
         energies_file (:obj:`str`):
             Path to ``yaml`` file with bond distortions and final energies
             (in eV), obtained using the CLI command ``snb-parse`` or the
-            function ``parse_energies()`.
+            function ``parse_energies()``.
         verbose (:obj:`bool`):
             Whether to print information about energy lowering
             distortions, if found.
@@ -225,7 +225,7 @@ def _sort_data(energies_file: str, verbose: bool = True, min_e_diff: float = 0.0
     Returns:
         defect_energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy, as
-            produced by ``_organize_data()`
+            produced by ``_organize_data()``
         energy_diff (:obj:`float`):
             Energy difference between minimum energy structure and
             ``Unperturbed`` (in eV).
@@ -271,7 +271,7 @@ def analyse_defect_site(
     site_num: Optional[int] = None,
     vac_site: Optional[list] = None,
 ) -> tuple:
-    """
+    r"""
     Analyse coordination environment and bond distances to nearest
     neighbours of defect site.
 
@@ -290,7 +290,7 @@ def analyse_defect_site(
 
     Returns:
         :obj:`tuple`:
-            Tuple of coordination analysis and bond length DataFrames,
+            Tuple of coordination analysis and bond length ``DataFrame``\s,
             respectively.
     """
     # get defect site
@@ -338,11 +338,11 @@ def analyse_structure(
     structure: Structure,
     output_path: str = ".",
 ) -> tuple:
-    """
+    r"""
     Analyse the local distortion of the input defect structure. Requires
     access to the ``distortion_metadata.json`` file generated with
     ShakeNBreak to read info about defect site. If lacking this,
-    can alternatively use ``analyse_defect_site()`.
+    can alternatively use ``analyse_defect_site()``.
 
     Args:
         defect_species (:obj:`str`):
@@ -350,12 +350,12 @@ def analyse_structure(
         structure (:obj:`~pymatgen.core.structure.Structure`):
             Defect structure to analyse
         output_path (:obj:`str`):
-            Path to directory containing ``distortion_metadata.json`
+            Path to directory containing ``distortion_metadata.json``
             (Default: '.', current directory)
 
     Returns:
         :obj:`tuple`:
-            Tuple of coordination analysis and bond length DataFrames,
+            Tuple of coordination analysis and bond length ``DataFrame``\s,
             respectively.
     """
     defect_name_without_charge = defect_species.rsplit("_", 1)[0]
@@ -391,14 +391,14 @@ def get_structures(
     store them in a dictionary matching the bond distortion to the final
     structure. By default, will read the structures from the distortion
     subdirectories present in each defect folder. If only certain
-    distortions should be parsed, use the argument ``bond_distortions`
+    distortions should be parsed, use the argument ``bond_distortions``
     to specify them.
 
     Args:
         defect_species (:obj:`str`):
             Defect name including charge (e.g. 'vac_1_Cd_0')
         output_path (:obj:`str`):
-            Path to top-level directory containing ``defect_species`
+            Path to top-level directory containing ``defect_species``
             subdirectories.
             (Default: current directory.
         bond_distortions (:obj:`list`, optional):
@@ -489,7 +489,7 @@ def get_energies(
         defect_species (:obj:`str`):
             Defect name including charge (e.g. 'vac_1_Cd_0')
         output_path (:obj:`str`):
-            Path to top-level directory containing ``defect_species`
+            Path to top-level directory containing ``defect_species``
             subdirectories.
             (Default: current directory)
         distortion_increment (:obj:`float`):
@@ -581,8 +581,8 @@ def calculate_struct_comparison(
     """
     Calculate either the summed atomic displacement, with metric = "disp",
     or the maximum distance between matched atoms, with metric = "max_dist",
-    (default) between each distorted structure in ``defect_struct_dict`,
-    and either 'Unperturbed' or a specified structure (`ref_structure`).
+    (default) between each distorted structure in ``defect_struct_dict``,
+    and either 'Unperturbed' or a specified structure (``ref_structure``).
     For metric = "disp", atomic displacements below ``min_dist`` (in Å,
     default 0.1 Å) are considered noise and omitted from the sum,
     to reduce supercell size dependence.
@@ -704,7 +704,7 @@ def compare_structures(
 ) -> Union[None, pd.DataFrame]:
     """
     Compare final bond-distorted structures with either 'Unperturbed' or
-    a specified structure (`ref_structure`), and calculate the summed
+    a specified structure (``ref_structure``), and calculate the summed
     atomic displacement (in Å), and maximum distance between matched
     atomic sites (in Å).
 
@@ -713,7 +713,7 @@ def compare_structures(
             Dictionary mapping bond distortion to (relaxed) structure
         defect_energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy (eV), as
-            produced by ``_organize_data()`.
+            produced by ``_organize_data()``.
         ref_structure (:obj:`str`` or :obj:`float`` or :obj:`Structure`):
             Structure to use as a reference for comparison (to compute
             atomic displacements). Either as a key from
@@ -723,7 +723,7 @@ def compare_structures(
             (Default: "Unperturbed")
         units (:obj:`str`):
             Energy units label for outputs (either 'eV' or 'meV').
-            Should be the same as the units in ``defect_energies_dict`,
+            Should be the same as the units in ``defect_energies_dict``,
             as this does not modify the supplied values.
             (Default: "eV")
         min_dist (:obj:`float`):
@@ -1005,7 +1005,7 @@ def get_site_magnetizations(
             List of distortions to analyse (e.g. ['Unperturbed', 0.1,
             -0.2])
         output_path (:obj:`str`):
-            Path to top-level directory containing ``defect_species`
+            Path to top-level directory containing ``defect_species``
             subdirectories.
             (Default: current directory)
         threshold (:obj:`float`, optional):
diff --git a/shakenbreak/cli.py b/shakenbreak/cli.py
index 0b238ae8..b5782e8c 100644
--- a/shakenbreak/cli.py
+++ b/shakenbreak/cli.py
@@ -242,7 +242,7 @@ def generate(
     defect_struct = Structure.from_file(defect)
     bulk_struct = Structure.from_file(bulk)
 
-    # Note that here the Defect.defect_structure is the defect ``supercell`
+    # Note that here the Defect.defect_structure is the defect ``supercell``
     # structure, not the defect ``primitive`` structure.
     defect_object = input.identify_defect(
         defect_structure=defect_struct,
@@ -926,7 +926,7 @@ def parse(defect, path, code, verbose):
 def analyse(defect, path, code, ref_struct, verbose):
     """
     Generate ``csv`` file mapping each distortion to its final energy (in eV) and its
-    mean displacement (in Angstrom and relative to ``ref_struct`).
+    mean displacement (in Angstrom and relative to ``ref_struct``).
 
     Can be run within a single defect folder, or in the top-level directory (either
     specifying ``defect`` or looping through all defect folders).
@@ -1406,10 +1406,10 @@ def groundstate(
 ):
     """
     Generate folders with the identified ground state structures. A folder (named
-    ``directory`) is created with the ground state structure (named
-    ``groundstate_filename`) for each defect present in the specified path (if ``path`` is
+    ``directory``) is created with the ground state structure (named
+    ``groundstate_filename``) for each defect present in the specified path (if ``path`` is
     the top-level directory) or for the current defect if run within a defect folder.
-    If the name of the structure/output files is not specified, the code assumes ``CONTCAR`
+    If the name of the structure/output files is not specified, the code assumes ``CONTCAR``
     (e.g. geometry optimisations performed with VASP). If using a different code,
     please specify the name of the structure/output files.
     """
diff --git a/shakenbreak/distortions.py b/shakenbreak/distortions.py
index 0fcb9aae..51522569 100644
--- a/shakenbreak/distortions.py
+++ b/shakenbreak/distortions.py
@@ -406,7 +406,7 @@ def rattle(
     """
     Given a pymatgen Structure object, apply random displacements to all atomic
     positions, with the displacement distances randomly drawn from a Gaussian
-    distribution of standard deviation ``stdev`.
+    distribution of standard deviation ``stdev``.
 
     Args:
         structure (:obj:`~pymatgen.core.structure.Structure`):
@@ -587,7 +587,7 @@ def _local_mc_rattle_displacements(
 
     Returns:
         :obj:`numpy.ndarray`:
-            atomic displacements (`Nx3`)
+            atomic displacements (Nx3)
     """
 
     def scale_stdev(disp, r_min, r):
@@ -685,7 +685,7 @@ def _generate_local_mc_rattled_structures(
 
     This process is repeated for each atom a number of times meaning
     the magnitude of the final displacements is not *directly*
-    connected to ``rattle_std`.
+    connected to ``rattle_std``.
 
     This function has been adapted from https://gitlab.com/materials-modeling/hiphive
 
@@ -721,7 +721,7 @@ def _generate_local_mc_rattled_structures(
         n_iter (:obj:`int`):
             Number of Monte Carlo cycles
         **kwargs:
-            Additional keyword arguments to be passed to ``mc_rattle`
+            Additional keyword arguments to be passed to ``mc_rattle``
 
     Returns:
         :obj:`list`:
@@ -758,7 +758,7 @@ def local_mc_rattle(
     """
     Given a pymatgen Structure object, apply random displacements to all atomic
     positions, with the displacement distances randomly drawn from a Gaussian
-    distribution of standard deviation ``stdev`. The random displacements
+    distribution of standard deviation ``stdev``. The random displacements
     tail off as we move away from the defect site.
 
     Args:
diff --git a/shakenbreak/energy_lowering_distortions.py b/shakenbreak/energy_lowering_distortions.py
index d9e40deb..64d4a0c4 100644
--- a/shakenbreak/energy_lowering_distortions.py
+++ b/shakenbreak/energy_lowering_distortions.py
@@ -104,9 +104,9 @@ def _compare_distortion(
     **sm_kwargs,
 ) -> dict:
     """
-    Compare the ground state distortion (`gs_distortion`) to the other
-    favourable distortions stored in ``low_energy_defects`. If different,
-    add distortion as separate entry to ``low_energy_defects`.
+    Compare the ground state distortion (``gs_distortion``) to the other
+    favourable distortions stored in ``low_energy_defects``. If different,
+    add distortion as separate entry to ``low_energy_defects``.
     If same, store together with the other similar distortions.
 
     Args:
@@ -645,7 +645,7 @@ def compare_struct_to_distortions(
 ) -> tuple:
     """
     Compares the ground-state structure found for a certain defect charge
-    state with all relaxed bond-distorted structures for ``defect_species`,
+    state with all relaxed bond-distorted structures for ``defect_species``,
     to avoid redundant work (testing this distorted structure for other
     charge states when it has already been found for them).
 
@@ -683,7 +683,7 @@ def compare_struct_to_distortions(
             matching structure compared to its unperturbed reference, bond
             distortion of the matching structure). True if a match is found
             between the input structure and the relaxed bond-distorted
-            structures for ``defect_species`, False if no match, None if no
+            structures for ``defect_species``, False if no match, None if no
             converged structures found for defect_species.
     """
     try:
@@ -693,7 +693,7 @@ def compare_struct_to_distortions(
             code=code,
             structure_filename=structure_filename,
         )
-    except FileNotFoundError:  # catch exception raised by ``analysis.get_structures()`
+    except FileNotFoundError:  # catch exception raised by ``analysis.get_structures()``
         return None, None, None, None
     defect_energies_dict = analysis.get_energies(
         defect_species=defect_species, output_path=output_path, verbose=False
@@ -811,14 +811,14 @@ def write_retest_inputs(
     """
     Create folders with relaxation input files for testing the low-energy
     distorted defect structures found for other charge states of that
-    defect, as identified with ``get_energy_lowering_distortions()`.
+    defect, as identified with ``get_energy_lowering_distortions()``.
 
     Args:
         low_energy_defects (:obj:`dict`):
             Dictionary of defects for which bond distortion found an
             energy-lowering distortion which is missed with normal
             unperturbed relaxation), generated by
-            ``get_energy_lowering_distortions()`. Has the form
+            ``get_energy_lowering_distortions()``. Has the form
             {defect: [list of distortion dictionaries (with
             corresponding charge states, energy lowering, distortion
             factors, structures and charge states for which these
@@ -833,7 +833,7 @@ def write_retest_inputs(
             (case-insensitive).
             (Default: "vasp")
         input_filename (:obj:`str`):
-            Name of the code input file if different from ``ShakeNBreak`
+            Name of the code input file if different from ``ShakeNBreak``
             default. Only applies to CP2K, Quantum Espresso, CASTEP and
             FHI-aims. If not specified, ``ShakeNBreak`` default name is
             assumed, that is: for Quantum Espresso: "espresso.pwi",
@@ -1195,19 +1195,19 @@ def write_groundstate_structure(
     verbose: bool = False,
 ) -> None:
     """
-    Writes the groundstate structure of each defect (if ``all=True`, default)
+    Writes the groundstate structure of each defect (if ``all=True``, default)
     to the corresponding defect folder, with an optional name
     (default "groundstate_POSCAR"), to then run continuation calculations.
 
     Args:
         all (:obj:`bool`):
             Write groundstate structures for all defect folders in the
-            (top-level) directory, specified by ``output_path`. If False,
+            (top-level) directory, specified by ``output_path``. If False,
             ``output_path`` should be a single defect folder, for which the
             groundstate structure will be written.
         output_path (:obj:`str`):
             Path to top-level directory with your distorted defect
-            calculation folders (if ``all=True`, else path to single defect
+            calculation folders (if ``all=True``, else path to single defect
             folder)(need CONTCAR files for structure matching) and
             distortion_metadata.json.
             (Default: current directory = "./")
diff --git a/shakenbreak/input.py b/shakenbreak/input.py
index 4262afe1..4488953a 100644
--- a/shakenbreak/input.py
+++ b/shakenbreak/input.py
@@ -1,7 +1,7 @@
 """
 Module containing functions to generate rattled and bond-distorted structures,
-as well as input files to run Gamma point relaxations with ``VASP`, ``CP2K`,
-`Quantum-Espresso`, ``FHI-aims`` and ``CASTEP`.
+as well as input files to run Gamma point relaxations with ``VASP``, ``CP2K``,
+``Quantum-Espresso``, ``FHI-aims`` and ``CASTEP``.
 """
 
 import contextlib
@@ -50,8 +50,8 @@
 
 def _warning_on_one_line(message, category, filename, lineno, file=None, line=None) -> str:
     """Output warning messages on one line."""
-    # To set this as warnings.formatwarning, we need to be able to take in ``file`
-    # and ``line`, but don't want to print them, so unused arguments here
+    # To set this as warnings.formatwarning, we need to be able to take in ``file``
+    # and ``line``, but don't want to print them, so unused arguments here
     return f"{os.path.split(filename)[-1]}:{lineno}: {category.__name__}: {message}\n"
 
 
@@ -287,7 +287,7 @@ def _create_vasp_input(
     output_path: str = ".",
     **kwargs,
 ) -> str:
-    """
+    r"""
     Creates folders for storing VASP ShakeNBreak files.
 
     Args:
@@ -304,16 +304,16 @@ def _create_vasp_input(
         user_potcar_settings (:obj:`dict`):
             Dictionary of user VASP POTCAR settings, to overwrite/update
             the ``doped`` defaults (e.g. {'Fe': 'Fe_pv', 'O': 'O'}}). Highly
-            recommended to look at output ``POTCAR`s, or ``shakenbreak`
-            ``shakenbreak/SnB_input_files/default_POTCARs.yaml`, to see what the default
-            ``POTCAR`` settings are. (Default: None)
+            recommended to look at output ``POTCAR``\s, or
+            ``shakenbreak/SnB_input_files/default_POTCARs.yaml``, to see what
+            the default ``POTCAR`` settings are. (Default: None)
         output_path (:obj:`str`):
             Path to directory in which to write distorted defect structures and
             calculation inputs.
             (Default is current directory = "./")
         **kwargs:
             Keyword arguments to pass to ``DefectDictSet.write_input()`` (e.g.
-            ``potcar_spec`).
+            ``potcar_spec``).
 
     Returns:
         :obj:`str`:
@@ -559,7 +559,7 @@ def _get_defect_entry_from_defect(
     charge_state: int = 0,
 ):
     """
-    Generate a DefectEntry from a Defect object, whose defect structure
+    Generate a ``DefectEntry`` from a ``Defect`` object, whose defect structure
     corresponds to the defect supercell (rather than unit cell). This is the case
     when initialising Distortions() from an old doped/pycdt defect dict or from
     structures specified by the user.
@@ -628,7 +628,7 @@ def _calc_number_electrons(
 ) -> int:
     """
     Calculates the number of extra/missing electrons of the neutral
-    defect species (in ``defect_object`) based on ``oxidation_states`.
+    defect species (in ``defect_object``) based on ``oxidation_states``.
 
     Args:
         defect_entry (:obj:`DefectEntry`):
@@ -1207,11 +1207,11 @@ def _find_sc_defect_coords(defect_entry):
     """
     Find defect fractional coordinates in defect supercell.
 
-    Targets cases where user generated DefectEntry manually and
+    Targets cases where user generated ``DefectEntry`` manually and
     didn't set the ``sc_defect_frac_coords`` attribute.
 
     Args:
-        defect_entry (DefectEntry): DefectEntry object
+        defect_entry (DefectEntry): ``DefectEntry`` object
 
     Returns:
         frac_coords (list): Fractional coordinates of defect in defect supercell
@@ -1431,7 +1431,7 @@ def apply_snb_distortions(
 ) -> dict:
     """
     Applies rattle and bond distortions to ``num_nearest_neighbours`` of the
-    unperturbed defect structure of ``defect_entry`.
+    unperturbed defect structure of ``defect_entry``.
 
     Args:
         defect_entry (:obj:`DefectEntry`):
@@ -1644,8 +1644,8 @@ def apply_snb_distortions(
 
 class Distortions:
     """
-    Class to apply rattle and bond distortion to all defects in ``defect_entries`
-    (each defect as a ``doped`` or ``pymatgen`` DefectEntry object).
+    Class to apply rattle and bond distortion to all defects in ``defect_entries``
+    (each defect as a ``doped`` or ``pymatgen`` ``DefectEntry`` object).
     """
 
     def __init__(
@@ -1660,28 +1660,28 @@ def __init__(
         distorted_atoms: Optional[list] = None,
         **mc_rattle_kwargs,
     ):
-        """
+        r"""
         Args:
             defect_entries (Union[DefectsGenerator, list, dict, DefectEntry]):
-                Either a ``DefectsGenerator`` object from ``doped`, or a list/dictionary
-                of, or single, DefectEntry object(s).
-                E.g.: [DefectEntry(), DefectEntry(), ...], or single DefectEntry.
+                Either a ``DefectsGenerator`` object from ``doped``, or a list/dictionary
+                of, or single, ``DefectEntry`` object(s).
+                E.g.: ``[DefectEntry(), DefectEntry(), ...]``, or single ``DefectEntry``.
                 If a ``DefectsGenerator`` object or a dictionary (->
-                {defect_species: DefectEntry}), the defect folder names will be
+                ``{defect_species: DefectEntry}``), the defect folder names will be
                 set equal to ``defect_species`` (with charge states included). If
                 a list or single ``DefectEntry`` object is provided, the defect
-                folder names will be set equal to ``DefectEntry.name`` if the ``name`
-                attribute is set for all input ``DefectEntry`s, otherwise generated
+                folder names will be set equal to ``DefectEntry.name`` if the ``name``
+                attribute is set for all input ``DefectEntry``\s, otherwise generated
                 according to the ``doped`` convention
                 (see: https://doped.readthedocs.io/en/latest/generation_tutorial.html).
 
                 Defect charge states (from which bond distortions are determined) are
                 taken from the ``DefectEntry.charge_state`` property.
 
-                Alternatively, a defects dict generated by ``ChargedDefectStructures`
-                from ``PyCDT`/`doped<2.0`` can also be used as input, and the defect names
+                Alternatively, a defects dict generated by ``ChargedDefectStructures``
+                from ``PyCDT``/``doped<2.0`` can also be used as input, and the defect names
                 and charge states generated by these codes will be used
-                E.g.: {"bulk": {..}, "vacancies": [{...}, {...},], ...}
+                E.g.: ``{"bulk": {..}, "vacancies": [{...}, {...},], ...}``
             oxidation_states (:obj:`dict`):
                 Dictionary of oxidation states for species in your material,
                 used to determine the number of defect neighbours to distort
@@ -1697,7 +1697,7 @@ def __init__(
                 (Default: None)
             distortion_increment (:obj:`float`):
                 Bond distortion increment. Distortion factors will range from
-                0 to +/-0.6, in increments of ``distortion_increment`.
+                0 to +/-0.6, in increments of ``distortion_increment``.
                 Recommended values: 0.1-0.3
                 (Default: 0.1)
             bond_distortions (:obj:`list`):
@@ -2036,8 +2036,8 @@ def _parse_number_electrons(
                 where charge_change is the negative of the number of
                 extra/missing electrons.
             defect_entry (:obj:`DefectEntry`):
-                DefectEntry in dictionary of defect_entries. Must be a
-                ``doped`` or ``pymatgen`` DefectEntry object.
+                ``DefectEntry`` in dictionary of defect_entries. Must be a
+                ``doped`` or ``pymatgen`` ``DefectEntry`` object.
             verbose (:obj:`bool`):
                 Whether to print the number of extra/missing electrons for
                 the defect.
@@ -2171,15 +2171,15 @@ def _setup_distorted_defect_dict(
     ) -> dict:
         """
         Setup ``distorted_defect_dict`` with info for ``defect`` in
-        ``DefectEntry`.
+        ``DefectEntry``.
 
         Args:
             defect_entry (:obj:`doped.core.DefectEntry`):
-                DefectEntry object to generate ``distorted_defect_dict`` from.
+                ``DefectEntry`` object to generate ``distorted_defect_dict`` from.
 
         Returns:
             :obj:`dict`
-                Dictionary with information for ``defect`.
+                Dictionary with information for ``defect``.
         """
         defect = defect_entry.defect
         defect_type = defect.defect_type.name.lower()
@@ -2272,10 +2272,10 @@ def apply_distortions(
         verbose: Optional[bool] = None,
     ) -> tuple[dict, dict]:
         """
-        Applies rattle and bond distortion to all defects in ``defect_entries`.
+        Applies rattle and bond distortion to all defects in ``defect_entries``.
         Returns a dictionary with the distorted (and undistorted) structures
         for each charge state of each defect.
-        If file generation is desired, instead use the methods ``write_<code>_files()`.
+        If file generation is desired, instead use the methods ``write_<code>_files()``.
 
         Args:
             verbose (:obj:`bool`):
@@ -2464,7 +2464,7 @@ def write_vasp_files(
         verbose: Optional[bool] = None,
         **kwargs,
     ) -> tuple[dict, dict]:
-        """
+        r"""
         Generates the input files for ``vasp_gam`` relaxations of all output
         structures.
 
@@ -2472,20 +2472,20 @@ def write_vasp_files(
             user_incar_settings (:obj:`dict`):
                 Dictionary of user VASP INCAR settings (e.g.
                 {"ENCUT": 300, ...}), to overwrite the ``ShakenBreak`` defaults
-                for those tags. Highly recommended to look at output ``INCAR`s,
-                or ``shakenbreak/SnB_input_files/incar.yaml`` to see what the default ``INCAR`
-                settings are. Note that any flags that aren't numbers or
+                for those tags. Highly recommended to look at output ``INCAR``\s,
+                or ``shakenbreak/SnB_input_files/incar.yaml`` to see what the default
+                ``INCAR`` settings are. Note that any flags that aren't numbers or
                 True/False need to be input as strings with quotation marks
-                (e.g. ``{"ALGO": "All"}`). (Default: None)
+                (e.g. ``{"ALGO": "All"}``). (Default: None)
             user_potcar_functional (str):
                 POTCAR functional to use. Default is "PBE" and if this fails,
                 tries "PBE_52", then "PBE_54".
             user_potcar_settings (:obj:`dict`):
                 Dictionary of user VASP POTCAR settings, to overwrite/update
                 the ``doped`` defaults (e.g. {'Fe': 'Fe_pv', 'O': 'O'}}). Highly
-                recommended to look at output ``POTCAR`s, or ``shakenbreak`
-                ``shakenbreak/SnB_input_files/default_POTCARs.yaml`, to see what the default
-                ``POTCAR`` settings are. (Default: None)
+                recommended to look at output ``POTCAR``\s, or
+                ``shakenbreak/SnB_input_files/default_POTCARs.yaml``, to see what
+                the default ``POTCAR`` settings are. (Default: None)
             write_files (:obj:`bool`):
                 Whether to write output files (Default: True)
             output_path (:obj:`str`):
@@ -2496,7 +2496,7 @@ def write_vasp_files(
                 Whether to print distortion information (bond atoms and
                 distances). (Default: None -- medium level verbosity)
             kwargs:
-                Additional keyword arguments to pass to ``_create_vasp_input()`
+                Additional keyword arguments to pass to ``_create_vasp_input()``
                 (Mainly for testing purposes).
 
         Returns:
@@ -2581,12 +2581,13 @@ def write_espresso_files(
                 (Defaults: None)
             input_parameters (:obj:`dict`, optional):
                 Dictionary of user Quantum Espresso input parameters, to
-                overwrite/update ``shakenbreak`` default ones (see
-                ``shakenbreak/SnB_input_files/qe_input.yaml`).
+                overwrite/update ShakeNBreak defaults (see
+                ``shakenbreak/SnB_input_files/qe_input.yaml``).
                 (Default: None)
             input_file (:obj:`str`, optional):
                 Path to Quantum Espresso input file, to overwrite/update
-                ``shakenbreak`` default ones (see ``shakenbreak/SnB_input_files/qe_input.yaml`).
+                ShakeNBreak defaults (see
+                ``shakenbreak/SnB_input_files/qe_input.yaml``).
                 If both ``input_parameters`` and ``input_file`` are provided,
                 the input_parameters will be used.
                 (Default: None)
@@ -2711,7 +2712,7 @@ def write_cp2k_files(
         Args:
             input_file (:obj:`str`, optional):
                 Path to CP2K input file. If not set, default input file will be
-                used (see ``shakenbreak/SnB_input_files/cp2k_input.inp`).
+                used (see ``shakenbreak/SnB_input_files/cp2k_input.inp``).
             write_structures_only (:obj:`bool`, optional):
                 Whether to only write the structure files (in CIF format)
                 (without calculation inputs).
@@ -2773,8 +2774,8 @@ def write_castep_files(
 
         Args:
             input_file (:obj:`str`, optional):
-                Path to CASTEP input (`.param`) file. If not set, default input
-                file will be used (see ``shakenbreak/SnB_input_files/castep.param`).
+                Path to CASTEP input (``.param``) file. If not set, default input
+                file will be used (see ``shakenbreak/SnB_input_files/castep.param``).
             write_structures_only (:obj:`bool`, optional):
                 Whether to only write the structure files (in CIF format)
                 (without calculation inputs).
@@ -2995,7 +2996,7 @@ def from_structures(
                 [(defect Structure, frac_coords/index), ...] to aid site-matching.
 
                 Defect charge states (from which bond distortions are determined) are
-                set to the range: 0 - {Defect oxidation state}, with a ``padding`
+                set to the range: 0 - {Defect oxidation state}, with a ``padding``
                 (default = 1) on either side of this range.
             bulk (:obj:`pymatgen.core.structure.Structure`):
                 Bulk supercell structure, matching defect supercells.
@@ -3018,7 +3019,7 @@ def from_structures(
                 (Default: None)
             distortion_increment (:obj:`float`):
                 Bond distortion increment. Distortion factors will range from
-                0 to +/-0.6, in increments of ``distortion_increment`.
+                0 to +/-0.6, in increments of ``distortion_increment``.
                 Recommended values: 0.1-0.3
                 (Default: 0.1)
             bond_distortions (:obj:`list`):
diff --git a/shakenbreak/io.py b/shakenbreak/io.py
index b442f5a5..cbc6603f 100644
--- a/shakenbreak/io.py
+++ b/shakenbreak/io.py
@@ -199,7 +199,7 @@ def parse_fhi_aims_energy(defect_dir, dist, energy, aims_out):
 
     if defect == os.path.basename(os.path.normpath(path)) and not [
         dir for dir in path if (os.path.isdir(dir) and os.path.basename(os.path.normpath(dir)) == defect)
-    ]:  # if ``defect`` is in end of ``path`` and ``path`` doesn't have a subdirectory called ``defect`
+    ]:  # if ``defect`` is in end of ``path`` and ``path`` doesn't have a subdirectory called ``defect``
         # then remove defect from end of path
         path = os.path.dirname(path)
 
@@ -555,7 +555,7 @@ def read_castep_structure(
     filename: str,
 ) -> Union[Structure, str]:
     """
-    Reads a structure from CASTEP output (`.castep`) file and returns it as a
+    Reads a structure from CASTEP output (``.castep``) file and returns it as a
     pymatgen Structure.
 
     Args:
diff --git a/shakenbreak/plotting.py b/shakenbreak/plotting.py
index 84a8d8f1..b55b70e8 100644
--- a/shakenbreak/plotting.py
+++ b/shakenbreak/plotting.py
@@ -99,7 +99,7 @@ def _verify_data_directories_exist(
     output_path: str,
     defect_species: str,
 ) -> None:
-    """Check top-level directory (e.g. ``output_path`) and defect folders exist."""
+    """Check top-level directory (e.g. ``output_path``) and defect folders exist."""
     # Check directories and input
     if not os.path.isdir(output_path):  # if output_path does not exist, raise error
         raise FileNotFoundError(f"Path {output_path} does not exist! Skipping {defect_species}.")
@@ -155,7 +155,7 @@ def _cast_energies_to_floats(
     Args:
         energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy (eV), as produced by
-            ``_organize_data()`` or ``analysis.get_energies()`)..
+            ``_organize_data()`` or ``analysis.get_energies()``)..
         defect_species (:obj:`str`):
             Defect name including charge (e.g. 'vac_1_Cd_0')
 
@@ -222,7 +222,7 @@ def _purge_data_dicts(
         disp_dict (dict):
             dictionary with displacements (for each structure relative to
             Unperturbed), in the output format of
-            ``analysis.calculate_struct_comparison()`
+            ``analysis.calculate_struct_comparison()``
         energies_dict (dict):
             dictionary with final energies (for each structure relative to ¡
             Unperturbed), in the output format of ``analysis.get_energies()`` or
@@ -252,18 +252,18 @@ def _remove_high_energy_points(
 ) -> tuple[dict, dict]:
     """
     Remove points whose energy is higher than the reference (Unperturbed) by
-    more than ``max_energy_above_unperturbed`.
+    more than ``max_energy_above_unperturbed``.
 
     Args:
         energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy (eV), as produced by
-            ``analysis._organize_data()`` or ``analysis.get_energies()`
+            ``analysis._organize_data()`` or ``analysis.get_energies()``
         max_energy_above_unperturbed (:obj:`float`):
-            Maximum energy (in chosen ``units`), relative to the unperturbed
+            Maximum energy (in chosen ``units``), relative to the unperturbed
             structure, to show on plot
         disp_dict (:obj:`dict`):
             Dictionary matching distortion to sum of atomic displacements, as
-            produced by ``analysis.calculate_struct_comparison()`
+            produced by ``analysis.calculate_struct_comparison()``
             (Default: None)
 
     Returns:
@@ -273,7 +273,7 @@ def _remove_high_energy_points(
         # remove high energy points
         if energies_dict["distortions"][key] - energies_dict["Unperturbed"] > max_energy_above_unperturbed:
             energies_dict["distortions"].pop(key)
-            if disp_dict and key in disp_dict:  # only exists if user selected ``add_colorbar=True`
+            if disp_dict and key in disp_dict:  # only exists if user selected ``add_colorbar=True``
                 disp_dict.pop(key)
     return energies_dict, disp_dict
 
@@ -310,7 +310,7 @@ def _get_displacement_dict(
             (Default: 'max_dist')
         energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy (eV), as produced by
-            ``_organize_data()`` or ``analysis.get_energies()`)
+            ``_organize_data()`` or ``analysis.get_energies()``)
         add_colorbar (:obj:`bool`):
             Whether to add a colorbar indicating structural similarity between
             each structure and the unperturbed one.
@@ -320,8 +320,8 @@ def _get_displacement_dict(
             (Default: "vasp")
 
     Returns:
-        Tuple[bool, dict, dict]: tuple of ``add_colorbar`, ``energies_dict`` and
-        ``disp_dict`
+        Tuple[bool, dict, dict]: tuple of ``add_colorbar``, ``energies_dict`` and
+        ``disp_dict``
     """
     try:
         defect_structs = analysis.get_structures(
@@ -834,7 +834,7 @@ def plot_all_defects(
             matched sites ('max_dist', default).
             (Default: "max_dist")
         max_energy_above_unperturbed (:obj:`float`):
-            Maximum energy (in chosen ``units`), relative to the unperturbed structure,
+            Maximum energy (in chosen ``units``), relative to the unperturbed structure,
             to show on the plot.
             (Default: 0.5 eV)
         units (:obj:`str`):
@@ -1023,7 +1023,7 @@ def plot_defect(
             Defect name including charge (e.g. 'vac_1_Cd_0')
         energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy (eV), as produced by
-            ``_organize_data()`` or ``analysis.get_energies()`)
+            ``_organize_data()`` or ``analysis.get_energies()``)
         output_path (:obj:`str`):
             Path to top-level directory with your distorted defect calculations
             (to calculate structure comparisons and save plots)
@@ -1047,7 +1047,7 @@ def plot_defect(
             matched sites ('max_dist', default).
             (Default: "max_dist")
         max_energy_above_unperturbed (:obj:`float`):
-            Maximum energy (in chosen ``units`), relative to the unperturbed
+            Maximum energy (in chosen ``units``), relative to the unperturbed
             structure, to show on the plot.
             (Default: 0.5 eV)
         units (:obj:`str`):
@@ -1434,11 +1434,11 @@ def plot_colorbar(
     Args:
         energies_dict (:obj:`dict`):
             Dictionary matching distortion to final energy (eV), as produced by
-            ``analysis.get_energies()`` or ``analysis._organize_data()`.
+            ``analysis.get_energies()`` or ``analysis._organize_data()``.
         disp_dict (:obj:`dict`):
             Dictionary matching bond distortions to structure comparison metric
             (metric = 'disp' or 'max_dist'), as produced by
-            ``analysis.calculate_struct_comparison()`.
+            ``analysis.calculate_struct_comparison()``.
         defect_species (:obj:`str`):
             Specific defect name that will appear in plot labels (in LaTeX form)
              and file names (e.g 'vac_1_Cd_0')
@@ -1465,7 +1465,7 @@ def plot_colorbar(
             or the maximum distance between matched sites ('max_dist', default).
             (Default: "max_dist")
         max_energy_above_unperturbed (:obj:`float`):
-            Maximum energy (in chosen ``units`), relative to the unperturbed
+            Maximum energy (in chosen ``units``), relative to the unperturbed
             structure, to show on the plot.
             (Default: 0.5 eV)
         save_plot (:obj:`bool`):
@@ -1617,7 +1617,7 @@ def plot_datasets(
         datasets (:obj:`list`):
             List of {distortion: energy} dictionaries to plot (each dictionary
             matching distortion to final energy (eV), as produced by
-            ``analysis._organize_data()`` or ``analysis.get_energies()`)
+            ``analysis._organize_data()`` or ``analysis.get_energies()``)
         dataset_labels (:obj:`list`):
             Labels for each dataset plot legend. If None, defaults to
             ["Distortions"]*len(datasets).
@@ -1637,7 +1637,7 @@ def plot_datasets(
         num_nearest_neighbours (:obj:`int`):
             Number of distorted neighbour atoms (e.g. 2)
         max_energy_above_unperturbed (:obj:`float`):
-            Maximum energy (in chosen ``units`), relative to the unperturbed
+            Maximum energy (in chosen ``units``), relative to the unperturbed
             structure, to show on the plot.
             (Default: 0.5 eV)
         style_file (PathLike):
diff --git a/tests/test_input.py b/tests/test_input.py
index f328c0de..6b608072 100644
--- a/tests/test_input.py
+++ b/tests/test_input.py
@@ -11,7 +11,6 @@
 
 import numpy as np
 from ase.build import bulk, make_supercell
-from ase.calculators.aims import Aims
 from ase.io import read
 from doped.generation import get_defect_name_from_entry
 from doped.vasp import _test_potcar_functional_choice, DefectRelaxSet
@@ -2990,6 +2989,7 @@ def test_write_fhi_aims_files(self):
         # # User defined parameters
         # for i in self.cdte_defect_folders_old_names:
         #     if_present_rm(i)  # remove test-generated defect folders
+        # from ase.calculators.aims import Aims
         # ase_calculator = Aims(
         #     k_grid=(1, 1, 1),
         #     relax_geometry=("bfgs", 5e-4),