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

Improve type annotations and comments for io.cif #3820

Merged
merged 31 commits into from May 15, 2024

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented May 11, 2024

Summary

  • Add type annotations and tweak comments for io.cif
  • Minor code format tweak
  • Simplify "check to see if" to "check if" in comments
  • Remove if __name__ == "__main__" from core.libxcfunc (legacy from another PR)

Potentially Breaking Changes (very unlikely)

  1. Make parse_oxi_states and parse_magmoms of CifParser private methods. Rationale:

    • These two parse methods are used exclusively for the private _get_structure method to parse corresponding properties from the file.
  2. Remove unnecessary lattice argument from parse_magmoms method (now private). Rationale:

    • This argument is only used to check if Lattice is None, and could be done outside this method.

      pymatgen/pymatgen/io/cif.py

      Lines 850 to 869 in 2e1c301

      @staticmethod
      def parse_magmoms(data, lattice=None):
      """Parse atomic magnetic moments from data dictionary."""
      if lattice is None:
      raise ValueError("Magmoms given in terms of crystal axes in magCIF spec.")
      try:
      magmoms = {
      data["_atom_site_moment_label"][i]: np.array(
      [
      str2float(data["_atom_site_moment_crystalaxis_x"][i]),
      str2float(data["_atom_site_moment_crystalaxis_y"][i]),
      str2float(data["_atom_site_moment_crystalaxis_z"][i]),
      ]
      )
      for i in range(len(data["_atom_site_moment_label"]))
      }
      except (ValueError, KeyError):
      return None
      return magmoms

@DanielYang59 DanielYang59 marked this pull request as ready for review May 12, 2024 04:23
@DanielYang59 DanielYang59 changed the title Add type annotations and tweak comments for io.cif Improve type annotations and comments for io.cif May 12, 2024
@DanielYang59
Copy link
Contributor Author

@janosh. Could you please review this as well? Thanks!

@janosh janosh enabled auto-merge (squash) May 15, 2024 16:23
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 @DanielYang59, this looks good! 👍

@janosh janosh merged commit bb68c78 into materialsproject:master May 15, 2024
23 checks passed
@DanielYang59 DanielYang59 deleted the add-types-for-io-cif branch May 16, 2024 00:44
@DanielYang59
Copy link
Contributor Author

Thanks for reviewing!

DanielYang59 added a commit to DanielYang59/pymatgen that referenced this pull request May 16, 2024
fix `core.operations`

add types for site, mypy errors to fix

remove no_type_check decorator

move dunder methods to the top

fix mypy errors

remove debug tag

improve `spectrum`

finish `core.tensors`

finish `xcfunc`

fix hash of `SymmOp`

finish `core.trajectory`

Add types for `core.molecular_orbitals/operations/sites/spectrum/tensor/xcfunc`  (materialsproject#3829)

* fix `core.molecular_orbitals`

* fix `core.operations`

* add types for site, mypy errors to fix

* remove no_type_check decorator

* move dunder methods to the top

* fix mypy errors

* remove debug tag

* improve `spectrum`

* finish `core.tensors`

* finish `xcfunc`

* fix hash of `SymmOp`

* add a missing type

* Revert "fix hash of `SymmOp`"

This reverts commit bf2a953.

* fix some types in operations

* "TEST": remove one unused var, relocate another

* final tweak types

* avoid hard-code class name

* format tweaks

* type tweak

* fix unit test

* replace all `[0:x]` with `[:x]`

Guard `TYPE_CHECKING` only imports (materialsproject#3827)

* flake8 --select=TYP001

* fix type import

* format docstring to google style

* fix more unguarded typecheck imports

* format more docs to Google format

* trigger CI (better var names)

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>

move structures out of util dir (materialsproject#3831)

Add matgenb in the aux link section. Because apparently it is not
"discoverable". Fixes materialsproject#3811.

More updates.

Move AIMS notebooks to matgenb.

Add README in examples folder that point to proper resources.

Improve type annotations and comments for `io.cif` (materialsproject#3820)

* remove duplicate warning

* type and docstring tweaks

* add some types for io.cif

* add comments and types

* temp save of some formatting

* revert functional change

* revert unrelated changes

* fix unit test

* remove update that does nothing

* relocate `sub_space_group` and `space_groups` to their usage

* add more types

* pre-commit auto-fixes

* breaking: make parse_magmom/oxi_stats private

* remove merge header

* fix unit test

* add more types

* fix mypy errors

* add a few spaces

* remove if name ==main

* simplify "check to see if" in comments

* final tweaks

* revise docstring

* replace deprecated abc.abstractproperty

* add missing doc strings and standardize existing

* breaking: fix typo in method name orthongonalize_structure

* revert accidental change in test_composition.py

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
janosh added a commit that referenced this pull request May 17, 2024
* relocate dunder methods to top for core.trajectory

fix `core.operations`

add types for site, mypy errors to fix

remove no_type_check decorator

move dunder methods to the top

fix mypy errors

remove debug tag

improve `spectrum`

finish `core.tensors`

finish `xcfunc`

fix hash of `SymmOp`

finish `core.trajectory`

Add types for `core.molecular_orbitals/operations/sites/spectrum/tensor/xcfunc`  (#3829)

* fix `core.molecular_orbitals`

* fix `core.operations`

* add types for site, mypy errors to fix

* remove no_type_check decorator

* move dunder methods to the top

* fix mypy errors

* remove debug tag

* improve `spectrum`

* finish `core.tensors`

* finish `xcfunc`

* fix hash of `SymmOp`

* add a missing type

* Revert "fix hash of `SymmOp`"

This reverts commit bf2a953.

* fix some types in operations

* "TEST": remove one unused var, relocate another

* final tweak types

* avoid hard-code class name

* format tweaks

* type tweak

* fix unit test

* replace all `[0:x]` with `[:x]`

Guard `TYPE_CHECKING` only imports (#3827)

* flake8 --select=TYP001

* fix type import

* format docstring to google style

* fix more unguarded typecheck imports

* format more docs to Google format

* trigger CI (better var names)

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>

move structures out of util dir (#3831)

Add matgenb in the aux link section. Because apparently it is not
"discoverable". Fixes #3811.

More updates.

Move AIMS notebooks to matgenb.

Add README in examples folder that point to proper resources.

Improve type annotations and comments for `io.cif` (#3820)

* remove duplicate warning

* type and docstring tweaks

* add some types for io.cif

* add comments and types

* temp save of some formatting

* revert functional change

* revert unrelated changes

* fix unit test

* remove update that does nothing

* relocate `sub_space_group` and `space_groups` to their usage

* add more types

* pre-commit auto-fixes

* breaking: make parse_magmom/oxi_stats private

* remove merge header

* fix unit test

* add more types

* fix mypy errors

* add a few spaces

* remove if name ==main

* simplify "check to see if" in comments

* final tweaks

* revise docstring

* replace deprecated abc.abstractproperty

* add missing doc strings and standardize existing

* breaking: fix typo in method name orthongonalize_structure

* revert accidental change in test_composition.py

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>

* remove accidental change

* fix mypy errors

* fix mypy error

* add some for core.units

* rename `ArrayWithFloatWithUnit` to `ArrayWithUnit` in comment

* fix mypy errors

* tweak docstring for units

* nest internal funcs for units

* simplify module docstring

* revert to accessing private attrib

* fix unit test and revert support for `Unit`

* use `str` over `Unit`

* support unit as both str and Unit

* tweak docstring example

* improve IndexError messages

* test_index_error

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
janosh added a commit to esoteric-ephemera/pymatgen that referenced this pull request May 17, 2024
…3820)

* remove duplicate warning

* type and docstring tweaks

* add some types for io.cif

* add comments and types

* temp save of some formatting

* revert functional change

* revert unrelated changes

* fix unit test

* remove update that does nothing

* relocate `sub_space_group` and `space_groups` to their usage

* add more types

* pre-commit auto-fixes

* breaking: make parse_magmom/oxi_stats private

* remove merge header

* fix unit test

* add more types

* fix mypy errors

* add a few spaces

* remove if name ==main

* simplify "check to see if" in comments

* final tweaks

* revise docstring

* replace deprecated abc.abstractproperty

* add missing doc strings and standardize existing

* breaking: fix typo in method name orthongonalize_structure

* revert accidental change in test_composition.py

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
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.

None yet

2 participants