Skip to content

Commit

Permalink
Refactor SnB_input_files
Browse files Browse the repository at this point in the history
Former-commit-id: d88b00f
  • Loading branch information
kavanase committed Oct 20, 2024
1 parent b9bca6f commit 71de470
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: ^(docs|tests|SnB_input_files|.github|shakenbreak/scripts|CITATION*|MANIFEST*)
exclude: ^(docs|tests|shakenbreak/SnB_input_files|.github|CITATION*|MANIFEST*)
repos:
# Lint and format, isort, docstrings...
- repo: https://github.com/charliermarsh/ruff-pre-commit
Expand Down
4 changes: 2 additions & 2 deletions docs/Generation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ we'll get a warning and we'll need to specify the defect site with the ``--defec
.. NOTE::
To specify additional distortion parameters, we can use a
`config.yaml <https://github.com/SMTG-Bham/ShakeNBreak/blob/main/SnB_input_files/example_generate_config.yaml>`_
`config.yaml <https://github.com/SMTG-Bham/ShakeNBreak/blob/main/shakenbreak/SnB_input_files/example_generate_config.yaml>`_
file like the one below and use the ``--config`` flag to specify its path (i.e. ``snb-generate --config ./my_config.yaml``).
A detailed description of all the parameters is available in the Python API section
(:ref:`shakenbreak.input.Distortions class <api_input>`).
Expand Down Expand Up @@ -122,7 +122,7 @@ the following directory structures will be parsed correctly:
.. NOTE::
To specify the charge state range for each defect, as well as other optional arguments, we can use a
`config.yaml <https://github.com/SMTG-Bham/ShakeNBreak/blob/main/SnB_input_files/example_generate_all_config.yaml>`_ file
`config.yaml <https://github.com/SMTG-Bham/ShakeNBreak/blob/main/shakenbreak/SnB_input_files/example_generate_all_config.yaml>`_ file
like the one below. A detailed description of all the parameters is available in the
Python API section (:ref:`shakenbreak.input.Distortions class <api_input>`).

Expand Down
13 changes: 1 addition & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ def run(self):
_install_custom_font()


# https://stackoverflow.com/questions/27664504/how-to-add-package-data-recursively-in-python-setup-py
def package_files(directory):
"""Include package data."""
paths = []
for path, _dir, filenames in os.walk(directory):
paths.extend(os.path.join("..", path, filename) for filename in filenames)
return paths


input_files = package_files("SnB_input_files/")

with open("README.md", encoding="utf-8") as file:
long_description = file.read()

