Skip to content

Commit

Permalink
Espresso: streamline file copying / additional recipes (#1974)
Browse files Browse the repository at this point in the history
## Summary of Changes

This pull request introduces several improvements and new features to
Quacc Espresso, enhancing the user experience and expanding its
capabilities:

**Streamlined Input/Output Naming:**

- Quacc Espresso now enforces predefined names for **all** input and
output files removing the little freedom users had for this. This
ensures consistency across different calculations and reduce the
potential for errors.

**Intelligent File Copying:**

- When users provide a prev_dir argument, Quacc will now determines
which files to copy based on the binary and input data. This will reduce
the amount of data being copied overall, I think this was one of your
suggestions on a previous merge request.

**New Recipes for Electron-Phonon Calculations:**

- Two new recipes have been added to perform electron-phonon
calculations and Fourier interpolation of the phonon potential. It's a
little step toward future compatibility with codes such as EPW.

Some tests have been modified to be more robust, some internal functions
have been modified as well.

note to self: the two recipes have to be added to the list of recipes

### Checklist

- [ ] I have read the ["Guidelines"
section](https://quantum-accelerators.github.io/quacc/dev/contributing.html#guidelines)
of the contributing guide. Don't lie! 😉
- [ ] My PR is on a custom branch and is _not_ named `main`.
- [ ] I have added relevant, comprehensive [unit
tests](https://quantum-accelerators.github.io/quacc/dev/contributing.html#unit-tests).

### Notes

- Your PR will likely not be merged without proper and thorough tests.
- If you are an external contributor, you will see a comment from
[@buildbot-princeton](https://github.com/buildbot-princeton). This is
solely for the maintainers.
- When your code is ready for review, ping one of the [active
maintainers](https://quantum-accelerators.github.io/quacc/about/contributors.html#active-maintainers).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Andrew S. Rosen <asrosen93@gmail.com>
  • Loading branch information
3 people authored Apr 9, 2024
1 parent bd23ed3 commit 06faf4e
Show file tree
Hide file tree
Showing 18 changed files with 1,106 additions and 241 deletions.
6 changes: 4 additions & 2 deletions docs/user/recipes/recipes_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ The list of available quacc recipes is shown below. The "Req'd Extras" column sp
| Espresso Post Processing | `#!Python @job` | [quacc.recipes.espresso.core.post_processing_job][] | |
| Espresso Phonon | `#!Python @job` | [quacc.recipes.espresso.phonons.phonon_job][] | |
| Espresso Grid Phonon | `#!Python @flow` | [quacc.recipes.espresso.phonons.grid_phonon_flow][] | |
| Espresso q2r | `#!Python @job` | [quacc.recipes.espresso.phonons.q2r_job][] | |
| Espresso matdyn | `#!Python @job` | [quacc.recipes.espresso.phonons.matdyn_job][] | |
| Espresso Q2R | `#!Python @job` | [quacc.recipes.espresso.phonons.q2r_job][] | |
| Espresso Matdyn | `#!Python @job` | [quacc.recipes.espresso.phonons.matdyn_job][] | |
| Espresso Phonon DOS Flow | `#!Python @flow` | [quacc.recipes.espresso.phonons.phonon_dos_flow][] | |
| Espresso DVSCF Q2R | `#!Python @job` | [quacc.recipes.espresso.phonons.dvscf_q2r_job][] | |
| Espresso PostAHC | `#!Python @job` | [quacc.recipes.espresso.phonons.postahc_job][] | |
| Espresso Non-SCF | `#!Python @job` | [quacc.recipes.espresso.core.non_scf_job][] | |
| Espresso DOS | `#!Python @job` | [quacc.recipes.espresso.dos.dos_job][] | |
| Espresso DOS Flow | `#!Python @flow` | [quacc.recipes.espresso.dos.dos_flow][] | |
Expand Down
59 changes: 37 additions & 22 deletions src/quacc/calculators/espresso/espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
get_pseudopotential_info,
remove_conflicting_kpts_kspacing,
)
from quacc.utils.dicts import recursive_dict_merge
from quacc.utils.dicts import Remove, recursive_dict_merge, remove_dict_entries
from quacc.utils.files import load_yaml_calc

if TYPE_CHECKING:
Expand All @@ -38,7 +38,8 @@


class EspressoTemplate(EspressoTemplate_):
"""This is a wrapper around the ASE Espresso template that allows for the use of
"""
A wrapper around the ASE Espresso template that allows for the use of
other binaries such as pw.x, ph.x, cp.x, etc.
"""

Expand Down Expand Up @@ -72,6 +73,8 @@ def __init__(

self.binary = binary

self._ase_known_binary = self.binary in ALL_KEYS

self.test_run = test_run

self.nruns = 0
Expand Down Expand Up @@ -125,13 +128,16 @@ def write_input(
properties=properties,
**parameters,
)
elif self.binary == "ph":
elif self.binary in ["ph", "phcg"]:
with Path.open(directory / self.inputname, "w") as fd:
write_espresso_ph(fd=fd, properties=properties, **parameters)
else:
with Path.open(directory / self.inputname, "w") as fd:
write_fortran_namelist(
fd, binary=self.binary, properties=properties, **parameters
fd,
binary=self.binary if self._ase_known_binary else None,
properties=properties,
**parameters,
)

def execute(self, *args: Any, **kwargs: Any) -> None:
Expand Down Expand Up @@ -203,7 +209,7 @@ def read_results(self, directory: Path | str) -> dict[str, Any]:
if self.binary == "pw":
atoms = read(directory / self.outputname, format="espresso-out")
results = dict(atoms.calc.properties())
elif self.binary == "ph":
elif self.binary in ["ph", "phcg"]:
with Path.open(directory / self.outputname, "r") as fd:
results = read_espresso_ph(fd)
elif self.binary == "dos":
Expand All @@ -218,13 +224,7 @@ def read_results(self, directory: Path | str) -> dict[str, Any]:
energy = lines[1:, 0]
dos = lines[1:, 1]
pdos = lines[1:, 2]
results = {
"projwfc_results": {
"energy": energy,
"dos": dos,
"pdos": pdos,
}
}
results = {"projwfc_results": {"energy": energy, "dos": dos, "pdos": pdos}}
elif self.binary == "matdyn":
fldos = Path(directory, "matdyn.dos")
if fldos.exists():
Expand Down Expand Up @@ -267,7 +267,7 @@ def _output_handler(
outkeys = espresso_prepare_dir(espresso_outdir, self.binary)

input_data = parameters.get("input_data", {})
input_data = recursive_dict_merge(input_data, outkeys)
input_data = recursive_dict_merge(input_data, outkeys, verbose=True)

parameters["input_data"] = input_data

Expand All @@ -291,7 +291,23 @@ def _sanity_checks(self, parameters: dict[str, Any]) -> None:
"""
input_data = parameters.get("input_data", {})

if self.binary == "ph":
if self.binary == "pw":
system = input_data.get("system", {})

occupations = system.get("occupations", "fixed")
smearing = system.get("smearing", None)
degauss = system.get("degauss", None)

if occupations == "fixed" and not (smearing is None and degauss is None):
LOGGER.warning(
"The occupations are set to 'fixed' but smearing or degauss is also set. This will be ignored."
)
system["smearing"] = Remove
system["degauss"] = Remove

parameters["input_data"]["system"] = system

elif self.binary in ["ph", "phcg"]:
input_ph = input_data.get("inputph", {})
qpts = parameters.get("qpts", (0, 0, 0))

Expand Down Expand Up @@ -322,14 +338,13 @@ def _sanity_checks(self, parameters: dict[str, Any]) -> None:
parameters["input_data"]["inputph"] = input_ph
parameters["qpts"] = qpts

return parameters
return remove_dict_entries(parameters, remove_trigger=Remove)


class Espresso(Espresso_):
"""
This is a wrapper around the ASE Espresso calculator that adjusts input_data
A wrapper around the ASE Espresso calculator that adjusts input_data
parameters and allows for the use of presets.
Templates are used to set the binary and input/output file names.
"""

Expand Down Expand Up @@ -385,21 +400,21 @@ def __init__(
self._user_calc_params = {}

template = template or EspressoTemplate("pw")

self._binary = template.binary

full_path = Path(
SETTINGS.ESPRESSO_BIN_DIR, SETTINGS.ESPRESSO_BINARIES[template.binary]
SETTINGS.ESPRESSO_BIN_DIR, SETTINGS.ESPRESSO_BINARIES[self._binary]
)
self._bin_path = str(full_path)
self._binary = template.binary

if self._binary in ALL_KEYS:
if template._ase_known_binary:
self._cleanup_params()
else:
LOGGER.warning(
f"the binary you requested, `{self._binary}`, is not supported by ASE. This means that presets and usual checks will not be carried out, your `input_data` must be provided in nested format."
)

template.binary = None

self.kwargs["input_data"] = Namelist(self.kwargs.get("input_data"))
self._user_calc_params = self.kwargs

Expand Down
Loading

0 comments on commit 06faf4e

Please sign in to comment.