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
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
from ._cliimpl import ( create_ArgumentParser,
|
|
23
|
+
cli_entry_point,
|
|
24
|
+
print )
|
|
25
|
+
|
|
26
|
+
def parseArgs( progname, args, return_parser=False ):
|
|
27
|
+
|
|
28
|
+
descr="""Output McStas-Union code in McStas instrument (.instr) format to
|
|
29
|
+
define material with NAME based on specified NCrystal CFGSTR. Providing the
|
|
30
|
+
--split option will split NCrystal processes into physics types at the
|
|
31
|
+
McStas-Union level, rather than internally in NCrystal."""
|
|
32
|
+
|
|
33
|
+
parser = create_ArgumentParser(prog = progname,
|
|
34
|
+
description=descr)
|
|
35
|
+
parser.add_argument('union_mat_name', metavar='NAME', type=str,
|
|
36
|
+
help="Resulting NAME of McStas-Union material.")
|
|
37
|
+
parser.add_argument('cfgstr', metavar='CFGSTR', type=str,
|
|
38
|
+
help="NCrystal cfg-string of the material.")
|
|
39
|
+
parser.add_argument('--split','-s',action='store_true',
|
|
40
|
+
help=("Splits NCrystal processes"
|
|
41
|
+
"into physics types at the McStas-Union level,"
|
|
42
|
+
"rather than internally in NCrystal."))
|
|
43
|
+
parser.add_argument("--output",'-o',default='',type=str,
|
|
44
|
+
help=("Output file name (defaults to stdout)."))
|
|
45
|
+
parser.add_argument('--force','-f',action='store_true',
|
|
46
|
+
help=("Override output file if it already exists."))
|
|
47
|
+
if return_parser:
|
|
48
|
+
return parser
|
|
49
|
+
args = parser.parse_args(args)
|
|
50
|
+
return args
|
|
51
|
+
|
|
52
|
+
def create_argparser_for_sphinx( progname ):
|
|
53
|
+
return parseArgs(progname,[],return_parser=True)
|
|
54
|
+
|
|
55
|
+
@cli_entry_point
|
|
56
|
+
def main( progname, args ):
|
|
57
|
+
args = parseArgs( progname, args )
|
|
58
|
+
from .mcstasutils import cfgstr_2_union_instrument_code
|
|
59
|
+
|
|
60
|
+
code = cfgstr_2_union_instrument_code( cfgstr = args.cfgstr,
|
|
61
|
+
name = args.union_mat_name,
|
|
62
|
+
split_by_physics = args.split )
|
|
63
|
+
if not args.output or args.output=='stdout':
|
|
64
|
+
print( code )
|
|
65
|
+
else:
|
|
66
|
+
import pathlib
|
|
67
|
+
p = pathlib.Path( args.output )
|
|
68
|
+
if p.is_file() and not args.force:
|
|
69
|
+
raise SystemExit(f'File already exists (use --force to overwrite): {p}')
|
|
70
|
+
if not p.parent.is_dir():
|
|
71
|
+
raise SystemExit(f'Output directory does not exist: {p.parent}')
|
|
72
|
+
from ._common import write_text
|
|
73
|
+
write_text(p,code)
|
|
74
|
+
print(f"Wrote: {p}")
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
from ._cliimpl import cli_entry_point
|
|
23
|
+
|
|
24
|
+
def create_argparser_for_sphinx( progname ):
|
|
25
|
+
from ._ncmat2cpp_impl import parseArgs
|
|
26
|
+
return parseArgs(progname,[],return_parser=True)
|
|
27
|
+
|
|
28
|
+
@cli_entry_point
|
|
29
|
+
def main( progname, arglist ):
|
|
30
|
+
from ._ncmat2cpp_impl import main as main_impl
|
|
31
|
+
main_impl( progname, arglist )
|
|
@@ -0,0 +1,180 @@
|
|
|
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
|
+
from ._cliimpl import ( create_ArgumentParser,
|
|
23
|
+
cli_entry_point,
|
|
24
|
+
print, warn )
|
|
25
|
+
|
|
26
|
+
def parseArgs( progname, arglist, return_parser=False ):
|
|
27
|
+
|
|
28
|
+
progname_tool='nctool'
|
|
29
|
+
descr=f"""
|
|
30
|
+
|
|
31
|
+
Script which can be used to create input files with reflections for McStas
|
|
32
|
+
crystalline sample components like PowderN and Single_crystal, based on NCrystal
|
|
33
|
+
cfg-strings (usually referring to NCMAT files with crystalline single-phase
|
|
34
|
+
materials).
|
|
35
|
+
|
|
36
|
+
Example invocations:
|
|
37
|
+
|
|
38
|
+
$> {progname} "Y2SiO5_sg15_YSO.ncmat" --format=laz -o YSO.laz
|
|
39
|
+
$> {progname} "Y2SiO5_sg15_YSO.ncmat" --format=lau -o YSO.lau
|
|
40
|
+
|
|
41
|
+
It might be useful to set certain parameters in the cfg-string in addition
|
|
42
|
+
to the input file name. For more information about available parameters,
|
|
43
|
+
refer to https://github.com/mctools/ncrystal/wiki/CfgRefDoc, or run the
|
|
44
|
+
cmd:
|
|
45
|
+
|
|
46
|
+
$> {progname_tool} --doc
|
|
47
|
+
|
|
48
|
+
For instance, to change the material temperature from room temperature, and
|
|
49
|
+
to leave out reflections at dspacing<0.5Aa, run:
|
|
50
|
+
|
|
51
|
+
$> {progname} "Y2SiO5_sg15_YSO.ncmat;dcutoff=0.5;temp=200K" --format=laz -o YSO_200K_largedsp.laz
|
|
52
|
+
$> {progname} "Y2SiO5_sg15_YSO.ncmat;dcutoff=0.5;temp=200K" --format=lau -o YSO_200K_largedsp.lau
|
|
53
|
+
|
|
54
|
+
To browse materials which are available in default NCrystal installations,
|
|
55
|
+
refer to https://github.com/mctools/ncrystal/wiki/Data-library. To list
|
|
56
|
+
actually available files in your installation, run:
|
|
57
|
+
|
|
58
|
+
$> {progname_tool} --browse
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
from argparse import RawTextHelpFormatter
|
|
62
|
+
import textwrap
|
|
63
|
+
parser = create_ArgumentParser(prog = progname,
|
|
64
|
+
description=descr,
|
|
65
|
+
formatter_class=RawTextHelpFormatter)
|
|
66
|
+
helpw = 60
|
|
67
|
+
def wrap(t):
|
|
68
|
+
return textwrap.fill(t,width=helpw)
|
|
69
|
+
|
|
70
|
+
parser.add_argument('CFGSTR', type=str,
|
|
71
|
+
help=wrap("NCrystal cfg-string representing the material"
|
|
72
|
+
" to load. For the purposes of the present"
|
|
73
|
+
" script, it might be particularly relevant to"
|
|
74
|
+
" set the temp and dcutoff parameters"))
|
|
75
|
+
parser.add_argument('--format','-f',default=None,choices=('laz','lau'),
|
|
76
|
+
help=wrap('What types of output files to produce. Choices'
|
|
77
|
+
' are "lau" for .lau files for McStas'
|
|
78
|
+
' PowderN or "laz" for .laz files for'
|
|
79
|
+
' McStas Single_crystal.'))
|
|
80
|
+
parser.add_argument('--output','-o',type=str,default=None,
|
|
81
|
+
help="Name of output file (default: stdout)")
|
|
82
|
+
parser.add_argument('--quiet','-q',default=False,action='store_true',
|
|
83
|
+
help=wrap('Silence non-error output'
|
|
84
|
+
' (automatic if --output=stdout).'))
|
|
85
|
+
|
|
86
|
+
if return_parser:
|
|
87
|
+
return parser
|
|
88
|
+
|
|
89
|
+
_warned_outfile = False
|
|
90
|
+
for i in range(len(arglist)):
|
|
91
|
+
if arglist[i].startswith('--outfile'):
|
|
92
|
+
arglist[i] = '--output' + arglist[i][len('--outfile'):]
|
|
93
|
+
if not _warned_outfile:
|
|
94
|
+
_warned_outfile = True
|
|
95
|
+
warn('The --outfile option has been renamed to --output')
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
args=parser.parse_args( arglist )
|
|
99
|
+
|
|
100
|
+
if not args.format:
|
|
101
|
+
parser.error('Please specify output type with --format,'
|
|
102
|
+
' either --format=laz or --format=lau (run'
|
|
103
|
+
' with --help for details)')
|
|
104
|
+
|
|
105
|
+
#TODO: We could use a common function for the following logic (including the
|
|
106
|
+
#stdout logic). Perhaps we should simply have a special "type" for the
|
|
107
|
+
#argparse option? Also, in general --quiet and --force are connected to
|
|
108
|
+
#--output.
|
|
109
|
+
|
|
110
|
+
if args.output is not None and args.output!='stdout':
|
|
111
|
+
import pathlib
|
|
112
|
+
of = pathlib.Path(args.output)
|
|
113
|
+
if of.is_dir():
|
|
114
|
+
parser.error(f'Output destination is directory: {of}')
|
|
115
|
+
if of.exists():
|
|
116
|
+
parser.error(f'Output destination already exists: {of}')
|
|
117
|
+
ofr = of.resolve().absolute()
|
|
118
|
+
if not ofr.parent.exists() or not ofr.parent.is_dir():
|
|
119
|
+
parser.error('Output destination is in non-existing'
|
|
120
|
+
f' directory: {ofr.parent}')
|
|
121
|
+
args.output = ofr
|
|
122
|
+
else:
|
|
123
|
+
args.output = 'stdout'
|
|
124
|
+
return args
|
|
125
|
+
|
|
126
|
+
def create_argparser_for_sphinx( progname ):
|
|
127
|
+
return parseArgs(progname,[],return_parser=True)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@cli_entry_point
|
|
131
|
+
def main( progname, arglist ):
|
|
132
|
+
|
|
133
|
+
#parse hidden option (needed for unit tests):
|
|
134
|
+
override_prec = None
|
|
135
|
+
override_opt = '--override-prec='
|
|
136
|
+
hidden_args, standard_args = [], []
|
|
137
|
+
for a in arglist:
|
|
138
|
+
(hidden_args
|
|
139
|
+
if a.startswith(override_opt)
|
|
140
|
+
else standard_args).append( a )
|
|
141
|
+
arglist = standard_args
|
|
142
|
+
if hidden_args:
|
|
143
|
+
override_prec = int(hidden_args[-1][len(override_opt):])
|
|
144
|
+
|
|
145
|
+
args = parseArgs( progname, arglist )
|
|
146
|
+
do_quiet = ( args.quiet or args.output == 'stdout' )
|
|
147
|
+
|
|
148
|
+
def invoke():
|
|
149
|
+
_main_impl(args,do_quiet,override_prec)
|
|
150
|
+
|
|
151
|
+
if do_quiet:
|
|
152
|
+
from ._common import modify_ncrystal_print_fct_ctxmgr
|
|
153
|
+
with modify_ncrystal_print_fct_ctxmgr('block'):
|
|
154
|
+
invoke()
|
|
155
|
+
else:
|
|
156
|
+
invoke()
|
|
157
|
+
|
|
158
|
+
def _main_impl( args, do_quiet, override_prec ):
|
|
159
|
+
|
|
160
|
+
from . import mcstasutils
|
|
161
|
+
full_info = True
|
|
162
|
+
kwargs = dict(cfgstr = args.CFGSTR,
|
|
163
|
+
tgtformat = args.format,
|
|
164
|
+
verbose = full_info)
|
|
165
|
+
if override_prec:
|
|
166
|
+
kwargs['fp_format'] = f'%.{override_prec}g'
|
|
167
|
+
|
|
168
|
+
content_iter = mcstasutils.cfgstr_2_hkl( **kwargs )
|
|
169
|
+
#TODO: common helper function?
|
|
170
|
+
if args.output is None or args.output == 'stdout':
|
|
171
|
+
import sys
|
|
172
|
+
for line in content_iter:
|
|
173
|
+
sys.stdout.write(line + '\n')
|
|
174
|
+
else:
|
|
175
|
+
from ._common import write_text
|
|
176
|
+
write_text( args.output,
|
|
177
|
+
( '\n'.join( content_iter ) + '\n' ) )
|
|
178
|
+
if not do_quiet:
|
|
179
|
+
import pathlib
|
|
180
|
+
print(f"Wrote {pathlib.Path(args.output).name}")
|