Skip to content

Update Phonopy Interface#508

Merged
jan-janssen merged 10 commits intomainfrom
phonopy_interface
Jul 24, 2025
Merged

Update Phonopy Interface#508
jan-janssen merged 10 commits intomainfrom
phonopy_interface

Conversation

@jan-janssen
Copy link
Copy Markdown
Member

@jan-janssen jan-janssen commented Jul 24, 2025

Summary by CodeRabbit

  • Refactor
    • Simplified function and method interfaces to accept unified data objects for phonon calculations and plotting, reducing the need to pass separate data components.
  • Tests
    • Updated all relevant tests to use the new unified interfaces for obtaining the Hessian matrix, ensuring consistency with the refactored code.
  • Documentation
    • Adjusted example usage in the free energy calculation notebook to reflect the updated function signatures.

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 24, 2025

Warning

Rate limit exceeded

@jan-janssen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5808354 and f25da97.

📒 Files selected for processing (2)
  • atomistics/workflows/phonons/helper.py (9 hunks)
  • notebooks/free_energy_calculation.ipynb (1 hunks)

Walkthrough

The changes update the interfaces of several phonon-related helper functions to accept higher-level Phonopy objects or dictionaries instead of raw data arrays. Corresponding updates are made throughout the workflow code, tests, and a notebook to align with the new function signatures, centralizing data extraction and improving interface consistency.

Changes

Files / Areas Change Summary
atomistics/workflows/phonons/helper.py Refactored function signatures: get_hesse_matrix, plot_dos, and plot_band_structure now accept Phonopy objects or dicts instead of raw data arrays. Internal logic updated accordingly.
atomistics/workflows/phonons/workflow.py Updated internal method calls to use new helper function signatures, simplifying data passing and removing legacy try-except logic.
notebooks/free_energy_calculation.ipynb Updated usage of get_hesse_matrix to pass the Phonopy object instead of force constants; cleared one cell output.
tests/test_ase_interface/test_phonons_ase_gpaw.py
tests/test_ase_interface/test_phonons_ase_mace.py
tests/test_ase_interface/test_phonons_ase_matgl.py
tests/test_phonons_ase_emt.py
tests/test_phonons_lammpsfile.py
tests/test_phonons_lammpslib_functional.py
tests/test_hessian_lammpslib.py
Updated tests to call get_hesse_matrix with a Phonopy object instead of its force_constants attribute. No other test logic changed.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Phonopy
    participant Helper

    Caller->>Helper: get_hesse_matrix(phonopy)
    Helper->>Phonopy: extract force_constants
    Helper-->>Caller: return Hesse matrix

    Caller->>Helper: plot_dos(phonopy_dict)
    Helper->>phonopy_dict: extract DOS data
    Helper-->>Caller: plot DOS

    Caller->>Helper: plot_band_structure(phonopy)
    Helper->>Phonopy: extract band structure, path, labels
    Helper-->>Caller: plot band structure
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A hop, a skip, a signature change,
Now Phonopy objects are all the rage!
No more arrays passed hand to hand,
Centralized logic, isn’t it grand?
With tests and notebooks in harmony anew,
This rabbit says: “Great job, crew!” 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch phonopy_interface

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
notebooks/free_energy_calculation.ipynb (1)

663-670: Heavy CPU overhead – compute the Hessian once, not every MD step

get_hesse_matrix(phonopy=phonopy_obj) is now correct for the new helper-signature, but the call is located inside the inner for i in tqdm(steps_lst) loop.
Nothing inside that loop mutates phonopy_obj, so the result is identical for all 3 000 iterations per λ. You end up executing an expensive phonopy routine (supercell → dynamical-matrix → FC) roughly

n_temperatures × n_λ × steps
≈ 7 × 5 × 3 000 ≈ 100 000 times.

Move the computation out of the MD-step loop (e.g. directly after analyse_results_for_harmonic_approximation) and pass the cached force_constants variable to evaluate_with_hessian. That drops the runtime from hours to seconds.

