ENH Phonons: New class method to save results & new class to enable future analysis
Checklist
-
I have read the contribution guidelines. -
Unit tests have been added for any new or changed code, and the test suite passes. Note: Your request will likely not be merged without the appropriate tests. -
"closes #XXXX" is in the body of the MR description to link the related issue, if applicable.
Description
The Phonons
class currently does not have a way to save the real-space dynamical (D_N
) matrix or force constant (C_N
) matrix for later reuse. A new method, save_run_results
, has been added which can be called to write to a NumPy compressed archived file for these quantities, along with additional attributes. This allows for use at a later time and further analysis, for example, one would not have to rerun a Phonons.run()
, Phonons.read()
, and then Phonons.get_band_structure()
.
In order to construct the band structure and use several other Phonons
class methods from the saved file, a new class within ase.phonons
called PhononsFromFile
has been implemented. The class requires the NumPy compressed archived filed format generated by the save_run_results
method in order to be instantiated. The new class was created instead of making changes to Phonons
in order to prevent method exposure from the base class ase.phonons.Displacement
, which would result in invalid1 calls. Therefore, only valid Phonons
method calls have been wrapped within PhononsFromFile
.
Documentation has been written for both the new method and class. A new unit test in test_phonons.py has been add and passes. No additional dependencies are needed.
Example
atoms = bulk('Al', 'fcc', a=4.05)
N = 7
path = atoms.cell.bandpath()
from ase.phonons import Phonons, PhononsFromFile
ph = Phonons(atoms, EMT(), supercell=(N, N, N), delta=0.05)
ph.run()
ph.read(acoustic=True)
savefile = "phonons.results.npz"
ph.save_run_results(filename=savefile)
ph_read = PhononsFromFile(savefile)
bs_read = ph_read.get_band_structure(path, verbose=False)
dos_read = ph_read.get_dos()
Related attempts
I did try to implement a serialization approach using pickle
and then dill
, however, there were far too many challenges with handling the Calculator
objects stored in Displacements
class.
-
The reason this doesn't work is because the
ase.Atoms
and thease.calculators
objects are not stored and this would also require making changes to thePhonons
class initialization and then adding a method withinPhonons
to read the file.↩