ncrystal-python 3.9.81__py3-none-any.whl
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/__init__.py +85 -0
- NCrystal/__main__.py +98 -0
- NCrystal/_chooks.py +854 -0
- NCrystal/_cli_cif2ncmat.py +269 -0
- NCrystal/_cli_endf2ncmat.py +503 -0
- NCrystal/_cli_hfg2ncmat.py +144 -0
- NCrystal/_cli_mcstasunion.py +74 -0
- NCrystal/_cli_ncmat2cpp.py +31 -0
- NCrystal/_cli_ncmat2hkl.py +180 -0
- NCrystal/_cli_nctool.py +1018 -0
- NCrystal/_cli_vdos2ncmat.py +463 -0
- NCrystal/_cli_verifyatompos.py +257 -0
- NCrystal/_cliimpl.py +307 -0
- NCrystal/_cliwrap_config.py +36 -0
- NCrystal/_common.py +499 -0
- NCrystal/_coreimpl.py +114 -0
- NCrystal/_hfgdata.py +546 -0
- NCrystal/_hklobjects.py +136 -0
- NCrystal/_is_std.py +0 -0
- NCrystal/_locatelib.py +210 -0
- NCrystal/_miscimpl.py +354 -0
- NCrystal/_mmc.py +757 -0
- NCrystal/_msg.py +60 -0
- NCrystal/_ncmat2cpp_impl.py +445 -0
- NCrystal/_ncmatimpl.py +2131 -0
- NCrystal/_numpy.py +76 -0
- NCrystal/_testimpl.py +579 -0
- NCrystal/api.py +56 -0
- NCrystal/atomdata.py +177 -0
- NCrystal/cfgstr.py +77 -0
- NCrystal/cifutils.py +1795 -0
- NCrystal/cli.py +96 -0
- NCrystal/constants.py +134 -0
- NCrystal/core.py +1910 -0
- NCrystal/datasrc.py +226 -0
- NCrystal/exceptions.py +66 -0
- NCrystal/hfg2ncmat.py +270 -0
- NCrystal/mcstasutils.py +438 -0
- NCrystal/misc.py +317 -0
- NCrystal/mmc.py +35 -0
- NCrystal/ncmat.py +778 -0
- NCrystal/ncmat2cpp.py +80 -0
- NCrystal/obsolete.py +67 -0
- NCrystal/plot.py +484 -0
- NCrystal/plugins.py +49 -0
- NCrystal/test.py +76 -0
- NCrystal/vdos.py +1034 -0
- ncrystal_python-3.9.81.dist-info/LICENSE +206 -0
- ncrystal_python-3.9.81.dist-info/METADATA +515 -0
- ncrystal_python-3.9.81.dist-info/RECORD +53 -0
- ncrystal_python-3.9.81.dist-info/WHEEL +5 -0
- ncrystal_python-3.9.81.dist-info/entry_points.txt +10 -0
- ncrystal_python-3.9.81.dist-info/top_level.txt +1 -0
NCrystal/cli.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
|
|
2
|
+
################################################################################
|
|
3
|
+
## ##
|
|
4
|
+
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
|
+
## ##
|
|
6
|
+
## Copyright 2015-2024 NCrystal developers ##
|
|
7
|
+
## ##
|
|
8
|
+
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
|
+
## you may not use this file except in compliance with the License. ##
|
|
10
|
+
## You may obtain a copy of the License at ##
|
|
11
|
+
## ##
|
|
12
|
+
## http://www.apache.org/licenses/LICENSE-2.0 ##
|
|
13
|
+
## ##
|
|
14
|
+
## Unless required by applicable law or agreed to in writing, software ##
|
|
15
|
+
## distributed under the License is distributed on an "AS IS" BASIS, ##
|
|
16
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ##
|
|
17
|
+
## See the License for the specific language governing permissions and ##
|
|
18
|
+
## limitations under the License. ##
|
|
19
|
+
## ##
|
|
20
|
+
################################################################################
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
Module providing access to the ncrystal commandline tools via the Python API.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
def cli_tool_list( canonical_names = True ):
|
|
29
|
+
"""
|
|
30
|
+
Get list of available NCrystal command line tools. The canonical_names flag
|
|
31
|
+
controls whether to return canonical (ncrystal_ncmat2cpp, nctool, ...) or
|
|
32
|
+
short (ncmat2cpp, nctool, ...) names.
|
|
33
|
+
"""
|
|
34
|
+
from ._cliimpl import cli_tool_list_impl
|
|
35
|
+
return cli_tool_list_impl( canonical_names = canonical_names )
|
|
36
|
+
|
|
37
|
+
def cli_tool_lookup( name ):
|
|
38
|
+
"""Try to lookup command line tool name, accepting various aliases, to for
|
|
39
|
+
instance recognise both short names like "ncmat2cpp" and canonical names
|
|
40
|
+
like "ncrystal_ncmat2cpp".
|
|
41
|
+
|
|
42
|
+
Returns a dictionary with both a 'canonical_name', 'short_name', and
|
|
43
|
+
'shellcmd'. Here, the 'canonical_name' is the canonical name of the
|
|
44
|
+
corresponding command-line script in standard installations, the
|
|
45
|
+
'short_name' is the shortest name which can be used to identify the tool,
|
|
46
|
+
and 'shellcmd' is the actual name of the shell command in the present
|
|
47
|
+
installation.
|
|
48
|
+
|
|
49
|
+
Returns None in case the name could not be resolved to an available tool.
|
|
50
|
+
|
|
51
|
+
"""
|
|
52
|
+
from ._cliimpl import cli_tool_lookup_impl
|
|
53
|
+
return cli_tool_lookup_impl( name )
|
|
54
|
+
|
|
55
|
+
def run( toolname, *arguments ):
|
|
56
|
+
"""Can be used to invoke ncrystal command-line tools such as nctool,
|
|
57
|
+
ncrystal_ncmat2cpp, ncrystal_hfg2ncmat, etc. directly via the Python API
|
|
58
|
+
without the need for spawning separate subprocesses or actually using a
|
|
59
|
+
shell to execute command scripts. It also makes it easier to invoke the
|
|
60
|
+
tools in a cross platform way, by staying exclusively in the Python API.
|
|
61
|
+
|
|
62
|
+
Example:
|
|
63
|
+
|
|
64
|
+
run('ncrystal_ncmat2cpp','Al_sg225.ncmat','-o','myal.cpp')
|
|
65
|
+
|
|
66
|
+
Is the same as running the command in the terminal (here typical unix shell
|
|
67
|
+
syntax):
|
|
68
|
+
|
|
69
|
+
$> ncrystal_ncmat2cpp Al_sg225.ncmat -o myal.cpp
|
|
70
|
+
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
from ._cliimpl import _resolve_cmd_and_import_climod
|
|
74
|
+
climod, argv = _resolve_cmd_and_import_climod( toolname, arguments )
|
|
75
|
+
|
|
76
|
+
from ._cliimpl import ( ctxmgr_modify_argparse_creation,
|
|
77
|
+
_cli_call_from_pyapi_ctx )
|
|
78
|
+
try:
|
|
79
|
+
with _cli_call_from_pyapi_ctx():
|
|
80
|
+
with ctxmgr_modify_argparse_creation(exit_on_error = False,
|
|
81
|
+
redirect_stderr_to_stdout = True):
|
|
82
|
+
climod.main( argv )
|
|
83
|
+
except SystemExit as e:
|
|
84
|
+
#Map SystemExit to either a clean return or a RuntimeError.
|
|
85
|
+
if str(e) in ('','0'):
|
|
86
|
+
return#ended OK
|
|
87
|
+
if len(e.args)==1 and isinstance(e.args[0],int):
|
|
88
|
+
ec = e.args[0]
|
|
89
|
+
elif str(e).isdigit():
|
|
90
|
+
ec = str(e)
|
|
91
|
+
else:
|
|
92
|
+
ec = 1
|
|
93
|
+
msg = f'Command ended with exit code {ec}'
|
|
94
|
+
if not str(e).isdigit():
|
|
95
|
+
msg = str(e)
|
|
96
|
+
raise RuntimeError(msg) from e
|
NCrystal/constants.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
|
|
2
|
+
################################################################################
|
|
3
|
+
## ##
|
|
4
|
+
## This file is part of NCrystal (see https://mctools.github.io/ncrystal/) ##
|
|
5
|
+
## ##
|
|
6
|
+
## Copyright 2015-2024 NCrystal developers ##
|
|
7
|
+
## ##
|
|
8
|
+
## Licensed under the Apache License, Version 2.0 (the "License"); ##
|
|
9
|
+
## you may not use this file except in compliance with the License. ##
|
|
10
|
+
## You may obtain a copy of the License at ##
|
|
11
|
+
## ##
|
|
12
|
+
## http://www.apache.org/licenses/LICENSE-2.0 ##
|
|
13
|
+
## ##
|
|
14
|
+
## Unless required by applicable law or agreed to in writing, software ##
|
|
15
|
+
## distributed under the License is distributed on an "AS IS" BASIS, ##
|
|
16
|
+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ##
|
|
17
|
+
## See the License for the specific language governing permissions and ##
|
|
18
|
+
## limitations under the License. ##
|
|
19
|
+
## ##
|
|
20
|
+
################################################################################
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
Various constants and neutron energy / wavelength / wavenumber conversions
|
|
25
|
+
methods like for instance wl2ekin and ekin2wl. Note that all conversion
|
|
26
|
+
functions can be used with numpy arrays in addition to scalar numbers.
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
#some constants (NB: Copied here from NCMath.hh - must keep synchronized!!):
|
|
31
|
+
|
|
32
|
+
from ._numpy import _ensure_numpy, _np
|
|
33
|
+
|
|
34
|
+
constant_c = 299792458e10# speed of light in Aa/s
|
|
35
|
+
constant_dalton2kg = 1.660539040e-27# amu to kg
|
|
36
|
+
constant_dalton2eVc2 = 931494095.17# amu to eV/c^2
|
|
37
|
+
constant_avogadro = 6.022140857e23# mol^-1
|
|
38
|
+
constant_boltzmann = 8.6173303e-5# eV/K
|
|
39
|
+
const_neutron_mass_amu = 1.00866491588# [amu]
|
|
40
|
+
constant_planck = 4.135667662e-15 # [eV*s]
|
|
41
|
+
|
|
42
|
+
kPi = 3.1415926535897932384626433832795028841971694
|
|
43
|
+
k2Pi = 6.2831853071795864769252867665590057683943388
|
|
44
|
+
k4Pidiv100 = 0.125663706143591729538505735331180115367886776
|
|
45
|
+
k4PiSq = 39.4784176043574344753379639995046045412547976
|
|
46
|
+
kInf = float('inf')
|
|
47
|
+
|
|
48
|
+
_as_np_array = ( lambda x : _np.asarray(x,dtype=float) ) if _np else ( lambda *a,**kwargs : _ensure_numpy() )
|
|
49
|
+
def wlsq2ekin( wlsq ):
|
|
50
|
+
"""Neutron wavelength squared (angstrom^2) to energy (eV)"""
|
|
51
|
+
if hasattr(wlsq,'__len__'):
|
|
52
|
+
x = _as_np_array( wlsq )
|
|
53
|
+
wlsqnonzero = ( x != 0.0 )
|
|
54
|
+
wlsqinv = 1.0 / _np.where( wlsqnonzero, x, 1.0)#fallback 1.0 wont be used
|
|
55
|
+
return _const_wlsqekin * _np.where( wlsqnonzero, wlsqinv, kInf )
|
|
56
|
+
else:
|
|
57
|
+
return _const_wlsqekin / wlsq if wlsq else kInf
|
|
58
|
+
|
|
59
|
+
def wl2ekin( wl ):
|
|
60
|
+
"""Neutron wavelength (angstrom) to energy (eV)"""
|
|
61
|
+
if hasattr(wl,'__len__'):
|
|
62
|
+
x = _as_np_array( wl )
|
|
63
|
+
return wlsq2ekin( x*x )
|
|
64
|
+
else:
|
|
65
|
+
return wlsq2ekin( wl*wl )
|
|
66
|
+
|
|
67
|
+
def ekin2wl( ekin ):
|
|
68
|
+
"""Neutron energy (eV) to wavelength (angstrom)"""
|
|
69
|
+
if hasattr(ekin,'__len__'):
|
|
70
|
+
x = _as_np_array( ekin )
|
|
71
|
+
ekinnonzero = x != 0.0
|
|
72
|
+
ekininv = 1.0 / _np.where( ekinnonzero, x, 1.0)#fallback 1.0 wont be used
|
|
73
|
+
return _np.sqrt( _const_wlsqekin * _np.where( ekinnonzero, ekininv, kInf ) )
|
|
74
|
+
else:
|
|
75
|
+
from math import sqrt as _math_sqrt
|
|
76
|
+
return _math_sqrt( _const_wlsqekin / ekin ) if ekin else kInf
|
|
77
|
+
|
|
78
|
+
def ekin2wlsq( ekin ):
|
|
79
|
+
"""Neutron energy (eV) to wavelength squared (angstrom^2)"""
|
|
80
|
+
if hasattr(ekin,'__len__'):
|
|
81
|
+
x = _as_np_array( ekin )
|
|
82
|
+
ekinnonzero = x != 0.0
|
|
83
|
+
ekininv = 1.0 / _np.where( ekinnonzero, x, 1.0)#fallback 1.0 wont be used
|
|
84
|
+
return _const_wlsqekin * _np.where( ekinnonzero, ekininv, kInf )
|
|
85
|
+
else:
|
|
86
|
+
return ( _const_wlsqekin / ekin ) if ekin else kInf
|
|
87
|
+
|
|
88
|
+
def ekin2wlsqinv( ekin ):
|
|
89
|
+
"""Neutron energy (eV) to inverse wavelength squared (1/angstrom^2)"""
|
|
90
|
+
return ekin * _const_inv_wlsqekin#constant is 1/_const_wlsqekin
|
|
91
|
+
|
|
92
|
+
_const_wlsqekin = 0.081804209605330899 # ekin = _const_wlsqekin /wl^2
|
|
93
|
+
_const_inv_wlsqekin = 12.22430978582345950656 # 1 / _const_wlsqekin
|
|
94
|
+
_const_ekin2ksq_factor = k4PiSq * _const_inv_wlsqekin
|
|
95
|
+
_const_ksq2ekin_factor = 1.0 / _const_ekin2ksq_factor
|
|
96
|
+
|
|
97
|
+
def ekin2ksq( ekin ):
|
|
98
|
+
"""Neutron energy (eV) to wavenumber squared, (k^2, in units of 1/angstrom^2)"""
|
|
99
|
+
return _const_ekin2ksq_factor * ekin
|
|
100
|
+
|
|
101
|
+
def ekin2k( ekin ):
|
|
102
|
+
"""Neutron energy (eV) to wavenumber, (k, in units of 1/angstrom)"""
|
|
103
|
+
if hasattr(ekin,'__len__'):
|
|
104
|
+
_ = _const_ekin2ksq_factor * _as_np_array( ekin )
|
|
105
|
+
return _np.sqrt( _ )
|
|
106
|
+
else:
|
|
107
|
+
from math import sqrt
|
|
108
|
+
return sqrt( _const_ekin2ksq_factor * ekin )
|
|
109
|
+
|
|
110
|
+
def ksq2ekin( ksq ):
|
|
111
|
+
"""Wavenumber squared, (k^2, in units of 1/angstrom^2) to neutron energy (eV)"""
|
|
112
|
+
return _const_ksq2ekin_factor * ksq
|
|
113
|
+
|
|
114
|
+
def wl2k( wl ):
|
|
115
|
+
"""Neutron wavelength (angstrom) to wavenumber, (k, in units of 1/angstrom)"""
|
|
116
|
+
if hasattr(wl,'__len__'):
|
|
117
|
+
x = _as_np_array( wl )
|
|
118
|
+
wlnonzero = x != 0.0
|
|
119
|
+
wlinv = 1.0 / _np.where( wlnonzero, x, 1.0)#fallback 1.0 wont be used
|
|
120
|
+
return k2Pi * _np.where( wlnonzero, wlinv, kInf )
|
|
121
|
+
else:
|
|
122
|
+
return k2Pi / wl if wl else kInf
|
|
123
|
+
|
|
124
|
+
def wl2ksq( wl ):
|
|
125
|
+
"""Neutron wavelength (angstrom) to wavenumber squared, (k^2, in units of 1/angstrom^2)"""
|
|
126
|
+
return ( wl2k(wl) )**2
|
|
127
|
+
|
|
128
|
+
def k2wl( k ):
|
|
129
|
+
"""Wavenumber, (k, in units of 1/angstrom) to neutron wavelength (angstrom)"""
|
|
130
|
+
return wl2k( k )#using that k2wl = wl2k (both are f(x)=2pi/x)
|
|
131
|
+
|
|
132
|
+
def k2ekin( k ):
|
|
133
|
+
"""Wavenumber, (k, in units of 1/angstrom) to neutron energy (eV)"""
|
|
134
|
+
return ksq2ekin( k * k )
|