Skip to content

Fix enhanced CLI explicit-donor handling and writeout tuple unpacking#541

Merged
rolan701 merged 2 commits into
hjkgrp:mainfrom
Holaxis-ai:codex/pydentate-lazy-import
Apr 20, 2026
Merged

Fix enhanced CLI explicit-donor handling and writeout tuple unpacking#541
rolan701 merged 2 commits into
hjkgrp:mainfrom
Holaxis-ai:codex/pydentate-lazy-import

Conversation

@mikec-ai
Copy link
Copy Markdown
Contributor

run_build_complex() imported pydentate before checking whether any ligand was actually missing coordinating atoms. That made commands with explicit --usercatoms fail in environments where pydentate was not installed, even though donor prediction was not needed for the run.

After fixing that, the same enhanced CLI path hit a second bug: it overwrote mol with the full return value of enforce_metal_ligand_distances_and_optimize(...), which returns a tuple. The later mol.writexyz(...) call then failed with:

AttributeError: 'tuple' object has no attribute 'writexyz'

This patch defers the pydentate import until it is actually needed, unpacks the return value of enforce_metal_ligand_distances_and_optimize(...) before writeout, and adds a CLI regression test for the explicit --usercatoms path.

Repro before

python -m molSimplify \
  --ligand NCCCOCCN \
  --usercatoms '[0,7]' \
  --occupancy 3 \
  --metal Fe \
  --ox 2 \
  --spin 1 \
  --geometry octahedral \
  --run-dir /tmp/molsimplify-cli-probe-repro

In an environment without pydentate, this failed immediately with:

ModuleNotFoundError: No module named 'pydentate'

After the lazy-import change, the same command progressed to the next bug in the same CLI path:

AttributeError: 'tuple' object has no attribute 'writexyz'

With both fixes in place, the command completes and writes the expected output files.

Test

conda run -n materials-cli-molsimplify python -m pytest -q tests/test_cli.py
2 passed

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.68%. Comparing base (44c0b8e) to head (48a8da1).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
molSimplify/__main__.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #541      +/-   ##
==========================================
+ Coverage   40.26%   40.68%   +0.41%     
==========================================
  Files          93       93              
  Lines       30325    30327       +2     
==========================================
+ Hits        12211    12339     +128     
+ Misses      18114    17988     -126     
Flag Coverage Δ
unittests 40.68% <50.00%> (+0.41%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@rolan701
Copy link
Copy Markdown
Contributor

Everything looks good here!

Thanks,

  • Roland

@rolan701 rolan701 merged commit b112cd1 into hjkgrp:main Apr 20, 2026
9 of 10 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.

2 participants