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

get_xspectra_structures: Refactor and Improve Code #1026

Merged

Conversation

PNOGillespie
Copy link
Contributor

Overview

In this PR, we have re-factored various components of get_xspectra_structures as part of ongoing improvement work. These changes are the first of two improvements intended to enable users to set symmetry data manually instead of relying on automatic symmetry analysis - ultimately enabling the same feature for the XspectraCrystalWorkChain and any others which use the same structure preparation tools.

This PR will be followed by a second one in which the logic for the XSpectra WorkChains will be added in order to properly exploit the changes in this PR. The overall changes have been separated into 2 PRs due to the number of changes made here as part of the re-factoring process.

Changes

  • Moves supercell creation, processes for molecules, and generation of equivalent_sites_data to separate functions.
  • Adds functionality for users to manually provide symmetry data, thus enabling the CalcFunction to be used as a means to generate structures with user control over which exact sites to mark.
  • Fixes a bug discovered in the case where non-hubbard structures with custom Kind names lost their Kind names when converting the ASE supercell to StructureData type.
  • Removes unnecessary usage of dict.keys() iterables where simply iterating over the dictionary directly can be used instead.
  • Fixes a small oversight in the tests where spglib_settings was mistakenly named spglib_options.

Refactors major components of `get_xspectra_structures` as part of
ongoing improvement work. These changes are the first of two
improvements intended to enable users to set symmetry data manually
instead of relying on automatic symmetry analysis - ultimately enabling
the same feature for the `XspectraCrystalWorkChain` and any others which
use the same structure preparation tools.

Changes:
* Moves supercell creation, processes for molecules, and generation of
  `equivalent_sites_data` to separate functions.
* Adds functionality for users to manually provide symmetry data, thus
  enabling the `CalcFunction` to be used as a means to generate structures
 with user control over which exact sites to mark.
* Fixes a bug discovered in the case where non-hubbard structures with
  custom Kind names lost their Kind names when converting the ASE
supercell to `StructureData` type.
* Fixes a small oversight in the tests where `spglib_settings` was
  mistakenly named `spglib_options`.
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

Thanks, @PNOGillespie, for the work!

Could you also add a test when setting symmetry data manually.

from pymatgen.symmetry.analyzer import PointGroupAnalyzer

result = {'output_params': {}}
# If we are working with a molecule, check for pymatgen_settings
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# If we are working with a molecule, check for pymatgen_settings

Copy link
Member

Choose a reason for hiding this comment

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

Could you also fix this? The structure is a molecule inside this function.

Copy link
Contributor Author

@PNOGillespie PNOGillespie Apr 30, 2024

Choose a reason for hiding this comment

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

Sorry about that. I thought I'd removed the comment in the first set of corrections that I committed. It's been removed in the latest commit

for the input structure. If False, will instead use symmetry data provided
via the `equivalent_sites_data` and `spacegroup_number` inputs and generate all
the structures based on this information. Defaults to True.
- equivalent_sites_data: a Dict object taking the form of the `equivalent_sites_data` dict normally
Copy link
Member

@superstar54 superstar54 Apr 30, 2024

Choose a reason for hiding this comment

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

The description of equivalent_sites_data is not clear to the user.

Comment on lines 231 to 233
is_molecule_input = False
if 'is_molecule_input' in unwrapped_kwargs:
is_molecule_input = kwargs['is_molecule_input'].value
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
is_molecule_input = False
if 'is_molecule_input' in unwrapped_kwargs:
is_molecule_input = kwargs['is_molecule_input'].value
is_molecule_input = kwargs.get('is_molecule_input', False)

this should work because one can use AiiDA Bool data in the if condition directly.

1st set of changes requested for aiidateam#1026:

* Added test of manual symmetry data input functionality.
* Removed unnecessary checks for keys of Bool nodes in
  `unwrapped_kwargs` as well as extracting of truth values in favour of
using Bool objects directly.
* Removed unnecessary comment in `process_molecular_system`
* Added example to docstring to demonstrate format for
  `equivalent_sites_data` input
@PNOGillespie
Copy link
Contributor Author

Hi @superstar54, Thanks for the feedback. I've added a simple test for manual symmetry data input and cleaned up a few things as you suggested doing in one of your comments.

I also added an example of how the equivalent_sites_data input needs to be formatted. Was that the part which was unclear in the docstring, or do you think there's more to do on that?

superstar54
superstar54 previously approved these changes Apr 30, 2024
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

LGTM!

Changes the docstring so that the `equivalent_sites_data` example is
in-line, as required by the docs. Also adds a sentence stating which
options are required and that all other options are ignored.
@PNOGillespie
Copy link
Contributor Author

Hi @superstar54. I fixed the issue with the docstring by formatting the example to be in-line. I also added a sentence to better explain what needs to be in the equivalent_sites_data dictionary.

Let me know if anything else is needed.

@superstar54 superstar54 self-requested a review April 30, 2024 11:49
Removes an unnecessary comment from `process_molecule_input` which
should have been removed in a previous commit.
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

LGTM!

@superstar54 superstar54 merged commit 210c40b into aiidateam:main May 2, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants