Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Nov 19, 2024
2 parents a8a765a + 31f1e1f commit 44fda8d
Show file tree
Hide file tree
Showing 408 changed files with 20,302 additions and 11,268 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/issue-metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
# Calculate the last day of the previous month
last_day=$(date -d "$first_day +1 month -1 day" +%Y-%m-%d)
#Set an environment variable with the date range
# Set an environment variable with the date range
echo "$first_day..$last_day"
echo "last_month=$first_day..$last_day" >> "$GITHUB_ENV"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
- name: ruff
run: |
ruff --version
ruff check .
ruff format --check .
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Release # makes PyPI releases
# Make PyPI releases
name: Release

on:
release:
Expand Down Expand Up @@ -26,12 +27,12 @@ jobs:
- name: Check out repo
uses: actions/checkout@v4

- uses: actions/setup-python@v5
name: Install Python
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Build sdist
- name: Build source distribution
run: |
pip install build
python -m build --sdist
Expand Down Expand Up @@ -65,8 +66,11 @@ jobs:
release:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/pymatgen
permissions:
# For pypi trusted publishing
# For PyPI trusted publishing
id-token: write
steps:
- name: Set up Python
Expand All @@ -81,9 +85,8 @@ jobs:
merge-multiple: true
path: dist

- name: Publish to PyPi or TestPyPI
- name: Publish to PyPI or TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true
repository-url: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.task == 'test-release' && 'https://test.pypi.org/legacy/' || '' }}
11 changes: 9 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:

env:
PMG_MAPI_KEY: ${{ secrets.PMG_MAPI_KEY }}
PMG_VASP_PSP_DIR: ${{ github.workspace }}/tests/files
MPLBACKEND: Agg # non-interactive backend for matplotlib