Expand Down Expand Up @@ -192,7 +181,7 @@ def package_files(directory):
},
# Specify any non-python files to be distributed with the package
package_data={
"shakenbreak": ["shakenbreak/*", *input_files],
"shakenbreak": ["shakenbreak/*"],
},
include_package_data=True,
# Specify the custom installation class
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions shakenbreak/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def snb():
@click.option(
"--config",
"-conf",
help="Config file for advanced distortion settings. See example in"
" SnB_input_files/example_generate_config.yaml",
help="Config file for advanced distortion settings. See example in "
"shakenbreak/SnB_input_files/example_generate_config.yaml",
default=None,
type=click.Path(exists=True, dir_okay=False),
show_default=True,
Expand Down Expand Up @@ -426,7 +426,7 @@ def generate(
"--config",
"-conf",
help="Config file for advanced distortion settings. See example in "
"/SnB_input_files/example_generate_all_config.yaml",
"shakenbreak/SnB_input_files/example_generate_all_config.yaml",
default=None,
type=click.Path(exists=True, dir_okay=False, file_okay=True),
show_default=True,
Expand Down
26 changes: 12 additions & 14 deletions shakenbreak/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
from shakenbreak import analysis, distortions, io

MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
default_potcar_dict = loadfn(f"{MODULE_DIR}/../SnB_input_files/default_POTCARs.yaml")
default_potcar_dict = loadfn(f"{MODULE_DIR}/SnB_input_files/default_POTCARs.yaml")
# Load default INCAR settings for the ShakeNBreak geometry relaxations
default_incar_settings = loadfn(os.path.join(MODULE_DIR, "../SnB_input_files/incar.yaml"))
default_incar_settings = loadfn(os.path.join(MODULE_DIR, "SnB_input_files/incar.yaml"))


_ignore_pmg_warnings() # Ignore pymatgen POTCAR warnings
Expand Down Expand Up @@ -305,7 +305,7 @@ def _create_vasp_input(
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`
`SnB_input_files/default_POTCARs.yaml`, to see what the default
`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
Expand Down Expand Up @@ -2466,7 +2466,7 @@ def write_vasp_files(
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 `SnB_input_files/incar.yaml` to see what the default `INCAR`
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)
Expand All @@ -2477,7 +2477,7 @@ def write_vasp_files(
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`
`SnB_input_files/default_POTCARs.yaml`, to see what the default
`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)
Expand Down Expand Up @@ -2575,11 +2575,11 @@ def write_espresso_files(
input_parameters (:obj:`dict`, optional):
Dictionary of user Quantum Espresso input parameters, to
overwrite/update `shakenbreak` default ones (see
`SnB_input_files/qe_input.yaml`).
`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 `SnB_input_files/qe_input.yaml`).
`shakenbreak` default ones (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)
Expand Down Expand Up @@ -2619,7 +2619,7 @@ def write_espresso_files(

# Update default parameters with user defined values
if pseudopotentials and not write_structures_only:
default_input_parameters = loadfn(os.path.join(MODULE_DIR, "../SnB_input_files/qe_input.yaml"))
default_input_parameters = loadfn(os.path.join(MODULE_DIR, "SnB_input_files/qe_input.yaml"))
if input_file and not input_parameters:
input_parameters = io.parse_qe_input(input_file)
if input_parameters:
Expand Down Expand Up @@ -2693,7 +2693,7 @@ def write_espresso_files(

def write_cp2k_files(
self,
input_file: Optional[str] = f"{MODULE_DIR}/../SnB_input_files/cp2k_input.inp",
input_file: Optional[str] = f"{MODULE_DIR}/SnB_input_files/cp2k_input.inp",
write_structures_only: Optional[bool] = False,
output_path: str = ".",
verbose: Optional[bool] = None,
Expand Down Expand Up @@ -2725,15 +2725,13 @@ def write_cp2k_files(
"""
if os.path.exists(input_file) and not write_structures_only:
cp2k_input = Cp2kInput.from_file(input_file)
elif (
os.path.exists(f"{MODULE_DIR}/../SnB_input_files/cp2k_input.inp") and not write_structures_only
):
elif os.path.exists(f"{MODULE_DIR}/SnB_input_files/cp2k_input.inp") and not write_structures_only:
warnings.warn(
f"Specified input file {input_file} does not exist! Using"
" default CP2K input file "
"(see shakenbreak/shakenbreak/cp2k_input.inp)"
)
cp2k_input = Cp2kInput.from_file(f"{MODULE_DIR}/../SnB_input_files/cp2k_input.inp")
cp2k_input = Cp2kInput.from_file(f"{MODULE_DIR}/SnB_input_files/cp2k_input.inp")

distorted_defects_dict, self.distortion_metadata = self.apply_distortions(
verbose=verbose,
Expand All @@ -2757,7 +2755,7 @@ def write_cp2k_files(

def write_castep_files(
self,
input_file: Optional[str] = f"{MODULE_DIR}/../SnB_input_files/castep.param",
input_file: Optional[str] = f"{MODULE_DIR}/SnB_input_files/castep.param",
write_structures_only: Optional[bool] = False,
output_path: str = ".",
verbose: Optional[bool] = None,
Expand Down

0 comments on commit 71de470

Please sign in to comment.