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

Improve string parsing in reaction.delta method #325

Merged
merged 4 commits into from
Mar 9, 2024
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ If **autodE** is used in a publication please consider citing the [paper](https:
- Jonathon Vandezande ([@jevandezande](https://github.com/jevandezande))
- Shoubhik Maiti ([@shoubhikraj](https://github.com/shoubhikraj))
- Daniel Hollas ([@danielhollas](https://github.com/danielhollas))
- Nils Heunemann ([@nilsheunemann](https://github.com/NilsHeunemann))
11 changes: 9 additions & 2 deletions autode/reactions/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,17 @@ def delta(self, delta_type: str) -> Optional[Energy]:
"""

def delta_type_matches(*args):
return any(s in delta_type.lower() for s in args)
return any(
s
in delta_type.lower()
.replace("ddagger", "")
.replace("double dagger", "")
for s in args
)

def is_ts_delta():
return delta_type_matches("ddagger", "‡", "double dagger")
ts_synonyms = ["ddagger", "‡", "double dagger"]
return any(s in delta_type.lower() for s in ts_synonyms)

# Determine the species on the left and right-hand sides of the equation
lhs: List[Species] = self.reacs
Expand Down
3 changes: 3 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Bug Fixes
*********
- ...

Usability improvements/Changes
******************************
- Added consistent aliases for double dagger across all energies in :code:`autode.reaction.delta`

1.4.2
------
Expand Down
30 changes: 30 additions & 0 deletions tests/test_reaction_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,36 @@ def test_barrierless_h_g():
assert np.isclose(rxn.delta("G‡"), 0.7) # -2+0.6 -> -1+0.3 --> ∆ = 0.7


@pytest.mark.parametrize("energy_syn", ["E", "Energy"])
@pytest.mark.parametrize("enthalpy_syn", ["H", "Enthalpy"])
@pytest.mark.parametrize("free_syn", ["G", "free energy", "free_energy"])
@pytest.mark.parametrize("ts_syn", ["ddagger", "‡", "double dagger"])
def test_energy_synonyms(energy_syn, enthalpy_syn, free_syn, ts_syn):
a = Reactant(atoms=[Atom("H"), Atom("H", x=0.7, y=0.7), Atom("H", x=1.0)])
a.energies.extend(
[PotentialEnergy(-2), EnthalpyCont(0.2), FreeEnergyCont(0.6)]
)

b = Product(atoms=[Atom("H"), Atom("H", x=-1.0), Atom("H", x=1.0)])
b.energies.extend(
[PotentialEnergy(-1), EnthalpyCont(0.1), FreeEnergyCont(0.3)]
)

rxn = reaction.Reaction(a, b)
# Test potential energies
assert np.isclose(rxn.delta(energy_syn + ts_syn), 1.0)

# Test enthalpies
assert np.isclose(
rxn.delta(enthalpy_syn + ts_syn), 0.9
) # -2+0.2 -> -1+0.1 --> ∆ = 0.9

# Test free energies
assert np.isclose(
rxn.delta(free_syn + ts_syn), 0.7
) # -2+0.6 -> -1+0.3 --> ∆ = 0.7


def test_same_composition():
r1 = reaction.Reaction(
Reactant(atoms=[Atom("C"), Atom("H", x=1)]),
Expand Down
Loading