Lattice dynamics workflow using Pheasy - #1063
Conversation
Modified some parts based on Janine's comments.
…atomate2 into atomate2_jz_pheasy
…group for crystals.
|
I don't remember off hand how much the two schemas differ, can you point me to the fields that are needed in the legacy schema that are missing in the new emmet one @hrushikesh-s? |
|
Hi @esoteric-ephemera , I compared the legacy atomate2 phonon schema against the new emmet one. The main differences are:
Aside -- I tried to restore the legacy phonon schema functionality for the phonon, QHA, and Grüneisen workflows, and have fixed the associated test failures. Can you pls take a look and confirm whether these changes align with the goal of continuing to support the legacy schema for these workflows in the short term, with a plan to migrate to the emmet schema later? |
|
Also, it's worthwhile to mention that the current PR makes use of my fork of Pheasy repo, and the PR is underway on Pheasy to make it compatible with the current atomate2 style reading of .npy files for disp & force matrices |
|
Thanks! From the timeline: i will likely look at it after Easter (next week earliest). I have to grade and prepare my teaching this week. I would also like to test and explore the changes in detail. |
| return Response(output={"plus": plus_struct, "minus": minus_struct}) | ||
|
|
||
|
|
||
| @job(data=[PhononBSDOSDoc]) |
There was a problem hiding this comment.
With this new workflow, no object needs to be transferred to "data"?
| ) | ||
|
|
||
|
|
||
| @job(data=[PhononBSDOSDoc]) |
There was a problem hiding this comment.
Or at least a replacement for this one?
| from atomate2.common.schemas.phonons import ( | ||
| PhononBSDOSDoc, | ||
| PhononComputationalSettings, | ||
| PhononJobDirs, | ||
| PhononUUIDs, | ||
| ThermalDisplacementData, | ||
| ) |
There was a problem hiding this comment.
I understood that we keep this for now, yes? Why not keeping the tests as long as we keep the schema?
| @@ -0,0 +1,362 @@ | |||
| """Flow for calculating (an)harmonic FCs and phonon energy renorma. with pheasy.""" | |||
There was a problem hiding this comment.
| """Flow for calculating (an)harmonic FCs and phonon energy renorma. with pheasy.""" | |
| """Flow for calculating (an)harmonic FCs and phonon energy renormalisation with pheasy.""" |
| if cal_anhar_fcs: | ||
| # Due to the cutoff radius of the force constants use the unit of Borh in ALM, | ||
| # we need to convert the cutoff radius from Angstrom to Bohr. | ||
| with ALM(lattice * 1.89, positions, numbers) as alm: |
There was a problem hiding this comment.
I assume this is accurate enough for a cutoff but maybe more digits?
| force_constants = parse_FORCE_CONSTANTS(filename=new_fc_file) | ||
| phonon.force_constants = force_constants | ||
| phonon.symmetrize_force_constants() | ||
|
|
||
| phonon.save(_DEFAULT_FILE_PATHS["phonopy"]) | ||
|
|
||
| # get phonon band structure | ||
| kpath_dict, kpath_concrete = _get_kpath( | ||
| structure=get_pmg_structure(phonon.primitive), | ||
| kpath_scheme=kpath_scheme, | ||
| symprec=symprec, | ||
| ) | ||
|
|
||
| npoints_band = kwargs.get("npoints_band", 101) | ||
| qpoints, connections = get_band_qpoints_and_path_connections( | ||
| kpath_concrete, npoints=kwargs.get("npoints_band", 101) | ||
| ) | ||
|
|
||
| # phonon band structures will always be computed | ||
| phonon.run_band_structure( | ||
| qpoints, path_connections=connections, with_eigenvectors=True | ||
| ) | ||
| phonon.write_yaml_band_structure(filename=_DEFAULT_FILE_PATHS["band_structure"]) | ||
| bs_symm_line = get_ph_bs_symm_line( | ||
| _DEFAULT_FILE_PATHS["band_structure"], | ||
| labels_dict=kpath_dict, | ||
| has_nac=born is not None, | ||
| ) |
There was a problem hiding this comment.
can more code be reused from phonon.py? If we have an update for the plotting, we would need to fix it here as well. Same for the code below.
| from importlib.util import find_spec | ||
|
|
||
| if not find_spec("openff"): | ||
| raise ImportError( | ||
| "openff must be installed via conda forge to use with atomate2:\n" | ||
| "conda install -c conda-force openff" | ||
| ) | ||
|
|
There was a problem hiding this comment.
can you check if this is consistent with how we handle this accross atomate2?
| assert_allclose( | ||
| ph_doc.primitive_matrix, | ||
| [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], | ||
| rtol=1e-5, | ||
| atol=1e-10, | ||
| ) | ||
| assert ph_doc.code == "vasp" | ||
| assert isinstance( | ||
| ph_doc.post_process_settings, | ||
| PhononComputationalSettings, | ||
| ) | ||
| assert ph_doc.post_process_settings.npoints_band == 101 | ||
| assert ph_doc.post_process_settings.kpath_scheme == "seekpath" | ||
| assert ph_doc.post_process_settings.kpoint_density_dos == 7000 | ||
|
|
||
| assert ph_doc.chemsys == "Si" |
There was a problem hiding this comment.
I don't see a test that actually checks the new implemented functionality. How do we make sure that the results stay consistent?
|
Hi @hrushikesh-s , I left a few comments. My main points:
|
|
Hey @hrushikesh-s sorry I missed your messages. These schema changes are very much intentional:
This is to explicitly allow for storing these as separate objects.
There is an opt-in setting for using the new emmet models. The default is still to use the pymatgen models in atomate2 (opt-out).
There is no reason to store The
A model computed field will still be saved in the document if it has been calculated. It is just a way to defer calculating an expensive model field until the user requests it Regarding the other fields being renamed, the document model explicitly handles the migration internally. You don't have to do anything to coerce the fields. Put a decent amount of work into it to do that since it needed to migrate our existing data seamlessly too Please revert these changes regarding the schema or communicate what changes you need in the schema to get the workflows to run correctly |
|
Hi @JaGeo and @esoteric-ephemera, thanks for your detailed comments. I will start working on the comments this Friday and will keep you updated. |
| # When this code is run on Github tests, it is failing because it is | ||
| # not able to find the FORCE_CONSTANTS file. This is because the file is | ||
| # somehow getting generated in some temp directory. Can you fix the bug? |
|
@hrushikesh-s do you have a suggestion for the timeline? More and more conflicts start to show up and it will only get harder to finally merge |
Resolve conflicts: - pyproject.toml: keep main's phonopy<4 pin alongside pheasy/alamode extras - common/flows/phonons.py: keep main's TorchSim-aware phonon_displacement_maker typing together with the phonon_doc_schema switch - common/jobs/phonons.py: adopt main's batched/socket run_phonon_displacements (TorchSim + check_class_name handling) while keeping store_displaced_structures; drop duplicated get_factor in favor of the schemas.phonons implementation - tests/aims: keep compat-accessor assertions with main's updated reference values; drop test_phonon_default_socket_flow (removed on main) - tests/forcefields: keep emmet-schema assertions (flow runs with phonon_doc_schema='emmet'); make reference values CHGNet-variant aware Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJTjGwg4Finfu8JeXLFBA3
- restore tests/common/schemas/test_phonons.py: the legacy schema is kept, so its tests are kept as well - openff/__init__.py: use the try/except ImportError pattern consistent with the rest of atomate2 (and fix conda-forge typo) - pheasy.py: replace the 1.89 Angstrom->Bohr factor with a full-precision ANGSTROM_TO_BOHR constant (CODATA 2018) - factor band-structure and DOS post-processing/plotting into shared _run_band_structure_and_plot/_run_total_dos_and_plot helpers in common/jobs/phonons.py, reused by pheasy.py (3 duplicated blocks removed) - tests/vasp/flows/test_pheasy.py: assert on the actual phonon results (acoustic sum rule at Gamma, max optical branch frequency, 0 K limits, room-T heat capacity, Dulong-Petit high-T limit) - tests/forcefields: anchor emmet-schema thermo assertions to the established reference values from main for both CHGNet variants - complete the pheasy flow docstring wording Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJTjGwg4Finfu8JeXLFBA3
- tutorials/pheasy_workflow.ipynb: mock-VASP tutorial for the pheasy lattice-dynamics workflow (mirrors the Si test data), with pointers to the anharmonic/renormalization options and the forcefield PhononMaker - listed in tutorials/tutorials.md toctree - excluded from the notebook CI job (which does not install the pheasy extra), following the openmm/torchsim/lammps pattern Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TJTjGwg4Finfu8JeXLFBA3
| return Response(output={"plus": plus_struct, "minus": minus_struct}) | ||
|
|
||
|
|
||
| @job(data=[PhononBSDOSDoc]) |
There was a problem hiding this comment.
Are you sure this should be removed?
| ALM = None | ||
|
|
||
| # CODATA 2018: 1 Angstrom = 1 / 0.529177210903 Bohr | ||
| ANGSTROM_TO_BOHR = 1.8897261246257702 |
There was a problem hiding this comment.
Are you using this at multiple places? If you, please make a module for it. Eg "utils.units.py"
Summary
Include a summary of major changes in bullet points:
Additional dependencies introduced (if any)
Before a pull request can be merged, the following items must be checked:
The easiest way to handle this is to run the following in the correct sequence on
your local machine. Start with running
ruffandruff formaton your new code. This willautomatically reformat your code to PEP8 conventions and fix many linting issues.
Run ruff on your code.
type check your code.