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