Skip to content

Commit

Permalink
add callback unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
corinwagen committed Jan 3, 2025
1 parent 32575a6 commit 85cf5f8
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion geometric/tests/test_neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,27 @@ def test_psi4_hcn_neb_optimize_1(localizer, molecule_engine_hcn):

assert chain.coordtype == "cart"

final_chain, optCycle = geometric.neb.OptimizeChain(chain, engine, params)
class StepCounter:
"""Simple class to store the number of steps."""
num_steps: int

def __init__(self):
self.num_steps = 0

def __call__(self, chain):
self.num_steps += 1

step_counter = StepCounter()

final_chain, optCycle = geometric.neb.OptimizeChain(
chain,
engine,
params,
save_callback=step_counter
)

assert optCycle <= 10
assert step_counter.num_steps == optCycle + 1 # the callback gets called once more
assert final_chain.maxg < params.maxg
assert final_chain.avgg < params.avgg

Expand Down

0 comments on commit 85cf5f8

Please sign in to comment.