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.
Files changed (53) hide show
  1. NCrystal/__init__.py +85 -0
  2. NCrystal/__main__.py +98 -0
  3. NCrystal/_chooks.py +854 -0
  4. NCrystal/_cli_cif2ncmat.py +269 -0
  5. NCrystal/_cli_endf2ncmat.py +503 -0
  6. NCrystal/_cli_hfg2ncmat.py +144 -0
  7. NCrystal/_cli_mcstasunion.py +74 -0
  8. NCrystal/_cli_ncmat2cpp.py +31 -0
  9. NCrystal/_cli_ncmat2hkl.py +180 -0
  10. NCrystal/_cli_nctool.py +1018 -0
  11. NCrystal/_cli_vdos2ncmat.py +463 -0
  12. NCrystal/_cli_verifyatompos.py +257 -0
  13. NCrystal/_cliimpl.py +307 -0
  14. NCrystal/_cliwrap_config.py +36 -0
  15. NCrystal/_common.py +499 -0
  16. NCrystal/_coreimpl.py +114 -0
  17. NCrystal/_hfgdata.py +546 -0
  18. NCrystal/_hklobjects.py +136 -0
  19. NCrystal/_is_std.py +0 -0
  20. NCrystal/_locatelib.py +210 -0
  21. NCrystal/_miscimpl.py +354 -0
  22. NCrystal/_mmc.py +757 -0
  23. NCrystal/_msg.py +60 -0
  24. NCrystal/_ncmat2cpp_impl.py +445 -0
  25. NCrystal/_ncmatimpl.py +2131 -0
  26. NCrystal/_numpy.py +76 -0
  27. NCrystal/_testimpl.py +579 -0
  28. NCrystal/api.py +56 -0
  29. NCrystal/atomdata.py +177 -0
  30. NCrystal/cfgstr.py +77 -0
  31. NCrystal/cifutils.py +1795 -0
  32. NCrystal/cli.py +96 -0
  33. NCrystal/constants.py +134 -0
  34. NCrystal/core.py +1910 -0
  35. NCrystal/datasrc.py +226 -0
  36. NCrystal/exceptions.py +66 -0
  37. NCrystal/hfg2ncmat.py +270 -0
  38. NCrystal/mcstasutils.py +438 -0
  39. NCrystal/misc.py +317 -0
  40. NCrystal/mmc.py +35 -0
  41. NCrystal/ncmat.py +778 -0
  42. NCrystal/ncmat2cpp.py +80 -0
  43. NCrystal/obsolete.py +67 -0
  44. NCrystal/plot.py +484 -0
  45. NCrystal/plugins.py +49 -0
  46. NCrystal/test.py +76 -0
  47. NCrystal/vdos.py +1034 -0
  48. ncrystal_python-3.9.81.dist-info/LICENSE +206 -0
  49. ncrystal_python-3.9.81.dist-info/METADATA +515 -0
  50. ncrystal_python-3.9.81.dist-info/RECORD +53 -0
  51. ncrystal_python-3.9.81.dist-info/WHEEL +5 -0
  52. ncrystal_python-3.9.81.dist-info/entry_points.txt +10 -0
  53. ncrystal_python-3.9.81.dist-info/top_level.txt +1 -0
