Skip to content
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

126 apw missing energy parameters #139

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

ndaelman-hu
Copy link
Contributor

This is an intermediate solution. It adds the missing energy parameters, corrects the FP-APW parsing in exciting and already prepares for the next release.
It also provides some general functionalities for unrolling all APW orbitals.

TODO:

  1. Extend to Wien2k and Fleur (maybe Elk?)
  2. Add testing for the general functionalities and the new exciting version (waiting for examples).

Closes #126

@ndaelman-hu ndaelman-hu self-assigned this Jul 21, 2023
@ndaelman-hu ndaelman-hu added bug Something isn't working. It also represents a quick fix in response to a bug. feature / enhancement New feature or request labels Jul 21, 2023
key_vals_converted: dict[str, Any] = {}
for key_val in key_vals:
if len(key_val) != 2:
raise ValueError(f'Invalid key-value pair: {key_val}')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace raise with a warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that the basis_set output will be complete bull. When should an error be fatal?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but we do not want to terminate parsing due to this. simply do not write to archive if deemed incorrect.

@@ -283,3 +286,136 @@ def extract_polarization_outputs():
workflow.m_add_sub_section(ParticleHoleExcitations.tasks, task)

xs_workflow_archive.workflow2 = workflow


class OrbitalAPWConstructor:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add test

except AttributeError:
self.wavefunctions[key] = np.append(self.wavefunctions[key], converted[key])
elif val != converted[key]:
raise ValueError(f'Wavefunction {key} does not match previous value')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid raising exceptions

Copy link
Collaborator

@JosePizarro3 JosePizarro3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, finished with my review.

I can only comment on the fact that OrbitalAPWConstructor is not very understandable right now. Do you have any examples at hand that you can share? (I think that's why Alvin asked you for testing on this).

Furthermore, I would be more verbose. Especially with names of functions, descriptions, names of variables, etc. You can also add comments to make it even more clear.

Besides these comments, do you mind checking the getattr / setattr thingy? Also, pycodestyle is failing.

return dict(sorted({**settings, **kwargs}.items()))

def append_wavefunction(self, settings, **kwargs):
'''
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add descriptions here and below in other functions?

if self.wavefunctions:
for key, val in self.wavefunctions.items():
converted = self._convert(settings, **kwargs)
if getattr(OrbitalAPW, key, {}).get('shape'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndaelman-hu @ladinesa is this correct? I remember Theodore saying that one can safely use getattr for MSections, but just wanted to make sure 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getattr is fine, just avoid setattr.

# convert to NOMAD section
formatted_orbital = OrbitalAPW()
for term, val in orbital.items():
setattr(formatted_orbital, term, val)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back to my comment above on getattr (which again, it is just to confirm, so most probably you can use it) setattr should not be used and instead you should m_add_sub_section.

You have an example in nomad/normalizing/method.py:ExcitedStateMethod, at the end I was adding to simulation depending on the dict self._method_def (which is defined at the beginning of the MethodNormalizer().

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can do formatted_orbital.m_set(formatted_orbital.m_get_quantity_defintion(tem), val)

['l_quantum_number', 'j_quantum_number', 'k_quantum_number']
)

def _convert(self, settings: dict[str, Any], **kwargs) -> dict[str, Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could actually live out of OrbitalAPWConstructor, but you decide. Furthermore, the naming of the function could be more verbose: _convert_to_dict.

'''
Return the stored orbitals as a sorted list of `OrbitalAPW` sections.
'''
def _sort_func(orbital: dict[str, Any], term: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what this function does.

@ndaelman-hu
Copy link
Contributor Author

I can only comment on the fact that OrbitalAPWConstructor is not very understandable right now.

Indeed, documentation is something that I still wanted to add. OrbitalAPWConstructor is not necessarily finished either. It was only applied to exciting and might need some additional changes. Basically, its purpose is as a toolkit for handling different schemas on how the APW basis is written by code. Orbitals are defined for each l-channel (quantum angular momentum), but often times it is written in a more compressed format by the code. Typically, these will have some kind of default to which they add or amend orbitals. Instead, in NOMAD, I am showing them in a more verbose or "unrolled" way (each compression is different).

I am generating some figures to aid in the explanation:
apw_unrolling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. It also represents a quick fix in response to a bug. feature / enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

APW missing energy parameters
3 participants