-
Notifications
You must be signed in to change notification settings - Fork 89
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
Stresses API #487
Stresses API #487
Conversation
Indeed my norm rule hadn't covered the case of multiple partials in a Dual yet, I'll extend it shortly! |
c23b200
to
42b40f5
Compare
Stresses are not correct with symmetries, as expected:
without and with symmetries, respectively, for a compressed silicon (a=9.26). The first is correct: negative stresses (and therefore positive pressure) that are only in the diagonal direction (because only a is a free parameter) |
So this needs an unfold_BZ(scfres), which is also needed for @LaurentVidal95 's Wannier PR anyway |
end | ||
function compute_stresses(scfres) | ||
compute_stresses(scfres.basis, scfres.ψ, scfres.occupation) | ||
end |
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.
I guess one should also have a stresses_cart
for consistency?
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.
I'm not super confortable with stress definitions so I'd rather have just one that matches what's found in the literature. Forces are more intuitive
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.
I see, but forces in the literature are usually cartesian as well. Perhaps we should only support cartesian forces? Or we wait until we understand more and decide then.
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.
Well OK, cartesian stresses might make sense. Forces in reduced coordinates definitely makes sense, it's what you want to do for geometry optimization for instance. For stresses I'm not sure what to do about the division by volume, so let's leave it as is for now.
TODO (reminder to self) add tests |
42b40f5
to
3f3eb1e
Compare
Good to go from my end |
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.
I'm not yet fully convinced about the name unfold_BZ
, because nothing is really done to the BZ. It is only the symmetry that is undone, so IR-wedge -> full BZ. Maybe remove_symmetries_scfres
? disable_symmetries_scfres
?
src/symmetry.jl
Outdated
for ik_unfolded in 1:length(basis_unfolded.kpoints) | ||
kpt_unfolded = basis_unfolded.kpoints[ik_unfolded] | ||
ik_irred, symop = unfold_mapping(basis_irred, kpt_unfolded) | ||
if !is_ψ |
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.
How about better calling this flag apply_symops or something like that.
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.
I don't want to give the impression this is a general thing : it's really specialized for psi
src/symmetry.jl
Outdated
ψ = unfold_ψ(scfres.basis, basis_unfolded, scfres.ψ) | ||
eigenvalues = unfold_array(scfres.basis, basis_unfolded, scfres.eigenvalues) | ||
occupation = unfold_array(scfres.basis, basis_unfolded, scfres.occupation) |
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.
I think I would structure this differently. For me these three objects are inherently connected and I think it makes sense to fuse the loop, i.e. to handle them simultaneously. That way you also get rid of this strange is_\psi
thingy. Also what other k-Point specific objects will we need to transfer in such an unfolding? I don't thing any more.
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.
So you'd just merge the unfold_BZ and unfold_array functions? I kind of like the separation. You could have other things, like a partial density, a matrix element for a response computation, etc
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.
True, but in this setup you do a lot of duplicate work unfold_mapping
is computed each unfold_array
call. I can see us quickly overusing unfold_BZ
, so I'm not too happy about this structure. If you have the unfolding as the outer loop it's still easy to add an extra line if you have an additional entry in your scfres.
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.
Unfold_mapping is cheap. I definitely would wait until we have a better idea of the use cases for this before doing any refactoring. Not convinced merging functions would help here
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.
OTOH is_psi
flag is really annoying and the wrapping it into two function names as well. It feels very hackish and I'm not a fan of this solution. If you swap inner and outer loop than you have that info and do not need that strange nested function call structure. I think that is the easiest solution and as you say, when we need more we refactor.
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.
I've removed the extra functions which were more confusing than anything (trying to pretend this is a high-level API even if it's pretty hacky). But I really don't want to merge the functions : this is already a pain to write and read, having an extra function does help I feel
Well the irreducible BZ gets unfolded into the reducible BZ, so the name works, no? Nothing is done to the symmetries field of scfres, so disable_symmetries would be a bit misleading |
Review done, thanks! |
ok yes, it's only in the scfres where things are really happening that is true. So then |
Not a fan of unfold_bz_scfres(scfres). The long-term plan is for scfres to get a struct, so that this becomes a dispatch. |
ok then leave off the |
Built on top of #486
@niklasschmitz I'm getting an error in one of your fallbacks (looks like it's because I forward differentiate wrt several parameters at once), can you take a look?