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

SpaceGroup changes #3859

Merged
merged 25 commits into from
Jul 14, 2024
Merged

SpaceGroup changes #3859

merged 25 commits into from
Jul 14, 2024

Conversation

kaueltzen
Copy link
Contributor

@kaueltzen kaueltzen commented Jun 4, 2024

Summary

Fixes #3845 , #3861 and #3862 .

Includes the following changes in the symmetry module:

  • The SpaceGroup symbol attribute now refers to its Hermann-Mauguin symbol with underscore notation of screw axes.
  • The setting of the 7 rhombohedral space group types is now stored in an additional hexagonal bool attribute which can be set explicitly or by appending the setting to the int_symbol string parameter with the setting appended as before. The latter overrides the former for backwards compatibility.
  • The SpaceGroup point_group attribute now always refers to the point group in Hermann Mauguin notation.
  • A class method from_space_group was added to PointGroup which initializes the 32 crystal classes from a SpaceGroup string in Hermann-Mauguin notation.
  • Changes of the space group databases symm_data.json and symm_ops.json were made which are documented in dev_scripts/update_spacegroup_data.py .
  • If the full symbol is not available (for non-standard settings), a warning is now issued.
  • Tests for the abovementioned points were added
  • Notes on how to convert the old to the new symbol were added to docs/compatibility.md

kaueltzen and others added 3 commits June 4, 2024 13:21
… corrected Schoenflies point group attribute, changed handling of rhombohedral space group type settings by adding a SpaceGroup hexagonal bool attribute, modified and added tests.
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks @kaueltzen for submitting this fix! 👍 i left 3 questions

if int_symbol in SpaceGroup.sg_encoding:
self.full_symbol = SpaceGroup.sg_encoding[int_symbol]["full_symbol"]
self.point_group = SpaceGroup.sg_encoding[int_symbol]["point_group"]
else:
self.full_symbol = re.sub(r" ", "", spg["universal_h_m"])
self.point_group = spg["schoenflies"]
self.full_symbol = spg["hermann_mauguin"] # TODO full symbol not available from spg->maybe not add?
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate on this TODO? does this mean the current full_symbol is incorrect or incomplete?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - as far as I can see, the full symbol (e.g., F4/m-32/m instead of Fm-3m) is only contained in SpaceGroup.sg_encoding, but not in SpaceGroup.SYMM_OPS. Both spg keys "hermann_mauguin" and "universal_h_m" do not contain this information. We could still set this attribute but issue a warning (maybe that's better than not setting it in these cases?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a warning and this seems to be only invoked when initializing non-standard settings (as expected). E.g., SpaceGroup("Pmc2_1") does not invoke a warning, but SpaceGroup("P2_1ma") does.

However, I struggle to write a test for that:

    def test_full_symbol_warning(self):
        with pytest.warns(Warning,
                          match="Full symbol not available, falling back to short Hermann Mauguin symbol P2_1ma instead.") as warns:
            _ = SpaceGroup("P2_1ma")
        assert len(warns) == 1

This fails with Failed: DID NOT WARN. No warnings of type (<class 'UserWarning'>,) were emitted. Emitted warnings: []. and I don't understand why. Any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

are you sure you weren't testing against the PyPI release of pymatgen? your test passes for me. just pushed it to this PR. i expect it'll pass here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for figuring out this issue! a33cc3c

self.full_symbol = re.sub(r" ", "", spg["universal_h_m"])
self.point_group = spg["schoenflies"]
self.full_symbol = spg["hermann_mauguin"] # TODO full symbol not available from spg->maybe not add?
self.point_group = spg["schoenflies"].split("^")[0] # TODO map onto Hermann Mauguin notation?
Copy link
Member

Choose a reason for hiding this comment

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

let's come to a decision here before merging this PR. what would be the benefits of mapping onto Hermann Mauguin notation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The information is the same, but in these cases we'd have different notations for space group (Hermann Mauguin) and point group (Schoenflies) within one object. Also, it might cause issues if one wants to compare the point groups for a larger dataset (and the same point group could be there in different representations).

In order to map it, we would either need a database or we could, in principle, extract the point group in Hermann Mauguin notation from the space group symbol (by removing the centering and translation parts of symmetry elements) - this would require additional testing, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe there could be a PointGroup class method from_spacegroup() that does exactly this?

Copy link
Member

Choose a reason for hiding this comment

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

that sounds like a good idea! would you prefer to do that in a separate PR (or just open an issue for it)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, i'd prefer to just open an issue for it and add it in this PR - will do both tomorrow (:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the new class method and also added this info directly to the symm_ops.json database so it does not have to be called every time when initializing a SpaceGroup object. The changes to symm_ops.json and symm_data.json are documented in dev_scripts.update_space_group_data.py - was not sure if this is the correct place, though!

Copy link
Member

Choose a reason for hiding this comment

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

thank you! this is great. it's super valuable to leave such a thorough paper trial for people to understand what happened later

Comment on lines +222 to +225
def test_valid_symbol(self): # Added after issue #3845
for num in range(1, 231):
symbol = SpaceGroup.from_int_number(num).symbol
assert SpaceGroup(symbol).int_number == num
Copy link
Member

Choose a reason for hiding this comment

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

this is definitely a good test to have and an argument in favor of the changes in this PR

def test_hexagonal(self):
for num in (146, 148, 155, 160, 161, 166, 167):
sg = SpaceGroup.from_int_number(num, hexagonal=False)
assert not sg.symbol.endswith("H")
Copy link
Member

Choose a reason for hiding this comment

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

why remove this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it as the representation ("H" as last character) is not part of the symbol attribute in any case now.
We could maybe still keep this test and replace the assertion with a test for the hexagonal attribute assert sg.hexagonal == False to check that this is given correctly to the SpaceGroup init.

Copy link
Member

Choose a reason for hiding this comment

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

replacing the assertion with a test for the hexagonal attribute sounds good

@mkhorton
Copy link
Member

mkhorton commented Jun 4, 2024

Many thanks for this @kaueltzen!

In case it is helpful in future, adding a note that the maggroups module in pymatgen uses a different dataset (from ISO-MAG, used with permission). It may or may not be helpful to cross-check information, since it's a superset of the crystallographic groups.

Important note for this PR: this technically counts as a breaking change. I can imagine cases whereby users are generating and storing space group strings in a database, for example, with the previous logic. Therefore, can you add a note to docs/compatibility.md noting the change, and how affected users can replace their previous symbol with the new symbol?

@JaGeo
Copy link
Member

JaGeo commented Jun 5, 2024

Important note for this PR: this technically counts as a breaking change. I can imagine cases whereby users are generating and storing space group strings in a database, for example, with the previous logic. Therefore, can you add a note to docs/compatibility.md noting the change, and how affected users can replace their previous symbol with the new symbol?

Thanks @mkhorton ! We know it is breaking. We had asked in the issue how to handle this. Thanks for pointing out how to do it in the best way! Very helpful.

@mkhorton
Copy link
Member

mkhorton commented Jun 5, 2024

No problem, apologies I’d missed the issue comment.

@kaueltzen
Copy link
Contributor Author

Many thanks for this @kaueltzen!

In case it is helpful in future, adding a note that the maggroups module in pymatgen uses a different dataset (from ISO-MAG, used with permission). It may or may not be helpful to cross-check information, since it's a superset of the crystallographic groups.

Important note for this PR: this technically counts as a breaking change. I can imagine cases whereby users are generating and storing space group strings in a database, for example, with the previous logic. Therefore, can you add a note to docs/compatibility.md noting the change, and how affected users can replace their previous symbol with the new symbol?

Thanks @mkhorton for pointing that out! Will add a note.

@kaueltzen
Copy link
Contributor Author

kaueltzen commented Jun 5, 2024

Hey, while working on the new PointGroup class method from_space_group(), I found another bug in SpaceGroup referenced here: #3862 which is also important for this PR.
What are your thoughts on that? @JaGeo @janosh @mkhorton

@janosh janosh added fix Bug fix PRs breaking Breaking change symmetry Space groups and the like labels Jun 5, 2024
@kaueltzen
Copy link
Contributor Author

kaueltzen commented Jun 5, 2024

Another minor issue: the space group types I2_12_12_1 and P2_12_12_1 are mapped onto I/P2_12_121 in SpaceGroup.full_sg_mapping , the wrong key is also there in SpaceGroup.sg_encoding . Will fix that as well.

kaueltzen and others added 10 commits June 6, 2024 13:10
…odified symm_ops.json and symm_data.json (documented in dev_scripts/update_space_group_data.py) to have same notation, added point group and short Hermann Mauguin symbol to symm_ops, fixed some typos, fixed rhombohedral space group type orbit issue.
Signed-off-by: Katharina Ueltzen <94910364+kaueltzen@users.noreply.github.com>
…entity blickrichtungen and missed underscores, added warning to SpaceGroup init if full symbol is not available (for non-standard settings), added tests.
@kaueltzen
Copy link
Contributor Author

Hey @mkhorton @shyuep this is ready to be reviewed.

@JaGeo
Copy link
Member

JaGeo commented Jun 24, 2024

As far as I see it, all review requests have been addressed by @kaueltzen . Would be great if this could be merged if the changes are fine.

@JaGeo
Copy link
Member

JaGeo commented Jun 27, 2024

Oh, now there are some conflicts 🫠

@shyuep
Copy link
Member

shyuep commented Jun 27, 2024

It is just a switch to a src based layout. Once you move the files, the conflicts should be simple to resolve.

Resolve merge conflicts.
@kaueltzen
Copy link
Contributor Author

It is just a switch to a src based layout. Once you move the files, the conflicts should be simple to resolve.

Hey @shyuep @mkhorton the merge conflicts have been resolved. Could you please review this?

@JaGeo
Copy link
Member

JaGeo commented Jul 14, 2024

@shyuep is there anything that still needs to be done here? We would be very happy if this could be merged and fixed.

@shyuep shyuep merged commit c2c5ea6 into materialsproject:master Jul 14, 2024
31 of 33 checks passed
@shyuep
Copy link
Member

shyuep commented Jul 14, 2024

Merged. Thanks,

@JaGeo
Copy link
Member

JaGeo commented Jul 14, 2024

@shyuep thank you!

@DanielYang59
Copy link
Contributor

Looks like this PR breaks one of the unit tests in windows?

 _______________ TestSpacegroupAnalyzer.test_get_crystal_system ________________

self = <symmetry.test_analyzer.TestSpacegroupAnalyzer testMethod=test_get_crystal_system>

    def test_get_crystal_system(self):
        crystal_system = self.sg.get_crystal_system()
        assert crystal_system == "orthorhombic"
        assert self.disordered_sg.get_crystal_system() == "tetragonal"
    
        orig_spg = self.sg._space_group_data["number"]
>       self.sg._space_group_data["number"] = 0
E       TypeError: 'SpglibDataset' object does not support item assignment

Feel free to ping me if there's anything I could help :)

@JaGeo
Copy link
Member

JaGeo commented Jul 15, 2024

@kaueltzen could you maybe take a look?

@kaueltzen
Copy link
Contributor Author

kaueltzen commented Jul 15, 2024

Hi @DanielYang59 i cannot see where this might be due to the SpaceGroup changes. it seems like it is due to the latest spglib release? https://spglib.readthedocs.io/en/stable/releases.html#v2-5-0-9-jul-2024

The output data is not longer in dict format but in classes like SpglibDataset. The dict-like interface is planned to be removed, so there will be a lot of necessary changes in pymatgen. would modifiying the version of spglib to <2.5.0 in pyproject.toml be ok for you for now?

@DanielYang59
Copy link
Contributor

DanielYang59 commented Jul 15, 2024

@kaueltzen Apologize, I didn't look very closely into the failure (just noticed unit tests begin to fail after this PR, and this is related to spacegroup). Sorry for misleading you.

I could confirm using spglig lower than 2.5.0 fixed this meanwhile :)

@kaueltzen
Copy link
Contributor Author

I could confirm using spglig lower than 2.5.0 fixed this meanwhile :)

Great 👍 and thanks for looking into this!

kaueltzen added a commit to kaueltzen/pymatgen that referenced this pull request Jul 22, 2024
shyuep pushed a commit that referenced this pull request Nov 13, 2024
* Modified SpaceGroup.is_subgroup() following issue #3937, added tests.

* Added crystal_system attribute to PointGroup, modified is_subgroup warning of SymmetryGroup.

* Modified is_subgroup of PointGroup to raise NotImplementedError if group subgroup relationship would be possible (fr. crystal system), but cannot be checked currently due to crystallographic direction issue.

* Enabled PointGroup init from different settings, added test for that, added missing setting differences (trigonal groups), re-enabled SpaceGroup.is_subgroup shortcut with constraint of non-klassengleiche group subgroup relationship

* Removed bug in short Hermann Mauguin symbol of some trigonal groups introduced by myself in #3859

---------

Signed-off-by: Katharina Ueltzen <94910364+kaueltzen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change fix Bug fix PRs symmetry Space groups and the like
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect SpaceGroup symbol attribute for 16 space group types
6 participants