Skip to content

Run dftbplus_thermo in an optional isolated working directory - #54

Merged
galjos merged 2 commits into
feed-ase-atoms-to-run-thermofrom
isolate-dftbplus-run-directory
Jun 26, 2026
Merged

Run dftbplus_thermo in an optional isolated working directory#54
galjos merged 2 commits into
feed-ase-atoms-to-run-thermofrom
isolate-dftbplus-run-directory

Conversation

@galjos

@galjos galjos commented Jun 26, 2026

Copy link
Copy Markdown
Member

Closes #53. Stacked on #52 (retargets to main once that merges) — it depends on #52 because the pipeline now runs on the in-memory optimized atoms rather than re-reading a file from the working directory.

The DFTB+ steps read and write fixed filenames (geo_opt.gen, hessian.out, vibrations.tag, modes_in.hsd, ...) in the current directory, so running more than one molecule in the same directory clobbers the previous molecule's geometry/Hessian/frequencies. This blocks any batch/screening loop (#33).

Change

  • Add a directory argument to dftbplus_thermo; the pipeline runs there via a _run_in_directory context manager that creates the directory and restores the previous working directory afterwards (including on error).
  • Backward-compatible: defaults to the current directory, so existing single-molecule workflows are unchanged.
  • chdir-based, so correct for sequential and multi-process batches; per-thread parallelism within one process would need the calculators to thread a directory through (follow-up).

Tests

  • Unit tests for _run_in_directory: isolates into the target dir and restores the cwd, restores on exception, and is a no-op for None.
  • Verified locally with the real DFTB+ binaries: two molecules run into separate directories, the cwd is untouched, and results are independent and physically sensible (H2O 45.05, NH3 45.97 cal/(mol*K)).

148 passed, 0 skipped (suite run with DFTB+ binaries); pylint 8.04/10.

The DFTB+ steps read and write fixed filenames (geo_opt.gen, hessian.out,
vibrations.tag, ...) in the current directory, so running more than one molecule
in the same directory clobbers the previous result. Add a directory argument to
dftbplus_thermo that runs the pipeline in its own directory via a context
manager, restoring the previous working directory afterwards. Defaults to the
current directory, so existing behaviour is unchanged.
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.00%. Comparing base (8039bd7) to head (594560c).

Additional details and impacted files
@@                       Coverage Diff                        @@
##           feed-ase-atoms-to-run-thermo      #54      +/-   ##
================================================================
+ Coverage                         94.27%   95.00%   +0.72%     
================================================================
  Files                                21       21              
  Lines                              1206     1221      +15     
================================================================
+ Hits                               1137     1160      +23     
+ Misses                               69       61       -8     
Flag Coverage Δ
unittests 95.00% <100.00%> (+0.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dftbplus_thermo only runs under the DFTB+ binaries, which CI skips, so the new
directory branch showed as uncovered. Add a test that mocks the calculator
pipeline (Geoopt/Hessian/Modes/run_thermo) and asserts the steps run inside the
given directory and the working directory is restored.
@galjos
galjos merged commit 0576e46 into feed-ase-atoms-to-run-thermo Jun 26, 2026
3 checks passed
@galjos
galjos deleted the isolate-dftbplus-run-directory branch June 26, 2026 15:59
galjos added a commit that referenced this pull request Jun 26, 2026
Closes #53. Re-targets the work from #54 onto main: #54 was stacked on
the #52 branch and got merged into that branch instead of main (which
was squash-merged separately), so the change never landed. These are the
same commits, cleanly rebased onto current main.

The DFTB+ steps read and write fixed filenames (`geo_opt.gen`,
`hessian.out`, `vibrations.tag`, `modes_in.hsd`, ...) in the current
directory, so running more than one molecule in the same directory
clobbers the previous molecule's geometry/Hessian/frequencies. This
blocks any batch/screening loop (#33).

## Change
- Add a `directory` argument to `dftbplus_thermo`; the pipeline runs
there via a `_run_in_directory` context manager that creates the
directory and restores the previous working directory afterwards
(including on error).
- Backward-compatible: defaults to the current directory, so existing
single-molecule workflows are unchanged.
- chdir-based, so correct for sequential and multi-process batches;
per-thread parallelism within one process would need the calculators to
thread a directory through (follow-up).

## Tests
- Unit tests for `_run_in_directory`: isolates into the target dir and
restores the cwd, restores on exception, no-op for `None`.
- A mocked-pipeline test drives `dftbplus_thermo(..., directory=...)`
without the binaries, covering the directory wiring in CI (api.py
coverage 87% -> 93%).
- Verified locally with the real DFTB+ binaries: two molecules run into
separate directories, the cwd is untouched, results independent and
physically sensible (H2O 45.05, NH3 45.97 cal/(mol*K)).

144 passed, 5 skipped (no binaries); pylint 8.04/10.
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