[WIP] Add PheasyCalc class for higher order phonon calculations#65
[WIP] Add PheasyCalc class for higher order phonon calculations#65leslie-zheng wants to merge 128 commits into
PheasyCalc class for higher order phonon calculations#65Conversation
PheasyCalc class for higher order phonon calculations
PheasyCalc class for higher order phonon calculationsPheasyCalc class for higher order phonon calculations
|
@rul048 You will take charge of reviewing PRs. But for now, I will be the one to merge them. |
|
@rul048 When are you going to review this? Are you actually interested in maintaining matcalc? |
Signed-off-by: Runze Liu <146490083+rul048@users.noreply.github.com>
| """ | ||
| A class for phonon, higher-order force constants and thermal property calculations using pheasy. | ||
|
|
||
| The `PhononCalc` class extends the `PropCalc` class to provide |
There was a problem hiding this comment.
Here should be PheasyCalc not PhononCalc.
| if i apply it and will give a huge error in force calculation""" | ||
|
|
||
| # sga = SpacegroupAnalyzer(structure, symprec=self.symprec) | ||
| # structure_in = sga.get_primitive_standard_structure() |
There was a problem hiding this comment.
If the commented out codes here are not needed, we could remove them.
| self.supercell_matrix = np.array(transformation.transformation_matrix.transpose().tolist()) | ||
| # transfer it to array | ||
|
|
||
| # self.supercell_matrix = supercell.lattice.matrix |
There was a problem hiding this comment.
Same as above. If the commented out codes here are not needed, we could remove them.
| subprocess.call(pheasy_cmd_1, shell=True) | ||
| subprocess.call(pheasy_cmd_2, shell=True) | ||
| subprocess.call(pheasy_cmd_3, shell=True) | ||
| subprocess.call(pheasy_cmd_4, shell=True) |
There was a problem hiding this comment.
I recommend not using (plenty of) command lines internally unless necessary. If unavoidable, please give the command a clear and descriptive name that reflects its purpose.
using alamode to calculate force constants
alamode for higher order
shyuep
left a comment
There was a problem hiding this comment.
Automated PR review generated by Claude (Opus 4.7) on behalf of @shyuep. Based purely on the diff and current GitHub Actions state — no code was executed locally.
Thanks for the contribution, @leslie-zheng — adding PheasyCalc, AlamodeCalc, and FourPhononCalc for higher-order force constants and 4-phonon thermal conductivity is a substantial and welcome capability. However, the PR in its current [WIP] state has several blockers and needs significant cleanup before it can be merged.
Blockers:
-
Hardcoded user-specific binary paths. Multiple
subprocesscall sites embed personal absolute paths:_alamode.py:subprocess.run("mpirun -n 1 /home/jzheng4/alamode/_build/alm/alm alamode.in", shell=True, check=False)(and thealamode_anhar.incounterpart)._fourphonon.py:subprocess.run(["mpirun", "-n", "1", "/home/jzheng4/FourPhonon-sampling_method/ShengBTE"], check=True).
FourPhononCalcalready exposespath_to_shengbte/path_to_fourphononconstructor params — please actually use them in the subprocess calls.AlamodeCalcshould expose an analogouspath_to_alamodeparameter (or read from$ALAMODE/which alm). No code path should hardcode/home/jzheng4/.... -
shell=True+check=False. Allsubprocess.call(..., shell=True)andsubprocess.run(..., shell=True, check=False)calls silently swallow failures. Ifalm,pheasy, orShengBTEfail (missing binary, bad input file, MPI error), the calculator continues with stale/missing output files and returns a result that looks valid but is wrong. Useshell=Falsewithargvlists,check=True, and capture stderr for diagnostics.shell=Trueis also an injection risk if any path or argument is ever derived from user input. -
Hardcoded composition-specific identifiers in
_alamode.py:f.write(" PREFIX = EuZnAs_harmonic\n")andFC2XML = EuZnAs_harmonic.xmlare hardcoded for the EuZnAs test system. Derive from the structure's reduced formula or accept aprefixparameter.f.write("&cutoff\n *-* 18 10 7.5\n/")hardcodes cutoff radii. Parameterize using the existingcutoff_distance_cubic/quartic/ etc. attributes (which are currently defined but unused in this code path).L1_ALPHA = 3.82925e-06,CONV_TOL = 1.0e-8— surface as__init__parameters with documented defaults.
-
CI is fully red and the branch is dirty (CONFLICTING). Lint, test, and
pre-commit.ciall fail; rebase ontomainand runruff check --fix . && ruff format .andmypyper @rul048's earlier ask. -
Patch coverage is 14% (235 uncovered lines). External-binary calls are hard to unit-test, but the pure-Python logic absolutely should be — in particular
_parse_xml,_get_forceconstants_xml,_write_fc2_phonopy, the input-file generators, and the unit conversion logic (Bohr/Rydberg). Add tests with small fixture XML/FORCE_CONSTANTSfiles.
Other issues:
- Many duplicated
import subprocessstatements at function scope (e.g. insideif self.calc_anharmonic:); move all imports to the module top. - Large blocks of commented-out debug code (
# subprocess.run(["mpirun", ...,# write_force_constants_to_hdf5(...),# print(np.shape(fc_full))). Please delete;gitis the history. pheasy>=0.0.2is added as a hard dependency inpyproject.toml, but pheasy is very early-stage and not on conda-forge. Make it optional via an extras group (e.g.pheasy = ["pheasy>=0.0.2"]) andimportit lazily inside the calculator, raising a clearImportErrorwith install instructions if missing — this is how matcalc handlesphono3py-only paths.AlamodeCalc.__init__has 26 parameters; consider grouping anharmonic-only options into a dedicated dataclass / dict, and ensure every parameter is actually consumed (several look unused in the current code path)._calc_forcesis duplicated semantically across_phonon.pyand the new_alamode.py; extract to a shared helper.- Variable name
disp_array = np.array(disp_array)rebinds list → array; rename for clarity. Alsofor i, (disp, force) in enumerate(zip(...))doesn't usei— drop theenumerate. - The
try: import f90nml except ImportError: f90nml = Nonepattern is fine, but I don't seef90nmlused anywhere in the visible diff — confirm it's needed or drop.
Process suggestion: this is ~1650 lines across three independent calculators. I'd strongly recommend splitting:
- PR 1:
PheasyCalconly (LASSO-fitted harmonic FCs). - PR 2:
AlamodeCalc(higher-order FCs, depends on PheasyCalc patterns). - PR 3:
FourPhononCalc(4-phonon thermal conductivity).
Each can then be reviewed and tested in isolation, which is much more tractable.
I am happy to do another pass once the blockers above are addressed and CI is green. The underlying capability — anharmonic FCs and 4-phonon transport via foundation potentials — is exactly the direction matcalc should be growing.
|
🤖 Automated PR review (generated by Claude on behalf of @shyuep)
Generated by Claude Code |
Signed-off-by: Shyue Ping Ong <shyuep@users.noreply.github.com>
- Convert reST docstrings to Google style to match repo convention. - Drop commented-out code, the stray triple-quoted "comment", and dead blocks. - Replace hardcoded Bohr/Ry conversion constants with ase.units. - Replace hardcoded /home/jzheng4/... binary paths with configurable `path_to_shengbte` / `alm_command` attributes (the existing `path_to_*` kwargs were unused). - Replace hardcoded `EuZnAs_harmonic` Alamode prefix with an `alm_prefix` kwarg. - Factor Alamode I/O into `_write_alamode_dfset`, `_read_sposcar`, `_write_alamode_input` helpers; drop the duplicated harmonic / anharmonic input-writing blocks. - Harden the optional `f90nml` import in FourPhononCalc -- was caught at import and rebound to None then used unconditionally; now imported inside calc() with a clear ImportError. - Add AlamodeCalc, FourPhononCalc, PheasyCalc to `matcalc.__all__` (they were imported but never exported); drop the duplicated `version()` block. - Rename `many_T` -> `many_t`, `parallelled_calc` -> `parallel_calc` (PEP 8 / typo). - Fix unused loop indices and the E741 ambiguous `l`. - Silence pre-existing complexity (C901/PLR0912/PLR0915) on `calc` via per-method noqa; magnitudes are much smaller than the original but still over the project thresholds. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
Major changes:
Todos
If this is work in progress, what else needs to be done?
Checklist
ruff.mypy.duecredit@due.dcitedecorators to reference relevant papers by DOI (example)Tip: Install
pre-commithooks to auto-check types and linting before every commit: