nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
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 moyopy,
50 pytest-xdist,
51 pytestCheckHook,
52}:
53
54buildPythonPackage rec {
55 pname = "pymatgen";
56 version = "2025.10.7";
57 pyproject = true;
58
59 disabled = pythonAtLeast "3.13";
60
61 src = fetchFromGitHub {
62 owner = "materialsproject";
63 repo = "pymatgen";
64 tag = "v${version}";
65 hash = "sha256-pbnWSmU2rtqUbjZBmzJz3HE1t5zZTJv7HSfrcVUFxmU=";
66 };
67
68 build-system = [ setuptools ];
69
70 nativeBuildInputs = [
71 cython
72 glibcLocales
73 ];
74
75 dependencies = [
76 bibtexparser
77 joblib
78 matplotlib
79 monty
80 networkx
81 numpy
82 orjson
83 palettable
84 pandas
85 plotly
86 pybtex
87 requests
88 ruamel-yaml
89 scipy
90 spglib
91 sympy
92 tabulate
93 tqdm
94 uncertainties
95 ];
96
97 optional-dependencies = {
98 abinit = [ netcdf4 ];
99 ase = [ ase ];
100 ci = [
101 pytest
102 pytest-cov
103 # pytest-split
104 ];
105 docs = [
106 invoke
107 sphinx
108 # sphinx_markdown_builder
109 sphinx-rtd-theme
110 ];
111 electronic_structure = [
112 # fdint
113 ];
114 mlp = [
115 # chgnet
116 # matgl
117 ];
118 numba = [ numba ];
119 vis = [ vtk ];
120 };
121
122 pythonImportsCheck = [ "pymatgen" ];
123
124 nativeCheckInputs = [
125 addBinToPathHook
126 moyopy
127 pytestCheckHook
128 pytest-xdist
129 ]
130 ++ lib.concatAttrValues optional-dependencies;
131
132 preCheck =
133 # ensure tests can find these
134 ''
135 export PMG_TEST_FILES_DIR="$(realpath ./tests/files)"
136 ''
137 # Prevents 'Fatal Python error: Aborted' on darwin during checkPhase
138 + lib.optionalString stdenv.hostPlatform.isDarwin ''
139 export MPLBACKEND="Agg"
140 '';
141
142 disabledTests = [
143 # Flaky
144 "test_numerical_eos_values"
145 "test_pca"
146 "test_static_si_no_kgrid"
147 "test_thermal_conductivity"
148 ]
149 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
150 # AttributeError: 'NoneType' object has no attribute 'items'
151 "test_mean_field"
152 ]
153 ++ lib.optionals stdenv.hostPlatform.isDarwin [
154 # attempt to insert nil object from objects[1]
155 "test_timer_10_2_7"
156 "test_timer"
157 ];
158
159 disabledTestPaths = lib.optionals stdenv.hostPlatform.isDarwin [
160 # Crash when running the pmg command
161 # Critical error: required built-in appearance SystemAppearance not found
162 "tests/cli/test_pmg_plot.py"
163
164 # attempt to insert nil object from objects[1]
165 # https://github.com/materialsproject/pymatgen/issues/4452
166 "tests/io/abinit/test_abitimer.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/${src.tag}";
173 license = lib.licenses.mit;
174 maintainers = with lib.maintainers; [ psyanticy ];
175 };
176}