Skip to content

Add optional external DFTB+ backend#139

Closed
karmachoi wants to merge 3 commits into
Open-Quantum-Platform:mainfrom
karmachoi:feat/dftbplus-external-backend
Closed

Add optional external DFTB+ backend#139
karmachoi wants to merge 3 commits into
Open-Quantum-Platform:mainfrom
karmachoi:feat/dftbplus-external-backend

Conversation

@karmachoi

@karmachoi karmachoi commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add optional method=dftb input/schema support and [dftb] execution settings
  • add DFTB+ dftb_in.hsd/geo.gen writer, fixture parsers for detailed.out and results.tag, and a shell-out runner
  • route energy/gradient runtype calls through the external backend when method=dftb
  • add fixture/unit coverage and a documented H2O gradient example that requires local DFTB+ parameters

DFTB+ availability and skip/error behavior

  • DFTB+ is optional; CI/unit tests use fixtures and a fake executable, so no DFTB+ installation is required.
  • Runtime execution raises clear DFTBPlusError messages if the configured executable is missing/not executable, if [dftb] sk_path is unset or missing, if DFTB+ exits nonzero, or if expected output files are absent.
  • I checked this macOS runner: dftb+ is not installed, and Homebrew does not provide a straightforward dftbplus formula (brew search dftb only returned dfmt), so no live DFTB+ numerical reference is included.

Tests

  • PASS: python3 -m unittest tests.test_dftbplus_backend -v (9 tests)
  • PASS: python3 -m py_compile pyoqp/oqp/library/dftbplus.py pyoqp/oqp/library/runfunc.py pyoqp/oqp/molecule/oqpdata.py pyoqp/oqp/utils/input_checker.py tests/test_dftbplus_backend.py
  • PASS: python3 -m unittest tests.test_opentrustregion_linalg_config -v (3 tests)
  • NOT RUN here: tests.test_geometric_optimizer is not present on this branch.
  • LOCAL ENV BLOCKER ONLY: python3 -m unittest tests.test_single_point_scf_fallback -v could not import because this scheduled-runner Python (/Users/cheolhochoi/.hermes/hermes-agent/venv/bin/python3) lacks numpy; this is unrelated to the DFTB+ code path.

Scope note

This PR is kept independent of the geomeTRIC optimizer work; it only adds the external DFTB+ energy/gradient backend and optional manual example.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7a43721415

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +273 to +275
grad_array = np.asarray(flat, dtype=np.float64)
ffi.memmove(mol.data._data.grad, grad_array, grad_array.nbytes)
except Exception:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Persist DFTB gradients in mol.grads on successful runs

When method=dftb and runtype=grad, the normal path is the try branch (NumPy + oqp.ffi available), but that branch only memmoves into the C buffer and never updates mol.grads. This leaves Python-level results inconsistent (PyOQP.results() returns grad: None), and downstream code that expects mol.grads after a gradient run can fail or silently miss gradient data.

Useful? React with 👍 / 👎.

Comment on lines +20 to +24
_SYMBOLS = {
1: "H", 2: "He", 3: "Li", 4: "Be", 5: "B", 6: "C", 7: "N", 8: "O", 9: "F", 10: "Ne",
11: "Na", 12: "Mg", 13: "Al", 14: "Si", 15: "P", 16: "S", 17: "Cl", 18: "Ar",
19: "K", 20: "Ca", 35: "Br", 53: "I",
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include Zn in DFTB element symbol mapping

The hardcoded _SYMBOLS table omits atomic number 30 (Zn), so _symbols_for_atoms() raises DFTBPlusError for Zn-containing systems before DFTB+ is invoked. This blocks valid workflows with common parameter sets (including 3ob-family usage implied by the new backend) and is an avoidable regression introduced by the new external runner.

Useful? React with 👍 / 👎.

@karmachoi

Copy link
Copy Markdown
Contributor Author

Closing this upstream PR per Cheol’s request. GPU/DFTB coding should remain on the fork first rather than going directly to upstream.

@karmachoi karmachoi closed this May 25, 2026
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.

1 participant