1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pythonAtLeast,
6 fetchFromGitHub,
7
8 # build-system
9 setuptools,
10
11 # nativeBuildInputs
12 cython,
13 glibcLocales,
14
15 # dependencies
16 bibtexparser,
17 joblib,
18 matplotlib,
19 monty,
20 networkx,
21 numpy,
22 orjson,
23 palettable,
24 pandas,
25 plotly,
26 pybtex,
27 requests,
28 ruamel-yaml,
29 scipy,
30 spglib,
31 sympy,
32 tabulate,
33 tqdm,
34 uncertainties,
35
36 # optional-dependencies
37 netcdf4,
38 ase,
39 pytest,
40 pytest-cov,
41 invoke,
42 sphinx,
43 sphinx-rtd-theme,
44 numba,
45 vtk,
46
47 # tests
48 addBinToPathHook,
49 pytest-xdist,
50 pytestCheckHook,
51}:
52
53buildPythonPackage rec {
54 pname = "pymatgen";
55 version = "2025.6.14";
56 pyproject = true;
57
58 disabled = pythonAtLeast "3.13";
59
60 src = fetchFromGitHub {
61 owner = "materialsproject";
62 repo = "pymatgen";
63 tag = "v${version}";
64 hash = "sha256-HMYYhXT5k/EjG1sIBq/53K9ogeSk8ZEJQBrDHCgz+SA=";
65 };
66
67 build-system = [ setuptools ];
68
69 nativeBuildInputs = [
70 cython
71 glibcLocales
72 ];
73
74 dependencies = [
75 bibtexparser
76 joblib
77 matplotlib
78 monty
79 networkx
80 numpy
81 orjson
82 palettable
83 pandas
84 plotly
85 pybtex
86 requests
87 ruamel-yaml
88 scipy
89 spglib
90 sympy
91 tabulate
92 tqdm
93 uncertainties
94 ];
95
96 optional-dependencies = {
97 abinit = [ netcdf4 ];
98 ase = [ ase ];
99 ci = [
100 pytest
101 pytest-cov
102 # pytest-split
103 ];
104 docs = [
105 invoke
106 sphinx
107 # sphinx_markdown_builder
108 sphinx-rtd-theme
109 ];
110 electronic_structure = [
111 # fdint
112 ];
113 mlp = [
114 # chgnet
115 # matgl
116 ];
117 numba = [ numba ];
118 vis = [ vtk ];
119 };
120
121 pythonImportsCheck = [ "pymatgen" ];
122
123 nativeCheckInputs = [
124 addBinToPathHook
125 pytestCheckHook
126 pytest-xdist
127 ]
128 ++ lib.flatten (builtins.attrValues optional-dependencies);
129
130 preCheck =
131 # ensure tests can find these
132 ''
133 export PMG_TEST_FILES_DIR="$(realpath ./tests/files)"
134 '';
135
136 disabledTests = [
137 # Flaky
138 "test_numerical_eos_values"
139 "test_pca"
140 "test_static_si_no_kgrid"
141 "test_thermal_conductivity"
142 ]
143 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
144 # AttributeError: 'NoneType' object has no attribute 'items'
145 "test_mean_field"
146 ]
147 ++ lib.optionals stdenv.hostPlatform.isDarwin [
148 # Fatal Python error: Aborted
149 # matplotlib/backend_bases.py", line 2654 in create_with_canvas
150 # https://github.com/materialsproject/pymatgen/issues/4452
151 "test_angle"
152 "test_as_dict_from_dict"
153 "test_attributes"
154 "test_basic"
155 "test_core_state_eigen"
156 "test_eos_func"
157 "test_get_info_cohps_to_neighbors"
158 "test_get_plot"
159 "test_get_point_group_operations"
160 "test_matplotlib_plots"
161 "test_ph_plot_w_gruneisen"
162 "test_plot"
163 "test_proj_bandstructure_plot"
164 "test_structure"
165 "test_structure_environments"
166
167 # attempt to insert nil object from objects[1]
168 "test_timer_10_2_7"
169 "test_timer"
170 ];
171
172 disabledTestPaths = [
173 # We have not packaged moyopy yet.
174 "tests/analysis/test_prototypes.py::test_get_protostructure_label_from_moyopy"
175 ]
176 ++ lib.optionals stdenv.hostPlatform.isDarwin [
177 # Crash when running the pmg command
178 # Critical error: required built-in appearance SystemAppearance not found
179 "tests/cli/test_pmg_plot.py"
180
181 # attempt to insert nil object from objects[1]
182 # https://github.com/materialsproject/pymatgen/issues/4452
183 "tests/io/abinit/test_abitimer.py"
184 ];
185
186 meta = {
187 description = "Robust materials analysis code that defines core object representations for structures and molecules";
188 homepage = "https://pymatgen.org/";
189 changelog = "https://github.com/materialsproject/pymatgen/releases/tag/v${version}";
190 license = lib.licenses.mit;
191 maintainers = with lib.maintainers; [ psyanticy ];
192 };
193}