pyemaps 2.0.0__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 (112) hide show
  1. pyemaps/COPYING +798 -0
  2. pyemaps/CifFile/CifFile_module.py +3117 -0
  3. pyemaps/CifFile/StarFile.py +2496 -0
  4. pyemaps/CifFile/TypeContentsParser.py +82 -0
  5. pyemaps/CifFile/YappsStarParser_1_0.py +289 -0
  6. pyemaps/CifFile/YappsStarParser_1_1.py +288 -0
  7. pyemaps/CifFile/YappsStarParser_2_0.py +369 -0
  8. pyemaps/CifFile/YappsStarParser_STAR2.py +382 -0
  9. pyemaps/CifFile/__init__.py +7 -0
  10. pyemaps/CifFile/drel/__init__.py +1 -0
  11. pyemaps/CifFile/drel/drel_ast_yacc.py +582 -0
  12. pyemaps/CifFile/drel/drel_lex.py +228 -0
  13. pyemaps/CifFile/drel/drel_runtime.py +126 -0
  14. pyemaps/CifFile/drel/parsetab.py +185 -0
  15. pyemaps/CifFile/drel/py_from_ast.py +628 -0
  16. pyemaps/CifFile/parsetab.py +185 -0
  17. pyemaps/CifFile/yapps3_compiled_rt.py +390 -0
  18. pyemaps/README.md +201 -0
  19. pyemaps/__config__.py +91 -0
  20. pyemaps/__init__.py +233 -0
  21. pyemaps/__main__.py +219 -0
  22. pyemaps/__version__.py +1 -0
  23. pyemaps/cdata/Aluminium.xtl +4 -0
  24. pyemaps/cdata/AluminiumOxide.xtl +5 -0
  25. pyemaps/cdata/Aluminium_FCC.xtl +4 -0
  26. pyemaps/cdata/BariumTitanate_180k.xtl +6 -0
  27. pyemaps/cdata/BariumTitanate_270k.xtl +7 -0
  28. pyemaps/cdata/BariumTitanate_Tetra.xtl +7 -0
  29. pyemaps/cdata/BiMnO3.xtl +27 -0
  30. pyemaps/cdata/Boron_Tetra.xtl +8 -0
  31. pyemaps/cdata/CadmiumSelenide_Hex.xtl +5 -0
  32. pyemaps/cdata/CadmiumSulfide_Cubic.xtl +5 -0
  33. pyemaps/cdata/CadmiumSulfide_Hex.xtl +5 -0
  34. pyemaps/cdata/Chromium_BCC.xtl +4 -0
  35. pyemaps/cdata/CoSb3_Skutterudite.xtl +5 -0
  36. pyemaps/cdata/CopperOxide.xtl +5 -0
  37. pyemaps/cdata/Copper_FCC.xtl +4 -0
  38. pyemaps/cdata/Cu2O_Cuprite.xtl +5 -0
  39. pyemaps/cdata/Diamond.xtl +4 -0
  40. pyemaps/cdata/ErbiumPyrogermanate.xtl +9 -0
  41. pyemaps/cdata/FePd_Tetra.xtl +5 -0
  42. pyemaps/cdata/FeS2_Pyrite.xtl +15 -0
  43. pyemaps/cdata/GalliumAntimonide.xtl +5 -0
  44. pyemaps/cdata/GalliumArsenide.xtl +5 -0
  45. pyemaps/cdata/GalliumNitride.xtl +5 -0
  46. pyemaps/cdata/Germanium.xtl +4 -0
  47. pyemaps/cdata/Gold_FCC.xtl +4 -0
  48. pyemaps/cdata/IndiumArsenide.xtl +5 -0
  49. pyemaps/cdata/LaMnO3.xtl +7 -0
  50. pyemaps/cdata/LeadZirconateTitanate.xtl +8 -0
  51. pyemaps/cdata/Li2MnO3.xtl +13 -0
  52. pyemaps/cdata/NaFeO2.xtl +6 -0
  53. pyemaps/cdata/Nb3Sn.xtl +5 -0
  54. pyemaps/cdata/Pentacene.xtl +39 -0
  55. pyemaps/cdata/Silicon.xtl +4 -0
  56. pyemaps/cdata/StrontiumTitanate.xtl +6 -0
  57. pyemaps/cdata/TelluriumDioxide.xtl +5 -0
  58. pyemaps/cdata/TinDioxide_RT.xtl +5 -0
  59. pyemaps/cdata/TitaniumDioxide_Anatase.xtl +5 -0
  60. pyemaps/cdata/TitaniumDioxide_Rutile.xtl +5 -0
  61. pyemaps/cdata/TungstenDiselenide.xtl +5 -0
  62. pyemaps/cdata/VanadiumDioxide_RT.xtl +6 -0
  63. pyemaps/cdata/ZincOxide.xtl +5 -0
  64. pyemaps/cdata/Zinc_HCP.xtl +4 -0
  65. pyemaps/cdata/ZirconiumNitride.xtl +5 -0
  66. pyemaps/cdata/limno2.xtl +6 -0
  67. pyemaps/crystals.py +1415 -0
  68. pyemaps/ddiffs.py +147 -0
  69. pyemaps/diffract/__init__.py +70 -0
  70. pyemaps/diffract/bloch_dec.py +779 -0
  71. pyemaps/diffract/csf_dec.py +242 -0
  72. pyemaps/diffract/dif_dec.py +519 -0
  73. pyemaps/diffract/dpgen_dec.py +175 -0
  74. pyemaps/diffract/mxtal_dec.py +201 -0
  75. pyemaps/diffract/powder_dec.py +137 -0
  76. pyemaps/diffract/stereo_dec.py +111 -0
  77. pyemaps/display.py +791 -0
  78. pyemaps/emcontrols.py +1017 -0
  79. pyemaps/errors.py +266 -0
  80. pyemaps/fileutils.py +1001 -0
  81. pyemaps/kdiffs.py +1221 -0
  82. pyemaps/license.txt +42 -0
  83. pyemaps/samples/adf.py +137 -0
  84. pyemaps/samples/al.img +0 -0
  85. pyemaps/samples/al_dpgen.py +57 -0
  86. pyemaps/samples/al_ediom.py +94 -0
  87. pyemaps/samples/convert_image.py +88 -0
  88. pyemaps/samples/dm_diff.py +225 -0
  89. pyemaps/samples/mask.im3 +0 -0
  90. pyemaps/samples/powder.py +51 -0
  91. pyemaps/samples/raw.img +0 -0
  92. pyemaps/samples/si_bloch.py +120 -0
  93. pyemaps/samples/si_constructor.py +51 -0
  94. pyemaps/samples/si_csf.py +59 -0
  95. pyemaps/samples/si_dif.py +134 -0
  96. pyemaps/samples/si_lacbed.py +59 -0
  97. pyemaps/samples/si_pyemaps.py +80 -0
  98. pyemaps/samples/si_scm.py +156 -0
  99. pyemaps/samples/si_stereo.py +116 -0
  100. pyemaps/scattering/__init__.py +26 -0
  101. pyemaps/scattering/sct_dec.py +31 -0
  102. pyemaps/spg/__init__.py +25 -0
  103. pyemaps/spg/spg_dec.py +60 -0
  104. pyemaps/stackimg.py +1031 -0
  105. pyemaps/xtal.py +222 -0
  106. pyemaps-2.0.0.dist-info/METADATA +231 -0
  107. pyemaps-2.0.0.dist-info/RECORD +112 -0
  108. pyemaps-2.0.0.dist-info/WHEEL +5 -0
  109. pyemaps-2.0.0.dist-info/entry_points.txt +2 -0
  110. pyemaps-2.0.0.dist-info/licenses/COPYING +798 -0
  111. pyemaps-2.0.0.dist-info/licenses/license.txt +42 -0
  112. pyemaps-2.0.0.dist-info/top_level.txt +1 -0
