structuretoolkit 0.0.41__tar.gz → 0.0.42__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/PKG-INFO +6 -3
  2. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/pyproject.toml +6 -2
  3. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/_version.py +2 -2
  4. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/build/__init__.py +6 -0
  5. structuretoolkit-0.0.42/src/structuretoolkit/build/materialsproject.py +138 -0
  6. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/.gitignore +0 -0
  7. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/LICENSE +0 -0
  8. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/README.md +0 -0
  9. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/__init__.py +0 -0
  10. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/__init__.py +0 -0
  11. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/distance.py +0 -0
  12. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/dscribe.py +0 -0
  13. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/neighbors.py +0 -0
  14. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/phonopy.py +0 -0
  15. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/pyscal.py +0 -0
  16. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/snap.py +0 -0
  17. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/spatial.py +0 -0
  18. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/strain.py +0 -0
  19. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/symmetry.py +0 -0
  20. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/build/aimsgb.py +0 -0
  21. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/build/compound.py +0 -0
  22. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/build/mesh.py +0 -0
  23. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/build/sqs.py +0 -0
  24. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/build/surface.py +0 -0
  25. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/common/__init__.py +0 -0
  26. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/common/error.py +0 -0
  27. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/common/helper.py +0 -0
  28. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/common/phonopy.py +0 -0
  29. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/common/pymatgen.py +0 -0
  30. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/common/pyscal.py +0 -0
  31. {structuretoolkit-0.0.41 → structuretoolkit-0.0.42}/src/structuretoolkit/visualize.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: structuretoolkit
3
- Version: 0.0.41
3
+ Version: 0.0.42
4
4
  Summary: build, analyse and visualise atomistic structures for materials science
5
5
  Project-URL: Homepage, https://github.com/pyiron/structuretoolkit
6
6
  Project-URL: Documentation, https://github.com/pyiron/structuretoolkit
@@ -49,7 +49,7 @@ Classifier: Topic :: Scientific/Engineering :: Physics
49
49
  Requires-Python: <3.15,>=3.10
50
50
  Requires-Dist: ase<=3.28.0,>=3.20.1
51
51
  Requires-Dist: numpy<=2.4.3,>=1.23.5
52
- Requires-Dist: scipy<=1.17.0,>=1.15.0
52
+ Requires-Dist: scipy<=1.17.1,>=1.15.0
53
53
  Provides-Extra: clusters
54
54
  Requires-Dist: scikit-learn==1.8.0; extra == 'clusters'
55
55
  Provides-Extra: dscribe
@@ -59,10 +59,13 @@ Requires-Dist: aimsgb<=1.1.1,>=1.0.2; extra == 'grainboundary'
59
59
  Requires-Dist: pymatgen<=2026.3.23,>=2022.2.1; extra == 'grainboundary'
60
60
  Provides-Extra: matplotlib
61
61
  Requires-Dist: matplotlib==3.10.8; extra == 'matplotlib'
62
+ Provides-Extra: mp-api
63
+ Requires-Dist: mp-api==0.45.15; extra == 'mp-api'
64
+ Requires-Dist: pymatgen<=2026.3.23,>=2022.2.1; extra == 'mp-api'
62
65
  Provides-Extra: nglview
63
66
  Requires-Dist: nglview<=4.0.1,>=2.7.7; extra == 'nglview'
64
67
  Provides-Extra: phonopy
65
- Requires-Dist: phonopy<=3.2.1,>=2.16.2; extra == 'phonopy'
68
+ Requires-Dist: phonopy<=3.5.0,>=2.16.2; extra == 'phonopy'
66
69
  Requires-Dist: spglib==2.7.0; extra == 'phonopy'
67
70
  Provides-Extra: plotly
68
71
  Requires-Dist: plotly<=6.6.0,>=4.14.3; extra == 'plotly'
@@ -26,7 +26,7 @@ classifiers = [
26
26
  dependencies = [
27
27
  "ase>=3.20.1,<=3.28.0",
28
28
  "numpy>=1.23.5,<=2.4.3",
29
- "scipy>=1.15.0,<=1.17.0",
29
+ "scipy>=1.15.0,<=1.17.1",
30
30
  ]
31
31
  dynamic = ["version"]
32
32
 
@@ -52,9 +52,13 @@ surface = [
52
52
  "pymatgen>=2022.2.1,<=2026.3.23",
53
53
  ]
54
54
  phonopy = [
55
- "phonopy>=2.16.2,<=3.2.1",
55
+ "phonopy>=2.16.2,<=3.5.0",
56
56
  "spglib==2.7.0",
57
57
  ]
58
+ mp-api = [
59
+ "mp-api==0.45.15",
60
+ "pymatgen>=2022.2.1,<=2026.3.23",
61
+ ]
58
62
 
59
63
  [tool.ruff]
60
64
  exclude = [".ci_support", "tests", "setup.py", "_version.py"]
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.41'
32
- __version_tuple__ = version_tuple = (0, 0, 41)
31
+ __version__ = version = '0.0.42'
32
+ __version_tuple__ = version_tuple = (0, 0, 42)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -2,6 +2,10 @@ from structuretoolkit.build.aimsgb import get_grainboundary_info, grainboundary
2
2
  from structuretoolkit.build.compound import B2, C14, C15, C36, D03
3
3
  from structuretoolkit.build.mesh import create_mesh
4
4
  from structuretoolkit.build.sqs import sqs_structures
5
+ from structuretoolkit.build.materialsproject import (
6
+ search as materialsproject_search,
7
+ by_id as materialsproject_by_id,
8
+ )
5
9
  from structuretoolkit.build.surface import (
6
10
  get_high_index_surface_info,
7
11
  high_index_surface,
@@ -19,4 +23,6 @@ __all__ = [
19
23
  "sqs_structures",
20
24
  "get_high_index_surface_info",
21
25
  "high_index_surface",
26
+ "materialsproject_search",
27
+ "materialsproject_by_id",
22
28
  ]
@@ -0,0 +1,138 @@
1
+ from typing import Any, Iterable
2
+ from collections.abc import Generator
3
+ from ase.atoms import Atoms
4
+ from structuretoolkit.common.pymatgen import pymatgen_to_ase
5
+
6
+
7
+ def search(
8
+ chemsys: str | list[str], fields: Iterable[str] = (), api_key=None, **kwargs
9
+ ) -> Generator[dict[str, Any], None, None]:
10
+ """
11
+ Search the database for all structures matching the given query.
12
+
13
+ Note that `chemsys` takes distinct values for unaries, binaries and so! A query with `chemsys=["Fe", "O"]` will
14
+ return iron and oxygen structures but not iron oxide. Similarly `chemsys=["Fe-O"]` will
15
+ not return unary structures.
16
+
17
+ All keyword arguments for filtering from the original API are supported. See the
18
+ `original docs <https://docs.materialsproject.org/downloading-data/using-the-api>`_ for them.
19
+
20
+ Search for all iron structures:
21
+
22
+ >>> irons = structuretoolkit.build.materialsproject.search("Fe")
23
+ >>> len(list(irons))
24
+ 10
25
+
26
+ Search for all structures with Al, Li that are on the T=0 convex hull:
27
+
28
+ >>> alli = structuretoolkit.build.materialsproject.search(['Al', 'Li', 'Al-Li'], is_stable=True)
29
+ >>> len(list(alli))
30
+ 6
31
+
32
+ Usage is only possible with an API key obtained from the Materials Project. To do this, create an account with
33
+ them, login and access `this webpage <https://next-gen.materialsproject.org/api#api-key>`.
34
+
35
+ Once you have a key, either pass it as the `api_key` parameter or export an
36
+ environment variable, called `MP_API_KEY`, in your shell setup.
37
+
38
+ Args:
39
+ chemsys (str, list of str): confine search to given elements; either an element symbol or multiple element
40
+ symbols separated by dashes; if a list of strings is given return structures matching either of them
41
+ fields (iterable of str): pass as `fields` to :meth:`mp_api.MPRester.summary.search` to request additional
42
+ database entries beyond the structure
43
+ api_key (str, optional): if your API key is not exported in the environment flag MP_API_KEY, pass it here
44
+ **kwargs: passed verbatim to :meth:`mp_api.MPRester.summary.search` to further filter the results
45
+
46
+ Returns:
47
+ list of dict: one dictionary for each search results with at least keys
48
+ 'material_id': database key of the hit
49
+ 'structure': ASE atoms object
50
+ plus any requested via `fields`.
51
+ """
52
+ from mp_api.client import MPRester
53
+
54
+ rest_kwargs = {
55
+ "use_document_model": False, # returns results as dictionaries
56
+ "include_user_agent": True, # send some additional software version info to MP
57
+ }
58
+ if api_key is not None:
59
+ rest_kwargs["api_key"] = api_key
60
+ with MPRester(**rest_kwargs) as mpr:
61
+ results = mpr.summary.search(
62
+ chemsys=chemsys,
63
+ **kwargs,
64
+ fields=list(fields) + ["structure", "material_id"],
65
+ )
66
+ for r in results:
67
+ if "structure" in r:
68
+ r["structure"] = pymatgen_to_ase(r["structure"])
69
+ yield r
70
+
71
+
72
+ def by_id(
73
+ material_id: str | int,
74
+ final: bool = True,
75
+ conventional_unit_cell: bool = False,
76
+ api_key=None,
77
+ ) -> Atoms | list[Atoms]:
78
+ """
79
+ Retrieve a structure by material id.
80
+
81
+ This is how you would ask for the iron ground state:
82
+
83
+ >>> structuretoolkit.build.materialsproject.by_id('mp-13')
84
+ Fe: [0. 0. 0.]
85
+ tags:
86
+ spin: [(0: 2.214)]
87
+ pbc: [ True True True]
88
+ cell:
89
+ Cell([[2.318956, 0.000185, -0.819712], [-1.159251, 2.008215, -0.819524], [2.5e-05, 0.000273, 2.459206]])
90
+
91
+ Usage is only possible with an API key obtained from the Materials Project. To do this, create an account with
92
+ them, login and access `this webpage <https://next-gen.materialsproject.org/api#api-key>`.
93
+
94
+ Once you have a key, either pass it as the `api_key` parameter or export an
95
+ environment variable, called `MP_API_KEY`, in your shell setup.
96
+
97
+ Args:
98
+ material_id (str): the id assigned to a structure by the materials project
99
+ api_key (str, optional): if your API key is not exported in the environment flag MP_API_KEY, pass it here
100
+ final (bool, optional): if set to False, returns the list of initial structures,
101
+ else returns the final structure. (Default is True)
102
+ conventional_unit_cell (bool, optional): if set to True, returns the standard conventional unit cell.
103
+ (Default is False)
104
+
105
+ Returns:
106
+ :class:`~.Atoms`: requested final structure if final is True
107
+ list of :class:~.Atoms`: a list of initial (pre-relaxation) structures if final is False
108
+
109
+ Raises:
110
+ ValueError: material id does not exist
111
+ """
112
+ from mp_api.client import MPRester
113
+
114
+ rest_kwargs = {
115
+ "include_user_agent": True, # send some additional software version info to MP
116
+ }
117
+ if api_key is not None:
118
+ rest_kwargs["api_key"] = api_key
119
+ with MPRester(**rest_kwargs) as mpr:
120
+ if final:
121
+ return pymatgen_to_ase(
122
+ mpr.get_structure_by_material_id(
123
+ material_id=material_id,
124
+ final=final,
125
+ conventional_unit_cell=conventional_unit_cell,
126
+ )
127
+ )
128
+ else:
129
+ return [
130
+ pymatgen_to_ase(mpr_structure)
131
+ for mpr_structure in (
132
+ mpr.get_structure_by_material_id(
133
+ material_id=material_id,
134
+ final=final,
135
+ conventional_unit_cell=conventional_unit_cell,
136
+ )
137
+ )
138
+ ]