steps:
- name: Check out repo
Expand All @@ -80,7 +80,12 @@ jobs:
pip install uv
uv pip install --editable '.[${{ matrix.config.extras }}]' --resolution=${{ matrix.config.resolution }}
# Install from wheels to test the content
uv pip install build
python -m build --wheel
uv pip install dist/*.whl
uv pip install pymatgen[${{ matrix.config.extras }}] --resolution=${{ matrix.config.resolution }}
- name: Install optional Ubuntu dependencies
if: matrix.config.os == 'ubuntu-latest'
Expand All @@ -97,6 +102,8 @@ jobs:
echo "$(realpath vampire-5.0/)" >> $GITHUB_PATH
- name: pytest split ${{ matrix.split }}
env:
PMG_TEST_FILES_DIR: "${{ github.workspace }}/tests/files"
run: |
micromamba activate pmg
pytest --splits 10 --group ${{ matrix.split }} --durations-path tests/files/.pytest-split-durations tests
Expand Down
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.4
rev: v0.7.2
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
stages: [commit, commit-msg]
stages: [pre-commit, commit-msg]
exclude_types: [html]
additional_dependencies: [tomli] # needed to read pyproject.toml below py3.11
exclude: src/pymatgen/analysis/aflow_prototypes.json
Expand All @@ -43,12 +43,12 @@ repos:
- id: double-quote-cython-strings

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.18.0
rev: 1.19.1
hooks:
- id: blacken-docs

- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.41.0
rev: v0.42.0
hooks:
- id: markdownlint
# MD013: line too long
Expand All @@ -59,12 +59,12 @@ repos:
args: [--disable, MD013, MD024, MD025, MD033, MD041, "--"]

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.8.0
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.379
rev: v1.1.387
hooks:
- id: pyright
44 changes: 31 additions & 13 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ For developers interested in expanding `pymatgen` for their own purposes, we rec

1. Create a free GitHub account (if you don't already have one) and perform the necessary setup (e.g., install SSH keys etc.).

1. Fork the `pymatgen` GitHub repo, i.e., go to the main [`pymatgen` GitHub repo](https://github.com/materialsproject/pymatgen) and click fork to create a copy of the `pymatgen` code base on your own GitHub account.
2. Fork the `pymatgen` GitHub repo, i.e., go to the main [`pymatgen` GitHub repo](https://github.com/materialsproject/pymatgen) and click fork to create a copy of the `pymatgen` code to your own GitHub account.

1. Install `git` on your local machine (if you don't already have it).
3. Install `git` on your local machine (if you haven't already).

1. Clone *your forked repo* to your local machine. You will work mostly with your local repo and only publish changes when they are ready to be merged:
4. Clone *your forked repo* to your local machine. You will work mostly with your local repo and only publish changes when they are ready to be merged:

```sh
git clone https://github.com/<username>/pymatgen

# (Alternative/Much Faster) If you don't need a full commit history/other branches
# git clone --depth 1 https://github.com/<username>/pymatgen
# git pull --unshallow # if you need the complete repo at some point
```

Note that the entire Github repo is fairly large because of the presence of test files, but these are necessary for rigorous testing.

1. Make a new branch for your contributions
5. Make a new branch for your contributions:

```sh
git checkout -b my-new-fix-or-feature # should be run from up-to-date master
```

1. Code (see [Coding Guidelines](#coding-guidelines)). Commit early and commit often. Keep your code up to date. You need to add the main repository to the list of your remotes.
6. Code (see [Coding Guidelines](#coding-guidelines)). Commit early and commit often. Keep your code up to date. You need to add the main repository to the list of your remotes:

```sh
git remote add upstream https://github.com/materialsproject/pymatgen
Expand All @@ -48,19 +52,19 @@ For developers interested in expanding `pymatgen` for their own purposes, we rec

Remember, pull is a combination of the commands fetch and merge, so there may be merge conflicts to be manually resolved.

1. Publish your contributions. Assuming that you now have a couple of commits that you would like to contribute to the main repository. Please follow the following steps:
7. Publish your contributions. Assuming that you now have a couple of commits that you would like to contribute to the main repository. Please follow the following steps:

1. If your change is based on a relatively old state of the main repository, then you should probably bring your repository up-to-date first to see if the change is not creating any merge conflicts.

1. Check that everything compiles cleanly and passes all tests. The `pymatgen` repo comes with a complete set of tests for all modules. If you have written new modules or methods, you must write tests for the new code as well (see [Coding Guidelines](#coding-guidelines)). Install and run `pytest` in your local repo directory and fix all errors before continuing further.
2. Check that everything compiles cleanly and passes all tests. The `pymatgen` repo comes with a complete set of tests for all modules. If you have written new modules or methods, you must write tests for the new code as well (see [Coding Guidelines](#coding-guidelines)). Install and run `pytest` in your local repo directory and fix all errors before continuing further.

1. If everything is ok, publish the commits to your GitHub repository.
3. If everything is ok, publish the commits to your GitHub repository:

```sh
git push origin master
```

1. Now that your commit is published, it doesn't mean that it has already been merged into the main repository. You should issue a merge request to `pymatgen` maintainers. They will pull your commits and run their own tests before releasing.
8. Now that your commit is published, it doesn't mean that it has already been merged into the main repository. You should issue a merge request to `pymatgen` maintainers. They will pull your commits and run their own tests before releasing.
"Work-in-progress" pull requests are encouraged, especially if this is your first time contributing to `pymatgen`, and the maintainers will be happy to help or provide code review as necessary. Put "\[WIP\]" in the title of your pull request to indicate it's not ready to be merged.

Expand All @@ -69,16 +73,30 @@ For developers interested in expanding `pymatgen` for their own purposes, we rec
Given that `pymatgen` is intended to be a long-term code base, we adopt very strict quality control and coding guidelines for all contributions to `pymatgen`. The following must be satisfied for your contributions to be accepted into `pymatgen`.

1. **Unit tests** are required for all new modules and methods. The only way to minimize code regression is to ensure that all code is well-tested. Untested contributions will not be accepted.
1. **Python PEP 8** [code style](https://python.org/dev/peps/pep-0008). We allow a few exceptions when they are well-justified (e.g., Element's atomic number is given a variable name of capital Z, in line with accepted scientific convention), but generally, PEP 8 must be observed. Code style will be automatically checked for all PRs and must pass before any PR is merged. To aid you, you can install and run the same set of formatters and linters that will run in CI using
To run the testsuite in you repository follow these steps:

```sh
cd path/to/repo
# Option One (Recommended): Install in editable mode
pip install -e '.[ci]' # or more optional dependencies
pytest tests
# Option Two: Use environment variable PMG_TEST_FILES_DIR
pip install '.[ci]'
PMG_TEST_FILES_DIR=$(pwd)/tests/files pytest tests # run the test suite providing the path for the test files
```

2. **PEP 8** [code style](https://python.org/dev/peps/pep-0008). We allow a few exceptions when they are well-justified (e.g., Element's atomic number is given a variable name of capital Z, in line with accepted scientific convention), but generally, PEP 8 should be observed. Code style will be automatically checked for all PRs and must pass before any PR is merged. To aid you, you can install and run the same set of formatters and linters that will run in CI using:
```sh
pre-commit install # ensures linters are run prior to all future commits
pre-commit run --files path/to/changed/files # ensure your current uncommitted changes don't offend linters
# or
pre-commit run --all-files # ensure your entire codebase passes linters
pre-commit run --all-files # ensure your entire codebase passes linters
```
1. **Python 3**. We only support Python 3.10+.
1. **Documentation** is required for all modules, classes and methods. In particular, the method doc strings should make clear the arguments expected and the return values. For complex algorithms (e.g., an Ewald summation), a summary of the algorithm should be provided and preferably with a link to a publication outlining the method in detail.
3. **Python 3**. We only support Python 3.10+.
4. **Documentation** is required for all modules, classes and methods. We prefer [Google Style Docstrings](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html). In particular, the method doc strings should make clear the arguments expected and the return values. For complex algorithms (e.g., an Ewald summation), a summary of the algorithm should be provided and preferably with a link to a publication outlining the method in detail.
For the above, if in doubt, please refer to the core classes in `pymatgen` for examples of what is expected.
33 changes: 25 additions & 8 deletions dev_scripts/chemenv/explicit_permutations_plane_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
perms_on_file = f"Permutations on file in this algorithm ({len(sep_plane_algo._permutations)}) "
print(f"{perms_on_file}\n{sep_plane_algo._permutations}")
permutations = sep_plane_algo.safe_separation_permutations(
ordered_plane=sep_plane_algo.ordered_plane, ordered_point_groups=sep_plane_algo.ordered_point_groups
ordered_plane=sep_plane_algo.ordered_plane,
ordered_point_groups=sep_plane_algo.ordered_point_groups,
)

sep_plane_algo._permutations = permutations
Expand All @@ -56,7 +57,10 @@
lgf = LocalGeometryFinder()
lgf.setup_parameters(structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE)
lgf.setup_test_perfect_environment(
cg_symbol, randomness=True, indices=range(cg.coordination_number), max_random_dist=0.05
cg_symbol,
randomness=True,
indices=range(cg.coordination_number),
max_random_dist=0.05,
)

lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
Expand All @@ -65,27 +69,40 @@
local_plane = None
found = False
for n_points in range(
sep_plane_algo.minimum_number_of_points, min(sep_plane_algo.maximum_number_of_points, 4) + 1
sep_plane_algo.minimum_number_of_points,
min(sep_plane_algo.maximum_number_of_points, 4) + 1,
):
if found:
break
for ipoints in itertools.combinations(sep_plane_algo.plane_points, n_points):
points_combination = [lgf.local_geometry.coords[ipoint] for ipoint in ipoints]
if n_points == 2:
if collinear(
points_combination[0], points_combination[1], lgf.local_geometry.central_site, tolerance=0.25
points_combination[0],
points_combination[1],
lgf.local_geometry.central_site,
tolerance=0.25,
):
continue
local_plane = Plane.from_3points(
points_combination[0], points_combination[1], lgf.local_geometry.central_site
points_combination[0],
points_combination[1],
lgf.local_geometry.central_site,
)
found = True
break
elif n_points == 3:
if collinear(points_combination[0], points_combination[1], points_combination[2], tolerance=0.25):
if collinear(
points_combination[0],
points_combination[1],
points_combination[2],
tolerance=0.25,
):
continue
local_plane = Plane.from_3points(
points_combination[0], points_combination[1], points_combination[2]
points_combination[0],
points_combination[1],
points_combination[2],
)
found = True
break
Expand Down Expand Up @@ -123,7 +140,7 @@
for icsm, csm in enumerate(csms):
found = False
for csm2 in csms_with_recorded_permutation:
if np.isclose(csm, csm2, rtol=0.0, atol=1.0e-6):
if np.isclose(csm, csm2, rtol=0.0, atol=1e-6):
found = True
break
if not found:
Expand Down
19 changes: 15 additions & 4 deletions dev_scripts/chemenv/get_plane_permutations_optimized.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ def random_permutations_iterator(initial_permutation, n_permutations):

# Setup the random environment
lgf.setup_test_perfect_environment(
cg_symbol, randomness=True, indices=range(cg.coordination_number), max_random_dist=0.05
cg_symbol,
randomness=True,
indices=range(cg.coordination_number),
max_random_dist=0.05,
)
lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
points_perfect = lgf.perfect_geometry.points_wcs_ctwcc()
Expand Down Expand Up @@ -201,7 +204,8 @@ def random_permutations_iterator(initial_permutation, n_permutations):

# Setup of safe permutations
permutations = algo.safe_separation_permutations(
ordered_plane=algo.ordered_plane, ordered_point_groups=algo.ordered_point_groups
ordered_plane=algo.ordered_plane,
ordered_point_groups=algo.ordered_point_groups,
)
algo._permutations = permutations
print(f"Safe permutations found ({len(permutations)})")
Expand Down Expand Up @@ -234,7 +238,10 @@ def random_permutations_iterator(initial_permutation, n_permutations):
)

sym_measures = [c["symmetry_measure"] for c in csms]
prt1(string="Continuous symmetry measures", printing_volume=printing_volume)
prt1(
string="Continuous symmetry measures",
printing_volume=printing_volume,
)
prt1(string=sym_measures, printing_volume=printing_volume)
csms_with_recorded_permutation: list = []
explicit_permutations = []
Expand Down Expand Up @@ -345,7 +352,11 @@ def random_permutations_iterator(initial_permutation, n_permutations):
)
# Setup of the local and perfect geometries
lgf.setup_test_perfect_environment(
cg_symbol, indices=indices_perm, randomness=True, max_random_dist=0.02, random_rotation=True
cg_symbol,
indices=indices_perm,
randomness=True,
max_random_dist=0.02,
random_rotation=True,
)
lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
points_perfect = lgf.perfect_geometry.points_wcs_ctwcc()
Expand Down
15 changes: 14 additions & 1 deletion dev_scripts/chemenv/plane_multiplicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@

# I:12
if cg_symbol == "I:12":
opposite_points = {0: 3, 1: 2, 2: 1, 3: 0, 4: 7, 5: 6, 6: 5, 7: 4, 8: 11, 9: 10, 10: 9, 11: 8}
opposite_points = {
0: 3,
1: 2,
2: 1,
3: 0,
4: 7,
5: 6,
6: 5,
7: 4,
8: 11,
9: 10,
10: 9,
11: 8,
}
edges = cg._edges
for edge in edges:
opposite_edge = [opposite_points[edge[0]], opposite_points[edge[1]]]
Expand Down
Loading

0 comments on commit 44fda8d

Please sign in to comment.