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/api.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
Meta-module providing the most commonly needed public API functions and classes
|
|
25
|
+
from NCrystal in a single module. It can be used as:
|
|
26
|
+
|
|
27
|
+
import NCrystal.api as NC
|
|
28
|
+
|
|
29
|
+
Which will for now do the same as "import NCrystal as NC". However, it might be
|
|
30
|
+
that we will eventually modify the default behaviour to not include anything
|
|
31
|
+
when merely doing "import NCrystal", so the "import NCrystal.api as NC" will be
|
|
32
|
+
more stable in the long rum.
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
#NB: reduce imported symbols here a bit in a future release (possibly by
|
|
37
|
+
#wrapping the removed function and placing in obsolete.py);
|
|
38
|
+
from .exceptions import * # noqa F403
|
|
39
|
+
from .core import * # noqa F403
|
|
40
|
+
from .datasrc import * # noqa F403
|
|
41
|
+
from .constants import wl2ekin, ekin2wl, ekin2ksq, wl2k, wl2ksq, constant_boltzmann # noqa F401
|
|
42
|
+
from .atomdata import atomDB, iterateAtomDB # noqa F401
|
|
43
|
+
from .cfgstr import normaliseCfg, decodeCfg, generateCfgStrDoc # noqa F401
|
|
44
|
+
from .ncmat import NCMATComposer, formatVectorForNCMAT # noqa F401
|
|
45
|
+
from .plugins import hasFactory, browsePlugins # noqa F401
|
|
46
|
+
from ._testimpl import * # noqa F403
|
|
47
|
+
from .vdos import createVDOSDebye, debyeIsotropicMSD, PhononDOSAnalyser, debyeTempFromIsotropicMSD, analyseVDOS # noqa F401
|
|
48
|
+
from .obsolete import * # noqa F403
|
|
49
|
+
|
|
50
|
+
#Some modules are left out on purpose (due to esoteric usage or non-standard
|
|
51
|
+
#dependencies that most users might not need):
|
|
52
|
+
#
|
|
53
|
+
# from .cifutils import *
|
|
54
|
+
# from .misc import *
|
|
55
|
+
# from .mcstasutils import *
|
|
56
|
+
#
|
NCrystal/atomdata.py
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
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
|
+
Utilities for accessing NCrystal's database of atomic data, with information
|
|
25
|
+
about atomic masses, scattering lengths, etc. Also contains a few other related
|
|
26
|
+
utilities, like a list of all element names.
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
__atomdb={}
|
|
31
|
+
def atomDB(Z,A=None,throwOnErrors=True):
|
|
32
|
+
"""Access internal database with data for isotopes and natural elements.
|
|
33
|
+
|
|
34
|
+
If A is provided, both A and Z must be integers, thus defining a specific isotope.
|
|
35
|
+
|
|
36
|
+
If Z is an integer and A is 0 or None, the corresponding natural element is provided.
|
|
37
|
+
|
|
38
|
+
Finally, the function can be called with a string identifying either natural
|
|
39
|
+
elements or isotopes: atomDB("Al"), atomDB("He3"), ...
|
|
40
|
+
|
|
41
|
+
In all cases, in case of errors or missing entries in the database, either
|
|
42
|
+
an NCBadInput exception is thrown (throwOnErrors==True) or None is
|
|
43
|
+
returned (when throwOnErrors==False).
|
|
44
|
+
"""
|
|
45
|
+
global __atomdb
|
|
46
|
+
import numbers
|
|
47
|
+
if isinstance(Z,numbers.Integral):
|
|
48
|
+
Z=int(Z)
|
|
49
|
+
key=(Z,int(A or 0))
|
|
50
|
+
strkey=False
|
|
51
|
+
else:
|
|
52
|
+
assert A is None,"Do not supply two arguments unless the first argument is an integer"
|
|
53
|
+
assert isinstance(Z,str),"The first argument to the function must either be of int or str type"
|
|
54
|
+
key=Z
|
|
55
|
+
strkey=True
|
|
56
|
+
obj=__atomdb.get(key,None)
|
|
57
|
+
if obj:
|
|
58
|
+
return obj
|
|
59
|
+
from ._chooks import _get_raw_cfcts,_str2cstr
|
|
60
|
+
_rawfct = _get_raw_cfcts()
|
|
61
|
+
if strkey:
|
|
62
|
+
rawatomdata=_rawfct['ncrystal_create_atomdata_fromdbstr'](_str2cstr(key))
|
|
63
|
+
else:
|
|
64
|
+
rawatomdata=_rawfct['ncrystal_create_atomdata_fromdb'](*key)
|
|
65
|
+
if not _rawfct['ncrystal_valid'](rawatomdata):
|
|
66
|
+
if not throwOnErrors:
|
|
67
|
+
return None
|
|
68
|
+
if strkey:
|
|
69
|
+
s='key="%s"'%key
|
|
70
|
+
else:
|
|
71
|
+
if key[1]==0:
|
|
72
|
+
s='Z=%i'%key[0]
|
|
73
|
+
else:
|
|
74
|
+
s='Z=%i,A=%i'%key
|
|
75
|
+
from .exceptions import NCBadInput
|
|
76
|
+
raise NCBadInput('atomDB: Could not find entry for key (%s)'%s)
|
|
77
|
+
from .core import AtomData
|
|
78
|
+
ad = AtomData(rawatomdata)
|
|
79
|
+
assert ad.isElement()
|
|
80
|
+
Z,A = ad.Z(), (ad.A() if ad.isSingleIsotope() else 0)
|
|
81
|
+
keys=[ (Z,A)]
|
|
82
|
+
if Z==1 and A==2:
|
|
83
|
+
keys+=['H2','D']
|
|
84
|
+
elif Z==1 and A==3:
|
|
85
|
+
keys+=['H3','T']
|
|
86
|
+
else:
|
|
87
|
+
assert ad.isNaturalElement() or ad.isSingleIsotope()
|
|
88
|
+
keys += [ ad.description(False) ]#guaranteed to give just symbol for natelem/singleisotope!
|
|
89
|
+
assert key in keys#Should always be true unless we forgot some keys above
|
|
90
|
+
assert ad.description(False) in keys#Should also be true, given guarantees for AtomData::description(false)
|
|
91
|
+
for k in keys:
|
|
92
|
+
__atomdb[k] = ad
|
|
93
|
+
return ad
|
|
94
|
+
|
|
95
|
+
def iterateAtomDB(objects=True):
|
|
96
|
+
"""Iterate over all entries in the internal database with data for isotopes and
|
|
97
|
+
natural elements. If objects=True, AtomData objects are returned. If
|
|
98
|
+
objects=False, (Z,A) values are returned (A=0 indicates a natural
|
|
99
|
+
element)."""
|
|
100
|
+
from ._chooks import _get_raw_cfcts
|
|
101
|
+
_rawfct = _get_raw_cfcts()
|
|
102
|
+
for z,a in _rawfct['atomdb_getall_za']():
|
|
103
|
+
yield atomDB(z,a) if objects else (int(z),int(a))
|
|
104
|
+
|
|
105
|
+
__all_element_names=tuple(["H", "He", "Li", "Be", "B", "C",
|
|
106
|
+
"N", "O", "F", "Ne", "Na", "Mg", "Al", "Si", "P", "S", "Cl",
|
|
107
|
+
"Ar", "K", "Ca", "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co",
|
|
108
|
+
"Ni", "Cu", "Zn", "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb",
|
|
109
|
+
"Sr", "Y", "Zr", "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag",
|
|
110
|
+
"Cd", "In", "Sn", "Sb", "Te", "I", "Xe", "Cs", "Ba", "La",
|
|
111
|
+
"Ce", "Pr", "Nd", "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho",
|
|
112
|
+
"Er", "Tm", "Yb", "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir",
|
|
113
|
+
"Pt", "Au", "Hg", "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr",
|
|
114
|
+
"Ra", "Ac", "Th", "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk",
|
|
115
|
+
"Cf", "Es", "Fm", "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh",
|
|
116
|
+
"Hs", "Mt", "Ds", "Rg", "Cn", "Nh", "Fl", "Mc", "Lv", "Ts",
|
|
117
|
+
"Og"])
|
|
118
|
+
|
|
119
|
+
__elem2z = [None]
|
|
120
|
+
def elementNameToZValue( element_name, allow_isotopes = False ):
|
|
121
|
+
"""Return Z value for element name (e.g. element_name="C" returns
|
|
122
|
+
6). Returns None if argument is not an element name. If
|
|
123
|
+
allow_isotopes==True, isotope names like "B10", "D", etc. will be decoded as
|
|
124
|
+
well and return the Z value of the corresponding element.
|
|
125
|
+
"""
|
|
126
|
+
if allow_isotopes:
|
|
127
|
+
if element_name in ('D','T'):
|
|
128
|
+
return 1
|
|
129
|
+
while element_name and element_name[-1].isdigit():
|
|
130
|
+
element_name = element_name[:-1]
|
|
131
|
+
if __elem2z[0] is None:
|
|
132
|
+
__elem2z[0] = dict( ( e, i+1 ) for i,e in enumerate(__all_element_names) )
|
|
133
|
+
return __elem2z[0].get(element_name, None )
|
|
134
|
+
|
|
135
|
+
def elementZToName( Z ):
|
|
136
|
+
"""
|
|
137
|
+
Return element name corresponding to given Z value, or None in case of invalid or out of range argument.
|
|
138
|
+
"""
|
|
139
|
+
import numbers
|
|
140
|
+
i = int(Z)-1 if isinstance(Z,numbers.Integral) else -1
|
|
141
|
+
return __all_element_names[i] if 0 <= i < len(__all_element_names) else None
|
|
142
|
+
|
|
143
|
+
def allElementNames():
|
|
144
|
+
"""Like knownElementNames, but also returns names of elements for which
|
|
145
|
+
NCrystal has no data. See also knownElementNames()."""
|
|
146
|
+
return __all_element_names
|
|
147
|
+
|
|
148
|
+
def isElementName( label ):
|
|
149
|
+
"""Determine whether label is a an element name like "H" or "He". See also
|
|
150
|
+
isKnownElement(..).
|
|
151
|
+
|
|
152
|
+
"""
|
|
153
|
+
return ( ( elementNameToZValue(label) is not None )
|
|
154
|
+
if __elem2z[0] is None else ( label in __elem2z[0] ) )
|
|
155
|
+
|
|
156
|
+
__all_known_element_names=[None,None]#list,set
|
|
157
|
+
def knownElementNames():
|
|
158
|
+
"""Returns tuple of all element names for which NCrystal has data
|
|
159
|
+
values. The elements are ordered by increasing Z value. See also
|
|
160
|
+
allElementNames()."""
|
|
161
|
+
if __all_known_element_names[0] is None:
|
|
162
|
+
ll=[]
|
|
163
|
+
for a in iterateAtomDB():
|
|
164
|
+
if a.isNaturalElement():
|
|
165
|
+
ll.append( (a.Z(),a.elementName()) )
|
|
166
|
+
ll = tuple( name for z,name in sorted(ll) )
|
|
167
|
+
__all_known_element_names[0] = ll
|
|
168
|
+
__all_known_element_names[1] = frozenset(ll)
|
|
169
|
+
return __all_known_element_names[0]
|
|
170
|
+
|
|
171
|
+
def isKnownElement( label ):
|
|
172
|
+
"""Determine whether or not label is an element name for which NCrystal has
|
|
173
|
+
data values. See also isElementName(..).
|
|
174
|
+
"""
|
|
175
|
+
if __all_known_element_names[1] is None:
|
|
176
|
+
knownElementNames()#trigger init
|
|
177
|
+
return label in __all_known_element_names[1]
|
NCrystal/cfgstr.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
Utilities for accessing NCrystal's database of atomic data, with information
|
|
25
|
+
about atomic masses, scattering lengths, etc. Also contains a few other related
|
|
26
|
+
utilities, like a list of all element names.
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def normaliseCfg(cfgstr):
|
|
31
|
+
"""Returns normalised version of cfgstr. This is done behind the scenes by
|
|
32
|
+
loading the specified cfg-string into a C++ MatCfg object and then
|
|
33
|
+
re-encoding it as a string.
|
|
34
|
+
"""
|
|
35
|
+
from ._chooks import _get_raw_cfcts
|
|
36
|
+
return _get_raw_cfcts()['nc_normcfgstr'](cfgstr)
|
|
37
|
+
|
|
38
|
+
def decodeCfg(cfgstr,*,asJSONStr=False):
|
|
39
|
+
"""Decodes cfg-string and returns as Python data structure (a dictionary). The
|
|
40
|
+
format of this data structure should be mostly self-evident by
|
|
41
|
+
inspection, and is not guaranteed to stay the same across NCrystal
|
|
42
|
+
versions. If asJSONStr=true, the data structure will be returned as a
|
|
43
|
+
JSON-encoded string, instead of a Python dictionary.
|
|
44
|
+
"""
|
|
45
|
+
from ._chooks import _get_raw_cfcts
|
|
46
|
+
_js = _get_raw_cfcts()['nc_cfgstr2json'](cfgstr)
|
|
47
|
+
if asJSONStr:
|
|
48
|
+
return _js
|
|
49
|
+
import json
|
|
50
|
+
return json.loads(_js)
|
|
51
|
+
|
|
52
|
+
def generateCfgStrDoc( mode = "print" ):
|
|
53
|
+
"""Generates documentation about the available cfg-str variables. Mode can
|
|
54
|
+
either be 'print' (print detailed explanation to stdout), 'txt_full' (return
|
|
55
|
+
detailed explanations as string), 'txt_short' (return short explanations as
|
|
56
|
+
string), 'json' (return json-encoded string), or 'python' (return python
|
|
57
|
+
data structures).
|
|
58
|
+
"""
|
|
59
|
+
modemap={'print':0,'txt_full':0,'txt_short':1,'json':2,'python':2}
|
|
60
|
+
modeint = modemap.get(mode,None)
|
|
61
|
+
if modeint is None:
|
|
62
|
+
from .exceptions import NCBadInput
|
|
63
|
+
raise NCBadInput('mode must be one of %s'%list(sorted(modemap.keys())))
|
|
64
|
+
from ._chooks import _get_raw_cfcts
|
|
65
|
+
_=_get_raw_cfcts()['nc_gencfgdoc'](modeint)
|
|
66
|
+
if mode == 'print':
|
|
67
|
+
print(_)
|
|
68
|
+
elif mode == 'python':
|
|
69
|
+
import json
|
|
70
|
+
return json.loads(_)
|
|
71
|
+
else:
|
|
72
|
+
return _
|
|
73
|
+
|
|
74
|
+
def decodecfg_vdoslux(cfgstr):
|
|
75
|
+
"""Extract vdoslux value from cfgstr."""
|
|
76
|
+
from ._chooks import _get_raw_cfcts,_str2cstr
|
|
77
|
+
return int(_get_raw_cfcts()['ncrystal_decodecfg_vdoslux'](_str2cstr(cfgstr)))
|