@@ -0,0 +1,136 @@
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
+ Experimental feature for more object-oriented and less efficient access to hkl
25
+ lists.
26
+
27
+ See also https://github.com/mctools/ncrystal/issues/164.
28
+
29
+ """
30
+
31
+ class HKLEntry:
32
+
33
+ """A group or family of HKL planes, all sharing the same value of d-spacing
34
+ and structure factor (fsquared). If .is_symequiv evaluates to True, these
35
+ exactly represent a group of symmetry-equivalent planes.
36
+ """
37
+ def __str__( self ):
38
+ hkl=self.hkl_label
39
+ return ( f'HKL( hkl_label=({hkl[0]},{hkl[1]},{hkl[2]}), '
40
+ f'd={self.d:g}Aa, F2={self.fsquared:g}barn, '
41
+ f'N={self.mult} )' )
42
+
43
+ def __init__(self,hh,kk,ll,mult,dsp,fsq,hklinfotype,issymeqv):
44
+ """For internal usage only, do not create therse objects manually."""
45
+ self.__h = hh
46
+ self.__k = kk
47
+ self.__l = ll
48
+ self.__mult = mult
49
+ self.__dsp = dsp
50
+ self.__fsq = fsq
51
+ self.__hklinfotype = hklinfotype
52
+ self.__issymeqv = issymeqv
53
+
54
+ @property
55
+ def hkl_type( self ):
56
+ """The type of HKL group represented by this entry. Returns
57
+ HKLInfoType.SymEqvGroup if this is a group of symmetry-equivalent
58
+ planes.
59
+ """
60
+ return self.__hklinfotype
61
+
62
+ @property
63
+ def is_symequiv(self):
64
+ """Returns True if .hkl_type equals HKLInfoType.SymEqvGroup."""
65
+ return self.__issymeqv
66
+
67
+ @property
68
+ def hkl_label( self ):
69
+ """Returns a hkl label for the entry, i.e. one of the hkl points in the
70
+ group as a tuple of three integers: (h,k,l)."""
71
+ return (int(self.__h[0]),int(self.__k[0]),int(self.__l[0]))
72
+
73
+ @property
74
+ def h( self ):
75
+ """
76
+ An array of h values. Note that this has half the length of
77
+ .multiplicity, since we exclude entries that can be generated from each
78
+ other by a mere sign flip.
79
+ """
80
+ return self.__h
81
+
82
+ @property
83
+ def k( self ):
84
+ """
85
+ An array of k values. Note that this has half the length of
86
+ .multiplicity, since we exclude entries that can be generated from each
87
+ other by a mere sign flip.
88
+ """
89
+ return self.__k
90
+
91
+ @property
92
+ def l( self ): # noqa E743
93
+ """
94
+ An array of l values. Note that this has half the length of
95
+ .multiplicity, since we exclude entries that can be generated from each
96
+ other by a mere sign flip.
97
+ """
98
+ return self.__l
99
+
100
+ @property
101
+ def dspacing( self ):
102
+ """The d-spacing value in units of angstrom."""
103
+ return self.__dsp
104
+
105
+ @property
106
+ def d( self ):
107
+ """The d-spacing value in units of angstrom."""
108
+ return self.__dsp
109
+
110
+ @property
111
+ def fsquared( self ):
112
+ """The squared structure factor (F^2) in units of barn."""
113
+ return self.__fsq
114
+
115
+ @property
116
+ def f2( self ):
117
+ """The squared structure factor (F^2) in units of barn."""
118
+ return self.__fsq
119
+
120
+ @property
121
+ def multiplicity( self ):
122
+ """The number of hkl points in the group."""
123
+ return self.__mult
124
+
125
+ @property
126
+ def mult( self ):
127
+ """The number of hkl points in the group."""
128
+ return self.__mult
129
+
130
+ def _iter_hklobjects( info ):
131
+ hklinfotype = info.hklInfoType()
132
+ issymeqv = info.hklIsSymEqvGroup()
133
+ for hh,kk,ll,mult,dsp,fsq in info.hklList(all_indices=True):
134
+ yield HKLEntry(hh,kk,ll,mult,dsp,fsq,
135
+ hklinfotype,issymeqv)
136
+
NCrystal/_is_std.py ADDED
File without changes
NCrystal/_locatelib.py ADDED
@@ -0,0 +1,210 @@
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
+ """Internal module providing ctypes-based hooks into the compiled NCrystal
23
+ shared library"""
24
+
25
+ import pathlib
26
+
27
+ _cache = [None]
28
+ def get_libpath_and_namespace():
29
+ if _cache[0] is None:
30
+ _cache[0] = _search()
31
+ return _cache[0]
32
+
33
+ def _detect_monolithic_installation():
34
+ #Determine if these python modules were installed via "pip install
35
+ #<ncrystalrepo>" (monolithic package with bore core and python parts), or if
36
+ #using a standard ncrystal-python package. Also detect conflicts in case a
37
+ #user did both, and thus messed up their environment.
38
+
39
+ d = pathlib.Path(__file__).parent
40
+ is_std = d.joinpath('_is_std.py').is_file()
41
+ is_mono = d.joinpath('_is_monolithic.py').is_file()
42
+ assert is_mono or is_std
43
+ if not ( is_mono and is_std ):
44
+ return is_mono
45
+
46
+ import textwrap
47
+ conflict_msg = textwrap.dedent("""
48
+
49
+ ERROR: Broken environment detected.
50
+
51
+ The current environment has traces of both a normal NCrystal installation
52
+ (where ncrystal-core and ncrystal-python modules are installed separately),
53
+ and a monolithic installation (most likely from running "pip install"
54
+ directly on the root of the ncrystal source tree). This latter method is
55
+ primarily intended for developers, and should never be performed in an
56
+ environment where NCrystal is already installed through other conventional
57
+ methods.
58
+
59
+ Most likely your environment is now broken. You can attempt to fix it by
60
+ uninstalling all NCrystal packages (with the same package manager that did
61
+ the original installation of that package), and then installing NCrystal
62
+ again from one source only. Or you might simply wish to remove and recreate
63
+ the environment from scratch.
64
+ """)
65
+ #We can not simply emit ImportError, since it might be taken by clients as
66
+ #"ncrystal not installed". We can choose RuntimeError or SystemExit. To be
67
+ #100% this triggers a warning, we pick SystemExit.
68
+ raise SystemExit(conflict_msg)
69
+
70
+ def _search():
71
+ #Try to determine the location of the NCrystal shared library. In order of
72
+ #preference, we try:
73
+ #
74
+ # 1) The NCrystal_LIB environment variable (intended for specialised usage,
75
+ # like CTests). Normally this variable is also enough for us to be able
76
+ # to decode the NCrystal namespace protection used, if any. But if it
77
+ # fails, one can use the NCRYSTAL_LIB_NAMESPACE_PROTECTION variable to
78
+ # specify it explicitly.
79
+ #
80
+ # 2) Attempt to get the location via a python module providing it (in case
81
+ # ncrystal-core was installed via PyPI for instance).
82
+ #
83
+ # 3) Invoke "ncrystal-config --show ..." for the information.
84
+ #
85
+ # If simplebuild devel mode we allow env var overrides, but apart from that
86
+ # always go straight to the ncrystal-config method.
87
+
88
+ # Always invoke _detect_monolithic_installation() since it also detects
89
+ # broken installations.
90
+ import os
91
+ verbose = 'NCRYSTAL_DEBUG_LIBSEARCH' in os.environ
92
+ if verbose:
93
+ from ._common import print
94
+ print('NCrystal._locatelib: Starting search for'
95
+ ' NCrystal shared library')
96
+ is_monolithic = _detect_monolithic_installation()
97
+ if verbose:
98
+ print('NCrystal._locatelib: monolithic installation'
99
+ f' = {"yes" if is_monolithic else "no"}')
100
+
101
+ v = _search_env_overrides()
102
+ if verbose and v:
103
+ print('NCrystal._locatelib: Succesfully searched via method: env vars')
104
+
105
+ is_simplebuild_devel = ( pathlib.Path(__file__).parent
106
+ .joinpath('_is_sblddevel.py').is_file() )
107
+
108
+ if not v and not is_simplebuild_devel:
109
+ v = _search_core_info_mod( is_monolithic )
110
+ if verbose and v:
111
+ print('NCrystal._locatelib: Succesfully searched via method: pymod')
112
+
113
+ if not v:
114
+ v = _search_nccfgapp( 'sb_nccmd_config'
115
+ if is_simplebuild_devel
116
+ else 'ncrystal-config' )
117
+ if verbose and v:
118
+ print('NCrystal._locatelib: Succesfully searched'
119
+ ' via method: ncrystal-config')
120
+
121
+ if not v:
122
+ from .exceptions import NCFileNotFound
123
+ raise NCFileNotFound('Could not locate the NCrystal shared library'
124
+ ' file. Have you installed the ncrystal-core'
125
+ ' package?')
126
+ lib, namespace, version = v
127
+ if verbose:
128
+ print(f'NCrystal._locatelib: namespace = "{namespace}"')
129
+ print(f'NCrystal._locatelib: lib = "{lib}"')
130
+
131
+ lib = pathlib.Path(lib)
132
+ if not lib.is_file():
133
+ from .exceptions import NCFileNotFound
134
+ raise NCFileNotFound('Problems locating the NCrystal shared library'
135
+ f' file. Tried "{lib}" unsuccesfully.')
136
+ version_ok = True
137
+ if version is not None:
138
+ from . import __version__ as _nc_version
139
+ version_ok = _nc_version.strip() == version.strip()
140
+ if version_ok:
141
+ return ( lib.absolute().resolve(), ( namespace or '' ) )
142
+
143
+ #Found it, but there was a version mismatch!
144
+ import textwrap
145
+ msg = textwrap.dedent(f"""
146
+ ERROR: Inconsistent environment detected.
147
+
148
+ The version of the installed core ncrystal modules ({version}) and the
149
+ ncrystal Python API ({_nc_version}) are not identical. This is not
150
+ supported.
151
+ """)
152
+ #The environment is not necessarily completely broken, but the NCrystal
153
+ #packages can not be used. Hence, we emit an ImportError here. However, we
154
+ #also emit a warning, in case the client code is hiding ImportError's, on
155
+ #the assumption it simply means NCrystal is not available.
156
+ from ._common import warn
157
+ warn(msg)
158
+ raise ImportError(msg)
159
+
160
+ def _search_env_overrides():
161
+ import os
162
+ #NB: The next two variables can NOT be namespaced. E.g. it will always be
163
+ #NCRYSTAL_LIB, and never e.g. NCRYSTAL<NAMESPACEHERE>_LIB:
164
+ lib = os.environ.get('NCRYSTAL_LIB')
165
+
166
+ #This second variable is hopefully not needed, since the namespace can
167
+ #hopefully be inferred from the shared library name, but we allow it as an
168
+ #ultimate fall-back option in case one is for some reason running with
169
+ #non-standard naming of the shared libraries:
170
+ ns = os.environ.get('NCRYSTAL_LIB_NAMESPACE_PROTECTION','')
171
+ if lib:
172
+ if not ns and '.' in lib and 'NCrystal-' in lib:
173
+ #Try to infer the namespace from the library name (so it is enough
174
+ #to set NCRYSTAL_LIB).
175
+ ll = lib.split('.')[0]
176
+ if 'NCrystal-' in ll:
177
+ ll = ll.split('NCrystal-')[-1]
178
+ if ll and 'NCrystal-' not in ll and '.' not in ll:
179
+ ns = ll
180
+ lib = pathlib.Path(lib)
181
+ if not lib.exists() or lib.is_dir():
182
+ from .exceptions import NCFileNotFound
183
+ raise NCFileNotFound('NCRYSTAL_LIB environment variable is set'
184
+ f' ("{lib}") but does not point'
185
+ ' to an actual file.')
186
+ return lib, ns, None
187
+
188
+ def _search_core_info_mod( is_monolithic ):
189
+ #Look for the standard module, installed by the ncrystal-core package.
190
+ try:
191
+ if is_monolithic:
192
+ import _ncrystal_core_monolithic.info as mod
193
+ else:
194
+ import _ncrystal_core.info as mod
195
+ except ModuleNotFoundError:
196
+ mod = None
197
+ if mod:
198
+ return mod.libpath(), mod.namespace(), mod.version()
199
+
200
+ def _search_nccfgapp( cmdname ):
201
+ #Try to query ncrystal-config script:
202
+ import subprocess
203
+ res = subprocess.run([cmdname,'--show','shlibpath','namespace','version'],
204
+ capture_output=True)
205
+ if res.returncode == 0:
206
+ lines = res.stdout.decode('utf8').splitlines()
207
+ if len(lines) == 3:
208
+ p = pathlib.Path(lines[0])
209
+ if p.is_file():
210
+ return p, ( lines[1].strip() or None ), lines[2].strip()