Skip to content

ENH Phonons: New class method to save results & new class to enable future analysis

Stefan Bringuier requested to merge stefanbringuier/ase:feature_2 into master

Checklist

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.

  1. The reason this doesn't work is because the ase.Atoms and the ase.calculators objects are not stored and this would also require making changes to the Phonons class initialization and then adding a method within Phonons to read the file.

Merge request reports