Repository: duartegroup/autodE
Pull request #325 (2024-02-27 17:04:15)

Improve string parsing in reaction.delta method
Previously the `reaction.delta` method would return the potential energy of the transition state when supplying `"G ddagger" ` or `"G double dagger"`. This behavior was unexpected.

After the change synonyms "ddagger" and "double dagger" can also be used with free energy. 


- Improved string parsing that all synonyms for double dagger can be used
- Added tests that determine if right energy is returned

***

## Checklist

* [x] The changes include an associated explanation of how/why
* [x] Test pass
* [x] Documentation has been updated
* [x] Changelog has been updated


t-young31: Hi @NilsHeunemann – this is awesome, thanks. Would you mind:

- [ ] Updating the [changelog](https://github.com/duartegroup/autodE/blob/master/doc/changelog.rst) 
- [ ] Add yourself to the [contributors list](https://github.com/duartegroup/autodE/blob/master/README.md#contributors)

Then I'm very happy to approve and merge this 🚀  
NilsHeunemann: Hi, thank you for the quick reply!
I just updated the changelog and added myself to the contributors list. 

Patch:
diff --git a/README.md b/README.md
index 3b8e650..7f3afaa 100644
--- a/README.md
+++ b/README.md
@@ -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))
diff --git a/autode/reactions/reaction.py b/autode/reactions/reaction.py
index 013d867..e24899b 100644
--- a/autode/reactions/reaction.py
+++ b/autode/reactions/reaction.py
@@ -431,10 +431,17 @@ class Reaction:
         """
 
         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
diff --git a/doc/changelog.rst b/doc/changelog.rst
index e5a1cfc..db0270a 100644
--- a/doc/changelog.rst
+++ b/doc/changelog.rst
@@ -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
 ------


Test patch:
diff --git a/tests/test_reaction_class.py b/tests/test_reaction_class.py
index b942e44..a7b5e31 100644
--- a/tests/test_reaction_class.py
+++ b/tests/test_reaction_class.py
@@ -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)]),