-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make animations of phonon displacement patterns #283
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,71 @@ | |||
cff-version: 1.2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file (and the LICENSE) seem to have been mistakenly copied from the project directory into the Python module folder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
This takes me back to the now rather under-maintained ascii-phonons program; it even uses Pillow! 😄 I did find that in practice it can be challenging to choose a good viewing direction; specifying as a Miller index works quite well but often needs a few interative adjustments. https://ascii-phonons.readthedocs.io/en/latest/GUI.html I have found Henrique Miranda's phonon website to be a superb tool for this stuff: https://henriquemiranda.github.io/phononwebsite/phonon.html Somewhere on the to-do list it seems a very good idea to provide a QpointPhononModes.to_web_json() method or similar, that produces the required data format for this website. Another relevant tool for directly rendering images from crystal structure is ASE, which can create PNG, .gif or povray outputs as well as write to multi-frame file formats supported by viewers such as Jmol or Ovito. I'm not sure it's a good idea to duplicate that functionality here when it is quite simple to create an Atoms from a Crystal. The |
euphonic/qpoint_phonon_modes.py
Outdated
""" | ||
|
||
# Needed to transform cartesian to crystal coordinates | ||
xyz2wyckoff = np.linalg.inv(self.crystal.cell_vectors.magnitude) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Crystal has a reciprocal_cell()
method for this purpose
euphonic/qpoint_phonon_modes.py
Outdated
Index of the Q vector. | ||
mode | ||
Index of the mode, or array of amplitudes for each mode. | ||
Providing an array allows mixing degenerated modes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This double-duty feels a bit awkward. Can you use complex numbers here as well? Is it useful to set disp_amplitude if also passing amplitudes here? Is it permitted to combine modes from multiple Q vectors?
It's helpful to minimise the number of paths through a function if possible; it makes the overall system easier to learn, document and maintain.
One approach might be to structure this as two public methods:
get_mode_displacement(qpt_index, mode, amplitude, supercell)
and
get_combined_displacements(amplitude, supercell)
where the latter amplitude
array runs over all q-points and indices. These would each generate an appropriate (scaled) eigenvector then call a common private method _displaced_crystal(crystal, eigenvector, supercell)
.
Then again, the code to generate the eigenvectors is very simple. Perhaps a better API would be to add nothing at all to QpointPhononModes, and instead create a Crystal.apply_eigenvector(eigenvector, supercell) -> Crystal
method on Crystal. That is more general and would support other (e.g. random) schemes of generating mass-scaled displacements. And to recreate these functions the user does
modes.crystal.apply_eigenvector(modes.eigenvectors[qpt_index, mode] * disp_amplitude, supercell)
or
weighted_evec = np.sum(modes.eigenvectors * weights, axis=(0, 1))
modes.crystal.apply_eigenvector(weighted_evec, supercell)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The backstory is that I was first implemented get_mode_displacement(qpt_index, mode, amplitude, supercell)
-like function, then I wanted to look at a double degenerated phonon. The eigenvectors of the degenerated subspace were not to my liking, and I wanted to take their linear combination with get_combined_displacements(amplitude, supercell)
-like function. In the end I managed to get what I want, but left the function in this awkward state.
With that experience, I feel like the apply_eigenvector
function on Crystal
is indeed a better choice. Feels more approachable and, with your snippets with the choice of the eigenvector, it is very clean.
@mstekiel any thoughts on this alternative approach? |
I like it very much! I think every person investigating lattice dynamics develops their own set of tools in the end :) Here, I wanted to be able to see the displacement to get an idea how a particular soft phonon looks like, within the packages provided by euphonics, Publication quality picture would require better tools, following those you listed in the first reply. Another utility/Pandora box, would be a |
Again, as a very active contributor to ASE my biased recommendation would be to toss the attributes of Crystal into ASE and write to one's favourite format from there. One would still need to use Even though it is only a few lines of code I suppose it would be helpful if that In any case it would be good for the Euphonic docs to have some nice tutorial examples that show people how to do this stuff, and can be used as the basis of user scripts. |
I'm working on the crystal system where I was interested in a particular phonon, and its displacement pattern. I adapted the functionality of euphonics to make gifs that show atomic vibrations of that phonon.
I introduced the
calculate_displacement
function that creates the displaced structure in a form of aCrystal
object. It follows the definition of Martin Dove's book, that you cite for neutron structure factor. Then I also made aplot_crystal
function that plots anyCrystal
on 3D axes.From here, I was able to make such animation, with the code below.
I think such functionality might be interesting to you and other authors. I had a lot of fun making and investigating it :)