pyemaps/license.txt ADDED
@@ -0,0 +1,42 @@
1
+ pyemaps - a transmission electron diffraction simulations in python
2
+ Copyright © 2021 - 2022 EMLab Solutions, Inc. All Rights Reserved
3
+
4
+ Free Base Features License (GNU General Public License v3.0)
5
+
6
+ ----
7
+
8
+ pyEMAPS is distributed for electron diffraction and microscopy research,
9
+ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licence for
11
+ more details.
12
+
13
+ pyEMAPS is free software under the terms of the GNU General Public Licence
14
+ as published by the Free Software Foundation, either version 3 of the Licence,
15
+ or (at your option) any later version. You should have received a copy of the
16
+ GNU General Public Licence along with **pyEMAPS**. If not,
17
+ see <https://www.gnu.org/licenses/>.
18
+
19
+ pemaps is free software for non-commercial use: you can
20
+ redistribute it and/or modify it under the terms of the GNU General \
21
+ Public License as published by the Free Software Foundation, either
22
+ version 3 of the License, or (at your option) any later version.
23
+
24
+
25
+ Commercial License for Extended Features
26
+
27
+ ----
28
+
29
+ **NOTE:** The extended features of pyEMAPS require a separate license for use
30
+ in commercial or production environments. These features are not covered under
31
+ the GNU General Public License above.
32
+
33
+ To obtain a commercial license for the extended features, please contact us at
34
+ `support@emlabsoftware.com` or visit `our website <https://www.emlabsolutions.com>`
35
+ for more information.
36
+
37
+ Usage of extended features without a valid license may be subject to legal action.
38
+
39
+ Additional copyright notices and license terms applicable to portions of pyemaps
40
+ are set forth in the COPYING file.
41
+
42
+ Contact supprort@emlabsoftware.com for any questions regarding the licence terms.
pyemaps/samples/adf.py ADDED
@@ -0,0 +1,137 @@
1
+
2
+
3
+ """
4
+ .. This file is part of pyEMAPS
5
+
6
+ .. ----
7
+
8
+ .. pyEMAPS is free software. You can redistribute it and/or modify
9
+ .. it under the terms of the GNU General Public License as published
10
+ .. by the Free Software Foundation, either version 3 of the License,
11
+ .. or (at your option) any later version..
12
+
13
+ .. pyEMAPS is distributed in the hope that it will be useful,
14
+ .. but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ .. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ .. GNU General Public License for more details.
17
+
18
+ .. You should have received a copy of the GNU General Public License
19
+ .. along with pyEMAPS. If not, see `<https://www.gnu.org/licenses/>`_.
20
+
21
+ .. Contact supprort@emlabsoftware.com for any questions and comments.
22
+
23
+ .. ----
24
+
25
+
26
+ .. Author: EMLab Solutions, Inc.
27
+ .. Date: May 27, 2023
28
+
29
+ This sample code is to demostrate basic usage of pyemaps' stem4d
30
+ module to obtain annular dark and bright field image from
31
+ an experimental diffraction image input.
32
+
33
+ This script is only available in with a license activation.
34
+
35
+ Contact: support@emlabsoftware.com for license information.
36
+
37
+ """
38
+
39
+ import os
40
+ from pathlib import Path
41
+ from pyemaps import StackImage, EM_INT, E_RAW
42
+
43
+ current_file = Path(os.path.abspath(__file__))
44
+ samples_path = current_file.parent.absolute()
45
+
46
+ def getDFFn():
47
+ '''
48
+ Imports sample experimental diffraction pattern image
49
+ with pyEMAPS preprietory 8-bytes header of integer data
50
+ type.
51
+
52
+ To use your own image file, modify this call to retrieve
53
+ the file and specify the image format and data type in
54
+ StackImage object creation. See document on StackImage class.
55
+
56
+ '''
57
+ return os.path.join(samples_path, 'adftest900.im3')
58
+
59
+ def getMaskFn():
60
+ '''
61
+ Imports sample experimental diffraction pattern image
62
+ with pyEMAPS preprietory 8-bytes header of integer data
63
+ type.
64
+
65
+ To use your own image file, modify this call to retrieve
66
+ the file.
67
+
68
+ '''
69
+ return os.path.join(samples_path, 'mask.im3')
70
+
71
+ def test_adf():
72
+ '''
73
+ Generate and display annular dark field for input image.
74
+
75
+ '''
76
+
77
+ adfn = getDFFn()
78
+
79
+ img = StackImage(adfn,
80
+ # nformat = E_SH, <-------- use E_RAW or E_NPY for raw or numpy array image format,
81
+ # default to pyEMAPS proprietory format E_SH
82
+ # noffset = 8, <-------- image head size or offset to image data, default 8
83
+ # dim, <-------- image dimensions in 3 integer tuple.
84
+ ndtype = EM_INT, #<-------- image data type, default to float type EM_FLOAT.
85
+ # supports double type also.
86
+
87
+ )
88
+
89
+ ret, _ = img.generateBDF(center = (256.0, 256.0),
90
+ rads = (50.0,200.0),
91
+ scol = 30,
92
+ bShow = True)
93
+
94
+ if ret != 0:
95
+ print(f'Annular bright or dark field image generation failed ')
96
+
97
+
98
+ def test_df():
99
+ '''
100
+
101
+ Generate and display bright or dark field for input image
102
+
103
+ '''
104
+
105
+ adfn = getDFFn()
106
+
107
+ img = StackImage(adfn, ndtype = EM_INT)
108
+
109
+ ret, _ = img.generateBDF(center = (1.0, 256.0),
110
+ rads = (0.0,200.0),
111
+ scol = 30,
112
+ bShow = True)
113
+
114
+ if ret != 0:
115
+ print(f'Annular bright field image generation failed ')
116
+
117
+ def test_maskedimage():
118
+ imgfn = getDFFn()
119
+ maskfn = getMaskFn()
120
+
121
+ img = StackImage(imgfn, ndtype = EM_INT)
122
+
123
+ scancol = 30
124
+ ret, _ = img.generateMaskedImage(maskfn,
125
+ scancol,
126
+ # bViewOriginal = True, <---- display the input image
127
+ bShow = True)
128
+
129
+ if ret != 0:
130
+ print(f'Masked image generation failed ')
131
+
132
+ if __name__ == '__main__':
133
+
134
+ test_adf() # <---------- annular bright or dark field image
135
+ test_df() # <---------- bright or dark field image
136
+ test_maskedimage()
137
+
pyemaps/samples/al.img ADDED
Binary file
@@ -0,0 +1,57 @@
1
+
2
+ """
3
+ This file is part of pyemaps
4
+ ___________________________
5
+
6
+ pyemaps is free software. You can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published
8
+ by the Free Software Foundation, either version 3 of the License,
9
+ or (at your option) any later version.
10
+
11
+ pyemaps is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with pyemaps. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ Contact supprort@emlabsoftware.com for any questions and comments.
20
+ ___________________________
21
+
22
+ Author: EMLab Solutions, Inc.
23
+ Date: April 02, 2023
24
+
25
+ This sample code is to demostrate basic usage of pyemaps' dpgen -
26
+ diffraction pattern (DP) generator module used as database
27
+ for stem4d module to search and index experimental diffraction
28
+ patterns images.
29
+
30
+ This script is for demonstration and only support crystal with
31
+ space group 225.
32
+
33
+ The complete crystal system support is available in pyemaps
34
+ full package and for purchase. Contact:
35
+ support@emlabsoftware.com
36
+ for price information.
37
+
38
+ """
39
+ def al_dpdb():
40
+ import os
41
+ from pyemaps import Crystal as crystal
42
+ from pyemaps import EMC, SIMC
43
+
44
+ cr = crystal.from_builtin('Aluminium')
45
+ xa0=(2,0,0) # x-axis
46
+ res = 200 # resolution
47
+ emc=EMC(zone=(0,0,1),simc=SIMC(gmax=3.9))
48
+
49
+ ret, dbfn = cr.generateDPDB(emc=emc,xa = xa0, res = res)
50
+
51
+ if ret != 0 or dbfn is None or not os.path.exists(dbfn):
52
+ print('Error generating diffraction pattern database')
53
+ return None
54
+ return dbfn
55
+
56
+ if __name__ == '__main__':
57
+ al_dpdb()
@@ -0,0 +1,94 @@
1
+ """
2
+ This file is part of pyemaps
3
+ ___________________________
4
+
5
+ pyemaps is free software. You can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published
7
+ by the Free Software Foundation, either version 3 of the License,
8
+ or (at your option) any later version.
9
+
10
+ pyemaps is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with pyemaps. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ Contact supprort@emlabsoftware.com for any questions and comments.
19
+ ___________________________
20
+
21
+ Author: EMLab Solutions, Inc.
22
+ Date: April 02, 2023
23
+
24
+ This sample code is to demostrate using pyemaps' dpgen and 4dstem
25
+ modules named _stem4d_ to search and index experimental diffraction patterns images.
26
+ This script is for demonstration and only support crystal with
27
+ space group 225.
28
+
29
+ The full feature with complete crystal system support is available in
30
+ pyemaps full package and for purchase. Contact:
31
+ support@emlabsoftware.com
32
+ for price information.
33
+
34
+ """
35
+ import os
36
+ from pathlib import Path
37
+ from pyemaps import EMC
38
+
39
+ current_file = Path(os.path.abspath(__file__))
40
+ samples_path = current_file.parent.absolute()
41
+
42
+ def getDPImageFn():
43
+ '''
44
+
45
+ Imports sample experimental diffraction pattern image
46
+ with an 8-bytes header from the samples directory
47
+
48
+ '''
49
+ return os.path.join(samples_path, 'al.img')
50
+
51
+ def test_dp_indexing(cname = 'Aluminium'):
52
+ '''
53
+
54
+ Searches and indexes imported diffraction pattern images
55
+ by theoretical diffraction patterns generated by pyemaps.
56
+
57
+ '''
58
+ from pyemaps import Crystal as cr
59
+ from pyemaps import StackImage, XDPImageError
60
+
61
+ cryst = cr.from_builtin(cname)
62
+
63
+ xa0=(2,0,0)
64
+ res = 200
65
+ ret, dbfn = cryst.generateDPDB(emc=EMC(zone=(0,0,1)), res = res, xa = xa0)
66
+
67
+ if ret != 0:
68
+ print(f'failed to generate a diffraction patterns databaes')
69
+ return -1
70
+
71
+ xifn = getDPImageFn()
72
+ alimg = StackImage(xifn)
73
+ try:
74
+ alimg.indexImage(dbfn,
75
+ cc = 29.0,
76
+ sigma = 3.0,
77
+ img_center = (99.923, 99.919),
78
+ rmin = 10,
79
+ search_box = 10.0,
80
+ scaling_option = (1,2),
81
+ filter_threshold = 0.0,
82
+ peak_threshold = 0.8)
83
+
84
+ except XDPImageError as e:
85
+ print(f'Error indexing image {e.message}')
86
+ return
87
+
88
+ # display diffractiom pattern in the database that best match the image pattern
89
+ StackImage.showMatchedDBDP()
90
+
91
+ if __name__ == '__main__':
92
+
93
+ test_dp_indexing()
94
+
@@ -0,0 +1,88 @@
1
+
2
+
3
+ """
4
+ .. This file is part of pyEMAPS
5
+
6
+ .. ----
7
+
8
+ .. pyEMAPS is free software. You can redistribute it and/or modify
9
+ .. it under the terms of the GNU General Public License as published
10
+ .. by the Free Software Foundation, either version 3 of the License,
11
+ .. or (at your option) any later version..
12
+
13
+ .. pyEMAPS is distributed in the hope that it will be useful,
14
+ .. but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ .. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ .. GNU General Public License for more details.
17
+
18
+ .. You should have received a copy of the GNU General Public License
19
+ .. along with pyEMAPS. If not, see `<https://www.gnu.org/licenses/>`_.
20
+
21
+ .. Contact supprort@emlabsoftware.com for any questions and comments.
22
+
23
+ .. ----
24
+
25
+
26
+ .. Author: EMLab Solutions, Inc.
27
+ .. Date: Oct 31, 2024
28
+
29
+ This sample code is to demostrate pyEMAPS helper tool to convert
30
+ a raw image to a pyEMAPS propietory small header image format.
31
+
32
+ This script is only available in with a license activation.
33
+
34
+ Contact: support@emlabsoftware.com for license information.
35
+
36
+ """
37
+
38
+ import os
39
+ from pathlib import Path
40
+ from pyemaps import StackImage
41
+
42
+ current_file = Path(os.path.abspath(__file__))
43
+ samples_path = current_file.parent.absolute()
44
+
45
+ def getRawImageFn():
46
+ '''
47
+ retrieves sample experimental diffraction pattern image
48
+ in raw image format of dimension (256, 256, 1), 4-bytes
49
+ real image data type and offset of 0, to be converted to
50
+ pyEMAPS proprietory image format.
51
+
52
+ To use your own image file, modify this call to retrieve
53
+ the file.
54
+
55
+ '''
56
+ return os.path.join(samples_path, 'raw.img')
57
+
58
+ def test_conversion():
59
+ '''
60
+
61
+ retrieves the raw image file and convert it to a pyEMAPS
62
+ small header image file.
63
+
64
+ If the input raw image file name does not contain directory,
65
+ this method will search the file in pyEMAPS data diretcory
66
+ set by the environment variable PYEMAPS_DATA or current
67
+ working directory in that order.
68
+
69
+ If the input file contains the fully qualified file path,
70
+ pyEMAPS will be using the folder that contains the file
71
+ to place the output image file. So, please make sure that
72
+ the input directory is writable.
73
+
74
+ The result pyEMAPS image file with small header will be saved
75
+ in a folder name `sh_converted` in the dierctory that
76
+ contains the original raw image file.
77
+
78
+ '''
79
+ rawfn = getRawImageFn()
80
+ StackImage.convertImage(rawfn,
81
+ # nformat=E_RAW, default
82
+ dim = (256, 256, 1),
83
+ # ndtype = E_FLOAT, default
84
+ noffset = 0
85
+ )
86
+
87
+ if __name__ == '__main__':
88
+ test_conversion()
@@ -0,0 +1,225 @@
1
+ import numpy as np
2
+ import DigitalMicrograph as DM
3
+
4
+ from pyemaps import Crystal as cr
5
+ from pyemaps import XMAX, YMAX
6
+ #----diffraction patterns generated by these bounds
7
+ # [-XMAX, XMAX, -YMAX, YMAX]
8
+
9
+ # screen size multiplier of diff bounds
10
+ mult = 4
11
+
12
+ #simple diffraction mode lookup
13
+ DIFF_MODE = ('Normal', 'CBED')
14
+ #------Diffraction modes-------
15
+ # 1 - normal
16
+ # 2 - CBED
17
+ def addline( x1, y1, x2, y2):
18
+ '''
19
+ reserved for later use
20
+ '''
21
+ xx1, yy1, xx2, yy2 = x1*2, y1*2, x2*2, y2*2
22
+ dmline = DM.NewLineAnnotation(xx1, yy1, xx2, yy2)
23
+
24
+ dmline.SetResizable(False)
25
+ dmline.SetMovable(False)
26
+ dmline.SetDeletable(False)
27
+ dmline.SetForegroundColor(0,1,0)
28
+ dmline.SetBackgroundColor(0.2,0.2,0.5)
29
+
30
+ return dmline
31
+
32
+
33
+ def adddisk( x1, y1, r, indx):
34
+ '''
35
+ reserved for later use
36
+ '''
37
+ xx1, yy1, rr = x1*2, y1*2, r*2
38
+ dmdisk = DM.NewOvalAnnotation()
39
+ dmdisk.SetCircle(xx1-r,yx1-r, xx1+rr,yy1+r)
40
+ dmdisk.SetLabel(indx)
41
+
42
+ return dmdisk
43
+
44
+
45
+ def SetCommonProp(comp):
46
+ '''
47
+ Setting common attributes of the line and circle annotation components
48
+ '''
49
+ comp.SetResizable(False)
50
+ comp.SetMovable(False)
51
+ comp.SetDeletable(False)
52
+
53
+ def show_diffract(dp, md=1, name = 'Diamond'):
54
+ #transform the plotting area based on pyemaps diffraction dimensions:
55
+ # XMAX
56
+ # YMAX
57
+ shape = (2*XMAX*mult,2*YMAX*mult)
58
+
59
+ #A new image from numpy array and initilize it to black background
60
+ dif_raw = np.ones((shape), dtype = np.float32)
61
+ dif_raw[:,:] = 255.0
62
+
63
+ #DM create the image
64
+ dm_dif_img = DM.CreateImage(dif_raw)
65
+ dif_img = dm_dif_img.ShowImage()
66
+ dif_img_disp = dm_dif_img.GetImageDisplay(0)
67
+
68
+ #validate diffraction mode
69
+ if md <1 or md > 2:
70
+ print(f'diffraction mode provided {md} not supported')
71
+ return 1
72
+
73
+ #set image title
74
+ img_title = str(f'Kinematic Diffraction Simulation: {name} in {DIFF_MODE[md-1]} Mode')
75
+ dm_dif_img.SetName(img_title)
76
+
77
+ #plotting Kikuchi and HOLZ lines and spots as DM components
78
+ num_klines = dp.nklines
79
+
80
+ if num_klines > 0:
81
+ klines = dp.klines
82
+ for kl in klines:
83
+ x1,y1,x2,y2, inten = kl #inten: intensity
84
+
85
+ xx1, yy1, = (x1+ XMAX)*mult,(y1 + YMAX)*mult
86
+ xx2, yy2 = (x2 + XMAX)*mult,(y2 + YMAX)*mult
87
+
88
+ kline = dif_img_disp.AddNewComponent(2, xx1, yy1, xx2, yy2)
89
+
90
+ SetCommonProp(kline)
91
+
92
+ if inten/5 > 0.8:
93
+ kline.SetForegroundColor(0.3, 0.3, 0.3) # dark grey
94
+ elif inten/5 > 0.6:
95
+ kline.SetForegroundColor(0.6, 0.6, 0.6)
96
+ elif inten/5 > 0.4:
97
+ kline.SetForegroundColor(0.8, 0.8, 0.8)
98
+ else:
99
+ kline.SetForegroundColor(0.9, 0.9, 0.9) # light grey
100
+ kline.SetBackgroundColor(0.2,0.2,0.5)# dark blue
101
+
102
+ num_disks = dp.ndisks
103
+
104
+ if num_disks > 0:
105
+ disks = dp.disks
106
+ for d in disks:
107
+ x1, y1, r, i1, i2, i3 = d
108
+ xx, yy, rr = (x1 + XMAX)*mult, (y1 + YMAX)*mult, r*mult
109
+
110
+ idx = '{:d} {:d} {:d}'.format(i1,i2,i3)
111
+
112
+ disk = dif_img_disp.AddNewComponent(6, xx-rr, yy-rr, xx+rr, yy+rr)
113
+
114
+ SetCommonProp(disk)
115
+ disk.SetForegroundColor(0.0,0.0,1.0) # blue
116
+ disk.SetBackgroundColor(0.5,0.5,0.75)# dark blue
117
+ if md == 1:
118
+ disk.SetFillMode(1)
119
+ else:
120
+ disk.SetFillMode(2)
121
+
122
+ # a bit tricky to figure out the index location, has to use
123
+ # the proxy component indxannot0 first.
124
+ indxannot0 = DM.NewTextAnnotation(0, 0, idx, 10)
125
+
126
+ t, l, b, r = indxannot0.GetRect()
127
+ w = r-l
128
+ h = b-t
129
+
130
+ nl = xx - ( w / 2)
131
+ # nr = xx + ( w / 2)
132
+ nt = yy -rr - h if md ==1 else yy - (h / 2)
133
+ # nb = yy + rr + h if md == 1 else yy + (h / 2)
134
+
135
+ indxannot = DM.NewTextAnnotation(nl, nt, idx, 10)
136
+
137
+ dif_img_disp.AddChildAtEnd(indxannot)
138
+ SetCommonProp(indxannot)
139
+ indxannot.SetForegroundColor(0.9,0,0) #light red
140
+ indxannot.SetBackgroundColor(1,1,0.5)
141
+
142
+ if md == 2:
143
+ num_hlines = dp.nhlines
144
+
145
+ if num_hlines > 0 :
146
+
147
+ hlines = dp.hlines
148
+ for hl in hlines:
149
+
150
+ x1, y1, x2, y2, inten = hl
151
+ xx1, yy1 = (x1 + XMAX)*mult, (y1 + YMAX)*mult
152
+ xx2, yy2 = (x2 + XMAX)*mult, (y2 + YMAX)*mult
153
+
154
+ hline = dif_img_disp.AddNewComponent(2, xx1, yy1, xx2, yy2)
155
+ SetCommonProp(hline)
156
+
157
+ if inten/5 > 0.8:
158
+ hline.SetForegroundColor(0.1,0.7,0.3) # dark grey
159
+ elif inten/5 > 0.6:
160
+ hline.SetForegroundColor(0.1,0.7,0.6)
161
+ elif inten/5 > 0.4:
162
+ hline.SetForegroundColor(0.1,0.7,0.8)
163
+ else:
164
+ hline.SetForegroundColor(0.1,0.7,0.9) # light grey
165
+
166
+ del dm_dif_img
167
+ return 0
168
+
169
+
170
+ def run_si_dm_sample():
171
+ from pyemaps import EMC
172
+ #-----------load crystal data into a Crystal class object-----------------
173
+ name = 'Silicon'
174
+ si = cr.from_builtin(name)
175
+
176
+ #-----------content of the crystal data-----------------------------------
177
+ print(si)
178
+
179
+ #-----------generate diffraction pattern in CBED mode---------------------
180
+ emc = EMC(tilt=(-0.2, 0.5), zone=(1,-1,2))
181
+
182
+ mode = DIFF_MODE.index('CBED')+1
183
+ _, si_dp_cbed = si.generateDP(mode = mode, dsize = 0.2, em_controls=emc)
184
+
185
+ #-----------Plot the pattern in DM----------------------------------------
186
+ show_diffract(si_dp_cbed, md = mode, name = name)
187
+
188
+
189
+ #-----------generate diffraction pattern in normal mode-------------------
190
+ _, si_dp = si.generateDP()
191
+ #print(si_dp)
192
+
193
+ #-----------content of the crystal data-----------------------------------
194
+ show_diffract(si_dp, name = name)
195
+
196
+
197
+ def run_si_dm_bloch():
198
+ from pyemaps import EMC
199
+ #-----------load crystal data into a Crystal class object-----------------
200
+ name = 'ErbiumPyrogermanate'
201
+ ep = cr.from_builtin(name)
202
+
203
+ #-----------content of the crystal data-----------------------------------
204
+ print(ep)
205
+
206
+ #-----------generate diffraction pattern in CBED mode---------------------
207
+ emc = EMC(tilt=(-0.2, 0.5), zone=(1,-1,2))
208
+
209
+ try:
210
+ _ = ep.generateBloch()
211
+
212
+ except Exception as e:
213
+ print(f'Error running dynamic diffraction simuation for {name}')
214
+ #-----------Plot the pattern in DM----------------------------------------
215
+ import os
216
+ imgpath = os.environ.get('PYEMAPS_DATA')
217
+ imgf = os.path.join(imgpath, 'bloch')
218
+
219
+ print(f'Generate image file is located at: {imgf}')
220
+ #-----------content of the crystal data-----------------------------------
221
+ # show_diffract(si_dp, name = name)
222
+
223
+ if __name__ == '__main__':
224
+ run_si_dm_sample()
225
+ run_si_dm_bloch()
Binary file
@@ -0,0 +1,51 @@
1
+ '''
2
+ This file is part of pyemaps
3
+ ___________________________
4
+
5
+ pyemaps is free software. You can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published
7
+ by the Free Software Foundation, either version 3 of the License,
8
+ or (at your option) any later version.
9
+
10
+ pyemaps is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with pyemaps. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ Contact supprort@emlabsoftware.com for any questions and comments.
19
+ ___________________________
20
+
21
+ Author: EMLab Solutions, Inc.
22
+ Date: May 31, 2022
23
+
24
+
25
+ This sample code is to demonstrate how to generate powder diffraction.
26
+ '''
27
+
28
+ def runPowderTests(bPrint=True):
29
+ from pyemaps import Crystal as cryst
30
+
31
+ si = cryst.from_builtin('Silicon')
32
+ if bPrint:
33
+ print(si)
34
+ psi = si.generatePowder()
35
+
36
+ di = cryst.from_builtin('Diamond')
37
+ if bPrint:
38
+ print(di)
39
+ pdi = di.generatePowder(absp = 1)
40
+
41
+ return (psi, pdi)
42
+
43
+ def main():
44
+
45
+ from pyemaps import plot2Powder
46
+ psi, pdi = runPowderTests()
47
+
48
+ plot2Powder(psi, pdi)
49
+
50
+ if __name__ == "__main__":
51
+ main()
Binary file