atomistics/workflows/phonons/helper.py (1)

530-558: Interface improvement with encapsulation concerns.

While the signature change to accept a Phonopy object is good, accessing private attributes phonopy._band_structure is problematic and fragile.

Consider finding a public API alternative or requesting the phonopy library to expose these attributes publicly. The current approach could break with phonopy updates.

# Current problematic access to private attributes
path_connections = phonopy._band_structure.path_connections
labels = phonopy._band_structure.labels

Would it be possible to:

  1. Use phonopy's public API to get this information?
  2. Store these values when calling auto_band_structure() in the workflow?
  3. Request the phonopy maintainers to add public accessors for these attributes?
🧹 Nitpick comments (1)
atomistics/workflows/phonons/helper.py (1)

447-469: Interface update is correct with a minor cleanup opportunity.

The function now properly accepts a phonopy dictionary and extracts DOS data from the nested structure.

Remove the unnecessary trailing commas in the tuple assignments:

-    dos_energies = (phonopy_dict["total_dos_dict"]["frequency_points"],)
-    dos_total = (phonopy_dict["total_dos_dict"]["total_dos"],)
+    dos_energies = phonopy_dict["total_dos_dict"]["frequency_points"]
+    dos_total = phonopy_dict["total_dos_dict"]["total_dos"]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b75b47 and 5808354.

📒 Files selected for processing (10)
  • atomistics/workflows/phonons/helper.py (7 hunks)
  • atomistics/workflows/phonons/workflow.py (3 hunks)
  • notebooks/free_energy_calculation.ipynb (2 hunks)
  • tests/test_ase_interface/test_phonons_ase_gpaw.py (2 hunks)
  • tests/test_ase_interface/test_phonons_ase_mace.py (2 hunks)
  • tests/test_ase_interface/test_phonons_ase_matgl.py (2 hunks)
  • tests/test_hessian_lammpslib.py (1 hunks)
  • tests/test_phonons_ase_emt.py (2 hunks)
  • tests/test_phonons_lammpsfile.py (2 hunks)
  • tests/test_phonons_lammpslib_functional.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
tests/test_phonons_ase_emt.py (2)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
tests/test_ase_interface/test_phonons_ase_gpaw.py (2)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
tests/test_phonons_lammpslib_functional.py (2)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
tests/test_ase_interface/test_phonons_ase_matgl.py (2)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
tests/test_hessian_lammpslib.py (2)
atomistics/workflows/phonons/helper.py (2)
  • force_constants (156-165)
  • get_hesse_matrix (421-443)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
tests/test_ase_interface/test_phonons_ase_mace.py (2)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
atomistics/workflows/phonons/workflow.py (1)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
tests/test_phonons_lammpsfile.py (2)
atomistics/workflows/phonons/workflow.py (1)
  • get_hesse_matrix (200-207)
atomistics/workflows/phonons/helper.py (1)
  • get_hesse_matrix (421-443)
atomistics/workflows/phonons/helper.py (1)
atomistics/workflows/phonons/workflow.py (2)
  • get_hesse_matrix (200-207)
  • plot_dos (254-269)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: unittest_matrix (macos-latest, 3.12)
  • GitHub Check: pip_check
  • GitHub Check: unittest_matrix (ubuntu-latest, 3.11)
  • GitHub Check: unittest_matrix (ubuntu-latest, 3.12)
  • GitHub Check: unittest_qe
  • GitHub Check: unittest_siesta
  • GitHub Check: unittest_matrix (windows-latest, 3.12)
  • GitHub Check: unittest_sphinxdft
  • GitHub Check: unittest_matgl
  • GitHub Check: notebooks
  • GitHub Check: unittest_mace
  • GitHub Check: unittest_orb
  • GitHub Check: coverage
🔇 Additional comments (12)
tests/test_phonons_ase_emt.py (1)

35-35: Interface update correctly implemented

