Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor thermo #992

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.1]

### Changed

- Moved `quacc.custodian` to `quacc.calculators.custodian`
- Renamed `quacc.thermo.ideal_gas` to `quacc.thermo.run_ideal_gas`
- Renamed `quacc.schemas.ase.summarize_thermo` to `quacc.schemas.ase.summarize_igt_thermo`

## [0.3.0]

### Changed

- Changed default `SCRATCH_DIR` from `/tmp` to `Path.cwd() / .scratch`
- Refactored decorator handling to be more concise
- Renamed `[optimizers]` extras to `[sella]`
- Moved `quacc.utils.wflows` into `quacc.wflow.decorators` and `quacc.wflow.prefect`
- Moved `quacc.utils.db` into `quacc.wflow.db`
- Moved `quacc.utils.calc` to `quacc.runners.calc`
- Moved `quacc.presets` to `quacc.calculators.presets`
- Refactored decorator handling to be more concise
- Renamed `[optimizers]` extras to `[sella]`

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions src/quacc/recipes/lj/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

from quacc import job
from quacc.runners.calc import run_ase_opt, run_ase_vib, run_calc
from quacc.runners.thermo import ideal_gas
from quacc.runners.thermo import run_ideal_gas
from quacc.schemas import fetch_atoms
from quacc.schemas.ase import (
summarize_igt_thermo,
summarize_opt_run,
summarize_run,
summarize_thermo,
summarize_vib_run,
)
from quacc.utils.dicts import merge_dicts
Expand Down Expand Up @@ -183,8 +183,8 @@ def freq_job(
vibrations, additional_fields={"name": "LJ Frequency"}
)

