1{
2 lib,
3 lammps,
4 stdenv,
5 buildPythonPackage,
6}:
7
8let
9 LAMMPS_SHARED_LIB = "${lib.getLib lammps}/lib/liblammps${stdenv.hostPlatform.extensions.library}";
10in
11buildPythonPackage {
12 inherit (lammps) pname version src;
13
14 env = {
15 # Needed for tests
16 inherit LAMMPS_SHARED_LIB;
17 };
18 # Don't perform checks if GPU is enabled - because libcuda.so cannot be opened in the sandbox
19 doCheck = if lammps.passthru.packages ? GPU then !lammps.passthru.packages.GPU else true;
20 preConfigure = ''
21 cd python
22 # Upstream assumes that the shared library is located in the same directory
23 # as the core.py file. We want to separate the shared library (built by
24 # cmake) and the Python library, so we perform this substitution:
25 substituteInPlace lammps/core.py \
26 --replace-fail \
27 "from inspect import getsourcefile" \
28 "getsourcefile = lambda f: \"${LAMMPS_SHARED_LIB}\""
29 '';
30
31 pythonImportsCheck = [
32 "lammps"
33 "lammps.pylammps"
34 ];
35
36 # We could potentially run other examples, but some of them are so old that
37 # they don't run with nowadays' LAMMPS. This one is simple enough and recent
38 # enough and it works.
39 checkPhase = ''
40 python examples/mc.py examples/in.mc
41 '';
42
43 meta = {
44 description = "Python Bindings for LAMMPS";
45 homepage = "https://docs.lammps.org/Python_head.html";
46 inherit (lammps.meta) license;
47 maintainers = with lib.maintainers; [ doronbehar ];
48 };
49}