Skip to content

Fix uninitialized optimizer status for single-atom systems (gfortran bug) - #1441

Merged
thfroitzheim merged 2 commits into
grimme-lab:mainfrom
mcbennet:issue_1440
Sep 17, 2026
Merged

thfroitzheim merged 2 commits into
grimme-lab:mainfrom
mcbennet:issue_1440

Conversation

@mcbennet

@mcbennet mcbennet commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix a bug in geometry optimization for single-atom systems when xTB is compiled with gfortran.

The ANCopt, FIRE, and L-ANCopt routines return immediately when mol%n == 1, because a single atom has no internal geometry to optimize. However, this return occurred before the output variables fail, iter, and optional iter_needed were initialized.

With gfortran, fail could therefore contain an undefined .true. (or equivalent) value. The caller interpreted this as a failed geometry optimization, producing a non-convergence error and a nonzero exit status. Other compilers happened not to expose the issue consistently.

Changes

  • Initialize fail to .false. and the iteration count to zero before the single-atom early return in:
    • ANCopt
    • FIRE
    • L-ANCopt
  • Initialize optional iter_needed when present.
  • Add a charged, single-atom Li⁺ optimization regression test to the Meson and CMake test suites.

The present changes should resolve #1440

Expected behavior

A command such as:

xtb lithium.xyz --chrg 1 --opt

should complete successfully.

Comment thread test/unit/CMakeLists.txt

add_test("xtb/Argparser_print_version" ${XTB-EXE} --version)
add_test("xtb/Argparser_print_help" ${XTB-EXE} --help)
add_test("xtb/Argparser_print_license" ${XTB-EXE} --license)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really command-line specific. Could you please move this into a optimization unit test (I don't think there is one present yet, but you can adapt one of the other unit tests)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the command-line test with a TestDrive optimizer suite covering ANCopt, FIRE, and L-ANCopt for a single atom. All cases verify fail = .false. and iter_needed = 0.

Comment thread assets/inputs/xyz/lithium.xyz Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be part of a unit test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed lithium.xyz; the single-atom Li+ molecule is now constructed directly in the unit test. All 30 xTB unit-test suites pass with gfortran.

@thfroitzheim
thfroitzheim merged commit f2a2ba9 into grimme-lab:main Sep 17, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-atom geometry optimization fails with gfortran

2 participants