pyemaps 2.9.0__tar.gz → 2.10.0__tar.gz

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 (141) hide show
  1. {pyemaps-2.9.0/pyemaps.egg-info → pyemaps-2.10.0}/PKG-INFO +28 -4
  2. {pyemaps-2.9.0 → pyemaps-2.10.0}/README.md +13 -1
  3. pyemaps-2.10.0/__version__.py +1 -0
  4. {pyemaps-2.9.0 → pyemaps-2.10.0}/crystals.py +22 -0
  5. pyemaps-2.10.0/diffract/_resources.py +110 -0
  6. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/bloch_dec.py +81 -9
  7. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/dpgen_dec.py +1 -1
  8. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/mxtal_dec.py +1 -1
  9. {pyemaps-2.9.0 → pyemaps-2.10.0}/emcontrols.py +0 -2
  10. {pyemaps-2.9.0 → pyemaps-2.10.0}/fileutils.py +90 -59
  11. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/adf.ipynb +90 -90
  12. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/al_cu_phasemap.ipynb +57 -57
  13. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/al_ediom.ipynb +40 -40
  14. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/al_orientmap.ipynb +143 -66
  15. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/powder.ipynb +33 -33
  16. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/probe.ipynb +61 -61
  17. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_bloch.ipynb +54 -54
  18. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_constructor.ipynb +34 -34
  19. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_csf.ipynb +49 -49
  20. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_dif.ipynb +66 -66
  21. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_lacbed.ipynb +53 -47
  22. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_multislice.ipynb +41 -41
  23. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_scm.ipynb +53 -53
  24. {pyemaps-2.9.0 → pyemaps-2.10.0}/notebooks/si_stereo.ipynb +34 -34
  25. {pyemaps-2.9.0 → pyemaps-2.10.0}/probe.py +49 -0
  26. {pyemaps-2.9.0 → pyemaps-2.10.0/pyemaps.egg-info}/PKG-INFO +28 -4
  27. {pyemaps-2.9.0 → pyemaps-2.10.0}/pyemaps.egg-info/SOURCES.txt +2 -0
  28. {pyemaps-2.9.0 → pyemaps-2.10.0}/pyemaps.egg-info/requires.txt +1 -1
  29. {pyemaps-2.9.0 → pyemaps-2.10.0}/setup.py +3 -2
  30. {pyemaps-2.9.0 → pyemaps-2.10.0}/stackimg.py +7 -7
  31. {pyemaps-2.9.0 → pyemaps-2.10.0}/xtal.py +2 -2
  32. pyemaps-2.9.0/__version__.py +0 -1
  33. {pyemaps-2.9.0 → pyemaps-2.10.0}/COPYING +0 -0
  34. {pyemaps-2.9.0 → pyemaps-2.10.0}/MANIFEST.in +0 -0
  35. {pyemaps-2.9.0 → pyemaps-2.10.0}/__config__.py +0 -0
  36. {pyemaps-2.9.0 → pyemaps-2.10.0}/__init__.py +0 -0
  37. {pyemaps-2.9.0 → pyemaps-2.10.0}/__main__.py +0 -0
  38. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Aluminium.xtl +0 -0
  39. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/AluminiumOxide.xtl +0 -0
  40. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Aluminium_FCC.xtl +0 -0
  41. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/BariumTitanate_180k.xtl +0 -0
  42. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/BariumTitanate_270k.xtl +0 -0
  43. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/BariumTitanate_Tetra.xtl +0 -0
  44. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/BiMnO3.xtl +0 -0
  45. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Boron_Tetra.xtl +0 -0
  46. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/CadmiumSelenide_Hex.xtl +0 -0
  47. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/CadmiumSulfide_Cubic.xtl +0 -0
  48. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/CadmiumSulfide_Hex.xtl +0 -0
  49. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Chromium_BCC.xtl +0 -0
  50. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/CoSb3_Skutterudite.xtl +0 -0
  51. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/CopperOxide.xtl +0 -0
  52. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Copper_FCC.xtl +0 -0
  53. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Cu2O_Cuprite.xtl +0 -0
  54. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Diamond.xtl +0 -0
  55. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/ErbiumPyrogermanate.xtl +0 -0
  56. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/FePd_Tetra.xtl +0 -0
  57. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/FeS2_Pyrite.xtl +0 -0
  58. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/GalliumAntimonide.xtl +0 -0
  59. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/GalliumArsenide.xtl +0 -0
  60. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/GalliumNitride.xtl +0 -0
  61. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Germanium.xtl +0 -0
  62. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Gold_FCC.xtl +0 -0
  63. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/IndiumArsenide.xtl +0 -0
  64. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/LaMnO3.xtl +0 -0
  65. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/LeadZirconateTitanate.xtl +0 -0
  66. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Li2MnO3.xtl +0 -0
  67. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/NaFeO2.xtl +0 -0
  68. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Nb3Sn.xtl +0 -0
  69. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Pentacene.xtl +0 -0
  70. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/SiAlONa.xtl +0 -0
  71. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Silicon.xtl +0 -0
  72. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/StrontiumTitanate.xtl +0 -0
  73. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/TelluriumDioxide.xtl +0 -0
  74. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/TinDioxide_RT.xtl +0 -0
  75. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/TitaniumDioxide_Anatase.xtl +0 -0
  76. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/TitaniumDioxide_Rutile.xtl +0 -0
  77. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/TungstenDiselenide.xtl +0 -0
  78. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/VanadiumDioxide_RT.xtl +0 -0
  79. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/ZincOxide.xtl +0 -0
  80. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/Zinc_HCP.xtl +0 -0
  81. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/ZirconiumNitride.xtl +0 -0
  82. {pyemaps-2.9.0 → pyemaps-2.10.0}/cdata/limno2.xtl +0 -0
  83. {pyemaps-2.9.0 → pyemaps-2.10.0}/cifreader.py +0 -0
  84. {pyemaps-2.9.0 → pyemaps-2.10.0}/ddiffs.py +0 -0
  85. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/__init__.py +0 -0
  86. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/csf_dec.py +0 -0
  87. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/dif_dec.py +0 -0
  88. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/powder_dec.py +0 -0
  89. {pyemaps-2.9.0 → pyemaps-2.10.0}/diffract/stereo_dec.py +0 -0
  90. {pyemaps-2.9.0 → pyemaps-2.10.0}/display.py +0 -0
  91. {pyemaps-2.9.0 → pyemaps-2.10.0}/dmreader.py +0 -0
  92. {pyemaps-2.9.0 → pyemaps-2.10.0}/emdreader.py +0 -0
  93. {pyemaps-2.9.0 → pyemaps-2.10.0}/errors.py +0 -0
  94. {pyemaps-2.9.0 → pyemaps-2.10.0}/expimage.py +0 -0
  95. {pyemaps-2.9.0 → pyemaps-2.10.0}/kdiffs.py +0 -0
  96. {pyemaps-2.9.0 → pyemaps-2.10.0}/license-exception.txt +0 -0
  97. {pyemaps-2.9.0 → pyemaps-2.10.0}/license.txt +0 -0
  98. {pyemaps-2.9.0 → pyemaps-2.10.0}/mibreader.py +0 -0
  99. {pyemaps-2.9.0 → pyemaps-2.10.0}/mrcreader.py +0 -0
  100. {pyemaps-2.9.0 → pyemaps-2.10.0}/orientmap.py +0 -0
  101. {pyemaps-2.9.0 → pyemaps-2.10.0}/phasemap.py +0 -0
  102. {pyemaps-2.9.0 → pyemaps-2.10.0}/picreader.py +0 -0
  103. {pyemaps-2.9.0 → pyemaps-2.10.0}/pyemaps.egg-info/dependency_links.txt +0 -0
  104. {pyemaps-2.9.0 → pyemaps-2.10.0}/pyemaps.egg-info/entry_points.txt +0 -0
  105. {pyemaps-2.9.0 → pyemaps-2.10.0}/pyemaps.egg-info/top_level.txt +0 -0
  106. {pyemaps-2.9.0 → pyemaps-2.10.0}/pyproject.toml +0 -0
  107. {pyemaps-2.9.0 → pyemaps-2.10.0}/readerbase.py +0 -0
  108. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/Al_COD_4004108.cif +0 -0
  109. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/Cu_COD_7101269.cif +0 -0
  110. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/Si_COD_2102763.cif +0 -0
  111. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/adf.py +0 -0
  112. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/al.img +0 -0
  113. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/al_cu_phasemap.py +0 -0
  114. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/al_dpgen.py +0 -0
  115. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/al_ediom.py +0 -0
  116. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/al_orientmap.py +0 -0
  117. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/convert_image.py +0 -0
  118. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/crystal_imaging.py +0 -0
  119. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/crystal_thickness.py +0 -0
  120. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/ctf.py +0 -0
  121. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/dm_diff.py +0 -0
  122. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/hrem.py +0 -0
  123. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/mask.im3 +0 -0
  124. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/powder.py +0 -0
  125. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/raw.img +0 -0
  126. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/ronchigram.py +0 -0
  127. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_bloch.py +0 -0
  128. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_constructor.py +0 -0
  129. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_csf.py +0 -0
  130. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_dif.py +0 -0
  131. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_lacbed.py +0 -0
  132. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_pyemaps.py +0 -0
  133. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_scm.py +0 -0
  134. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/si_stereo.py +0 -0
  135. {pyemaps-2.9.0 → pyemaps-2.10.0}/samples/stem_probe.py +0 -0
  136. {pyemaps-2.9.0 → pyemaps-2.10.0}/scattering/__init__.py +0 -0
  137. {pyemaps-2.9.0 → pyemaps-2.10.0}/scattering/sct_dec.py +0 -0
  138. {pyemaps-2.9.0 → pyemaps-2.10.0}/setup.cfg +0 -0
  139. {pyemaps-2.9.0 → pyemaps-2.10.0}/spg/__init__.py +0 -0
  140. {pyemaps-2.9.0 → pyemaps-2.10.0}/spg/spg_dec.py +0 -0
  141. {pyemaps-2.9.0 → pyemaps-2.10.0}/tiffreader.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyemaps
3
- Version: 2.9.0
3
+ Version: 2.10.0
4
4
  Summary: A Python Package for Transmission Electron Diffraction Simulations and Crystallographic Computing
5
5
  Home-page: https://github.com/emlab-solutions/pyemaps
6
6
  Author: EMLab Solutions, Inc.
@@ -24,7 +24,7 @@ Description-Content-Type: text/markdown
24
24
  License-File: license-exception.txt
25
25
  License-File: license.txt
26
26
  License-File: COPYING
27
- Requires-Dist: emaps>=2.6.0
27
+ Requires-Dist: emaps>=2.7.0
28
28
  Requires-Dist: numpy>=2.0
29
29
  Requires-Dist: matplotlib>=3.8.4
30
30
  Provides-Extra: emd
@@ -37,6 +37,8 @@ Dynamic: provides-extra
37
37
  Dynamic: requires-dist
38
38
  Dynamic: summary
39
39
 
40
+ <p align="center"><img src="https://emlab-solutions.github.io/pyemaps/_static/pyemaps-logo.svg" alt="pyEMAPS icon: an electron diffraction pattern" width="96"></p>
41
+
42
+
43
+
40
44
  # pyEMAPS
41
45
 
42
46
 
43
47
 
44
48
  **pyEMAPS** is a Python package for transmission electron diffraction simulations and
45
49
 
@@ -50,6 +52,13 @@ kinematical and dynamical electron diffraction described by J. C. H. Spence and
50
52
  [Release notes](https://emlab-solutions.github.io/pyemaps/rn.html) ·
51
53
 
52
54
  [Issues](https://github.com/emlab-solutions/pyemaps/issues)
53
55
 
54
56
 
55
57
 
58
+ <p align="center">
59
+
60
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/kinematic.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/kinematic.png" alt="Kinematic diffraction pattern of silicon" width="180"></a>
61
+
62
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/dynamic.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/bloch.png" alt="Bloch-wave CBED pattern of silicon" width="180"></a>
63
+
64
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/probe/ctf.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/ctf.png" alt="Contrast transfer function of an objective lens" width="180"></a>
65
+
66
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/stem4d/phase.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/phasemap.png" alt="Phase map of aluminium and copper grains" width="180"></a>
67
+
68
+ </p>
69
+
70
+
71
+
56
72
  ## Features
57
73
 
58
74
 
59
75
 
60
76
  The base features are free, under the GNU General Public License v3.0:
61
77
 
@@ -178,10 +187,13 @@ tools to the education and research communities.
178
187
  We're looking for experts in electron microscopy and crystallography, and Python enthusiasts, to
179
188
 
180
189
  join the project. Contact us at support@emlabsoftware.com if you're interested.
181
190
 
182
191
 
183
192
 
193
+ - [CONTRIBUTING.md](https://github.com/emlab-solutions/pyemaps/blob/main/CONTRIBUTING.md)
194
+
195
+ explains how to report a bug, suggest an idea and contribute changes. For licenses and everything
196
+
197
+ else, see [Contact](https://emlab-solutions.github.io/pyemaps/contact.html).
198
+
184
199
  - [DEVELOPMENT.md](https://github.com/emlab-solutions/pyemaps/blob/main/DEVELOPMENT.md)
185
200
 
186
201
  explains how to build pyEMAPS, run its tests and build the documentation, and how we work.
187
202
 
188
203
  - Please read and agree to our
189
204
 
190
- [Contributor License Agreement](https://github.com/emlab-solutions/pyemaps/blob/main/CONTRIBUTING.md)
191
-
205
+ [Contributor License Agreement](https://github.com/emlab-solutions/pyemaps/blob/main/CLA.md)
206
+
192
207
  before contributing.
193
208
 
194
209
  - We follow the
195
210
 
196
211
  [Contributor Covenant](https://www.contributor-covenant.org/version/2/0/code_of_conduct/) as our
197
212
 
@@ -1,3 +1,5 @@
1
+ <p align="center"><img src="https://emlab-solutions.github.io/pyemaps/_static/pyemaps-logo.svg" alt="pyEMAPS icon: an electron diffraction pattern" width="96"></p>
2
+
1
3
  # pyEMAPS
2
4
 
3
5
  **pyEMAPS** is a Python package for transmission electron diffraction simulations and
@@ -11,6 +13,13 @@ kinematical and dynamical electron diffraction described by J. C. H. Spence and
11
13
  [Release notes](https://emlab-solutions.github.io/pyemaps/rn.html) ·
12
14
  [Issues](https://github.com/emlab-solutions/pyemaps/issues)
13
15
 
16
+ <p align="center">
17
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/kinematic.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/kinematic.png" alt="Kinematic diffraction pattern of silicon" width="180"></a>
18
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/dynamic.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/bloch.png" alt="Bloch-wave CBED pattern of silicon" width="180"></a>
19
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/probe/ctf.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/ctf.png" alt="Contrast transfer function of an objective lens" width="180"></a>
20
+ <a href="https://emlab-solutions.github.io/pyemaps/user_guide/stem4d/phase.html"><img src="https://emlab-solutions.github.io/pyemaps/_static/images/cards/phasemap.png" alt="Phase map of aluminium and copper grains" width="180"></a>
21
+ </p>
22
+
14
23
  ## Features
15
24
 
16
25
  The base features are free, under the GNU General Public License v3.0:
@@ -139,10 +148,13 @@ tools to the education and research communities.
139
148
  We're looking for experts in electron microscopy and crystallography, and Python enthusiasts, to
140
149
  join the project. Contact us at support@emlabsoftware.com if you're interested.
141
150
 
151
+ - [CONTRIBUTING.md](https://github.com/emlab-solutions/pyemaps/blob/main/CONTRIBUTING.md)
152
+ explains how to report a bug, suggest an idea and contribute changes. For licenses and everything
153
+ else, see [Contact](https://emlab-solutions.github.io/pyemaps/contact.html).
142
154
  - [DEVELOPMENT.md](https://github.com/emlab-solutions/pyemaps/blob/main/DEVELOPMENT.md)
143
155
  explains how to build pyEMAPS, run its tests and build the documentation, and how we work.
144
156
  - Please read and agree to our
145
- [Contributor License Agreement](https://github.com/emlab-solutions/pyemaps/blob/main/CONTRIBUTING.md)
157
+ [Contributor License Agreement](https://github.com/emlab-solutions/pyemaps/blob/main/CLA.md)
146
158
  before contributing.
147
159
  - We follow the
148
160
  [Contributor Covenant](https://www.contributor-covenant.org/version/2/0/code_of_conduct/) as our
@@ -0,0 +1 @@
1
+ __version__ = "2.10.0"
@@ -1181,6 +1181,28 @@ class Crystal:
1181
1181
  :rtype: Crystal
1182
1182
  :raise ~pyemaps.errors.CrystalClassError: if the file isn't found, or its cell, atoms or space group don't
1183
1183
  validate.
1184
+
1185
+ pyEMAPS reads the unit cell, the space group (from the symmetry operators, the
1186
+ Hermann-Mauguin symbol or the number) and the atom sites with their occupancies and
1187
+ thermal factors. The crystal is named after the file's data block.
1188
+
1189
+ Example files: the samples include three CIF files of refined crystal structures from the
1190
+ `Crystallography Open Database <https://www.crystallography.net>`_ (COD), as COD
1191
+ distributes them:
1192
+ `Al_COD_4004108.cif <https://github.com/emlab-solutions/pyemaps/blob/main/samples/Al_COD_4004108.cif>`_
1193
+ (aluminium),
1194
+ `Cu_COD_7101269.cif <https://github.com/emlab-solutions/pyemaps/blob/main/samples/Cu_COD_7101269.cif>`_
1195
+ (copper) and
1196
+ `Si_COD_2102763.cif <https://github.com/emlab-solutions/pyemaps/blob/main/samples/Si_COD_2102763.cif>`_
1197
+ (silicon). ``pyemaps -cp samples`` copies them, with the sample scripts, into a
1198
+ *pyemaps_samples* folder in the current directory:
1199
+
1200
+ .. code-block:: python
1201
+
1202
+ from pyemaps import Crystal
1203
+
1204
+ al = Crystal.from_cif('Al_COD_4004108.cif') # run in pyemaps_samples
1205
+ print(al.name) # 4004108, the file's data block
1184
1206
  """
1185
1207
 
1186
1208
  cfn = fn
@@ -0,0 +1,110 @@
1
+ # This file is part of pyEMAPS.
2
+ # Copyright (C) 2021-2026 EMLab Solutions, Inc.
3
+ #
4
+ # SPDX-License-Identifier: GPL-3.0-or-later
5
+ #
6
+ # Additional permission under GPLv3 Section 7:
7
+ # See license-exception.txt for the exception permitting
8
+ # combination with the separately licensed backend, emaps.
9
+
10
+ '''
11
+ Memory and time estimates for dynamic diffraction (Bloch) sessions, so that a run too large
12
+ for the computer stops with a clear message before it allocates the memory, and a long run
13
+ says how long it will take before it starts.
14
+
15
+ The memory figures follow the backend's allocations:
16
+
17
+ * the beam matrix, one complex value (8 bytes) for each pair of beams: 8 x nbeams**2 bytes;
18
+ * at each sampling point, the strong-beam eigenproblem of N beams (the beams diagonalized):
19
+ about 48 x N**2 bytes for each thread working on one;
20
+ * the images, 4 bytes per pixel.
21
+ '''
22
+
23
+ import os
24
+ import sys
25
+
26
+ BEAM_MATRIX_BYTES = 8 # bytes per beam pair (COMPLEX)
27
+ EIGEN_BYTES = 48 # bytes per N**2, for each thread solving a sampling point
28
+ PIXEL_BYTES = 4 # float32 images
29
+
30
+ # Memory use above this fraction of the free memory gets a warning
31
+ MEMORY_WARN_FRACTION = 0.5
32
+
33
+ # The images' run time is estimated from one sampling point solved on its own, which the
34
+ # backend does with all threads: on a 6-core PC the sampling points then took 0.35 to 0.5
35
+ # times as long each, run side by side, for 500 to 1300 beams diagonalized.
36
+ PILOT_FACTOR = 0.5
37
+
38
+ # Runs estimated to take longer than this get a warning
39
+ LONG_RUN_SECONDS = 60
40
+
41
+ # The timing point is solved only when this many beams or more are diagonalized: below it, runs on
42
+ # a 6-core PC took under 10 seconds at the default sampling, and the point would cost up to 3%.
43
+ PILOT_MIN_NDIAG = 400
44
+
45
+
46
+ def available_memory():
47
+ '''Free physical memory in bytes, or None if it can't be found.'''
48
+ if sys.platform == 'win32':
49
+ import ctypes
50
+
51
+ class _MemoryStatusEx(ctypes.Structure):
52
+ _fields_ = [('dwLength', ctypes.c_ulong), ('dwMemoryLoad', ctypes.c_ulong),
53
+ ('ullTotalPhys', ctypes.c_ulonglong), ('ullAvailPhys', ctypes.c_ulonglong),
54
+ ('ullTotalPageFile', ctypes.c_ulonglong),
55
+ ('ullAvailPageFile', ctypes.c_ulonglong),
56
+ ('ullTotalVirtual', ctypes.c_ulonglong),
57
+ ('ullAvailVirtual', ctypes.c_ulonglong),
58
+ ('ullAvailExtendedVirtual', ctypes.c_ulonglong)]
59
+
60
+ status = _MemoryStatusEx()
61
+ status.dwLength = ctypes.sizeof(_MemoryStatusEx)
62
+ try:
63
+ if ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(status)):
64
+ return int(status.ullAvailPhys)
65
+ except (AttributeError, OSError):
66
+ return None
67
+ return None
68
+ try:
69
+ return os.sysconf('SC_AVPHYS_PAGES') * os.sysconf('SC_PAGE_SIZE')
70
+ except (AttributeError, ValueError, OSError):
71
+ return None
72
+
73
+
74
+ def openmp_threads():
75
+ '''The number of threads the backend's OpenMP loops use.'''
76
+ try:
77
+ n = int(os.environ.get('OMP_NUM_THREADS', '').split(',')[0])
78
+ if n > 0:
79
+ return n
80
+ except ValueError:
81
+ pass
82
+ return os.cpu_count() or 1
83
+
84
+
85
+ def beam_matrix_bytes(nbeams):
86
+ return BEAM_MATRIX_BYTES * nbeams * nbeams
87
+
88
+
89
+ def images_bytes(ndiag, threads, det_size, nslices):
90
+ '''Memory the images need: the eigenproblems solved at once, and the images themselves.'''
91
+ return EIGEN_BYTES * ndiag * ndiag * threads + PIXEL_BYTES * det_size * det_size * nslices
92
+
93
+
94
+ def gb(nbytes):
95
+ '''A memory size: "8.6 GB", "250 MB" below 1 GB, "4 KB" below 1 MB.'''
96
+ if nbytes < 1024**2:
97
+ return f'{max(1, round(nbytes / 1024))} KB'
98
+ if nbytes < 1024**3:
99
+ return f'{max(1, round(nbytes / 1024**2))} MB'
100
+ return f'{nbytes / 1024**3:.1f} GB'
101
+
102
+
103
+ def duration(seconds):
104
+ '''A rough duration: "about 3 minutes", "about 1.5 hours".'''
105
+ if seconds < 90:
106
+ n = max(1, round(seconds))
107
+ return f'about {n} second{"" if n == 1 else "s"}'
108
+ if seconds < 5400:
109
+ return f'about {round(seconds / 60)} minutes'
110
+ return f'about {seconds / 3600:.1f} hours'
@@ -66,6 +66,9 @@ def add_bloch(target):
66
66
  import numpy as np
67
67
  from numpy import asfortranarray as farray
68
68
  from .. import TY_NORMAL, TY_LACBED
69
+ import time
70
+ import warnings
71
+ from . import _resources as _res
69
72
 
70
73
  BIMG_EXT = '.im3'
71
74
  MAX_BIMGFN = 256
@@ -128,8 +131,10 @@ def add_bloch(target):
128
131
  :return: ``(n, points)``: the number of sampling points, and the points as a list of
129
132
  ``(i, j)`` tuples.
130
133
  :rtype: tuple
131
- :raise ~pyemaps.errors.BlochError: if an input is invalid, the backend's resource limit is reached, or the
132
- simulation fails.
134
+ :raise ~pyemaps.errors.BlochError: if an input is invalid, the backend's resource limit is reached, the
135
+ beam matrix (8 bytes for each pair of beams) needs more memory than is free, or the
136
+ simulation fails. The memory is checked before the session allocates it, and a
137
+ Python warning says if it needs more than half of what's free.
133
138
  """
134
139
  if aperture is None or not isinstance(aperture, (int, float)):
135
140
  raise BlochError('Objective aperture must be valid numberal')
@@ -176,17 +181,38 @@ def add_bloch(target):
176
181
  if ret == 0:
177
182
  dif.diff_internaldelete(1)
178
183
  raise BlochError('Error bloch runtime1')
179
-
184
+
185
+ # The session allocates the beam matrix first, 8 bytes per pair of beams: stop here,
186
+ # before it does, if it can't fit in the free memory.
187
+ nbeams = dif.get_nbeams()
188
+ need, free = _res.beam_matrix_bytes(nbeams), _res.available_memory()
189
+ if free is not None and need > free:
190
+ dif.diff_internaldelete(1)
191
+ raise BlochError(f'This crystal and zone have {nbeams:,} beams, which need '
192
+ f'{_res.gb(need)} of memory for the Bloch run, and this computer has '
193
+ f'{_res.gb(free)} free. Lower gmax or the excitation error limits '
194
+ f'in em_controls, or choose another zone, and retry')
195
+ if free is not None and need > _res.MEMORY_WARN_FRACTION * free:
196
+ warnings.warn(f'This crystal and zone have {nbeams:,} beams, which need '
197
+ f'{_res.gb(need)} of memory for the Bloch run, more than half of the '
198
+ f'{_res.gb(free)} free; the computer may slow down. Lowering gmax or '
199
+ f'the excitation error limits in em_controls uses less.', stacklevel=2)
200
+
180
201
  dif.diff_internaldelete(1)
181
-
202
+
182
203
  ret = bloch.dobloch(aperture,omega,sampling,0.0)
183
-
204
+
184
205
  if ret == 2:
185
206
  raise BlochError('Predefined Bloch computation resource limit reached')
186
207
 
208
+ if ret == -200:
209
+ raise BlochError(f'Too many beams to diagonalize ({int(bloch.ndiag_max):,}) for this '
210
+ f'crystal and zone: lower omega, or gmax or the excitation error '
211
+ f'limits in em_controls, and retry')
212
+
187
213
  if ret != 0:
188
214
  raise BlochError('Error computing dynamic diffraction')
189
-
215
+
190
216
  nsampling = bloch.get_nsampling()
191
217
  sampling_points = farray(np.zeros((2, nsampling)), dtype=int)
192
218
  sampling_points, ret = bloch.get_samplingpoints(sampling_points)
@@ -220,7 +246,39 @@ def add_bloch(target):
220
246
  self.session_controls=em_controls
221
247
  return nsampling, sp
222
248
 
223
- def getBlochImages(self,
249
+ def _checkBlochImages(self, det_size, nslices):
250
+ """
251
+ Before the session's images are made: raise BlochError if they need more memory than is
252
+ free, and warn if they will take long. The time is measured on this computer, by solving
253
+ one sampling point on its own (about 1% of the work) and scaling to all of them; only
254
+ when at least PILOT_MIN_NDIAG (400) beams are diagonalized, since smaller runs are short.
255
+ """
256
+ ndiag, ntilt = int(bloch.ndiag_max), int(bloch.ntilt)
257
+ threads = min(_res.openmp_threads(), max(ntilt, 1))
258
+ need, free = _res.images_bytes(ndiag, threads, det_size, nslices), _res.available_memory()
259
+ if free is not None and need > free:
260
+ images = f'{nslices:,} image' + ('' if nslices == 1 else 's')
261
+ raise BlochError(f'The images need {_res.gb(need)} of memory ({ndiag:,} beams '
262
+ f'diagonalized on {threads} threads, and {images} of '
263
+ f'{det_size} x {det_size}), and this computer has {_res.gb(free)} '
264
+ f'free. Lower omega, gmax or the excitation error limits, or make '
265
+ f'fewer or smaller images, and retry')
266
+ if free is not None and need > _res.MEMORY_WARN_FRACTION * free:
267
+ warnings.warn(f'The images need {_res.gb(need)} of memory, more than half of the '
268
+ f'{_res.gb(free)} free; the computer may slow down.', stacklevel=3)
269
+
270
+ if ndiag < _res.PILOT_MIN_NDIAG:
271
+ return # a short run: not worth timing
272
+ start = time.perf_counter()
273
+ _, ret = bloch.compute_scm([0, 0])
274
+ seconds = _res.PILOT_FACTOR * ntilt * (time.perf_counter() - start)
275
+ if ret == 0 and seconds > _res.LONG_RUN_SECONDS:
276
+ warnings.warn(f'These Bloch images will take {_res.duration(seconds)} on this '
277
+ f'computer: {ndiag:,} beams are diagonalized at each of {ntilt} '
278
+ f'sampling points. To shorten it, lower sampling (the time grows with '
279
+ f'its square), omega, or gmax in em_controls.', stacklevel=3)
280
+
281
+ def getBlochImages(self,
224
282
  sample_thickness = DEF_THICKNESS,
225
283
  pix_size = DEF_PIXSIZE,
226
284
  det_size = DEF_DETSIZE,
@@ -250,7 +308,8 @@ def add_bloch(target):
250
308
  :rtype: :py:class:`~pyemaps.ddiffs.BlochImgs`
251
309
  :raise ~pyemaps.errors.BlochListError: if *sample_thickness*, *pix_size* or *det_size* is invalid, or there
252
310
  are too many thicknesses.
253
- :raise ~pyemaps.errors.BlochError: if the images can't be made or the file can't be written.
311
+ :raise ~pyemaps.errors.BlochError: if the images need more memory than is free, they can't be made, or
312
+ the file can't be written.
254
313
 
255
314
  .. warning::
256
315
 
@@ -260,6 +319,11 @@ def add_bloch(target):
260
319
  - the detector size *det_size*: 256 instead of the default 512, for example, uses a
261
320
  quarter of the image memory;
262
321
  - the number of sampling points *sampling*.
322
+
323
+ Before making the images, pyEMAPS checks that they fit in the free memory. When 400
324
+ or more beams are diagonalized, it also times one sampling point on this computer, and
325
+ if the images will take more than a minute, a Python warning says roughly how long. The time grows with the square of *sampling*
326
+ and steeply with the number of beams diagonalized, which *omega* and *gmax* set.
263
327
  """
264
328
  from copy import deepcopy
265
329
 
@@ -291,6 +355,8 @@ def add_bloch(target):
291
355
  if ndep > MAX_DEPTH:
292
356
  raise BlochListError(f'Number of sample thickness cannot exceed {MAX_DEPTH}')
293
357
 
358
+ self._checkBlochImages(det_size, ndep * (bloch.getncalcbeams() if nType == TY_LACBED else 1))
359
+
294
360
  # save the input as optional control attributes
295
361
  imgfn =''
296
362
  if bSave:
@@ -591,7 +657,8 @@ def add_bloch(target):
591
657
  :type bSave: bool, optional
592
658
  :return: the images, each with the controls and thickness it was made with.
593
659
  :rtype: :py:class:`~pyemaps.ddiffs.BlochImgs`
594
- :raise ~pyemaps.errors.BlochError: if an input is invalid or the simulation fails.
660
+ :raise ~pyemaps.errors.BlochError: if an input is invalid, the run needs more memory than is free, or
661
+ the simulation fails.
595
662
  :raise ~pyemaps.errors.BlochListError: if *sample_thickness*, *pix_size* or *det_size* is invalid.
596
663
 
597
664
  .. warning::
@@ -602,6 +669,10 @@ def add_bloch(target):
602
669
  - the detector size *det_size*: 256 instead of the default 512, for example, uses a
603
670
  quarter of the image memory;
604
671
  - the number of sampling points *sampling*.
672
+
673
+ The run stops with a ``BlochError`` before allocating memory that isn't free, and a
674
+ Python warning says if the images will take more than a minute, timed on this
675
+ computer (see :py:meth:`~pyemaps.crystals.Crystal.getBlochImages`).
605
676
  """
606
677
  try:
607
678
 
@@ -654,6 +725,7 @@ def add_bloch(target):
654
725
  target.getSCMatrix = getSCMatrix
655
726
  target.getBlochImages = getBlochImages
656
727
  target.getCalculatedBeams = getCalculatedBeams
728
+ target._checkBlochImages = _checkBlochImages
657
729
  # target.getLACBEDImage = getLACBEDImage
658
730
  # ---These calls must be between beginBloch and endBloch calls
659
731
 
@@ -87,7 +87,7 @@ def add_dpgen(target):
87
87
  :raise ~pyemaps.errors.LicenseError: without an active pyEMAPS license (emaps 2.6.0
88
88
  and later).
89
89
 
90
- .. image:: https://github.com/emlab-solutions/imagepypy/raw/main/stereoprojectionmap.png
90
+ .. image:: https://raw.githubusercontent.com/emlab-solutions/imagepypy/main/stereoprojectionmap.png
91
91
  :width: 75%
92
92
  :align: center
93
93
  """
@@ -24,7 +24,7 @@ def add_mxtal(target):
24
24
  def printXYZ( mx):
25
25
  """
26
26
  Print a crystal structure from :py:meth:`~pyemaps.crystals.Crystal.generateMxtal` in XYZ format. See
27
- `XYZ format <https://wiki.jmol.org/index.php/File_formats/Formats/XYZ>`_.
27
+ `XYZ format <https://en.wikipedia.org/wiki/XYZ_file_format>`_.
28
28
 
29
29
  :param mx: the crystal structure.
30
30
  :type mx: :py:class:`~pyemaps.xtal.Xtal`, required
@@ -8,8 +8,6 @@
8
8
  # combination with the separately licensed backend, emaps.
9
9
 
10
10
  """
11
- Microscope and simulation controls.
12
-
13
11
  This module defines two control classes: :py:class:`EMControl` for the microscope, sample
14
12
  and detector, and :py:class:`SIMControl` for the simulation. The simulation controls change
15
13
  less often, so an EMControl holds a SIMControl.
@@ -283,84 +283,115 @@ def _getCIFInt(s):
283
283
 
284
284
  return int(sw)
285
285
 
286
- def _scrubCIFSymmXYZ(cf, maxlen):
286
+ _SYMOP_TERM_RX = re.compile(r'[+-]?[^+-]+')
287
+ _SYMOP_COEF_RX = re.compile(r'^(\d+(?:\.\d*)?|\.\d+)?\*?([xyz])$')
288
+ _SYMOP_AXES = {'x': 0, 'y': 1, 'z': 2}
289
+ _SYMOP_TOL = 2e-3 # translations given as decimals, e.g. 0.333 for 1/3
290
+
291
+
292
+ def _parseSymopNumber(s):
293
+ if '/' in s:
294
+ num, den = s.split('/', 1)
295
+ return float(num) / float(den)
296
+ return float(s)
297
+
298
+
299
+ def _parseSymop(op):
287
300
  '''
288
- scrub off those items white space and longer than MAX_SPG_LEN
301
+ Parse one symmetry operator such as ``-x+1/2,y+1/2,-z+1/2`` into its rotation
302
+ (a tuple of three integer rows) and translation (three numbers reduced to [0, 1)).
289
303
 
304
+ Case, spaces, quotes, term order, an explicit ``+`` and decimal or fractional
305
+ translations don't matter, so ``1/2-X, +Y, 0.5-Z`` parses the same as ``-x+1/2,y,-z+1/2``.
306
+ A trailing comma is ignored. Returns None if *op* isn't a valid operator.
307
+ '''
308
+ s = re.sub(r'\s+', '', op).strip('\'"').lower().rstrip(',')
309
+ parts = s.split(',')
310
+ if len(parts) != 3:
311
+ return None
312
+
313
+ rot = []
314
+ trans = []
315
+ for p in parts:
316
+ if not p or ''.join(_SYMOP_TERM_RX.findall(p)) != p:
317
+ return None
318
+ row = [0, 0, 0]
319
+ t = 0.0
320
+ for term in _SYMOP_TERM_RX.findall(p):
321
+ sign = -1 if term[0] == '-' else 1
322
+ body = term.lstrip('+-')
323
+ m = _SYMOP_COEF_RX.match(body)
324
+ try:
325
+ if m:
326
+ coef = float(m.group(1)) if m.group(1) else 1.0
327
+ if coef != int(coef):
328
+ return None
329
+ row[_SYMOP_AXES[m.group(2)]] += sign * int(coef)
330
+ else:
331
+ t += sign * _parseSymopNumber(body)
332
+ except (ValueError, ZeroDivisionError):
333
+ return None
334
+ rot.append(tuple(row))
335
+ trans.append(t % 1.0)
336
+
337
+ return tuple(rot), tuple(trans)
338
+
339
+
340
+ def _parseCIFSymmXYZ(cf):
341
+ '''
342
+ Parse the symmetry operators of a CIF; operators that don't parse are left out.
290
343
  '''
291
-
292
344
  res = []
293
- l = 0
294
345
  for c in cf:
295
- toks = re.split(r'\s+', c)
296
- s = ''.join(toks)
297
- if len(s) <= maxlen:
298
- l += 1
299
- res.append(s)
300
-
301
- return l, res
346
+ op = _parseSymop(c)
347
+ if op is not None:
348
+ res.append(op)
349
+ return len(res), res
302
350
 
303
- def _simplifyCIF(str1, str2):
304
- s1 = str1.replace('-', '+-').strip('+')
305
- s2 = str2.replace('-', '+-').strip('+')
306
-
307
- l1 = re.split(r'[+]', s1)
308
- l2 = re.split(r'[+]', s2)
309
351
 
310
- if len(l1) != len(l2):
311
-
312
- return 1
352
+ _SYMOP_IDENTITY = ((1, 0, 0), (0, 1, 0), (0, 0, 1))
313
353
 
314
- exp1 = set(l1)
315
- exp2 = set(l2)
316
-
317
- if exp1 == exp2:
318
- return 0
319
354
 
320
- return 1
321
-
322
- def _isCIFEquivalent(c, cc):
355
+ def _isSymopEquivalent(op1, op2, centerings=((0.0, 0.0, 0.0),)):
323
356
  '''
324
- Compare two expressions of symmetry in the form of
325
- expr1,expr2,expr3
326
- If they are the same arithmetic expressions, return True
327
- otherwise False
328
- '''
329
- # import concurrent.futures
330
-
331
- ct = re.split(r',', c)
332
- cct = re.split(r',', cc)
333
-
334
- if len(ct) != 3 or len(cct) != 3:
357
+ True if two parsed operators are the same: equal rotations, and translations that
358
+ differ by a lattice translation, or by one of the *centerings* plus a lattice translation.
359
+ '''
360
+ if op1[0] != op2[0]:
335
361
  return False
362
+ for c in centerings:
363
+ same = True
364
+ for t1, t2, tc in zip(op1[1], op2[1], c):
365
+ d = abs(t1 - t2 - tc) % 1.0
366
+ if min(d, 1.0 - d) > _SYMOP_TOL:
367
+ same = False
368
+ break
369
+ if same:
370
+ return True
371
+ return False
336
372
 
337
- sym_pairs = list(zip(ct, cct))
338
- for p in sym_pairs:
339
- res = _simplifyCIF(p[0], p[1])
340
- if res != 0:
341
- return False
342
- return True
343
373
 
344
- def _compareCIFSymmetry(n, coords, cf_coords):
374
+ def _compareCIFSymmetry(n, coords, cf_ops):
345
375
  '''
346
- compare two symmrety array if:
347
- 1. coords contained in cf_coords, return 0
348
- 2. otherwise return 1
349
- the comparison is done using sympy module with expression equivalence
350
- '''
376
+ Return 0 if each of the first *n* operators in *coords* (pyemaps space group
377
+ database strings) is one of the parsed CIF operators *cf_ops*, otherwise 1.
378
+
379
+ A CIF may list an operator combined with a centering translation, e.g. ``-y+1/2,x+1/2,z``
380
+ for ``-y,x,z`` in an F-centered cell, so translations are compared modulo the CIF's
381
+ centering vectors: the translations of its operators with an identity rotation.
382
+ '''
383
+ centerings = [t for r, t in cf_ops if r == _SYMOP_IDENTITY] or [(0.0, 0.0, 0.0)]
351
384
  count = 0
352
385
  for c in coords:
353
386
  count += 1
354
387
  if count > n:
355
388
  break
356
389
  cstr = ''.join([c[i].decode() for i in range(SPG_SYMMETRY_MAXLEN)]).strip()
357
-
358
- found = False
359
- for cfc in cf_coords:
360
- if _isCIFEquivalent(cstr, cfc):
361
- found = True
362
- break
363
- if not found:
390
+ op = _parseSymop(cstr)
391
+ if op is None:
392
+ return 1
393
+
394
+ if not any(_isSymopEquivalent(op, cfo, centerings) for cfo in cf_ops):
364
395
  return 1
365
396
  return 0
366
397
 
@@ -739,7 +770,7 @@ def loadCrystalCIFData(fn):
739
770
  elif '_space_group_symop_operation_xyz' in c_dict:
740
771
  cif_coords = c_dict['_space_group_symop_operation_xyz']
741
772
 
742
- l, pact = _scrubCIFSymmXYZ(cif_coords, SPG_SYMMETRY_MAXLEN)
773
+ l, pact = _parseCIFSymmXYZ(_as_list(cif_coords))
743
774
 
744
775
  max_match = -1
745
776
  new_pairs = []