ncrystal-python 3.9.88__py3-none-any.whl → 4.0.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 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__ = '3.9.88'
58
+ __version__ = '4.0.2'
59
59
  __status__ = "Production"
60
60
  __author__ = "NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)"
61
61
  __copyright__ = "Copyright 2015-2024 %s"%__author__
NCrystal/_common.py CHANGED
@@ -420,14 +420,23 @@ def extract_path( s ):
420
420
  return res_try
421
421
  return pathlib.Path(s)
422
422
 
423
- def download_url( url, decode_as_utf8_str = True, wrap_exception = True ):
423
+ def download_url( url,
424
+ decode_as_utf8_str = True,
425
+ wrap_exception = True,
426
+ timeout = None,
427
+ quiet_network_fail = False ):
428
+ """Download the provided url. The timeout value is in seconds if given.
429
+ Returns None on network failure if quiet_network_fail is True.
430
+ """
424
431
  import urllib.request
425
432
  import urllib.error
426
433
  try:
427
434
  req = urllib.request.Request(url)
428
- with urllib.request.urlopen(req) as response:
435
+ with urllib.request.urlopen(req, timeout = timeout ) as response:
429
436
  data = response.read()
430
437
  except urllib.error.URLError as e:
438
+ if quiet_network_fail:
439
+ return None
431
440
  if wrap_exception:
432
441
  from .exceptions import NCException
433
442
  raise NCException(f'Error downloading url "{url}": {e}')
NCrystal/cifutils.py CHANGED
@@ -1239,7 +1239,27 @@ def _cod_get_cifdata( codid, quiet = False ):
1239
1239
  return c
1240
1240
  if not quiet:
1241
1241
  _nc_common.print(f"Querying the Crystallography Open Database for entry {codid}")
1242
- result = _nc_common.download_url( "https://www.crystallography.net/cod/%i.cif"%(codid) )
1242
+
1243
+ mirror_urls = [
1244
+ "https://www.crystallography.net/cod/%i.cif",#canonical first
1245
+ 'https://qiserver.ugr.es/cod/%i.cif',
1246
+ 'http://cod.ibt.lt/cod/%i.cif',
1247
+ ]
1248
+
1249
+ result = None
1250
+ while result is None:
1251
+ #Fail gently and try next mirror - except for the last attempt.
1252
+ url = mirror_urls.pop(0)%codid
1253
+ result = _nc_common.download_url( url,
1254
+ timeout = 10.0,
1255
+ quiet_network_fail = bool(mirror_urls) )
1256
+ if result or not mirror_urls:
1257
+ break
1258
+ nextdescr = '/'.join(mirror_urls[0].split('/')[0:-1])+'/'
1259
+ _nc_common.print(f'Retrival failed. Trying mirror at: {nextdescr}')
1260
+
1261
+ assert result is not None
1262
+
1243
1263
  if len(_cod_cache)==10:
1244
1264
  _cod_cache.pop(0)
1245
1265
  _cod_cache.append( (codid, result ) )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ncrystal-python
3
- Version: 3.9.88
3
+ Version: 4.0.2
4
4
  Summary: Library for thermal neutron transport in crystals and other materials.
5
5
  Author: NCrystal developers (Thomas Kittelmann, Xiao Xiao Cai)
6
6
  License: The Apache 2.0 license is reproduced in the following. See the NOTICE file for
@@ -222,6 +222,10 @@ Requires-Dist: numpy>=1.22
222
222
  NCrystal : A library for thermal neutron transport in crystals and other materials
223
223
  ----------------------------------------------------------------------------------
224
224
 
225
+ ![PyPI - Version](https://img.shields.io/pypi/v/ncrystal)
226
+ ![Conda Version](https://img.shields.io/conda/vn/conda-forge/ncrystal)
227
+ ![Conda Platform](https://img.shields.io/conda/pn/conda-forge/ncrystal-core)
228
+
225
229
  This is a source distribution of NCrystal, a library and associated tools which
226
230
  enables calculations for Monte Carlo simulations of thermal neutrons in crystals
227
231
  and other materials. Supported is a range of physics including both coherent,
@@ -321,17 +325,21 @@ your compiler's include path, and that the NCrystal library is linked
321
325
  correctly. Here are some examples of how this could for instance be done, with a
322
326
  C and a C++ app respectively:
323
327
 
324
- export LDFLAGS="${LDFLAGS:-} -Wl,-rpath,$(ncrystal-config --show libdir) $(ncrystal-config --show libpath)"
325
- export CFLAGS="${CFLAGS:-} -I$(ncrystal-config --show includedir)"
326
- export CXXFLAGS="${CXXFLAGS:-} -I$(ncrystal-config --show includedir)"
327
- cc -std=c11 ${LDFLAGS} ${CFLAGS} my_c_code.c -o my_c_app
328
- c++ -std=c++17 ${LDFLAGS} ${CXXFLAGS} my_cpp_code.cpp -o my_cpp_app
328
+ ```
329
+ export LDFLAGS="${LDFLAGS:-} -Wl,-rpath,$(ncrystal-config --show libdir) $(ncrystal-config --show libpath)"
330
+ export CFLAGS="${CFLAGS:-} -I$(ncrystal-config --show includedir)"
331
+ export CXXFLAGS="${CXXFLAGS:-} -I$(ncrystal-config --show includedir)"
332
+ cc -std=c11 ${LDFLAGS} ${CFLAGS} my_c_code.c -o my_c_app
333
+ c++ -std=c++17 ${LDFLAGS} ${CXXFLAGS} my_cpp_code.cpp -o my_cpp_app
334
+ ```
329
335
 
330
336
  Then, in your code you can access the relevant APIs with with statements like:
331
337
 
332
- #include "NCrystal/NCrystal.hh" // C++ code, core NCrystal
333
- #include "NCrystal/ncrystal.h" // C code
334
- import NCrystal ## Python code
338
+ ```
339
+ #include "NCrystal/NCrystal.hh" // C++ code, core NCrystal
340
+ #include "NCrystal/ncrystal.h" // C code
341
+ import NCrystal ## Python code
342
+ ```
335
343
 
336
344
  In the ./examples/ directory of your NCrystal distribution that you got after
337
345
  downloading and unpacking the NCrystal source tar-ball, you will find small
@@ -339,8 +347,10 @@ examples of code using NCrystal. For C++/C, there is currently no documentation
339
347
  beyond the header files and examples. In the case of Python, there is integrated
340
348
  documentation available via the usual "help" function, accessed with:
341
349
 
342
- import NCrystal
343
- help(NCrystal)
350
+ ```
351
+ import NCrystal
352
+ help(NCrystal)
353
+ ```
344
354
 
345
355
  There are also several jupyter-lab notebooks showcasing the NCrystal python API
346
356
  at https://github.com/mctools/ncrystal-notebooks
@@ -403,13 +413,13 @@ which when used in a complete OpenMC project, results in the following material
403
413
  entry being added to the `materials.xml` produced:
404
414
 
405
415
  ```
406
- <material cfg="Polyethylene_CH2.ncmat;temp=50C" id="1" temperature="323.15">
407
- <density units="g/cm3" value="0.92" />
408
- <nuclide ao="0.66656284" name="H1" />
409
- <nuclide ao="0.00010382666666666666" name="H2" />
410
- <nuclide ao="0.32964066666666664" name="C12" />
411
- <nuclide ao="0.003692666666666666" name="C13" />
412
- </material>
416
+ <material cfg="Polyethylene_CH2.ncmat;temp=50C" id="1" temperature="323.15">
417
+ <density units="g/cm3" value="0.92" />
418
+ <nuclide ao="0.66656284" name="H1" />
419
+ <nuclide ao="0.00010382666666666666" name="H2" />
420
+ <nuclide ao="0.32964066666666664" name="C12" />
421
+ <nuclide ao="0.003692666666666666" name="C13" />
422
+ </material>
413
423
  ```
414
424
 
415
425
  Temperature, density and material composition were all created automatically
@@ -439,13 +449,13 @@ A few issues might warrent attention:
439
449
 
440
450
  For more information, please consult the user guide at:
441
451
 
442
- https://docs.openmc.org/
452
+ * https://docs.openmc.org/
443
453
 
444
454
  In particular note the sections concerning installation and usage of NCrystal in
445
455
  the sections:
446
456
 
447
- https://docs.openmc.org/en/stable/usersguide/install.html
448
- https://docs.openmc.org/en/stable/usersguide/materials.html
457
+ * https://docs.openmc.org/en/stable/usersguide/install.html
458
+ * https://docs.openmc.org/en/stable/usersguide/materials.html
449
459
 
450
460
 
451
461
 
@@ -466,27 +476,35 @@ the correct settings for doing so. Thus, you can always invoke "ncrystal-config
466
476
  active. Depending on how you installed McStas, NCrystal is most likely already
467
477
  available. If not, you can try one of the following ways of enabling it:
468
478
 
469
- $> conda install conda-forge::ncrystal [if you are in a conda-forge env]
470
- $> python3 -mpip install ncrystal [for non-conda users]
479
+ ```
480
+ $> conda install conda-forge::ncrystal [if you are in a conda-forge env]
481
+ $> python3 -mpip install ncrystal [for non-conda users]
482
+ ```
471
483
 
472
484
  It is beyond the scope for this README to provide a full documentation of
473
485
  McStas, or the Union sub-system, but if you are using McStasScript to compose
474
486
  your instruments, you can add NCrystal materials into your Union geometry using
475
487
  code like:
476
488
 
477
- from mcstasscript.tools.ncrystal_union import add_ncrystal_union_material
478
- add_ncrystal_union_material(instr, name="myAl", cfgstr="Al_sg225.ncmat;temp=10C")
489
+ ```
490
+ from mcstasscript.tools.ncrystal_union import add_ncrystal_union_material
491
+ add_ncrystal_union_material(instr, name="myAl", cfgstr="Al_sg225.ncmat;temp=10C")
492
+ ```
479
493
 
480
494
  This creates the material and gives it the name "myAl", which you must later
481
495
  attach to a particular Union volume, like for instance:
482
496
 
483
- myvol.set_parameters(radius=0.01, yheight=0.01,
484
- material_string='"myAl"', priority=1)
497
+ ```
498
+ myvol.set_parameters(radius=0.01, yheight=0.01,
499
+ material_string='"myAl"', priority=1)
500
+ ```
485
501
 
486
502
  If you are instead hand-editing your instrument files, you can generate code
487
503
  which defines Union materials from an NCrystal cfg-string by invoking:
488
504
 
505
+ ```
489
506
  $> python3 -mNCrystal.mcstasutils --union myAl 'Al_sg225.ncmat;temp=250K'
507
+ ```
490
508
 
491
509
  It should be noted that McStas 3.3 also provides a new SHELL syntax which can
492
510
  also be used to faciliate this invocation from with a classic .instr file.
@@ -1,4 +1,4 @@
1
- NCrystal/__init__.py,sha256=reIOKpITY39sEG213UvITze4Qv-eHpGNZCRqYcv0UcA,4156
1
+ NCrystal/__init__.py,sha256=Fm5bSI5_ExO4eoTB4LuJZNatE_LtUc989mLsTW28xkM,4155
2
2
  NCrystal/__main__.py,sha256=tYOeVhY6joHahgtnBwNgcBDd-WXYQoHFmpslk2TAlTY,3624
3
3
  NCrystal/_chooks.py,sha256=GtA8IkVIIJmrT-KtLKRJctgmBYs3pkfi4JNY0jfS7bc,43273
4
4
  NCrystal/_cli_cif2ncmat.py,sha256=Hmp8MWV7d3Bzu_5Ekiik9Pdv43yNyZygun8HtqShn78,14626
@@ -12,7 +12,7 @@ NCrystal/_cli_vdos2ncmat.py,sha256=SnLHzwc1Vg5V896zc4ou1Eug1tKwZR3qrGcCrMybjAI,2
12
12
  NCrystal/_cli_verifyatompos.py,sha256=cDcbLlaBUo6F9_nhFjNYXrqgAoPdpw_U2IUBFrTM3-g,12348
13
13
  NCrystal/_cliimpl.py,sha256=3boTxHnmX3ppqSvOHPauU4LPULr8OqHTF8a9KeBiU4E,13354
14
14
  NCrystal/_cliwrap_config.py,sha256=RPawApLbRrZRTkWdAP3JK_eTtU_nfPrARYcnfF1-7sE,2002
15
- NCrystal/_common.py,sha256=Dy81M0mxPVlv_W54W5uOEALR7wy3Tzx800gDMIwmXBQ,18255
15
+ NCrystal/_common.py,sha256=4iAfyhlQv-3Hvg9XRKlUBjwDZrL782ZZdRZHJ8f-ISQ,18597
16
16
  NCrystal/_coreimpl.py,sha256=dWBPwbdb8l8Bi3wfDaaQVyqSqTQzwDfs1oEIJR9KTiQ,5727
17
17
  NCrystal/_hfgdata.py,sha256=uYTB_xHTHVN8Vw91wr7_kXi18ileHJGNyVjnSi-Ss7g,62828
18
18
  NCrystal/_hklobjects.py,sha256=wQAUe3tD6UncSW-qfuyAh5jSGnA_2kzvE5-HZ43s3xQ,4974
@@ -28,7 +28,7 @@ NCrystal/_testimpl.py,sha256=kvJj-QHFZbJuPeYAT281bKHAIM7Y2XRN3a2m5gNJJlE,27337
28
28
  NCrystal/api.py,sha256=VRJLRLQ461OvEHAv5OGxqimAa7l3PY1mcTZMRQjSkkI,2973
29
29
  NCrystal/atomdata.py,sha256=gwq92dIQqmr8kg_pyquPAsUrI9TWLVOELuEh2OLgkVw,8072
30
30
  NCrystal/cfgstr.py,sha256=IVrMagRTD0TkAhuJkWkGKsJCX4ezG8Tf9uyfkhRjMgY,3741
31
- NCrystal/cifutils.py,sha256=G8MVx1LQlEHt0oai13Sj5cEwJuRkMdC4VB3-75cffS0,78162
31
+ NCrystal/cifutils.py,sha256=4pZuVYjpPBfJv_s4b_h06gHXrQxW--hN85kBZBqb0-o,78826
32
32
  NCrystal/cli.py,sha256=OMUi3NZEwKwvx1fRzNDwWG9Yb-Vm49kkyiMu9NHHTlM,4395
33
33
  NCrystal/constants.py,sha256=ldOyJAAhW0tBNDVexqTw1rxvcmwCnGJOueurXS44Plw,5919
34
34
  NCrystal/core.py,sha256=wH7o2JKzvEGyTNsnMtEdMWxI3Nkh3bBlWP3HMwjRWyk,83339
@@ -45,9 +45,9 @@ NCrystal/plot.py,sha256=Ack-OdgclwIGP-5nOlsoRP5enYaxUeIuT3zDKYtiKT4,19959
45
45
  NCrystal/plugins.py,sha256=U4EF25DlYE8aO6uoG5Ptyia5Nj08LCrVl7973BCIkDI,2440
46
46
  NCrystal/test.py,sha256=-BdnSN8lqwUallf6Q4UL35Rm_eA3BHG_V3-BdvDbkJQ,3310
47
47
  NCrystal/vdos.py,sha256=O6cQy70glPV5D94ssnHW5MuC4WO7OnqqKjDu3-MW4Q4,46763
48
- ncrystal_python-3.9.88.dist-info/LICENSE,sha256=cSwpZfFyXSC1mBPZgO2TbtGwoH2tR1SomMa5tEUU9o0,11509
49
- ncrystal_python-3.9.88.dist-info/METADATA,sha256=282Z_lv0D0nPPNzLzsYZFdhXCroNKqf5zs9yg1faNUA,27358
50
- ncrystal_python-3.9.88.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
51
- ncrystal_python-3.9.88.dist-info/entry_points.txt,sha256=JoeikOrVDenZuTEmdgeGAfHw_CsujEJPIGl3BP_tcKQ,469
52
- ncrystal_python-3.9.88.dist-info/top_level.txt,sha256=VIJdIQMfLIbKpFXA8xm0fKY5okz8s5IHrZTYDSH18y0,9
53
- ncrystal_python-3.9.88.dist-info/RECORD,,
48
+ ncrystal_python-4.0.2.dist-info/LICENSE,sha256=cSwpZfFyXSC1mBPZgO2TbtGwoH2tR1SomMa5tEUU9o0,11509
49
+ ncrystal_python-4.0.2.dist-info/METADATA,sha256=DwC4RZBf6D6a6w-z1eE7inqOenzuWO2HO5yd02aetUs,27566
50
+ ncrystal_python-4.0.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
51
+ ncrystal_python-4.0.2.dist-info/entry_points.txt,sha256=JoeikOrVDenZuTEmdgeGAfHw_CsujEJPIGl3BP_tcKQ,469
52
+ ncrystal_python-4.0.2.dist-info/top_level.txt,sha256=VIJdIQMfLIbKpFXA8xm0fKY5okz8s5IHrZTYDSH18y0,9
53
+ ncrystal_python-4.0.2.dist-info/RECORD,,