Skip to content

Cleanup 2026#33

Open
aronwalsh wants to merge 6 commits intomasterfrom
cleanup_26
Open

Cleanup 2026#33
aronwalsh wants to merge 6 commits intomasterfrom
cleanup_26

Conversation

@aronwalsh
Copy link
Member

This pull request introduces several improvements and fixes across the codebase, focusing on enhancing usability, maintainability, and correctness. Major updates include revamping the CI workflow, improving documentation and citation support, refining plotting and numerical routines, and cleaning up code style and logic.

Continuous Integration and Quality Assurance:

  • Modernized the .github/workflows/ci.yaml workflow: updated Python and action versions, expanded testing to Python 3.12, added a dedicated lint job using ruff, adjusted branch triggers, and improved Codecov upload logic.

Documentation and Citation:

  • Added a CITATION.cff file to provide standardized citation information for the project.
  • Enhanced the README.md with project badges, a quick usage example, and improved introductory text. [1] [2]

API and Code Quality Improvements:

  • Refactored macrodensity/__init__.py to explicitly import only public API functions and classes, improving clarity and maintainability.
  • Updated module docstrings in macrodensity/plotting.py and macrodensity/tools.py for better clarity and consistency. [1] [2]

Numerical and Plotting Fixes:

  • Corrected the calculation of the macroscopic average and periodic boundary wrapping in macrodensity/averages.py for more accurate results. [1] [2]
  • Fixed gradient magnitude calculations and field direction conventions in macrodensity/density.py and plotting routines, ensuring correct visualization of vector fields and potential gradients. [1] [2] [3] [4] [5]
  • Fixed axis selection and file saving logic in several plotting functions, improving output correctness and usability. [1] [2] [3] [4]

Code Logic and Style Cleanups:

  • Improved boolean checks and replaced unnecessary equality comparisons with more idiomatic Python. [1] [2] [3] [4]
  • Fixed array handling and interpolation logic in macrodensity/tools.py for functions like match_resolution, matched_spline_generate, and diff_potentials, ensuring correct numerical behavior. [1] [2] [3]
  • Corrected a loop logic error in read_gulp_potential to ensure all grid points are read.

These changes collectively improve the reliability, maintainability, and user experience of the MacroDensity package.

aronwalsh and others added 6 commits January 10, 2026 08:54
- Replace wildcard imports with explicit imports in __init__.py
- Fix boolean comparisons (== True/False) to use truthiness
- Remove empty else: pass blocks in plotting.py
- Remove commented-out code in plotting.py
- Fix float comparison in tests to use assertAlmostEqual

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix electric field sign: E = -grad(V), not grad(V) (plotting.py)
- Fix gradient magnitude: use sqrt(x^2+y^2+z^2) not x*y*z (plotting.py)
- Fix cube file lattice vectors: cell[0] not cell[1] for vector_a (plotting.py)
- Fix GULP potential reading: remove reversed() that inverted grid (io.py)
- Fix macroscopic_average normalization in else branch (averages.py)
- Fix periodic wrapping: use modulo instead of round() (averages.py)
- Fix np.append: use np.vstack with assignment (tools.py)
- Fix diff_potentials: rewrite to fix negative size and index bugs (tools.py)
- Fix matched_spline_generate: use interpolated A_new not original A (tools.py)
- Fix gradient_magnitude: vectorize, don't modify input array (density.py)
- Fix plane orientation: implement zoz and ozz cases (tools.py)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
New function to remove artificial electric fields in slab calculations
caused by periodic boundary conditions. The function:
- Auto-detects vacuum region by finding flat areas of the potential
- Fits a line to measure the electric field slope
- Subtracts a linear ramp to flatten the potential

Usage:
  corrected, field, vacuum = md.dipole_correction(planar_avg, lattice_z)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add get_layer_sites() function for identifying slab surface layers
- Update module docstrings to be cleaner and more descriptive
- Fix plt.savefig to fig.savefig for explicit figure saving

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move JOSSpaper directory to docs/JOSSpaper
- Add badges to README (CI, PyPI, docs, license)
- Add quick usage examples to README
- Add CITATION.cff for proper citation support

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update to latest GitHub Actions versions (checkout@v4, setup-python@v5)
- Add Python 3.12 to test matrix
- Trigger on all PRs to master/main (not just specific branches)
- Add basic linting with ruff (lenient for legacy code)
- Make codecov optional (don't fail without token)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@aronwalsh aronwalsh requested review from ireaml and keeeto January 14, 2026 20:23
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