structuretoolkit 0.0.40__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.40 → structuretoolkit-0.0.42}/PKG-INFO +13 -10
  2. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/pyproject.toml +14 -10
  3. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/_version.py +2 -2
  4. {structuretoolkit-0.0.40 → 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.40 → structuretoolkit-0.0.42}/src/structuretoolkit/build/sqs.py +29 -35
  7. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/.gitignore +0 -0
  8. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/LICENSE +0 -0
  9. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/README.md +0 -0
  10. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/__init__.py +0 -0
  11. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/__init__.py +0 -0
  12. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/distance.py +0 -0
  13. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/dscribe.py +0 -0
  14. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/neighbors.py +0 -0
  15. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/phonopy.py +0 -0
  16. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/pyscal.py +0 -0
  17. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/snap.py +0 -0
  18. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/spatial.py +0 -0
  19. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/strain.py +0 -0
  20. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/analyse/symmetry.py +0 -0
  21. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/build/aimsgb.py +0 -0
  22. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/build/compound.py +0 -0
  23. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/build/mesh.py +0 -0
  24. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/build/surface.py +0 -0
  25. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/common/__init__.py +0 -0
  26. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/common/error.py +0 -0
  27. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/common/helper.py +0 -0
  28. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/common/phonopy.py +0 -0
  29. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/common/pymatgen.py +0 -0
  30. {structuretoolkit-0.0.40 → structuretoolkit-0.0.42}/src/structuretoolkit/common/pyscal.py +0 -0
  31. {structuretoolkit-0.0.40 → 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.40
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
@@ -46,30 +46,33 @@ Classifier: Programming Language :: Python :: 3.11
46
46
  Classifier: Programming Language :: Python :: 3.12
47
47
  Classifier: Programming Language :: Python :: 3.13
48
48
  Classifier: Topic :: Scientific/Engineering :: Physics
49
- Requires-Python: <3.14,>=3.10
50
- Requires-Dist: ase<=3.27.0,>=3.20.1
51
- Requires-Dist: numpy<=2.3.5,>=1.23.5
52
- Requires-Dist: scipy<=1.17.0,>=1.15.0
49
+ Requires-Python: <3.15,>=3.10
50
+ Requires-Dist: ase<=3.28.0,>=3.20.1
51
+ Requires-Dist: numpy<=2.4.3,>=1.23.5
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
56
56
  Requires-Dist: dscribe==2.1.2; extra == 'dscribe'
57
57
  Provides-Extra: grainboundary
58
58
  Requires-Dist: aimsgb<=1.1.1,>=1.0.2; extra == 'grainboundary'
59
- Requires-Dist: pymatgen<=2025.10.7,>=2022.2.1; extra == 'grainboundary'
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<=2.47.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
- Requires-Dist: plotly<=6.5.2,>=4.14.3; extra == 'plotly'
71
+ Requires-Dist: plotly<=6.6.0,>=4.14.3; extra == 'plotly'
69
72
  Provides-Extra: pyscal
70
- Requires-Dist: pyscal3<=3.3.1,>=3.2.5; extra == 'pyscal'
73
+ Requires-Dist: pyscal3<=3.3.2,>=3.2.5; extra == 'pyscal'
71
74
  Provides-Extra: surface
72
- Requires-Dist: pymatgen<=2025.10.7,>=2022.2.1; extra == 'surface'
75
+ Requires-Dist: pymatgen<=2026.3.23,>=2022.2.1; extra == 'surface'
73
76
  Requires-Dist: spglib==2.7.0; extra == 'surface'
74
77
  Provides-Extra: symmetry
75
78
  Requires-Dist: spglib==2.7.0; extra == 'symmetry'
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["ase", "numpy", "scipy", "hatchling==1.28.0", "hatch-vcs==0.5.0"]
2
+ requires = ["ase", "numpy", "scipy", "hatchling==1.29.0", "hatch-vcs==0.5.0"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [project]
@@ -11,7 +11,7 @@ authors = [
11
11
  readme = "README.md"
12
12
  license = { file = "LICENSE" }
13
13
  keywords = ["pyiron"]
14
- requires-python = ">=3.10, <3.14"
14
+ requires-python = ">=3.10, <3.15"
15
15
  classifiers = [
16
16
  "Development Status :: 5 - Production/Stable",
17
17
  "Topic :: Scientific/Engineering :: Physics",
@@ -24,9 +24,9 @@ classifiers = [
24
24
  "Programming Language :: Python :: 3.13",
25
25
  ]
26
26
  dependencies = [
27
- "ase>=3.20.1,<=3.27.0",
28
- "numpy>=1.23.5,<=2.3.5",
29
- "scipy>=1.15.0,<=1.17.0",
27
+ "ase>=3.20.1,<=3.28.0",
28
+ "numpy>=1.23.5,<=2.4.3",
29
+ "scipy>=1.15.0,<=1.17.1",
30
30
  ]
31
31
  dynamic = ["version"]
32
32
 
@@ -39,22 +39,26 @@ Repository = "https://github.com/pyiron/structuretoolkit"
39
39
  dscribe = ["dscribe==2.1.2"]
40
40
  grainboundary = [
41
41
  "aimsgb>=1.0.2,<=1.1.1",
42
- "pymatgen>=2022.2.1,<=2025.10.7",
42
+ "pymatgen>=2022.2.1,<=2026.3.23",
43
43
  ]
44
- pyscal = ["pyscal3>=3.2.5,<=3.3.1"]
44
+ pyscal = ["pyscal3>=3.2.5,<=3.3.2"]
45
45
  nglview = ["nglview>=2.7.7,<=4.0.1"]
46
46
  matplotlib = ["matplotlib==3.10.8"]
47
- plotly = ["plotly>=4.14.3,<=6.5.2"]
47
+ plotly = ["plotly>=4.14.3,<=6.6.0"]
48
48
  clusters = ["scikit-learn==1.8.0"]
49
49
  symmetry = ["spglib==2.7.0"]
50
50
  surface = [
51
51
  "spglib==2.7.0",
52
- "pymatgen>=2022.2.1,<=2025.10.7",
52
+ "pymatgen>=2022.2.1,<=2026.3.23",
53
53
  ]
54
54
  phonopy = [
55
- "phonopy>=2.16.2,<=2.47.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.40'
32
- __version_tuple__ = version_tuple = (0, 0, 40)
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
+ ]
@@ -166,14 +166,8 @@ def sqs_structures(
166
166
  output_structures: int = 10,
167
167
  mode: str = "random",
168
168
  num_threads: int | None = None,
169
- prefactors: float | np.ndarray | None = None,
170
- pair_weights: np.ndarray | None = None,
171
169
  rtol: float | None = None,
172
170
  atol: float | None = None,
173
- which: Iterable[int] | None = None,
174
- shell_distances: Iterable[int] | None = None,
175
- minimal: bool | None = True,
176
- similar: bool | None = True,
177
171
  return_statistics: bool | None = False,
178
172
  ) -> Atoms | tuple[Atoms, dict[str, list], int, float]:
179
173
  """
@@ -188,54 +182,54 @@ def sqs_structures(
188
182
  output_structures (int): The number of output structures.
189
183
  mode (str): The mode for selecting configurations.
190
184
  num_threads (Optional[int]): The number of threads to use.
191
- prefactors (Optional[Union[float, np.ndarray]]): The prefactors for each shell.
192
- pair_weights (Optional[np.ndarray]): The pair weights.
193
185
  rtol (Optional[float]): The relative tolerance.
194
186
  atol (Optional[float]): The absolute tolerance.
195
- which (Optional[Iterable[int]]): The indices of the shells to optimize.
196
- shell_distances (Optional[Iterable[int]]): The distances for each shell.
197
- minimal (Optional[bool]): Whether to minimize the objective function.
198
- similar (Optional[bool]): Whether to generate similar structures.
199
187
  return_statistics (Optional[bool]): Whether to return additional statistics.
200
188
 
201
189
  Returns:
202
190
  Union[Atoms, Tuple[Atoms, Dict[str, list], int, float]]: The generated structures or a tuple containing the structures, short-range order parameters breakdown, number of iterations, and average cycle time.
203
191
 
204
192
  """
205
- from sqsgenerator import sqs_optimize
193
+ from sqsgenerator import optimize, to_ase
206
194
 
207
195
  composition = mole_fractions_to_composition(mole_fractions, len(structure))
208
196
 
209
197
  settings = {
210
198
  "atol": atol,
211
199
  "rtol": rtol,
212
- "mode": mode,
213
- "which": which,
214
- "structure": structure,
215
- "prefactors": prefactors,
216
- "shell_weights": weights,
217
- "iterations": iterations,
218
- "composition": composition,
219
- "pair_weights": pair_weights,
200
+ "iteration_mode": mode,
201
+ "structure": {
202
+ "lattice": structure.cell.array.tolist(),
203
+ "coords": structure.get_scaled_positions().tolist(),
204
+ "species": structure.get_chemical_symbols(),
205
+ },
206
+ "iterations": int(iterations),
207
+ "composition": {k: int(v) for k, v in composition.items()},
220
208
  "target_objective": objective,
221
- "shell_distances": shell_distances,
222
- "threads_per_rank": num_threads or cpu_count(),
223
- "max_output_configurations": output_structures,
209
+ "thread_config": num_threads or cpu_count(),
210
+ "max_results_per_objective": output_structures,
224
211
  }
212
+ if weights is not None:
213
+ settings["shell_weights"] = weights
214
+
225
215
  # not specifying a parameter in settings causes sqsgenerator to choose a "sensible" default,
226
216
  # hence we remove all entries with a None value
217
+ result = optimize({k: v for k, v in settings.items() if v is not None})
218
+
219
+ structures = []
220
+ sro_breakdown: list = []
221
+ finished = False
222
+ for r_lst in result:
223
+ if not finished:
224
+ for s in r_lst[1]:
225
+ structures.append(to_ase(s.structure()))
226
+ sro_breakdown.append(s.sro())
227
+ if len(structures) == output_structures:
228
+ finished = True
229
+ break
230
+ cycle_time = list(result.statistics.timings.values())[0]
231
+ num_iterations = result.config.iterations
227
232
 
228
- results, timings = sqs_optimize(
229
- {param: value for param, value in settings.items() if value is not None},
230
- minimal=minimal,
231
- similar=similar,
232
- make_structures=True,
233
- structure_format="ase",
234
- )
235
-
236
- structures, sro_breakdown = transpose(map(remap_sqs_results, results.values()))
237
- num_iterations = iterations
238
- cycle_time = np.average(list(map_dict(np.average, timings).values()))
239
233
  if not return_statistics:
240
234
  return structures
241
235
  else: