ncrystal-python 4.2.12__py3-none-any.whl → 4.3.2__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 +1 -1
- NCrystal/_chooks.py +93 -47
- NCrystal/_cli_cif2ncmat.py +7 -0
- NCrystal/_cli_endf2ncmat.py +11 -2
- NCrystal/_cli_hfg2ncmat.py +7 -0
- NCrystal/_cli_mcstasunion.py +7 -0
- NCrystal/_cli_minimc.py +507 -0
- NCrystal/_cli_ncmat2cpp.py +7 -0
- NCrystal/_cli_ncmat2endf.py +7 -0
- NCrystal/_cli_ncmat2hkl.py +7 -0
- NCrystal/_cli_nctool.py +37 -74
- NCrystal/_cli_query.py +92 -0
- NCrystal/_cli_vdos2ncmat.py +9 -0
- NCrystal/_cli_verifyatompos.py +7 -0
- NCrystal/_clientry.py +142 -0
- NCrystal/_cliimpl.py +12 -3
- NCrystal/_cliwrap_config.py +15 -2
- NCrystal/_common.py +99 -0
- NCrystal/_coreimpl.py +0 -9
- NCrystal/_hklobjects.py +1 -1
- NCrystal/_miscimpl.py +21 -2
- NCrystal/_mmc.py +66 -444
- NCrystal/_mmc_doc.py +473 -0
- NCrystal/_mmc_impl.py +444 -0
- NCrystal/_ncmatimpl.py +22 -12
- NCrystal/_testimpl.py +21 -11
- NCrystal/cifutils.py +1 -1
- NCrystal/core.py +22 -3
- NCrystal/hist.py +1078 -0
- NCrystal/mcstasutils.py +9 -4
- NCrystal/minimc.py +146 -0
- NCrystal/minimc_objects.py +481 -0
- NCrystal/misc.py +16 -0
- NCrystal/mmc.py +4 -12
- NCrystal/ncmat.py +32 -1
- NCrystal/plot.py +318 -115
- NCrystal/vdos.py +59 -70
- {ncrystal_python-4.2.12.dist-info → ncrystal_python-4.3.2.dist-info}/METADATA +1 -1
- ncrystal_python-4.3.2.dist-info/RECORD +65 -0
- {ncrystal_python-4.2.12.dist-info → ncrystal_python-4.3.2.dist-info}/WHEEL +1 -1
- {ncrystal_python-4.2.12.dist-info → ncrystal_python-4.3.2.dist-info}/entry_points.txt +3 -0
- NCrystal/_hist.py +0 -297
- ncrystal_python-4.2.12.dist-info/RECORD +0 -58
- {ncrystal_python-4.2.12.dist-info → ncrystal_python-4.3.2.dist-info}/licenses/LICENSE +0 -0
- {ncrystal_python-4.2.12.dist-info → ncrystal_python-4.3.2.dist-info}/top_level.txt +0 -0
NCrystal/__init__.py
CHANGED
|
@@ -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.2
|
|
58
|
+
__version__ = '4.3.2'
|
|
59
59
|
__status__ = "Production"
|
|
60
60
|
__author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)"
|
|
61
61
|
__copyright__ = "Copyright 2015-2024 %s"%__author__
|
NCrystal/_chooks.py
CHANGED
|
@@ -162,8 +162,9 @@ def _load(nclib_filename, ncrystal_namespace_protection ):
|
|
|
162
162
|
def fct(*args):
|
|
163
163
|
return raw(*args)
|
|
164
164
|
if error_check:
|
|
165
|
-
#NB: we should read about return types in the ctypes
|
|
166
|
-
#can just set an error checking function as
|
|
165
|
+
#NB: we should read about return types in the ctypes
|
|
166
|
+
#tutorial. Apparently one can just set an error checking function as
|
|
167
|
+
#the restype.
|
|
167
168
|
raw_fct = fct
|
|
168
169
|
def fcte(*aaa):
|
|
169
170
|
r = raw_fct(*aaa)
|
|
@@ -284,12 +285,15 @@ def _load(nclib_filename, ncrystal_namespace_protection ):
|
|
|
284
285
|
functions['iter_hkllist']=iter_hkllist
|
|
285
286
|
|
|
286
287
|
_raw_dealloc_dblptr = _wrap('ncrystal_dealloc_doubleptr',None,(_dblp,),hide=True)
|
|
287
|
-
|
|
288
|
+
|
|
289
|
+
def _cptr_to_nparray( cptr, n, dealloc = True ):
|
|
288
290
|
import numpy.ctypeslib as _np_ctypeslib
|
|
289
|
-
|
|
290
|
-
|
|
291
|
+
s = (int( n.value if hasattr(n,'value') else n ),)
|
|
292
|
+
a = _np_ctypeslib.as_array( cptr, shape=s )
|
|
293
|
+
a = a.copy()
|
|
294
|
+
if dealloc:
|
|
291
295
|
_raw_dealloc_dblptr(cptr)
|
|
292
|
-
return
|
|
296
|
+
return a
|
|
293
297
|
|
|
294
298
|
_wrap('ncrystal_info_ndyninfo',_uint,(ncrystal_info_t,))
|
|
295
299
|
_raw_di_base = _wrap('ncrystal_dyninfo_base',None,(ncrystal_info_t,_uint,_dblp,_uintp,_dblp,_uintp),hide=True)
|
|
@@ -820,49 +824,91 @@ def _load(nclib_filename, ncrystal_namespace_protection ):
|
|
|
820
824
|
_raw_setmsghandler(keepalive[-1])
|
|
821
825
|
functions['setmsghandler'] = ncrystal_setmsghandler
|
|
822
826
|
|
|
823
|
-
|
|
824
|
-
(_uint,_uint,
|
|
825
|
-
_cstr,_cstr,_cstr,
|
|
826
|
-
_charptrptr,_uintp,_dblpp,_dblpp),
|
|
827
|
-
hide=True)
|
|
828
|
-
def nc_runmmcsim_stdengine( nthreads,
|
|
829
|
-
tally_detail_lvl,
|
|
830
|
-
mat_cfgstr,
|
|
831
|
-
mmc_geomcfg,
|
|
832
|
-
mmc_srccfg ):
|
|
833
|
-
nthreads_ = _uint(int(nthreads))
|
|
834
|
-
assert 0<=tally_detail_lvl<=2
|
|
835
|
-
tally_detail_lvl_ = _uint(int(tally_detail_lvl))
|
|
836
|
-
mat_cfgstr_ = _str2cstr(mat_cfgstr)
|
|
837
|
-
mmc_geomcfg_ = _str2cstr(mmc_geomcfg)
|
|
838
|
-
mmc_srccfg_ = _str2cstr(mmc_srccfg)
|
|
839
|
-
t_json = _charptr()
|
|
840
|
-
t_exitangle_nbins = _uint()
|
|
841
|
-
t_exitangle_ct = _dblp()
|
|
842
|
-
t_exitangle_errsq = _dblp()
|
|
843
|
-
_raw_runmmcsim_stdengine( nthreads_,
|
|
844
|
-
tally_detail_lvl_,
|
|
845
|
-
mat_cfgstr_,
|
|
846
|
-
mmc_geomcfg_,
|
|
847
|
-
mmc_srccfg_,
|
|
848
|
-
t_json,
|
|
849
|
-
t_exitangle_nbins,
|
|
850
|
-
ctypes.byref(t_exitangle_ct),
|
|
851
|
-
ctypes.byref(t_exitangle_errsq) )
|
|
852
|
-
if t_json is not None:
|
|
853
|
-
t_json_cstr = ctypes.cast(t_json,_cstr).value
|
|
854
|
-
if t_json_cstr is not None:
|
|
855
|
-
_ = _cstr2str(t_json_cstr)
|
|
856
|
-
_raw_deallocstr(t_json)
|
|
857
|
-
t_json = _
|
|
858
|
-
else:
|
|
859
|
-
t_json = None
|
|
827
|
+
_raw_jsonquery = _wrap('ncrystal_jsonquery',_charptr,(_cstr,), hide=True)
|
|
860
828
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
829
|
+
def prepare_query_cstr( query ):
|
|
830
|
+
if not query:
|
|
831
|
+
raise NCBadInput("Missing or empty query")
|
|
832
|
+
sc = '\x07'
|
|
833
|
+
str_query = sc.join(query)
|
|
834
|
+
if len(query) != str_query.count(sc)+1:
|
|
835
|
+
raise NCBadInput("Can not use character 0x07 (ASCII BEL) in"
|
|
836
|
+
" JSON query strings" )
|
|
837
|
+
return _str2cstr(str_query)
|
|
864
838
|
|
|
865
|
-
|
|
839
|
+
def decode_query_result( raw_str ):
|
|
840
|
+
assert raw_str is not None
|
|
841
|
+
res=_cstr2str(ctypes.cast(raw_str,_cstr).value)
|
|
842
|
+
_raw_deallocstr(raw_str)
|
|
843
|
+
return res
|
|
844
|
+
|
|
845
|
+
def jsonquery( query ):
|
|
846
|
+
cstr_query = prepare_query_cstr(query)
|
|
847
|
+
raw_str = _raw_jsonquery( cstr_query )
|
|
848
|
+
return decode_query_result(raw_str)
|
|
849
|
+
functions['jsonquery'] = jsonquery
|
|
866
850
|
|
|
851
|
+
_FLEXMMCRUNCBTYPE = ctypes.CFUNCTYPE( _uint, _dblpp, _ulong, _ulong )
|
|
852
|
+
_raw_flexmmcrun = _wrap( 'ncrystal_flexmmcrun',_charptr,
|
|
853
|
+
(_cstr,_cstr,_FLEXMMCRUNCBTYPE ), hide=True )
|
|
854
|
+
def flexmmcrun( query, user_callback, callback_options ):
|
|
855
|
+
_ensure_numpy()
|
|
856
|
+
cstr_query = prepare_query_cstr(query)
|
|
857
|
+
cb_errors = []
|
|
858
|
+
def cb_wrapper( data, cbtype, data_len ):
|
|
859
|
+
if cb_errors:
|
|
860
|
+
return 2
|
|
861
|
+
rv = 0
|
|
862
|
+
try:
|
|
863
|
+
cbtype = int(cbtype)
|
|
864
|
+
assert cbtype in (1,2)
|
|
865
|
+
|
|
866
|
+
n = int(data_len)
|
|
867
|
+
assert 0 < n <= 1000000000
|
|
868
|
+
def load( i ):
|
|
869
|
+
return _cptr_to_nparray( data[i], n, dealloc=False)
|
|
870
|
+
|
|
871
|
+
pydata = dict( x = load(0), y = load(1), z = load(2),
|
|
872
|
+
ux = load(3), uy = load(4), uz = load(5),
|
|
873
|
+
ekin = load(6), w = load(7), nscat = load(8),
|
|
874
|
+
nscat_inelas = load(9) )
|
|
875
|
+
if cbtype==2:
|
|
876
|
+
pydata.update(
|
|
877
|
+
dict( x0 = load(10), y0 = load(11), z0 = load(12),
|
|
878
|
+
ux0 = load(13),uy0 = load(14), uz0 = load(15),
|
|
879
|
+
ekin0 = load(16), w0 = load(17) )
|
|
880
|
+
)
|
|
881
|
+
|
|
882
|
+
user_rv = user_callback( pydata )
|
|
883
|
+
#TODO: Currently not aborting a long simjob on ctrl-C if
|
|
884
|
+
# nthreads>2. Tricky to fix.
|
|
885
|
+
if not bool(user_rv):
|
|
886
|
+
rv = 0 # STD (usual case)
|
|
887
|
+
else:
|
|
888
|
+
#HALTERR or HALTSRC:
|
|
889
|
+
rv = ( 2 if ( isinstance(user_rv,str)
|
|
890
|
+
and user_rv=='error' ) else 1 )
|
|
891
|
+
if rv == 2 and not cb_errors:
|
|
892
|
+
cb_errors.append(None)
|
|
893
|
+
except BaseException as exc:
|
|
894
|
+
rv = 2
|
|
895
|
+
cb_errors.append(exc)
|
|
896
|
+
del exc #maybe not needed, but exc.__traceback__ references the
|
|
897
|
+
#function frame, so the function frame best not
|
|
898
|
+
#reference exc.
|
|
899
|
+
return rv
|
|
900
|
+
|
|
901
|
+
cb_c = _FLEXMMCRUNCBTYPE(cb_wrapper)
|
|
902
|
+
cbopt_c = None
|
|
903
|
+
if callback_options is not None and callback_options.strip():
|
|
904
|
+
cbopt_c = _str2cstr(callback_options)
|
|
905
|
+
raw_str = _raw_flexmmcrun( cstr_query, cbopt_c, cb_c )
|
|
906
|
+
if cb_errors:
|
|
907
|
+
#Rethrow exception from callback function
|
|
908
|
+
user_callback_exception = cb_errors[0]
|
|
909
|
+
raise user_callback_exception
|
|
910
|
+
return decode_query_result(raw_str)
|
|
911
|
+
|
|
912
|
+
functions['flexmmcrun'] = flexmmcrun
|
|
867
913
|
|
|
868
914
|
return functions
|
NCrystal/_cli_cif2ncmat.py
CHANGED
|
@@ -23,6 +23,13 @@ from ._cliimpl import ( create_ArgumentParser,
|
|
|
23
23
|
cli_entry_point,
|
|
24
24
|
print )
|
|
25
25
|
|
|
26
|
+
def climod_metadata():
|
|
27
|
+
return dict(
|
|
28
|
+
displaygroup = 'conv',
|
|
29
|
+
displayorder = 10,
|
|
30
|
+
descr = "Create NCMAT data based on CIF input."
|
|
31
|
+
)
|
|
32
|
+
|
|
26
33
|
def parseArgs( progname, arglist, return_parser=False ):
|
|
27
34
|
import textwrap
|
|
28
35
|
helpw = 60
|
NCrystal/_cli_endf2ncmat.py
CHANGED
|
@@ -30,6 +30,13 @@ from . import core as nccore
|
|
|
30
30
|
import warnings
|
|
31
31
|
import pathlib
|
|
32
32
|
|
|
33
|
+
def climod_metadata():
|
|
34
|
+
return dict(
|
|
35
|
+
displaygroup = 'conv',
|
|
36
|
+
displayorder = 999,
|
|
37
|
+
descr = "Import ENDF data to NCMAT format (based on PyNE)."
|
|
38
|
+
)
|
|
39
|
+
|
|
33
40
|
__pynecache=[None]
|
|
34
41
|
def import_pyne():
|
|
35
42
|
global __pynecache
|
|
@@ -38,10 +45,12 @@ def import_pyne():
|
|
|
38
45
|
|
|
39
46
|
try:
|
|
40
47
|
with warnings.catch_warnings():
|
|
41
|
-
|
|
48
|
+
#silence annoying pyne.endf QAWarning's:
|
|
49
|
+
warnings.simplefilter("ignore")
|
|
42
50
|
import pyne.endf
|
|
43
51
|
except ImportError:
|
|
44
|
-
raise RuntimeError('Could not "import pyne.endf". You probably need
|
|
52
|
+
raise RuntimeError('Could not "import pyne.endf". You probably need'
|
|
53
|
+
' to install PyNE (see http://pyne.io/)')
|
|
45
54
|
|
|
46
55
|
#Monkey-patch pyne.endf reader, which was ignoring optional sections with teff
|
|
47
56
|
#curves of non-principal atoms (see
|
NCrystal/_cli_hfg2ncmat.py
CHANGED
|
@@ -23,6 +23,13 @@ from ._cliimpl import ( create_ArgumentParser,
|
|
|
23
23
|
cli_entry_point,
|
|
24
24
|
print )
|
|
25
25
|
|
|
26
|
+
def climod_metadata():
|
|
27
|
+
return dict(
|
|
28
|
+
displaygroup = 'conv',
|
|
29
|
+
displayorder = 20,
|
|
30
|
+
descr = "Create NCMAT data for amorphous hydrogen-rich materials."
|
|
31
|
+
)
|
|
32
|
+
|
|
26
33
|
def _parseArgs( default_debye_temp, progname, arglist, return_parser=False ):
|
|
27
34
|
from argparse import RawTextHelpFormatter
|
|
28
35
|
|
NCrystal/_cli_mcstasunion.py
CHANGED
|
@@ -23,6 +23,13 @@ from ._cliimpl import ( create_ArgumentParser,
|
|
|
23
23
|
cli_entry_point,
|
|
24
24
|
print )
|
|
25
25
|
|
|
26
|
+
def climod_metadata():
|
|
27
|
+
return dict(
|
|
28
|
+
displaygroup = 'misc',
|
|
29
|
+
displayorder = 999,
|
|
30
|
+
descr = "Generate McStas-Union code for using NCrystal materials."
|
|
31
|
+
)
|
|
32
|
+
|
|
26
33
|
def parseArgs( progname, args, return_parser=False ):
|
|
27
34
|
|
|
28
35
|
descr="""Output McStas-Union code in McStas instrument (.instr) format to
|