Update phonopy to 3.0.0 #633
Conversation
📝 WalkthroughWalkthroughThe pull request updates the phonopy dependency from version 2.47.1 to 3.0.0 across four configuration and manifest files that define the project's dependencies and environment specifications. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pyproject.toml`:
- Line 42: Remove the deprecated factor parameter from Phonopy constructor calls
in src/atomistics/workflows/phonons/helper.py: locate the Phonopy(...)
invocations (around the block that calls generate_displacements(), accesses
supercells_with_displacements, assigns .forces and later reads .force_constants)
and delete the factor=... argument; if you need calculator-based unit conversion
instead, instantiate Phonopy with calculator=... and
set_factor_by_calculator=True as recommended or otherwise rely on the default
THz conversion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0336dafa-aff7-4d82-925d-6abda6fba7f0
📒 Files selected for processing (4)
.ci_support/environment-docs.yml.ci_support/environment.ymlbinder/environment.ymlpyproject.toml
| [project.optional-dependencies] | ||
| phonopy = [ | ||
| "phonopy==2.47.1", | ||
| "phonopy==3.0.0", |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find the actual Phonopy usages in helper.py and related files
find src -name "*.py" -type f | head -20Repository: pyiron/atomistics
Length of output: 865
🏁 Script executed:
# Search for Phonopy imports and usage patterns
rg -n --type=py -C2 'from phonopy|import phonopy|Phonopy\(' src tests 2>/dev/null | head -100Repository: pyiron/atomistics
Length of output: 5670
🏁 Script executed:
# Specifically check helper.py
if [ -f "src/atomistics/workflows/phonons/helper.py" ]; then
wc -l "src/atomistics/workflows/phonons/helper.py"
echo "---"
cat -n "src/atomistics/workflows/phonons/helper.py"
else
echo "Helper file not found; searching for it..."
find . -name "helper.py" -path "*/phonons/*" -type f
fiRepository: pyiron/atomistics
Length of output: 25737
🌐 Web query:
Phonopy 3.0.0 API release notes breaking changes
💡 Result:
Phonopy 3.0.0?
I couldn’t find any Phonopy v3.0.0 release notes—Phonopy’s published changelog shows v2.48.0 (Feb 15, 2026) as the latest entry, i.e., still on the 2.x line. [1]
If you meant Phono3py 3.0.0 (common mix-up): breaking / backward-incompatible changes
Phono3py v3.0.0 (Apr 19, 2024) lists these backward-incompatible changes: [2]
- Changed fc3 real→reciprocal transform method, changing results vs phono3py v2 behavior.
Compatibility options: use--v2in the CLI; in the Python API usemake_r0_average=True(default) when creatingPhono3py, and similarly forphono3py.load. - Dropped support for
disp_fc3.yamlanddisp_fc2.yaml(completely removed). - Dropped support for “old style”
phono3py-kaccumscript usage.
Sources: [1] Phonopy changelog, [2] Phono3py changelog.
🌐 Web query:
Phonopy 3.0.0 constructor parameters unitcell supercell_matrix primitive_matrix
💡 Result:
In phonopy 3.0.0, the Phonopy constructor begins like this (showing the three parameters you asked about): (raw.githubusercontent.com)
Phonopy(
unitcell: PhonopyAtoms,
supercell_matrix: Sequence[int] | Sequence[Sequence[int]] | NDArray | None = None,
primitive_matrix: Literal["P","F","I","A","C","R","auto"]
| Sequence[Sequence[float]] | NDArray | None = None,
...
)unitcell: aPhonopyAtomsobject (the input unit cell). (raw.githubusercontent.com)supercell_matrix: an integer supercell transformation given as either- length-3 integers (interpreted as a diagonal
[na, nb, nc]), or - a 3×3 integer matrix /
ndarray,
used to build the supercell from the unit cell. (raw.githubusercontent.com)
- length-3 integers (interpreted as a diagonal
primitive_matrix: a primitive-cell transformation given as either- a 3×3 float matrix /
ndarray, or - one of
"P","F","I","A","C","R","auto",
used to build the primitive cell from the unit cell. (raw.githubusercontent.com)
- a 3×3 float matrix /
Citations:
- 1: https://raw.githubusercontent.com/phonopy/phonopy/v3.0.0/phonopy/api_phonopy.py
- 2: https://raw.githubusercontent.com/phonopy/phonopy/v3.0.0/phonopy/api_phonopy.py
- 3: https://raw.githubusercontent.com/phonopy/phonopy/v3.0.0/phonopy/api_phonopy.py
- 4: https://raw.githubusercontent.com/phonopy/phonopy/v3.0.0/phonopy/api_phonopy.py
🌐 Web query:
Phonopy version 3.0.0 release date changelog
💡 Result:
Phonopy itself has not released a v3.0.0 (its releases are still in the 2.x series). (phonopy.github.io)
The v3.0.0 release you’re likely referring to is Phono3py v3.0.0, released on April 19, 2024. (phonopy.github.io)
Phono3py v3.0.0 changelog (highlights)
- Major release with backward-incompatible changes. (phonopy.github.io)
- Changed the real→reciprocal transform method for fc3 (affects results vs v2); v2-like behavior can be requested via
--v2(andmake_r0_average=Truedefaults for the API). (phonopy.github.io) - Dropped support for
disp_fc3.yamlanddisp_fc2.yaml. (phonopy.github.io) - Dropped support for old-style
phono3py-kaccumusage. (phonopy.github.io) - Removed
write_fc3_dat,write_triplets,write_grid_addressfromfile_IO.py; removed deprecated methods; and removed severalPhono3py.__init__()parameters (masses,band_indices,sigmas,sigma_cutoff). (phonopy.github.io)
Citations:
- 1: https://phonopy.github.io/phonopy/changelog.html?utm_source=openai
- 2: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
- 3: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
- 4: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
- 5: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
- 6: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
- 7: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
🌐 Web query:
Phonopy 3.0.0 generate_displacements method signature supercells_with_displacements property
💡 Result:
I couldn’t find any evidence that Phonopy has a “3.0.0” release line; the Phonopy docs/changelog I can access are for the 2.x series (e.g. v2.48.0), where the API below applies. In that API, displacement generation is done explicitly by calling generate_displacements(...) with a distance argument. [1]
generate_displacements (Phonopy API)
Signature (keyword args shown with typical defaults):
phonon.generate_displacements(
distance=0.01,
is_plusminus="auto",
is_diagonal=True,
is_trigonal=False,
)[2]
supercells_with_displacements (property/attribute)
After calling generate_displacements(), you can access the generated displaced supercells via:
phonon.supercells_with_displacements→ a list ofphonopy.structure.atoms.PhonopyAtomsobjects (one per displacement supercell). [3]
If you meant Phono3py 3.0.0 (not Phonopy), tell me and I’ll pull the exact 3.0.0 API details for that specific version.
Sources: [1] [2] [3]
🌐 Web query:
Phonopy 3.0.0 forces property force_constants attribute API
💡 Result:
- There is no “phonopy 3.0.0” release: on PyPI the latest phonopy is 2.48.0 (uploaded Feb 15, 2026). [1]
- The
forcesattribute/property you’re referring to matches the phono3py 3.x API: calculated supercell force sets are stored on the object asPhono3py.forceswith shape(num_supercells, num_atoms_in_supercell, 3). [2] - In phono3py, don’t expect a generic
force_constantsattribute on the main object: users have historically hitAttributeError: 'Phono3py' object has no attribute 'force_constants'. Instead, phono3py exposes force constants via order-specific data (e.g., fc2/fc3) after running the production routines (e.g.,produce_fc3()). [2][3]
Sources: [1] [2] [3]
🏁 Script executed:
cat pyproject.toml | grep -A 2 -B 2 phonopyRepository: pyiron/atomistics
Length of output: 182
🏁 Script executed:
# Verify PyPI availability of phonopy versions
pip index versions phonopy 2>/dev/null | head -20 || python3 << 'EOF'
import json
try:
import urllib.request
response = urllib.request.urlopen("https://pypi.org/pypi/phonopy/json", timeout=5)
data = json.loads(response.read())
releases = sorted(data['releases'].keys(), reverse=True)
print("Available phonopy versions (latest 20):")
for v in releases[:20]:
print(f" {v}")
except Exception as e:
print(f"Could not fetch PyPI data: {e}")
EOFRepository: pyiron/atomistics
Length of output: 2189
🌐 Web query:
Phonopy 3.0.0 constructor factor parameter documentation
💡 Result:
- There is no “Phonopy 3.0.0” release as of Feb 15, 2026 (latest Phonopy is v2.48.0). (phonopy.github.io)
- The “3.0.0” version you may be thinking of is Phono3py v3.0.0 (released Apr 19, 2024). (phonopy.github.io)
What factor refers to in the Python API
In both phonopy/phono3py Python usage, factor is documented as part of the NAC (non-analytical term correction) parameters dict (i.e., not a Phonopy(...) constructor argument):
nac_params = {
"born": ..., # Born effective charges
"dielectric": ..., # dielectric tensor
"factor": float, # unit conversion factor
}
ph.nac_params = nac_paramsThe docs describe factor as a “Unit conversion factor” inside nac_params, which is set via the *.nac_params attribute. (phonopy.github.io)
Related note (CLI)
If you were looking for a constructor-like “factor” because of older workflows: the --factor / FREQUENCY_CONVERSION_FACTOR mechanism is deprecated (since v2.44) in phonopy’s CLI context. (phonopy.github.io)
Citations:
- 1: https://phonopy.github.io/phonopy/changelog.html?utm_source=openai
- 2: https://phonopy.github.io/phono3py/changelog.html?utm_source=openai
- 3: https://phonopy.github.io/phono3py/phono3py-api.html?utm_source=openai
- 4: https://phonopy.github.io/phonopy/gruneisen.html?utm_source=openai
🌐 Web query:
site:github.com Phonopy v3.0.0 generate_displacements supercells_with_displacements
💡 Result:
In Phonopy / Phono3py, generate_displacements() populates a list of displaced supercells that you access via the attribute supercells_with_displacements:
# Phonopy
phonon.generate_displacements(distance=0.03)
supercells = phonon.supercells_with_displacements(Older docs also describe the getter get_supercells_with_displacements(), but the attribute access above is the direct way.) [1]
# Phono3py (v3.x)
ph3.generate_displacements()
supercells = ph3.supercells_with_displacements
n = len(supercells)supercells_with_displacements is a list of PhonopyAtoms supercells with the generated displacements. [2]
Sources: [1] [2]
🌐 Web query:
Phonopy 3.0.0 forces property assignment force_constants
💡 Result:
In Phonopy/Phono3py you generally don’t set force_constants by assigning to a forces property. The workflows are:
- You have force constants already (array
fc): set them explicitly via the API method (not by property assignment), e.g.
phonon.set_force_constants(fc)(typical Phonopy usage) [2].
- You have displacements + forces and want Phonopy/Phono3py to build force constants:
- Set the displacement dataset and then assign the forces array (shape
(n_supercells, n_atoms_supercell, 3)), and finally call the force-constants builder (e.g.produce_fc3()in Phono3py). Example shown in the Phono3py API:ph3.dataset = disp_datasetph3.forces = forcesph3.produce_fc3()[1].
If your goal is file-based I/O instead, Phonopy can read/write force constants from FORCE_CONSTANTS via settings (e.g. FORCE_CONSTANTS = READ/WRITE) [3].
Sources: Phono3py API example of setting forces then producing FCs [1]; Phonopy-style set_force_constants usage example [2]; Phonopy FORCE_CONSTANTS read/write setting [3].
🏁 Script executed:
python3 << 'EOF'
import json
import urllib.request
# Get PyPI data for phonopy 3.0.0
try:
response = urllib.request.urlopen("https://pypi.org/pypi/phonopy/3.0.0/json", timeout=10)
data = json.loads(response.read())
print("Phonopy 3.0.0 found on PyPI")
print(f"Release date: {data['releases'].get('3.0.0', [{}])[0].get('upload_time', 'N/A') if isinstance(data['releases'], dict) else 'N/A'}")
except Exception as e:
print(f"Error: {e}")
EOFRepository: pyiron/atomistics
Length of output: 195
🌐 Web query:
site:github.com/phonopy/phonopy "v3.0.0" Phonopy constructor factor parameter
💡 Result:
In phonopy/phonopy v3.0.0, the Phonopy constructor still accepts a factor: float | None = None parameter, but it is deprecated (deprecated since v2.24) and triggers a DeprecationWarning if you pass a non-None value. Its role is to set the internal frequency unit conversion factor (self._unit_conversion_factor). [1]
Behavior in __init__ is: [1]
- If
calculator is not Noneandset_factor_by_calculator=True, then
unit_conversion_factor = get_calculator_physical_units(interface_mode=calculator).factor - Else if
factor is None, then
unit_conversion_factor = get_physical_units().DefaultToTHz(default is conversion to THz for Å displacements and eV/Å forces) - Else (i.e.,
factorgiven), then
unit_conversion_factor = factor
So for v3.0.0, the recommended approach is to avoid factor and instead use calculator=... with set_factor_by_calculator=True, or rely on the default THz conversion. [1]
🌐 Web query:
Phonopy 3.0.0 API "def __init__" unitcell supercell_matrix primitive_matrix factor
💡 Result:
In Phonopy 3.x, the Phonopy constructor uses these inputs:
unitcell: aPhonopyAtomsobject (your input structure).supercell_matrix: the integer transformation that expandsunitcellinto the supercell (commonly[na, nb, nc]or a 3×3 integer matrix).primitive_matrix: the transformation that extracts the primitive cell fromunitcell(3×3 matrix or'auto'to let symmetry search determine it).factor: frequency unit conversion factor (to THz); you set it depending on the calculator/interface (e.g.AbinitToTHz,VaspToTHz, etc.). An example explicitly showsPhonopy(..., factor=AbinitToTHz). [1]
(These matrix meanings match the way the Phono3py API describes them as well—Phono3py’s instantiation is “similar to the instantiation ofPhonopyclass”.) [2]
Example usage:
from phonopy import Phonopy
from phonopy.units import AbinitToTHz
phonon = Phonopy(
unitcell,
supercell_matrix=[[2,0,0],[0,2,0],[0,0,2]],
primitive_matrix="auto",
factor=AbinitToTHz,
)[1] [2]
Remove deprecated factor parameter from Phonopy() constructor calls in src/atomistics/workflows/phonons/helper.py.
Phonopy 3.0.0 is available and the APIs (Phonopy() constructor with unitcell, supercell_matrix, primitive_matrix; generate_displacements(), supercells_with_displacements, .forces assignment, and .force_constants property) remain compatible. However, the factor parameter has been deprecated since Phonopy v2.24 and will trigger a DeprecationWarning at runtime in 3.0.0.
At line 286–294, replace the deprecated factor parameter with the recommended approach: rely on the default THz conversion by removing the factor argument, or if unit conversion from a specific calculator interface is needed, use the calculator= parameter with set_factor_by_calculator=True instead.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pyproject.toml` at line 42, Remove the deprecated factor parameter from
Phonopy constructor calls in src/atomistics/workflows/phonons/helper.py: locate
the Phonopy(...) invocations (around the block that calls
generate_displacements(), accesses supercells_with_displacements, assigns
.forces and later reads .force_constants) and delete the factor=... argument; if
you need calculator-based unit conversion instead, instantiate Phonopy with
calculator=... and set_factor_by_calculator=True as recommended or otherwise
rely on the default THz conversion.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #633 +/- ##
=======================================
Coverage 86.81% 86.81%
=======================================
Files 43 43
Lines 2419 2419
=======================================
Hits 2100 2100
Misses 319 319 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary by CodeRabbit