igt = ideal_gas(atoms, vibrations.get_frequencies(), energy=energy)
vib_summary["thermo"] = summarize_thermo(
igt = run_ideal_gas(atoms, vibrations.get_frequencies(), energy=energy)
vib_summary["thermo"] = summarize_igt_thermo(
igt,
temperature=temperature,
pressure=pressure,
Expand Down
8 changes: 4 additions & 4 deletions src/quacc/recipes/newtonnet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

from quacc import SETTINGS, job
from quacc.runners.calc import run_ase_opt, run_calc
from quacc.runners.thermo import ideal_gas
from quacc.runners.thermo import run_ideal_gas
from quacc.schemas import fetch_atoms
from quacc.schemas.ase import (
summarize_igt_thermo,
summarize_opt_run,
summarize_run,
summarize_thermo,
summarize_vib_run,
)
from quacc.utils.dicts import merge_dicts
Expand Down Expand Up @@ -225,8 +225,8 @@ def freq_job(
vib, additional_fields={"name": "ASE Vibrations Analysis"}
)

igt = ideal_gas(final_atoms, vib.get_frequencies(), energy=energy)
summary["thermo"] = summarize_thermo(
igt = run_ideal_gas(final_atoms, vib.get_frequencies(), energy=energy)
summary["thermo"] = summarize_igt_thermo(
igt,
temperature=temperature,
pressure=pressure,
Expand Down
10 changes: 5 additions & 5 deletions src/quacc/recipes/tblite/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

from quacc import job
from quacc.runners.calc import run_ase_opt, run_ase_vib, run_calc
from quacc.runners.thermo import ideal_gas
from quacc.runners.thermo import run_ideal_gas
from quacc.schemas import fetch_atoms
from quacc.schemas.ase import (
summarize_igt_thermo,
summarize_opt_run,
summarize_run,
summarize_thermo,
summarize_vib_run,
)
from quacc.utils.dicts import merge_dicts
Expand Down Expand Up @@ -196,7 +196,7 @@ def freq_job(
-------
FreqSchema
Dictionary of results from [quacc.schemas.ase.summarize_vib_run] and
[quacc.schemas.ase.summarize_thermo][]
[quacc.schemas.ase.summarize_igt_thermo][]
"""
atoms = fetch_atoms(atoms)
vib_kwargs = vib_kwargs or {}
Expand All @@ -210,8 +210,8 @@ def freq_job(
vibrations, additional_fields={"name": "TBLite Frequency"}
)

igt = ideal_gas(atoms, vibrations.get_frequencies(), energy=energy)
vib_summary["thermo"] = summarize_thermo(
igt = run_ideal_gas(atoms, vibrations.get_frequencies(), energy=energy)
vib_summary["thermo"] = summarize_igt_thermo(
igt,
temperature=temperature,
pressure=pressure,
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/runners/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ase import Atoms


def ideal_gas(
def run_ideal_gas(
atoms: Atoms,
vib_freqs: list[float | complex],
energy: float = 0.0,
Expand Down
2 changes: 1 addition & 1 deletion src/quacc/schemas/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ def summarize_vib_run(
return task_doc


def summarize_thermo(
def summarize_igt_thermo(
igt: IdealGasThermo,
temperature: float = 298.15,
pressure: float = 1.0,
Expand Down
10 changes: 5 additions & 5 deletions tests/runners/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
from ase.calculators.emt import EMT
from ase.units import invcm

from quacc.runners.thermo import ideal_gas
from quacc.runners.thermo import run_ideal_gas


def test_ideal_gas():
def test_run_ideal_gas():
co2 = molecule("CO2")
igt = ideal_gas(co2, [526, 526, 1480, 2565], spin_multiplicity=2)
igt = run_ideal_gas(co2, [526, 526, 1480, 2565], spin_multiplicity=2)
assert igt.geometry == "linear"
assert igt.spin == 0.5

co2 = molecule("CO2")
co2.calc = EMT()
co2.calc.results["magmom"] = 1.0
igt = ideal_gas(co2, [526, 526, 1480, 2565])
igt = run_ideal_gas(co2, [526, 526, 1480, 2565])
assert igt.spin == 0.5
assert igt.get_ZPE_correction() == pytest.approx(2548.5 * invcm)

co2 = molecule("CO2")
co2.calc = EMT()
co2.calc.results["magmom"] = 1.0
igt = ideal_gas(co2, [-12, 526, 526, 1480, 2565])
igt = run_ideal_gas(co2, [-12, 526, 526, 1480, 2565])
assert igt.get_ZPE_correction() == pytest.approx(2548.5 * invcm)
20 changes: 10 additions & 10 deletions tests/schemas/test_ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from monty.json import MontyDecoder, jsanitize

from quacc.schemas.ase import (
summarize_igt_thermo,
summarize_opt_run,
summarize_run,
summarize_thermo,
summarize_vib_run,
)

Expand Down Expand Up @@ -284,13 +284,13 @@ def test_summarize_vib_run(tmpdir):
assert len(results["results"]["vib_energies"]) == 6


def test_summarize_thermo(tmpdir):
def test_summarize_igt_thermo(tmpdir):
tmpdir.chdir()

# Make sure metadata is made
atoms = molecule("N2")
igt = IdealGasThermo([0.34], "linear", atoms=atoms, spin=0, symmetrynumber=2)
results = summarize_thermo(igt)
results = summarize_igt_thermo(igt)
assert results["natoms"] == len(atoms)
assert results["atoms"] == atoms
assert results["parameters_thermo"]["vib_energies"] == [0.34]
Expand All @@ -301,15 +301,15 @@ def test_summarize_thermo(tmpdir):
# Test DB
atoms = molecule("N2")
igt = IdealGasThermo([0.34], "linear", atoms=atoms, spin=0, symmetrynumber=2)
summarize_thermo(igt)
summarize_igt_thermo(igt)
store = MemoryStore()
summarize_thermo(igt, store=store)
summarize_igt_thermo(igt, store=store)
assert store.count() == 1

# Test remove_empties
atoms = molecule("N2")
igt = IdealGasThermo([0.34], "linear", atoms=atoms, spin=0, symmetrynumber=2)
results = summarize_thermo(igt, remove_empties=True)
results = summarize_igt_thermo(igt, remove_empties=True)
assert results["natoms"] == len(atoms)
assert results["atoms"] == atoms
assert results["parameters_thermo"]["vib_energies"] == [0.34]
Expand All @@ -322,7 +322,7 @@ def test_summarize_thermo(tmpdir):
igt = IdealGasThermo(
[0.0, 0.34], "linear", atoms=atoms, potentialenergy=-1, spin=0, symmetrynumber=2
)
results = summarize_thermo(igt)
results = summarize_igt_thermo(igt)
assert results["natoms"] == len(atoms)
assert results["atoms"] == atoms
assert results["parameters_thermo"]["vib_energies"] == [0.34]
Expand All @@ -336,7 +336,7 @@ def test_summarize_thermo(tmpdir):
igt = IdealGasThermo(
[0.0, 0.34], "linear", atoms=atoms, potentialenergy=-1, spin=0, symmetrynumber=2
)
results = summarize_thermo(igt)
results = summarize_igt_thermo(igt)
assert results.get("atoms_info", {}) != {}
assert results["atoms_info"].get("test_dict", None) == {"hi": "there", "foo": "bar"}
assert results["atoms"].info.get("test_dict", None) == {"hi": "there", "foo": "bar"}
Expand Down Expand Up @@ -365,7 +365,7 @@ def test_summarize_thermo(tmpdir):
spin=0.5,
symmetrynumber=6,
)
results = summarize_thermo(igt, temperature=1000.0, pressure=20.0)
results = summarize_igt_thermo(igt, temperature=1000.0, pressure=20.0)
assert results["natoms"] == len(atoms)
assert results["atoms"] == atoms
assert len(results["parameters_thermo"]["vib_energies"]) == 6
Expand All @@ -387,7 +387,7 @@ def test_summarize_thermo(tmpdir):
MontyDecoder().process_decoded(d)

with pytest.raises(ValueError):
summarize_thermo(igt, charge_and_multiplicity=[0, 1])
summarize_igt_thermo(igt, charge_and_multiplicity=[0, 1])


def test_errors(tmpdir):
Expand Down