Skip to content

Commit 17a90e1

Browse files
committed
Catch and allow minimisation convergence errors.
1 parent 2c004f8 commit 17a90e1

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/ghostly/_ghostly.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
try:
3333
from somd2 import _logger
34-
except:
34+
except Exception:
3535
from loguru import logger as _logger
3636

3737
import platform as _platform
@@ -940,6 +940,8 @@ def _triple(
940940
theta0s[idx] = []
941941

942942
# Perform multiple minimisations to get an average for the theta0 values.
943+
is_error = False
944+
num_errors = 0
943945
for _ in range(num_optimise):
944946
# Minimise the molecule.
945947
min_mol = _morph.link_to_reference(mol)
@@ -948,7 +950,11 @@ def _triple(
948950
constraint="none",
949951
platform="cpu",
950952
)
951-
minimiser.run()
953+
try:
954+
minimiser.run()
955+
except Exception:
956+
is_error = True
957+
num_errors += 1
952958

953959
# Commit the changes.
954960
min_mol = minimiser.commit()
@@ -957,9 +963,15 @@ def _triple(
957963
for idx in angle_idxs:
958964
try:
959965
theta0s[idx].append(min_mol.angles(*idx).sizes()[0].to(_radian))
960-
except:
966+
except Exception:
961967
raise ValueError(f"Could not find optimised angle term: {idx}")
962968

969+
if is_error:
970+
_logger.warning(
971+
f" {num_errors} minimisation(s) failed to converge during "
972+
f"angle optimisation at {_lam_sym} = {int(is_lambda1)}."
973+
)
974+
963975
# Compute the mean and standard error.
964976
import numpy as _np
965977

0 commit comments

Comments
 (0)