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
@@ -0,0 +1,120 @@
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: July 07, 2022
23
+
24
+ This sample code is to demostrate using pyemaps to generate and render
25
+ dynamic diffraction patterns.
26
+
27
+ """
28
+
29
+ from pyemaps import EMC, DEF_CBED_DSIZE
30
+
31
+ MAX_PROCWORKERS = 4
32
+ em_keys = ['tilt', 'zone']
33
+
34
+ def generate_bloch_images(name = 'Silicon', dsize = DEF_CBED_DSIZE, ckey = 'tilt', sim_rand=False):
35
+ '''
36
+ This routine demonstrate how to use pyemaps bloch module to generate dynamic diffraction paterns
37
+ : name: crystal name from builtin database
38
+ : dsize: diffracted beams size
39
+ : ckey: emcontrol key name
40
+ : sim_rand: randomized simulation control which is added to EMControl class, these controls
41
+ : are not changed much (default values if not set). But if changes are needed, then they
42
+ : are also set from within EMControl class
43
+ '''
44
+ import concurrent.futures
45
+ from pyemaps import Crystal as cryst
46
+ from pyemaps import BImgList, SIMC
47
+
48
+ cr = cryst.from_builtin(name)
49
+
50
+ fs=[]
51
+
52
+ emclist =[]
53
+
54
+ if sim_rand:
55
+ sc = SIMC._from_random()
56
+ else:
57
+ sc = SIMC()
58
+
59
+ for i in range(-3,3):
60
+ emc=EMC(cl=200)
61
+ if ckey == 'tilt':
62
+ emc.tilt=(i*0.5, 0.0)
63
+
64
+ if ckey == 'zone':
65
+ emc.zone=(0, i, 1)
66
+
67
+ if sim_rand:
68
+ emc.simc = sc
69
+
70
+ emc(simc=sc)
71
+ emclist.append(emc)
72
+
73
+ with concurrent.futures.ProcessPoolExecutor(max_workers=MAX_PROCWORKERS) as e:
74
+
75
+ for ec in emclist:
76
+ fs.append(e.submit(cr.generateBloch,
77
+ disk_size=dsize,
78
+ sampling = 20,
79
+ sample_thickness=(1750,1750,100),
80
+ em_controls = ec))
81
+
82
+ bimgs = BImgList(name)
83
+ for f in concurrent.futures.as_completed(fs):
84
+ try:
85
+ imgs = f.result()
86
+
87
+ except Exception as e:
88
+ print(f'Unable to obtain bloch image(s): {e}')
89
+ return None
90
+ else:
91
+ emc, img = imgs[0]
92
+ bimgs.add(emc, img)
93
+
94
+ # sorting the images by their associated controls
95
+ bimgs.sort()
96
+ return bimgs
97
+
98
+ from pyemaps import showBloch
99
+
100
+ def main():
101
+ em_keys = ['tilt', 'zone']
102
+
103
+ for k in em_keys:
104
+ imgs = generate_bloch_images(ckey=k)
105
+ if imgs is not None:
106
+ showBloch(imgs, layout='table', bSave=True, bClose=True)
107
+ else:
108
+ exit(1)
109
+
110
+ for k in em_keys:
111
+ imgs = generate_bloch_images(ckey=k, sim_rand=True)
112
+ if imgs is not None:
113
+ showBloch(imgs, bClose=True)
114
+ else:
115
+ exit(1)
116
+
117
+ if __name__ == '__main__':
118
+
119
+ main()
120
+
@@ -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: October 21, 2022
23
+
24
+
25
+ This sample code is to demonstrate how to generate .xyz crystal
26
+ construction data that can be visualized by Jmol and cloudEMAPS 2.0.
27
+ '''
28
+ def test_mxtal(bPrint=True, bSave=True):
29
+
30
+ from pyemaps import Crystal as cr
31
+ from pyemaps import CrystalClassError
32
+ from pyemaps import MxtalError
33
+ mx=None
34
+ try:
35
+ si = cr.from_builtin('Silicon')
36
+ if si and bPrint:
37
+ print(f'crytsal data to generate mxtal: {si}')
38
+ mx = si.generateMxtal(bound=0.1)
39
+ except (CrystalClassError, MxtalError) as e:
40
+ print(f'error: generating crystal structure data: {e.message}')
41
+ except Exception as e:
42
+ print(f'error: generating crystal structure data: {e}')
43
+ else:
44
+ if bPrint:
45
+ print(f'\nCrystal Structure Data Generated for {si.name}:')
46
+ si.printXYZ(mx)
47
+ if bSave:
48
+ si.writeXYZ(mx)
49
+ return mx
50
+ if __name__ == "__main__":
51
+ test_mxtal()
@@ -0,0 +1,59 @@
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 24, 2022
23
+
24
+
25
+ This sample code is to demonstrate how to generate crystal structure
26
+ factors.
27
+ '''
28
+ c_name = 'Silicon'
29
+
30
+ def runCSFTests(bPrint=True):
31
+ from pyemaps import Crystal as cr
32
+ si = cr.from_builtin(c_name)
33
+ if bPrint:
34
+ print(si)
35
+ # generate diffraction on the crystal instance with all default controls
36
+ # parameters, default controls returned as the first output ignored
37
+ v = 100
38
+ sm = 1.0
39
+
40
+ sfl = [1,2,3,4] # structure factor type list
41
+ # 1 -----X-ray Structure Factors
42
+ # 2 -----Electron Strcture Factors in kV
43
+ # 3 -----Electron Structure Factor in 1/Å
44
+ # 4 -----Electron Absorption Structure Factor in 1/Å^2
45
+
46
+ ampl = [1, 0] # structure factor format
47
+ # 1 -----amplitude and phase
48
+ # 0 -----real and imaginary
49
+
50
+ for i in sfl:
51
+ for j in ampl:
52
+
53
+ sfs = si.generateCSF(kv = v, smax = sm, sftype = i, aptype = j)
54
+ if bPrint:
55
+ si.printCSF(sfs)
56
+ return sfs
57
+
58
+ if __name__ == "__main__":
59
+ runCSFTests()
@@ -0,0 +1,134 @@
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 11, 2022
23
+
24
+
25
+ This sample code is to render kinematic diffraction patterns generated
26
+ by pyemaps by changing zone axis
27
+ '''
28
+ try:
29
+ from pyemaps import DEF_CBED_DSIZE, DEF_MODE
30
+ except ImportError as e:
31
+ print(f'pyEMAPS importing error: {e}')
32
+ exit(1)
33
+
34
+ from pyemaps import EMC, DPError,EMCError
35
+
36
+ MAX_PROCWORKERS = 4
37
+ em_keys = ['tilt', 'zone', 'defl', 'vt', 'cl']
38
+
39
+ def generate_difs(name = 'Silicon', mode = DEF_MODE, ckey = 'tilt', sim_rand=False):
40
+ '''
41
+ This routine demonstrate how to use pyemaps dif module to generate kinematic diffraction paterns
42
+
43
+ : name: crystal name from builtin database
44
+ : dsize: diffracted beams size
45
+ : ckey: emcontrol key name
46
+ : sim_rand: randomized simulation control which is added to EMControl class, these controls
47
+ : are not changed much (default values if not set). But if changes are needed, then they
48
+ : are also set from within EMControl class
49
+ '''
50
+ from pyemaps import DPList, SIMC
51
+ import concurrent.futures
52
+ from pyemaps import Crystal as cryst
53
+
54
+ cr = cryst.from_builtin(name)
55
+
56
+ if mode == 2:
57
+ dsize = DEF_CBED_DSIZE
58
+ else:
59
+ dsize = None
60
+
61
+ fs=[]
62
+ # create an empty diffraction pattern list
63
+ difs = DPList(name, mode = mode)
64
+
65
+ emclist =[]
66
+
67
+ if sim_rand:
68
+ sc = SIMC._from_random()
69
+
70
+ for i in range(-3,3):
71
+ emc = EMC()
72
+ if ckey == 'tilt':
73
+ emc.tilt = (i*0.5, 0.0)
74
+
75
+ if ckey == 'zone':
76
+ emc.zone= (0, i, 1)
77
+
78
+ if ckey == 'defl':
79
+ emc.defl= (i*0.5, 0.0)
80
+
81
+ if ckey == 'vt':
82
+ emc.vt= 200 + i*10
83
+
84
+ if ckey == 'cl':
85
+ emc.cl= 1000 + i*50
86
+
87
+ if sim_rand:
88
+ emc.simc = sc
89
+
90
+ emclist.append(emc)
91
+
92
+ with concurrent.futures.ProcessPoolExecutor(max_workers=MAX_PROCWORKERS) as e:
93
+
94
+ for ec in emclist:
95
+ fs.append(e.submit(cr.generateDP, mode=mode, dsize=dsize, em_controls = ec))
96
+
97
+ for f in concurrent.futures.as_completed(fs):
98
+ try:
99
+ emc, diffP = f.result()
100
+ difs.add(emc, diffP)
101
+
102
+ except (DPError, EMCError) as e:
103
+ print(f'{f} generated an exception: {e.message}')
104
+ exit(1)
105
+ except Exception as e:
106
+ print('failed to generate diffraction patterns with ' + str(e))
107
+ exit(1)
108
+
109
+ # sort the diffraction patern list by controls
110
+ difs.sort()
111
+
112
+ return difs
113
+
114
+ def main():
115
+
116
+ from pyemaps import showDif
117
+
118
+ for k in em_keys:
119
+ dpl = generate_difs(ckey=k, mode=2)
120
+ showDif(dpl,
121
+ layout='table' if k == 'tilt' or k == 'zone' else 'individual',
122
+ kShow=False,
123
+ iShow=False,
124
+ bSave=(k=='zone'),
125
+ bClose=True
126
+ )
127
+
128
+ for k in em_keys:
129
+ dpl = generate_difs(ckey=k, sim_rand=True)
130
+ showDif(dpl, bClose=True)
131
+
132
+ if __name__ == '__main__':
133
+
134
+ main()
@@ -0,0 +1,59 @@
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 25, 2023
23
+
24
+
25
+ This sample code is to demostrate using pyemaps to generate and render
26
+ dynamic diffraction patterns.
27
+
28
+
29
+ """
30
+
31
+ def generate_lacbed_images(name = 'Silicon', bSave = False, bShow=False):
32
+
33
+ from pyemaps import Crystal as cryst
34
+
35
+ cr = cryst.from_builtin(name)
36
+
37
+ try:
38
+ imgs = cr.generateBloch( disk_size = 0.5,
39
+ sampling = 10,
40
+ nType = 1,
41
+ sample_thickness=(1000,1000,100),
42
+ bSave=bSave)
43
+ except Exception as e:
44
+ print(f'Faild to obtain large angle CBED images: {e}')
45
+ return
46
+
47
+ imgs.sort()
48
+ if bShow:
49
+ showBloch(imgs,bClose=True)
50
+ return imgs
51
+
52
+ def main():
53
+ generate_lacbed_images(bSave=True, bShow=True)
54
+
55
+ from pyemaps import showBloch
56
+
57
+ if __name__ == '__main__':
58
+ main()
59
+
@@ -0,0 +1,80 @@
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
+ An example of using pyemaps crystal and diffraction modules to
22
+ 1) create a crystal from built-in data for Silicon
23
+ 2) generate kinematical diffraction patterns
24
+ 3) display the diffraction pattern using pyemaps's built-in plot function
25
+
26
+ See https://emlab-solutions.github.io/pyemaps/ for pemaps usage
27
+
28
+ Author: EMLab Solutions, Inc.
29
+ Date: May 07, 2022
30
+
31
+ """
32
+
33
+
34
+ def run_si_sample():
35
+ #import Crystal class from pyemaps as cryst
36
+ from pyemaps import Crystal as cr
37
+ from pyemaps import showDif, showBloch
38
+ from pyemaps import DPList
39
+ from pyemaps import BImgList
40
+ # create a crystal class instance and load it with builtin silicon data
41
+ c_name = 'Silicon'
42
+ si = cr.from_builtin(c_name)
43
+
44
+ # generate diffraction on the crystal instance with all default controls
45
+ # parameters, default controls returned as the first output ignored
46
+
47
+ dpl = DPList(c_name)
48
+
49
+ emc, si_dp = si.generateDP()
50
+ dpl.add(emc, si_dp)
51
+
52
+ #plot and show the diffraction pattern using pyemaps built-in plot function
53
+ showDif(dpl, bClose=True)
54
+
55
+ #hide Kikuchi lines
56
+ showDif(dpl, kShow=False, bClose=True)
57
+
58
+ #plot the following two DP in CBED mode (mode = 2)
59
+ dpl = DPList(c_name, mode = 2)
60
+
61
+ emc, si_dp = si.generateDP(mode = 2)
62
+ dpl.add(emc, si_dp)
63
+
64
+ #hide both Kukuchi line and Miller Indices
65
+ showDif(dpl, kShow=False, iShow=False, bClose=True)
66
+
67
+ #hide Miller Indices
68
+ showDif(dpl, iShow=False, bClose=True)
69
+
70
+ #Generate dynamic diffraction patterns using pyemaps' bloch module
71
+
72
+ try:
73
+ bloch_imgs_list = si.generateBloch(sampling = 20)
74
+
75
+ except Exception as e:
76
+ print(f'Error: {e}')
77
+
78
+ else:
79
+ showBloch(bloch_imgs_list, bClose=True) #grey color map
80
+ showBloch(bloch_imgs_list, bColor=True, bClose=True) #with predefined color map
@@ -0,0 +1,156 @@
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: October 19th, 2022
23
+
24
+
25
+ This sample code is to demonstrate how to generated scattering matrix
26
+ '''
27
+
28
+ c_name = 'Silicon'
29
+
30
+ def runSCMTests():
31
+
32
+ from pyemaps import Crystal as cr
33
+ from pyemaps import BlochError, EMC, SIMC
34
+ import random
35
+
36
+ si = cr.from_builtin(c_name)
37
+
38
+ print(si)
39
+ # -----generate scattering matrix on this crystal instance-----
40
+ # controls set as follows.
41
+
42
+ # For a list beams coordinates
43
+ # to generate more scattering matrix, run cr.printIBDetails()
44
+
45
+ ec =EMC(cl=200,
46
+ tilt=(0.0, 0.0),
47
+ simc = SIMC(gmax=2.0, excitation=(1.0,2.0))
48
+ )
49
+ ds = 0.25
50
+ ib_coords = (0, 0)
51
+ lscm = []
52
+ try:
53
+
54
+ ns, s = si.beginBloch(em_controls = ec,
55
+ dbsize = ds)
56
+
57
+ except Exception as e:
58
+ print(f'Failed to generate scattering matrix {e}')
59
+ else:
60
+
61
+ print(f'----Sampling points in this dynamic diffraction session---:')
62
+ print(f'Number of sampling points: {ns}')
63
+ print(f'{s}')
64
+
65
+ # get the scattering matrix and associated eigen values now
66
+ try:
67
+ ndim, si_scm, si_ev, si_beams = si.getSCMatrix(ib_coords = ib_coords)
68
+ except BlochError as e:
69
+ print(f'Failed to generate scattering matrix {e.message}')
70
+ except Exception as e:
71
+ print(f'Failed to generate scattering matrix {e}')
72
+ else:
73
+ print(f'\n----Scattering matrix at sampling point {ib_coords}----:')
74
+ print(f'Size of the scattering matrix: {ndim}x{ndim}')
75
+ print(f' \n{si_scm}')
76
+
77
+ print(f'\n----Eigen values at: {ib_coords}----')
78
+ print(si_ev)
79
+
80
+ print(f'\n----Diffracted beams at: {ib_coords}----')
81
+ print(si_beams)
82
+
83
+ print(f'\n----More details associated with scattering matrix calculation')
84
+ si.getIBDetails()
85
+
86
+ # select a random sampling point from s and calculate scattering matrix
87
+ randnum = random.randrange(0, ns-1)
88
+
89
+ ib_coords = s[randnum]
90
+ try:
91
+ nd, si_scm, si_ev, si_beams = si.getSCMatrix(ib_coords = ib_coords)
92
+ lscm.append(dict(ib=ib_coords, ndim=nd, scm=si_scm, ev=si_ev, beams=si_beams))
93
+ except Exception:
94
+ print(f'Error obtaining scattering matrix at random sampling points {ib_coords}')
95
+ else:
96
+ print(f'\n----Scattering matrix at a randomly selected sampling point {ib_coords}----:')
97
+ print(f'Size of the scattering matrix: {nd}x{nd}')
98
+ print(f'{si_scm}')
99
+ print(f'\n----Eigen values at: {ib_coords}----')
100
+ print(si_ev)
101
+ print(f'\n----Diffracted beams at: {ib_coords}----')
102
+ print(si_beams)
103
+
104
+ # show a list of calculated beams for current bloch session
105
+ ncb, cbs = si.getCalculatedBeams(bPrint=True)
106
+ # cleanup
107
+ si.endBloch()
108
+ return (dict(ncb=ncb, cbs=cbs), lscm)
109
+
110
+ def runSCMFullTests():
111
+
112
+ from pyemaps import Crystal as cr
113
+ from pyemaps import BlochError, EMC, SIMC
114
+
115
+ si = cr.from_builtin(c_name)
116
+
117
+ # -----generate scattering matrix on this crystal instance-----
118
+ # controls set as follows.
119
+
120
+ # For a list beams coordinates
121
+ # to generate more scattering matrix, run cr.printIBDetails()
122
+
123
+ ec =EMC(cl=200,
124
+ tilt=(0.0, 0.0),
125
+ simc = SIMC(gmax=2.0, excitation=(1.0,2.0))
126
+ )
127
+ ds = 0.25
128
+
129
+ lscm = []
130
+ try:
131
+
132
+ ns, s = si.beginBloch(em_controls = ec,
133
+ dbsize = ds)
134
+ nib, isblist = si.getIBDetails(bPrint=False)
135
+
136
+ except Exception as e:
137
+ print(f'Failed to generate scattering matrix {e}')
138
+ else:
139
+ # get the scattering matrix and associated eigen values now
140
+ try:
141
+ for i in range(ns):
142
+ ndim, si_scm, si_ev, si_beams = si.getSCMatrix(ib_coords = s[i])
143
+ lscm.append(dict(ib=s[i], ndim=ndim, scm=si_scm, ev=si_ev, beams=si_beams))
144
+ except BlochError as e:
145
+ print(f'Failed to generate scattering matrix {e.message}')
146
+ except Exception as e:
147
+ print(f'Failed to generate scattering matrix {e}')
148
+
149
+ # show a list of calculated beams for current bloch session
150
+ ncb, cbs = si.getCalculatedBeams(bPrint=False)
151
+ # cleanup
152
+ si.endBloch()
153
+ return (dict(ncb=ncb, cbs=cbs), dict(nscm=ns, lscm=lscm), dict(nib=nib, libt=isblist))
154
+
155
+ if __name__ == "__main__":
156
+ runSCMTests() #only sampling and print out two of the results