Skip to content

refactor(models,io): Simplify helpers and make models/io mypy-clean - #375

Merged
ericchansen merged 1 commit into
masterfrom
ericchansen-simplify-models-and-io-layer
Oct 20, 2026
Merged

ericchansen merged 1 commit into
masterfrom
ericchansen-simplify-models-and-io-layer

Conversation

@ericchansen

Copy link
Copy Markdown
Owner

Summary

Simplifies duplicated helpers across q2mm.models and q2mm.io (-444 net lines) and resolves all remaining static type errors across every q2mm.models.* and q2mm.io.* module so all 13 grandfathered model/I/O modules can be removed from [[tool.mypy.overrides]] in pyproject.toml.

Changes

  • Consolidate shared text-file path/lazy-lines/write handling (_TextFileBase) and template path resolution (_resolve_template_path) in q2mm/io/_helpers.py, removing duplicated boilerplate across GaussLog, JaguarIn, JaguarOut, MacroModel, MacroModelLog, Mol2, amber.py, mm3.py, and tinker.py.
  • Deduplicate adjacency construction and delegate bond-length/bond-angle math in q2mm/models/molecule.py to q2mm.geometry (bond_length, bond_angle).
  • Deduplicate 3x3 Hessian sub-block eigendecomposition projection (_project_subblock_along) in q2mm/models/seminario.py, frequency unit conversion constants and mass_weight_scale_3n usage in q2mm/models/hessian.py, enum coercion (_coerce_enum) in q2mm/models/observations.py, and token cleaning (_clean_env_tokens) in q2mm/models/identifiers.py.
  • Deduplicate CMAP grid finalization in q2mm/io/cmap.py, MM3 proper/improper torsion construction in q2mm/io/mm3.py, MacroModel term staging (_MacroModelTerm) in q2mm/io/macromodel.py, and scalar observation parsing in q2mm/io/reference.py.
  • Remove all 13 q2mm.models.* and q2mm.io.* entries from [[tool.mypy.overrides]] in pyproject.toml.

Testing

  • python -m ruff check q2mm/ test/ scripts/ (all checks passed)
  • python -m ruff format --check q2mm test scripts examples (288 files formatted)
  • python -m mypy q2mm/ (0 errors across 109 source files)
  • python -m pytest test/ -x -q -m "not (openmm or tinker or jax or jax_md or psi4)" (7,582 passed, 185 skipped)

Base automatically changed from ericchansen-refactor-review to master October 19, 2026 22:42
@ericchansen
ericchansen force-pushed the ericchansen-simplify-models-and-io-layer branch from cf2104a to 3d7f4d6 Compare October 19, 2026 22:45
@ericchansen
ericchansen requested a balanced review from Copilot October 19, 2026 22:58

Copilot AI 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.

🟡 Changes recommended

The refactor introduces an angle-projection division failure and repeated parsing of Gaussian logs without frequency modes.

2 open issues
What changed in this PR

Consolidates shared model and I/O helpers and extends mypy enforcement across those modules.

Changes:

  • Shares text-file handling, template resolution, and repeated model calculations.
  • Simplifies parser staging and strengthens type annotations.
  • Removes 13 mypy exemptions and adds shared-helper tests.
File Description
test/​test_io_helpers.py Tests shared helpers and parser inheritance.
q2mm/​models/​seminario.py Shares Hessian projection logic and tightens types.
q2mm/​models/​observations.py Centralizes enum coercion.
q2mm/​models/​molecule.py Shares adjacency and geometry calculations.
q2mm/​models/​identifiers.py Centralizes atom-type token cleaning.
q2mm/​models/​hessian.py Shares conversion constants and mass weighting.
q2mm/​models/​forcefield.py Simplifies parameter construction and keys.
q2mm/​io/​tinker.py Strengthens types and shares template resolution.
q2mm/​io/​reference.py Consolidates scalar observation parsing.
q2mm/​io/​openmm.py Clarifies export variable types.
q2mm/​io/​mol2.py Adopts shared text-file handling.
q2mm/​io/​mm3.py Unifies torsion construction and template resolution.
q2mm/​io/​macromodel.py Unifies staging records and file handling.
q2mm/​io/​jaguar.py Shares file handling and simplifies parsing.
q2mm/​io/​gaussian.py Refactors parser state and file handling.
q2mm/​io/​cmap.py Centralizes grid finalization.
q2mm/​io/​amber.py Tightens parameter types and shares template resolution.
q2mm/​io/​_helpers.py Adds shared file and template helpers.
pyproject.toml Removes model and I/O mypy exemptions.

Review effort: Balanced

Comment thread q2mm/io/gaussian.py Resolved
Comment thread q2mm/models/seminario.py Resolved
Consolidate duplicated text-file parser boilerplate, template-path
resolution, Hessian frequency conversion constants, and Seminario
3x3 sub-block projection, and fix type annotations across q2mm.models
and q2mm.io so all 13 grandfathered modules can be removed from
[[tool.mypy.overrides]].

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 20, 2026 17:38
@ericchansen
ericchansen force-pushed the ericchansen-simplify-models-and-io-layer branch from 3d7f4d6 to f86e8e9 Compare October 20, 2026 17:38
@ericchansen
ericchansen merged commit aca56eb into master Oct 20, 2026
20 checks passed
@ericchansen
ericchansen deleted the ericchansen-simplify-models-and-io-layer branch October 20, 2026 17:40

Copilot AI 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.

🟢 Approval recommended

No unresolved blocking issues remain, and both previously reported regressions are addressed with focused tests.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

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