The calls to get_hesse_matrix have been properly updated to use the new interface that accepts a Phonopy object instead of raw force constants. This aligns with the refactored function signature in atomistics/workflows/phonons/helper.py (lines 420-442).

Also applies to: 46-46

tests/test_ase_interface/test_phonons_ase_gpaw.py (1)

40-40: Interface update correctly implemented

The calls to get_hesse_matrix have been properly updated to use the new interface that accepts a Phonopy object instead of raw force constants. This change is consistent with the refactored function signature shown in the relevant code snippets.

Also applies to: 51-51

tests/test_phonons_lammpsfile.py (1)

82-82: Interface update correctly implemented

The calls to get_hesse_matrix have been properly updated to use the new interface that accepts a Phonopy object instead of raw force constants. This ensures compatibility with the refactored helper function in atomistics/workflows/phonons/helper.py.

Also applies to: 149-149

tests/test_ase_interface/test_phonons_ase_mace.py (1)

53-53: Interface update correctly implemented

The calls to get_hesse_matrix have been properly updated to use the new interface that accepts a Phonopy object instead of raw force constants. This change maintains consistency with the refactored function signature and the broader interface improvements across the phonon workflow.

Also applies to: 64-64

tests/test_phonons_lammpslib_functional.py (1)

57-57: Interface update correctly implemented

The call to get_hesse_matrix has been properly updated to use the new interface that accepts a Phonopy object instead of raw force constants. This change aligns with the refactored function signature in atomistics/workflows/phonons/helper.py and maintains consistency across all test files.

tests/test_ase_interface/test_phonons_ase_matgl.py (2)

51-51: LGTM: Correctly updated to new interface.

The change from force_constants=phonopy_obj.force_constants to phonopy=phonopy_obj properly aligns with the updated get_hesse_matrix function signature that now accepts a Phonopy object directly.


62-62: LGTM: Consistent interface update.

This change maintains consistency with the new get_hesse_matrix interface, ensuring the function receives the Phonopy object as expected.

tests/test_hessian_lammpslib.py (1)

75-75: LGTM: Properly updated function call.

The change correctly updates the get_hesse_matrix call to use the new interface that accepts the Phonopy object directly. The function still returns the Hesse matrix as expected by the force_constants parameter of evaluate_with_hessian.

atomistics/workflows/phonons/workflow.py (3)

207-207: LGTM! Clean interface update.

The change correctly aligns with the updated get_hesse_matrix helper function signature, which now accepts the entire Phonopy object for better encapsulation.


247-247: LGTM! Simplified interface.

The updated call correctly passes the Phonopy object to the helper function, which now handles band structure data extraction internally.


265-265: plot_dos interface change approved

Verified that self._phonopy_dict always contains a "total_dos_dict" entry with the expected keys ("frequency_points", "total_dos")—both the helper implementation and existing tests confirm this.

Please ensure in all call sites that analyse_structures() is invoked before plot_dos() so that self._phonopy_dict is populated.

• File: atomistics/workflows/phonons/workflow.py (line 265)
analyse_structures() defined at line 101

atomistics/workflows/phonons/helper.py (1)

421-443: Well-executed interface refactoring.

The function signature change from force_constants to phonopy object improves encapsulation. The implementation correctly extracts force constants from the Phonopy object while preserving the calculation logic.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 24, 2025

Codecov Report

Attention: Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

Project coverage is 85.34%. Comparing base (a0c6a5c) to head (f25da97).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
atomistics/workflows/phonons/helper.py 28.57% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #508      +/-   ##
==========================================
+ Coverage   85.31%   85.34%   +0.03%     
==========================================
  Files          43       43              
  Lines        2587     2586       -1     
==========================================
  Hits         2207     2207              
+ Misses        380      379       -1     

☔ 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.

@jan-janssen jan-janssen merged commit f88d032 into main Jul 24, 2025
27 of 28 checks passed
@jan-janssen jan-janssen deleted the phonopy_interface branch July 24, 2025 10:28
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