ncrystal-python 4.1.2__tar.gz → 4.1.4__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.
- {ncrystal_python-4.1.2/src/ncrystal_python.egg-info → ncrystal_python-4.1.4}/PKG-INFO +26 -276
- ncrystal_python-4.1.4/README.md +56 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/__init__.py +1 -1
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_testimpl.py +5 -147
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/test.py +10 -27
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4/src/ncrystal_python.egg-info}/PKG-INFO +26 -276
- ncrystal_python-4.1.2/README.md +0 -306
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/LICENSE +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/pyproject.toml +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/setup.cfg +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/__main__.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_chooks.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_cif2ncmat.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_endf2ncmat.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_hfg2ncmat.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_mcstasunion.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_ncmat2cpp.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_ncmat2hkl.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_nctool.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_vdos2ncmat.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cli_verifyatompos.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cliimpl.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_cliwrap_config.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_common.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_coreimpl.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_hfgdata.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_hklobjects.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_is_std.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_locatelib.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_miscimpl.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_mmc.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_msg.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_ncmat2cpp_impl.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_ncmatimpl.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/_numpy.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/api.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/atomdata.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/cfgstr.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/cifutils.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/cli.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/constants.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/core.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/datasrc.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/exceptions.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/hfg2ncmat.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/mcstasutils.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/misc.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/mmc.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/ncmat.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/ncmat2cpp.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/obsolete.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/plot.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/plugins.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/NCrystal/vdos.py +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/ncrystal_python.egg-info/SOURCES.txt +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/ncrystal_python.egg-info/dependency_links.txt +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/ncrystal_python.egg-info/entry_points.txt +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/ncrystal_python.egg-info/requires.txt +0 -0
- {ncrystal_python-4.1.2 → ncrystal_python-4.1.4}/src/ncrystal_python.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: ncrystal-python
|
|
3
|
-
Version: 4.1.
|
|
3
|
+
Version: 4.1.4
|
|
4
4
|
Summary: Library for thermal neutron transport in crystals and other materials.
|
|
5
5
|
Author: NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)
|
|
6
6
|
License: The Apache 2.0 license is reproduced in the following. See the NOTICE file for
|
|
@@ -222,42 +222,35 @@ Requires-Dist: numpy>=1.22
|
|
|
222
222
|
NCrystal : A library for thermal neutron transport in crystals and other materials
|
|
223
223
|
----------------------------------------------------------------------------------
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
The `ncrystal-python` package provides the Python API and command-line scripts
|
|
226
|
+
for NCrystal. To function it needs to acess NCrystal shared library behind the
|
|
227
|
+
scenes, and as such it requires the `ncrystal-core` package to function.
|
|
228
228
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
and
|
|
232
|
-
incoherent, elastic and inelastic scatterings in a wide range of materials,
|
|
233
|
-
including crystal powders, mosaic single crystals, layered single crystals,
|
|
234
|
-
amorphous solids, and liquids. Multiphase materials or isotopically enriched
|
|
235
|
-
material are supported as well, and the framework furthermore supports
|
|
236
|
-
phase-contrast (SANS) physics. Written in C++, interfaces and infrastructure
|
|
237
|
-
facilitate integration into existing simulation frameworks such as OpenMC
|
|
238
|
-
(https://docs.openmc.org/), Geant4 (https://geant4.web.cern.ch/) or McStas
|
|
239
|
-
(http://mcstas.org/), as well as allowing direct usage from C++, C or Python
|
|
240
|
-
code or via command-line tools. While the C++ library is designed with a high
|
|
241
|
-
degree of flexibility in mind for developers, typical end-user configuration is
|
|
242
|
-
deliberately kept simple and uniform across various applications and APIs - this
|
|
243
|
-
for instance allows tuning and validation of a particular material configuration
|
|
244
|
-
to be performed in one tool before it is then deployed in another.
|
|
229
|
+
In conda and Python environments, it is recommended that most users simply
|
|
230
|
+
install and depend on the package named `ncrystal` which itself depends on both
|
|
231
|
+
`ncrystal-core` and `ncrystal-python`.
|
|
245
232
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
233
|
+
Note that to support some esoteric installations, the `ncrystal-python` package
|
|
234
|
+
does not itself depend on the `ncrystal-core` package, which is another reason
|
|
235
|
+
that most users are recommended to simply install or depend only on the package
|
|
236
|
+
named `ncrystal`.
|
|
250
237
|
|
|
251
|
-
|
|
238
|
+
Installation of the `ncrystal-python` package more specifically provides (in
|
|
239
|
+
addition to what is found in the `ncrystal-core` package):
|
|
252
240
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
241
|
+
- The NCrystal python module.
|
|
242
|
+
- This allows you to do `import NCrystal` and use the Python API of NCrystal.
|
|
243
|
+
- Command-line utilities.
|
|
244
|
+
- These commands (e.g. `nctool`, `ncrystal_cif2ncmat`, ...) are actually
|
|
245
|
+
themselves written in Python, and can also be accessed from the Python API
|
|
246
|
+
itself via the `NCrystal.cli` module.
|
|
247
|
+
- Note that the special command `ncrystal-config` is provided by the
|
|
248
|
+
`ncrystal-core` package, _not_ the `ncrystal-python` package.
|
|
249
|
+
- Note that the `ncrystal-python` package can only be installed via Python
|
|
250
|
+
installation tools like pip.
|
|
251
|
+
- For convenience, the `ncrystal-core` package has a dependency on `numpy`.
|
|
252
|
+
|
|
253
|
+
# Referencing NCrystal in scientific work
|
|
261
254
|
|
|
262
255
|
A very substantial effort went into developing NCrystal. If you use it for your
|
|
263
256
|
work, we would appreciate it if you would use the following primary reference in
|
|
@@ -282,246 +275,3 @@ additionally also use the following reference in your work:
|
|
|
282
275
|
neutron scattering", Journal of Computational Physics 380 (2019) 400-407,
|
|
283
276
|
https://doi.org/10.1016/j.jcp.2018.11.043
|
|
284
277
|
|
|
285
|
-
The rest of this file gives a brief overview of the manners in which NCrystal
|
|
286
|
-
capabilities can be utilised. Further instructions and documentation, along with
|
|
287
|
-
the latest version of NCrystal, can be found at https://mctools.github.io/ncrystal/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
Using the NCrystal installation from the command-line
|
|
292
|
-
-----------------------------------------------------
|
|
293
|
-
|
|
294
|
-
After installing NCrystal and having sourced the setup.sh script mentioned in
|
|
295
|
-
the INSTALL file, you can run any of the commands from the $NCRYSTALDIR/bin
|
|
296
|
-
directory, which includes example code as well as the "nctool" command. Start by
|
|
297
|
-
reading the usage instructions:
|
|
298
|
-
|
|
299
|
-
$> nctool --help
|
|
300
|
-
|
|
301
|
-
Assuming you chose to install data files, you can try to let NCrystal load one
|
|
302
|
-
of the data files found in $NCRYSTALDIR/data/ (or provide the absolute path to a
|
|
303
|
-
data file downloaded from https://github.com/mctools/ncrystal/wiki/Data-library)
|
|
304
|
-
and either dump the derived information to the terminal...:
|
|
305
|
-
|
|
306
|
-
$> nctool --dump 'Al_sg225.ncmat;temp=10C'
|
|
307
|
-
|
|
308
|
-
Note that this included a choice of temperature. If you leave it out, it will
|
|
309
|
-
usually default to room temperature (20C). You can also plot (powder)
|
|
310
|
-
cross-sections and sampled scatter angles with:
|
|
311
|
-
|
|
312
|
-
$> nctool 'Al_sg225.ncmat;temp=10C'
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
Using the NCrystal installation from C++, C or Python code
|
|
317
|
-
-----------------------------------------------------------------------------
|
|
318
|
-
|
|
319
|
-
If you wish to use NCrystal from Python code, there is no special setup needed,
|
|
320
|
-
assuming NCrystal was installed correctly (cf. INSTALL.md). If you on the other
|
|
321
|
-
hand wish to use NCrystal from your compiled C++ or C code, you must put
|
|
322
|
-
appropriate build flags. The recommended way is using CMake to do this (see next
|
|
323
|
-
section), but otherwise you must ensure that the NCrystal header files are in
|
|
324
|
-
your compiler's include path, and that the NCrystal library is linked
|
|
325
|
-
correctly. Here are some examples of how this could for instance be done, with a
|
|
326
|
-
C and a C++ app respectively:
|
|
327
|
-
|
|
328
|
-
```
|
|
329
|
-
export LDFLAGS="${LDFLAGS:-} -Wl,-rpath,$(ncrystal-config --show libdir) $(ncrystal-config --show libpath)"
|
|
330
|
-
export CFLAGS="${CFLAGS:-} -I$(ncrystal-config --show includedir)"
|
|
331
|
-
export CXXFLAGS="${CXXFLAGS:-} -I$(ncrystal-config --show includedir)"
|
|
332
|
-
cc -std=c11 ${LDFLAGS} ${CFLAGS} my_c_code.c -o my_c_app
|
|
333
|
-
c++ -std=c++17 ${LDFLAGS} ${CXXFLAGS} my_cpp_code.cpp -o my_cpp_app
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
Then, in your code you can access the relevant APIs with with statements like:
|
|
337
|
-
|
|
338
|
-
```
|
|
339
|
-
#include "NCrystal/NCrystal.hh" // C++ code, core NCrystal
|
|
340
|
-
#include "NCrystal/ncrystal.h" // C code
|
|
341
|
-
import NCrystal ## Python code
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
In the ./examples/ directory of your NCrystal distribution that you got after
|
|
345
|
-
downloading and unpacking the NCrystal source tar-ball, you will find small
|
|
346
|
-
examples of code using NCrystal. For C++/C, there is currently no documentation
|
|
347
|
-
beyond the header files and examples. In the case of Python, there is integrated
|
|
348
|
-
documentation available via the usual "help" function, accessed with:
|
|
349
|
-
|
|
350
|
-
```
|
|
351
|
-
import NCrystal
|
|
352
|
-
help(NCrystal)
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
There are also several jupyter-lab notebooks showcasing the NCrystal python API
|
|
356
|
-
at https://github.com/mctools/ncrystal-notebooks
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Configuring CMake-based projects to use NCrystal
|
|
361
|
-
------------------------------------------------
|
|
362
|
-
|
|
363
|
-
Assuming NCrystal was built and installed via CMake, it is possible and
|
|
364
|
-
recommended for client projects to simply use NCrystal as a CMake package in
|
|
365
|
-
order to correctly build their C/C++ code which depends on the NCrystal C++ or C
|
|
366
|
-
APIs.
|
|
367
|
-
|
|
368
|
-
Depending on where NCrystal was installed on the system, it might be necessary
|
|
369
|
-
to let CMake know about it via the usual mechanisms (for instance passing
|
|
370
|
-
-DNCrystal_DIR=/path/to/ncrystalinstall as an argument to cmake on the command
|
|
371
|
-
line).
|
|
372
|
-
|
|
373
|
-
CMake code for a small project using NCrystal might look like the following
|
|
374
|
-
(assume that exampleapp.cc below includes the NCrystal/NCrystal.hh header):
|
|
375
|
-
|
|
376
|
-
cmake_minimum_required(VERSION 3.10...3.26)
|
|
377
|
-
project(MyExampleProject LANGUAGES CXX)
|
|
378
|
-
execute_process( COMMAND "ncrystal-config" "--show" "cmakedir"
|
|
379
|
-
OUTPUT_VARIABLE NCrystal_DIR
|
|
380
|
-
OUTPUT_STRIP_TRAILING_WHITESPACE )
|
|
381
|
-
find_package(NCrystal 4.0.0 REQUIRED)
|
|
382
|
-
add_executable(exampleapp "${PROJECT_SOURCE_DIR}/exampleapp.cc")
|
|
383
|
-
target_link_libraries( exampleapp NCrystal::NCrystal )
|
|
384
|
-
install( TARGETS exampleapp DESTINATION bin )
|
|
385
|
-
|
|
386
|
-
Note that the "execute_process( ... )" command above is optional, but is
|
|
387
|
-
required before the code can work in an environment where the NCrystal CMake
|
|
388
|
-
modules are not automatically injected into the CMake package search path (this
|
|
389
|
-
notably includes NCrystal installed via "pip install ncrystal").
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
Using the NCrystal with Geant4
|
|
394
|
-
------------------------------
|
|
395
|
-
|
|
396
|
-
The instructions for the NCrystal-Geant4 bindings are currently being
|
|
397
|
-
updated. Once complete, they will appear on
|
|
398
|
-
https://github.com/mctools/ncrystal-geant4
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
Using NCrystal with OpenMC
|
|
403
|
-
--------------------------
|
|
404
|
-
|
|
405
|
-
Using NCrystal materials in OpenMc is supported since OpenMC release 13.3, and
|
|
406
|
-
uses a nice simple syntax in the Python API:
|
|
407
|
-
|
|
408
|
-
```
|
|
409
|
-
mat = openmc.Material.from_ncrystal('Polyethylene_CH2.ncmat;temp=50C')
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
which when used in a complete OpenMC project, results in the following material
|
|
413
|
-
entry being added to the `materials.xml` produced:
|
|
414
|
-
|
|
415
|
-
```
|
|
416
|
-
<material cfg="Polyethylene_CH2.ncmat;temp=50C" id="1" temperature="323.15">
|
|
417
|
-
<density units="g/cm3" value="0.92" />
|
|
418
|
-
<nuclide ao="0.66656284" name="H1" />
|
|
419
|
-
<nuclide ao="0.00010382666666666666" name="H2" />
|
|
420
|
-
<nuclide ao="0.32964066666666664" name="C12" />
|
|
421
|
-
<nuclide ao="0.003692666666666666" name="C13" />
|
|
422
|
-
</material>
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
Temperature, density and material composition were all created automatically
|
|
426
|
-
from the cfg-string, and the cfg-string itself was also encoded. Upon launching
|
|
427
|
-
the simulation with the OpenMC binary executable `openmc`, it will handle the
|
|
428
|
-
material as usual, except that low-energy neutron scattering physics (currently
|
|
429
|
-
defined as ($E<5eV$) will be provided by the algorithms in NCrystal.
|
|
430
|
-
|
|
431
|
-
A few issues might warrent attention:
|
|
432
|
-
|
|
433
|
-
1. If you try to assemble the above xml manually, it is rather unlikely that you
|
|
434
|
-
will get the base densities and compositions right. It is safest to stick to
|
|
435
|
-
let the Python API compose the xml for you.
|
|
436
|
-
2. After creation with `mat=openmc.Material.from_ncrystal(..)`, you can not use
|
|
437
|
-
the usual OpenMC API to modify the material density, temperature, or
|
|
438
|
-
composition. So be sure to reflect the final desired material inside the
|
|
439
|
-
NCrystal cfg-string.
|
|
440
|
-
3. The OpenMC binaries must have been built with NCrystal support, or your job
|
|
441
|
-
will fail once you launch the simulation (you can check for this by running
|
|
442
|
-
the command `openmc -v`). Specifically (as documented on
|
|
443
|
-
https://docs.openmc.org/en/stable/usersguide/install.html) you must supply
|
|
444
|
-
the CMake flag `cmake -DOPENMC_USE_NCRYSTAL=on ..` (and make sure NCrystal is
|
|
445
|
-
available already). Note: we have agreement from OpenMC developers to enable
|
|
446
|
-
NCrystal support by default in the conda-forge version of OpenMC. So in "the
|
|
447
|
-
near future" (summer/fall 2023) conda users will always have NCrystal support
|
|
448
|
-
available in OpenMC.
|
|
449
|
-
|
|
450
|
-
For more information, please consult the user guide at:
|
|
451
|
-
|
|
452
|
-
* https://docs.openmc.org/
|
|
453
|
-
|
|
454
|
-
In particular note the sections concerning installation and usage of NCrystal in
|
|
455
|
-
the sections:
|
|
456
|
-
|
|
457
|
-
* https://docs.openmc.org/en/stable/usersguide/install.html
|
|
458
|
-
* https://docs.openmc.org/en/stable/usersguide/materials.html
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
Using NCrystal with McStas
|
|
463
|
-
--------------------------
|
|
464
|
-
|
|
465
|
-
NOTE: The following discussion concerns the modern McStas 3 branch, and might in
|
|
466
|
-
particular not be 100% accurate for releases earlier than McStas 3.3 (probably
|
|
467
|
-
OK for v3.2 though).
|
|
468
|
-
|
|
469
|
-
You can use NCrystal in two ways in McStas. You can either use it for advanced
|
|
470
|
-
studies with the McStas Union sub-system through the NCrystal_process component,
|
|
471
|
-
or it can be used via the dedicated NCrystal_sample.comp which is simpler but
|
|
472
|
-
less feature rich. In any case, the McStas instrument file compilation will need
|
|
473
|
-
to build against NCrystal, and it uses the ncrystal-config command to figure out
|
|
474
|
-
the correct settings for doing so. Thus, you can always invoke "ncrystal-config
|
|
475
|
-
-s" to find out if you have the right NCrystal installation available and
|
|
476
|
-
active. Depending on how you installed McStas, NCrystal is most likely already
|
|
477
|
-
available. If not, you can try one of the following ways of enabling it:
|
|
478
|
-
|
|
479
|
-
```
|
|
480
|
-
$> conda install conda-forge::ncrystal [if you are in a conda-forge env]
|
|
481
|
-
$> python3 -mpip install ncrystal [for non-conda users]
|
|
482
|
-
```
|
|
483
|
-
|
|
484
|
-
It is beyond the scope for this README to provide a full documentation of
|
|
485
|
-
McStas, or the Union sub-system, but if you are using McStasScript to compose
|
|
486
|
-
your instruments, you can add NCrystal materials into your Union geometry using
|
|
487
|
-
code like:
|
|
488
|
-
|
|
489
|
-
```
|
|
490
|
-
from mcstasscript.tools.ncrystal_union import add_ncrystal_union_material
|
|
491
|
-
add_ncrystal_union_material(instr, name="myAl", cfgstr="Al_sg225.ncmat;temp=10C")
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
This creates the material and gives it the name "myAl", which you must later
|
|
495
|
-
attach to a particular Union volume, like for instance:
|
|
496
|
-
|
|
497
|
-
```
|
|
498
|
-
myvol.set_parameters(radius=0.01, yheight=0.01,
|
|
499
|
-
material_string='"myAl"', priority=1)
|
|
500
|
-
```
|
|
501
|
-
|
|
502
|
-
If you are instead hand-editing your instrument files, you can generate code
|
|
503
|
-
which defines Union materials from an NCrystal cfg-string by invoking:
|
|
504
|
-
|
|
505
|
-
```
|
|
506
|
-
$> python3 -mNCrystal.mcstasutils --union myAl 'Al_sg225.ncmat;temp=250K'
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
It should be noted that McStas 3.3 also provides a new SHELL syntax which can
|
|
510
|
-
also be used to faciliate this invocation from with a classic .instr file.
|
|
511
|
-
|
|
512
|
-
On the other hand, the dedicated NCrystal_sample.comp component, embeds NCrystal
|
|
513
|
-
material simulations into simple shapes (currently boxes, cylinders and
|
|
514
|
-
spheres), and can be used for components representing samples, filters or
|
|
515
|
-
monochromators, entrance windows, etc. The component is since McStas v3.3 part
|
|
516
|
-
of the McStas release itself, and can be used in a .instr file - for instance if
|
|
517
|
-
you wish to set up an r=1cm sphere with powdered sapphire you would write:
|
|
518
|
-
|
|
519
|
-
COMPONENT mysample = NCrystal_sample(cfg="Al2O3_sg167_Corundum.ncmat",radius=0.01)
|
|
520
|
-
AT (0, 0, 0) RELATIVE PREVIOUS
|
|
521
|
-
|
|
522
|
-
For more documentation about the NCrystal_sample component, run:
|
|
523
|
-
|
|
524
|
-
$> mcdoc NCrystal_sample
|
|
525
|
-
|
|
526
|
-
Or consult the documentation online at
|
|
527
|
-
https://www.mcstas.org/download/components/
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
NCrystal : A library for thermal neutron transport in crystals and other materials
|
|
2
|
+
----------------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
The `ncrystal-python` package provides the Python API and command-line scripts
|
|
5
|
+
for NCrystal. To function it needs to acess NCrystal shared library behind the
|
|
6
|
+
scenes, and as such it requires the `ncrystal-core` package to function.
|
|
7
|
+
|
|
8
|
+
In conda and Python environments, it is recommended that most users simply
|
|
9
|
+
install and depend on the package named `ncrystal` which itself depends on both
|
|
10
|
+
`ncrystal-core` and `ncrystal-python`.
|
|
11
|
+
|
|
12
|
+
Note that to support some esoteric installations, the `ncrystal-python` package
|
|
13
|
+
does not itself depend on the `ncrystal-core` package, which is another reason
|
|
14
|
+
that most users are recommended to simply install or depend only on the package
|
|
15
|
+
named `ncrystal`.
|
|
16
|
+
|
|
17
|
+
Installation of the `ncrystal-python` package more specifically provides (in
|
|
18
|
+
addition to what is found in the `ncrystal-core` package):
|
|
19
|
+
|
|
20
|
+
- The NCrystal python module.
|
|
21
|
+
- This allows you to do `import NCrystal` and use the Python API of NCrystal.
|
|
22
|
+
- Command-line utilities.
|
|
23
|
+
- These commands (e.g. `nctool`, `ncrystal_cif2ncmat`, ...) are actually
|
|
24
|
+
themselves written in Python, and can also be accessed from the Python API
|
|
25
|
+
itself via the `NCrystal.cli` module.
|
|
26
|
+
- Note that the special command `ncrystal-config` is provided by the
|
|
27
|
+
`ncrystal-core` package, _not_ the `ncrystal-python` package.
|
|
28
|
+
- Note that the `ncrystal-python` package can only be installed via Python
|
|
29
|
+
installation tools like pip.
|
|
30
|
+
- For convenience, the `ncrystal-core` package has a dependency on `numpy`.
|
|
31
|
+
|
|
32
|
+
# Referencing NCrystal in scientific work
|
|
33
|
+
|
|
34
|
+
A very substantial effort went into developing NCrystal. If you use it for your
|
|
35
|
+
work, we would appreciate it if you would use the following primary reference in
|
|
36
|
+
your work:
|
|
37
|
+
|
|
38
|
+
X.-X. Cai and T. Kittelmann, NCrystal: A library for thermal neutron
|
|
39
|
+
transport, Computer Physics Communications 246 (2020) 106851,
|
|
40
|
+
https://doi.org/10.1016/j.cpc.2019.07.015
|
|
41
|
+
|
|
42
|
+
For work benefitting from elastic physics (e.g. Bragg diffraction), we
|
|
43
|
+
furthermore request that you additionally also use the following reference in
|
|
44
|
+
your work:
|
|
45
|
+
|
|
46
|
+
T. Kittelmann and X.-X. Cai, Elastic neutron scattering models
|
|
47
|
+
for NCrystal, Computer Physics Communications 267 (2021) 108082,
|
|
48
|
+
https://doi.org/10.1016/j.cpc.2021.108082
|
|
49
|
+
|
|
50
|
+
For work benefitting from our inelastic physics, we furthermore request that you
|
|
51
|
+
additionally also use the following reference in your work:
|
|
52
|
+
|
|
53
|
+
X.-X. Cai, T. Kittelmann, et. al., "Rejection-based sampling of inelastic
|
|
54
|
+
neutron scattering", Journal of Computational Physics 380 (2019) 400-407,
|
|
55
|
+
https://doi.org/10.1016/j.jcp.2018.11.043
|
|
56
|
+
|
|
@@ -55,7 +55,7 @@ For detailed usage conditions and licensing of this open source project, see:
|
|
|
55
55
|
|
|
56
56
|
#NB: Synchronize meta-data below with fields in setup.py+template_setup.py.in meta data:
|
|
57
57
|
__license__ = "Apache 2.0, http://www.apache.org/licenses/LICENSE-2.0"
|
|
58
|
-
__version__ = '4.1.
|
|
58
|
+
__version__ = '4.1.4'
|
|
59
59
|
__status__ = "Production"
|
|
60
60
|
__author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)"
|
|
61
61
|
__copyright__ = "Copyright 2015-2024 %s"%__author__
|
|
@@ -19,11 +19,10 @@
|
|
|
19
19
|
## ##
|
|
20
20
|
################################################################################
|
|
21
21
|
|
|
22
|
-
"""Implementation of the built-in
|
|
22
|
+
"""Implementation of the built-in tests."""
|
|
23
23
|
|
|
24
|
-
__all__ = ['test','test_cmdline','
|
|
24
|
+
__all__ = ['test','test_cmdline','test_all']
|
|
25
25
|
from ._common import print as _nc_print
|
|
26
|
-
import contextlib as _contextlib
|
|
27
26
|
|
|
28
27
|
def test( verbose = False ):
|
|
29
28
|
"""Quick test that NCrystal works as expected in the current installation."""
|
|
@@ -38,28 +37,10 @@ def test_cmdline( verbose = False ):
|
|
|
38
37
|
if verbose!='quiet':
|
|
39
38
|
_nc_print("Tests completed succesfully")
|
|
40
39
|
|
|
41
|
-
def test_cmake( verbose = False ):
|
|
42
|
-
"""Quick test that the NCrystal installation supports down-stream CMake/C++
|
|
43
|
-
projects (possibly after using ncrystal-config to get CMAKE_PREFIX_PATH and
|
|
44
|
-
(DY)LD_LIBRARY_PATHS setup).
|
|
45
|
-
"""
|
|
46
|
-
_actual_test_cmake( verbose = verbose, ignore_if_absent = False )
|
|
47
|
-
if verbose!='quiet':
|
|
48
|
-
_nc_print("Tests completed succesfully")
|
|
49
|
-
|
|
50
|
-
def test_extra( verbose = False ):
|
|
51
|
-
"""Run both test() and test_cmdline(). If CMake is present, also run test_cmake()."""
|
|
52
|
-
_actualtest( verbose = verbose )
|
|
53
|
-
_actual_test_cmdline( verbose = verbose )
|
|
54
|
-
_actual_test_cmake( verbose = verbose, ignore_if_absent = True )
|
|
55
|
-
if verbose!='quiet':
|
|
56
|
-
_nc_print("Tests completed succesfully")
|
|
57
|
-
|
|
58
40
|
def test_all( verbose = False ):
|
|
59
|
-
"""Run both test()
|
|
41
|
+
"""Run both test() and test_cmdline()."""
|
|
60
42
|
_actualtest( verbose = verbose )
|
|
61
43
|
_actual_test_cmdline( verbose = verbose )
|
|
62
|
-
_actual_test_cmake( verbose = verbose, ignore_if_absent = False )
|
|
63
44
|
if verbose!='quiet':
|
|
64
45
|
_nc_print("Tests completed succesfully")
|
|
65
46
|
|
|
@@ -396,22 +377,13 @@ def _create_pdfpages_inspector( real_pdfpages ):
|
|
|
396
377
|
realobj = real_pdfpages,
|
|
397
378
|
subfcts = [ ('__call__',dict(subfcts=['savefig','close'])) ] )
|
|
398
379
|
|
|
399
|
-
def _run_cmd( cmd
|
|
380
|
+
def _run_cmd( cmd ):
|
|
400
381
|
import sys
|
|
401
382
|
import subprocess
|
|
402
383
|
sys.stdout.flush()
|
|
403
384
|
sys.stderr.flush()
|
|
404
|
-
if env and sys.platform == 'darwin':
|
|
405
|
-
#osx's system protection #$%#^ is so damn annoying:
|
|
406
|
-
for name in ['DYLD_LIBRARY_PATH','LD_LIBRARY_PATH']:
|
|
407
|
-
v = env.get(name)
|
|
408
|
-
if v is not None:
|
|
409
|
-
from shlex import quote
|
|
410
|
-
#NB: "export A=B" is posix, not bash, so hopefully OK on all OSX
|
|
411
|
-
#shells:
|
|
412
|
-
cmd = 'export %s=%s && %s'%(name,quote(v),cmd)
|
|
413
385
|
try:
|
|
414
|
-
p = subprocess.Popen( cmd, shell=True,
|
|
386
|
+
p = subprocess.Popen( cmd, shell=True,
|
|
415
387
|
stdout=subprocess.PIPE,
|
|
416
388
|
stderr=subprocess.PIPE )
|
|
417
389
|
output = p.communicate()[0]
|
|
@@ -463,117 +435,3 @@ def _actual_test_cmdline( verbose ):
|
|
|
463
435
|
if not ok:
|
|
464
436
|
raise RuntimeError('Command failed: %s'%cmd)
|
|
465
437
|
prfct('testing of cmd-line utilities done')
|
|
466
|
-
|
|
467
|
-
@_contextlib.contextmanager
|
|
468
|
-
def _work_in_tmpdir():
|
|
469
|
-
"""Context manager for working in a temporary directory (automatically created+cleaned) and then switching back"""
|
|
470
|
-
import os
|
|
471
|
-
import tempfile
|
|
472
|
-
the_cwd = os.getcwd()
|
|
473
|
-
with tempfile.TemporaryDirectory() as tmpdir:
|
|
474
|
-
try:
|
|
475
|
-
os.chdir(tmpdir)
|
|
476
|
-
yield
|
|
477
|
-
finally:
|
|
478
|
-
os.chdir(the_cwd)#Important to leave tmpdir *before* deletion, to
|
|
479
|
-
#avoid PermissionError on Windows.
|
|
480
|
-
|
|
481
|
-
def _actual_test_cmake( verbose = False, ignore_if_absent = False ):
|
|
482
|
-
prfct = _get_prfct( verbose )
|
|
483
|
-
prfct('starting testing of compiled downstream cmake-based projects')
|
|
484
|
-
import shutil
|
|
485
|
-
cmakecmd = shutil.which('cmake')
|
|
486
|
-
if not cmakecmd:
|
|
487
|
-
if ignore_if_absent:
|
|
488
|
-
prfct('Skipping CMake test since "cmake" command not found.')
|
|
489
|
-
return
|
|
490
|
-
raise RuntimeError('cmake command not found')
|
|
491
|
-
|
|
492
|
-
prfct('Using cmake command: %s'%cmakecmd)
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
def _singleline2str( x ):
|
|
496
|
-
return ((x.decode() if hasattr(x,'decode') else x) or '').strip()
|
|
497
|
-
|
|
498
|
-
_cmd = 'ncrystal-config --show cmakedir'
|
|
499
|
-
ok, ncrystal_cmakedir = _run_cmd(_cmd)
|
|
500
|
-
if not ok:
|
|
501
|
-
raise RuntimeError('Command failed: %s'%_cmd)
|
|
502
|
-
ncrystal_cmakedir = _singleline2str(ncrystal_cmakedir)
|
|
503
|
-
prfct('ncrystal-config gives cmakedir: %s'%ncrystal_cmakedir)
|
|
504
|
-
_cmd = 'ncrystal-config --show libdir'
|
|
505
|
-
ok, ncrystal_libdir = _run_cmd(_cmd)
|
|
506
|
-
if not ok:
|
|
507
|
-
raise RuntimeError('Command failed: %s'%_cmd)
|
|
508
|
-
ncrystal_libdir = _singleline2str(ncrystal_libdir)
|
|
509
|
-
prfct('ncrystal-config gives libdir: %s'%ncrystal_libdir)
|
|
510
|
-
|
|
511
|
-
def prepend_to_path( envdict, pathvar, entry ):
|
|
512
|
-
from shlex import quote
|
|
513
|
-
entry = quote(((entry.decode() if hasattr(entry,'decode') else entry) or '').strip())
|
|
514
|
-
if not entry:
|
|
515
|
-
return
|
|
516
|
-
ll = [ entry ]
|
|
517
|
-
orig = envdict.get(pathvar,'')
|
|
518
|
-
if orig:
|
|
519
|
-
ll.append( orig )
|
|
520
|
-
envdict[pathvar] = ':'.join(ll)
|
|
521
|
-
|
|
522
|
-
import os
|
|
523
|
-
cmake_env = os.environ.copy()
|
|
524
|
-
runtime_env = os.environ.copy()
|
|
525
|
-
prfct('Testing with cmakedir added to CMAKE_PREFIX_PATH and libdir added to (DY)LD_LIBRARY_PATH')
|
|
526
|
-
prepend_to_path( cmake_env, 'CMAKE_PREFIX_PATH', ncrystal_cmakedir )
|
|
527
|
-
prepend_to_path( runtime_env, 'LD_LIBRARY_PATH', ncrystal_libdir )
|
|
528
|
-
prepend_to_path( runtime_env, 'DYLD_LIBRARY_PATH', ncrystal_libdir )
|
|
529
|
-
def runcmake(args,apply_CMAKE_ARGS=True):
|
|
530
|
-
cmake_args = cmake_env.get('CMAKE_ARGS','') if apply_CMAKE_ARGS else ''
|
|
531
|
-
cmd=f'{cmakecmd} {cmake_args} {args}'
|
|
532
|
-
ok, output = _run_cmd(cmd, env=cmake_env)
|
|
533
|
-
prfct(f'Launching: {cmd}')
|
|
534
|
-
if not ok:
|
|
535
|
-
raise RuntimeError(f'Test command failed: {cmd}')
|
|
536
|
-
|
|
537
|
-
downstream_cmake = """
|
|
538
|
-
cmake_minimum_required(VERSION 3.10...3.24)
|
|
539
|
-
project(MyExampleProject LANGUAGES CXX)
|
|
540
|
-
find_package(NCrystal REQUIRED)
|
|
541
|
-
file(WRITE "${PROJECT_BINARY_DIR}/cppsrc.cpp" "
|
|
542
|
-
#include \\"NCrystal/NCrystal.hh\\"
|
|
543
|
-
#include <iostream>
|
|
544
|
-
int main() {
|
|
545
|
-
auto pc = NCrystal::createScatter( \\"Al_sg225.ncmat;dcutoff=0.5;temp=25C\\" );
|
|
546
|
-
auto wl = NCrystal::NeutronWavelength{1.8};
|
|
547
|
-
auto xsect = pc.crossSectionIsotropic( wl );
|
|
548
|
-
std::cout << \\"Powder Al x-sect at \\" << wl << \\" is \\" << xsect << std::endl;
|
|
549
|
-
return 0;
|
|
550
|
-
}
|
|
551
|
-
")
|
|
552
|
-
add_executable(exampleapp "${PROJECT_BINARY_DIR}/cppsrc.cpp")
|
|
553
|
-
target_link_libraries( exampleapp NCrystal::NCrystal )
|
|
554
|
-
install( TARGETS exampleapp DESTINATION bin )
|
|
555
|
-
"""
|
|
556
|
-
|
|
557
|
-
import pathlib
|
|
558
|
-
with _work_in_tmpdir():
|
|
559
|
-
td = pathlib.Path('.').absolute()
|
|
560
|
-
( td / 'src' ).mkdir()
|
|
561
|
-
( td / 'src' / 'CMakeLists.txt' ).write_text(downstream_cmake)
|
|
562
|
-
( td / 'bld' ).mkdir()
|
|
563
|
-
os.chdir( td / 'bld' )
|
|
564
|
-
runcmake('../src -DCMAKE_INSTALL_PREFIX=../install')
|
|
565
|
-
runcmake('--build . --target install --config Release',apply_CMAKE_ARGS=False)
|
|
566
|
-
os.chdir( td )
|
|
567
|
-
app = ( td / 'install' / 'bin' / 'exampleapp' )
|
|
568
|
-
if not app.exists():
|
|
569
|
-
raise RuntimeError('Could not produce example app in downstream cmake project')
|
|
570
|
-
prfct(f'Launching: {app}')
|
|
571
|
-
ok, output = _run_cmd(str(app),env=runtime_env)
|
|
572
|
-
if not ok:
|
|
573
|
-
raise RuntimeError('Could not launch example app compiled in downstream cmake project')
|
|
574
|
-
#envrun = os.environ.copy()
|
|
575
|
-
expected_output='Powder Al x-sect at 1.8Aa is 1.44816barn'
|
|
576
|
-
if not output.decode().strip()==expected_output:
|
|
577
|
-
raise RuntimeError('Example app compiled in downstream cmake project produces unexpected output')
|
|
578
|
-
prfct('App produced expected output')
|
|
579
|
-
prfct('testing of compiled downstream cmake-based projects done')
|
|
@@ -22,55 +22,38 @@
|
|
|
22
22
|
"""Module which is intended to trigger the built-in test from the command line
|
|
23
23
|
by running python3 -m NCrystal.test"""
|
|
24
24
|
|
|
25
|
-
from ._testimpl import ( test, test_cmdline,
|
|
26
|
-
test_extra, test_all ) # noqa F401
|
|
25
|
+
from ._testimpl import ( test, test_cmdline, test_all ) # noqa F401
|
|
27
26
|
|
|
28
27
|
if __name__ == '__main__':
|
|
29
28
|
from . import _testimpl as _tests
|
|
30
29
|
import sys
|
|
31
30
|
args=set(sys.argv[1:])
|
|
32
31
|
if '-h' in args or '--help' in args:
|
|
33
|
-
print('Run tests. By default the standard tests if no keywords
|
|
34
|
-
'
|
|
32
|
+
print('Run tests. By default the standard tests if no keywords'
|
|
33
|
+
' (std/cmdline/all)\nare supplied (use "verbose"/"quiet" for'
|
|
34
|
+
' printout control).')
|
|
35
35
|
raise SystemExit
|
|
36
36
|
do_quiet = ('quiet' in args)
|
|
37
37
|
do_verbose = ( not do_quiet) and ('verbose' in args)
|
|
38
|
-
do_cmake = ('cmake' in args)
|
|
39
38
|
do_cmdline = ('cmdline' in args)
|
|
40
|
-
do_extra = ('extra' in args)
|
|
41
39
|
do_all = ('all' in args)
|
|
42
40
|
do_std = ('std' in args)
|
|
43
41
|
|
|
44
|
-
if not
|
|
42
|
+
if not do_cmdline and not do_all:
|
|
45
43
|
do_std = True
|
|
46
44
|
|
|
47
|
-
|
|
45
|
+
if do_all:
|
|
46
|
+
do_std = True
|
|
47
|
+
do_cmdline = True
|
|
48
|
+
|
|
49
|
+
unknown = args - set(['cmdline','all','std','verbose','quiet'])
|
|
48
50
|
for u in unknown:
|
|
49
51
|
raise SystemExit('Unknown keyword: %s'%u)
|
|
50
52
|
|
|
51
53
|
test_kwargs = dict( verbose = ('quiet' if do_quiet else do_verbose) )
|
|
52
|
-
if do_extra and do_cmake:
|
|
53
|
-
do_all = True
|
|
54
|
-
|
|
55
|
-
if ( do_cmake and do_std and do_cmdline ):
|
|
56
|
-
do_all = True
|
|
57
|
-
|
|
58
|
-
if do_all:
|
|
59
|
-
_tests.test( **test_kwargs )
|
|
60
|
-
_tests.test_cmdline( **test_kwargs )
|
|
61
|
-
_tests.test_cmake( **test_kwargs )
|
|
62
|
-
raise SystemExit
|
|
63
|
-
|
|
64
|
-
if do_extra:
|
|
65
|
-
_tests.test_extra( **test_kwargs )
|
|
66
|
-
do_std = False
|
|
67
|
-
do_cmdline = False
|
|
68
54
|
|
|
69
55
|
if do_std:
|
|
70
56
|
_tests.test( **test_kwargs )
|
|
71
57
|
|
|
72
58
|
if do_cmdline:
|
|
73
59
|
_tests.test_cmdline( **test_kwargs )
|
|
74
|
-
|
|
75
|
-
if do_cmake:
|
|
76
|
-
_tests.test_cmake( **test_kwargs )
|