mlgidGUI 0.4.1__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 (202) hide show
  1. mlgidGUI/__init__.py +52 -0
  2. mlgidGUI/__main__.py +7 -0
  3. mlgidGUI/__version.py +1 -0
  4. mlgidGUI/app/__init__.py +8 -0
  5. mlgidGUI/app/actions_stack.py +1 -0
  6. mlgidGUI/app/app.py +67 -0
  7. mlgidGUI/app/cif_rois/__init__.py +0 -0
  8. mlgidGUI/app/cif_rois/cif_peaks_calculation.py +57 -0
  9. mlgidGUI/app/cif_rois/cif_simulation/__init__.py +0 -0
  10. mlgidGUI/app/cif_rois/cif_simulation/data/__init__.py +0 -0
  11. mlgidGUI/app/cif_rois/cif_simulation/data/atoms.py +15 -0
  12. mlgidGUI/app/cif_rois/cif_simulation/data/export_database.py +28 -0
  13. mlgidGUI/app/cif_rois/cif_simulation/experiment.py +57 -0
  14. mlgidGUI/app/cif_rois/cif_simulation/giwaxs_sim.py +286 -0
  15. mlgidGUI/app/cif_rois/cif_simulation/int_sim.py +105 -0
  16. mlgidGUI/app/cif_rois/cif_simulation/possible_directions.py +20 -0
  17. mlgidGUI/app/cif_rois/cif_simulation/q_sim.py +159 -0
  18. mlgidGUI/app/data_manager/__init__.py +4 -0
  19. mlgidGUI/app/data_manager/data_manager.py +164 -0
  20. mlgidGUI/app/data_manager/import_from_h5.py +68 -0
  21. mlgidGUI/app/data_manager/load_data.py +78 -0
  22. mlgidGUI/app/data_manager/pascal/__init__.py +2 -0
  23. mlgidGUI/app/data_manager/pascal/annotation_fabric.py +59 -0
  24. mlgidGUI/app/data_manager/pascal/draw_objects.py +119 -0
  25. mlgidGUI/app/data_manager/pascal/exceptions.py +6 -0
  26. mlgidGUI/app/data_manager/pascal/format_convertor.py +127 -0
  27. mlgidGUI/app/data_manager/pascal/pascal_annotation.py +85 -0
  28. mlgidGUI/app/data_manager/pascal/protocol_implementations.py +28 -0
  29. mlgidGUI/app/data_manager/pascal/protocols.py +47 -0
  30. mlgidGUI/app/data_manager/pascal/utils.py +64 -0
  31. mlgidGUI/app/data_manager/save_dataset.py +57 -0
  32. mlgidGUI/app/data_manager/save_h5.py +178 -0
  33. mlgidGUI/app/data_manager/saving_parameters.py +88 -0
  34. mlgidGUI/app/debug_tracker.py +129 -0
  35. mlgidGUI/app/edf_reader.py +135 -0
  36. mlgidGUI/app/file_manager/__init__.py +201 -0
  37. mlgidGUI/app/file_manager/config_manager.py +76 -0
  38. mlgidGUI/app/file_manager/keys.py +542 -0
  39. mlgidGUI/app/file_manager/npy_file_manager.py +17 -0
  40. mlgidGUI/app/file_manager/object_file_manager.py +77 -0
  41. mlgidGUI/app/file_manager/project_structure.py +169 -0
  42. mlgidGUI/app/file_manager/read_fits.py +76 -0
  43. mlgidGUI/app/file_manager/read_geometry.py +54 -0
  44. mlgidGUI/app/file_manager/read_images.py +31 -0
  45. mlgidGUI/app/file_manager/read_meta_roi.py +40 -0
  46. mlgidGUI/app/file_manager/read_polar_images.py +22 -0
  47. mlgidGUI/app/file_manager/read_radial_profile.py +6 -0
  48. mlgidGUI/app/file_manager/read_roi_data.py +39 -0
  49. mlgidGUI/app/fitting/__init__.py +5 -0
  50. mlgidGUI/app/fitting/background.py +92 -0
  51. mlgidGUI/app/fitting/fit.py +128 -0
  52. mlgidGUI/app/fitting/fit_holder.py +273 -0
  53. mlgidGUI/app/fitting/fit_object.py +247 -0
  54. mlgidGUI/app/fitting/functions.py +107 -0
  55. mlgidGUI/app/fitting/range_strategy.py +14 -0
  56. mlgidGUI/app/fitting/utils.py +17 -0
  57. mlgidGUI/app/geometry.py +236 -0
  58. mlgidGUI/app/geometry_holder.py +131 -0
  59. mlgidGUI/app/image_holder.py +200 -0
  60. mlgidGUI/app/image_processing.py +23 -0
  61. mlgidGUI/app/polar_image.py +96 -0
  62. mlgidGUI/app/profiles/__init__.py +5 -0
  63. mlgidGUI/app/profiles/angular_profile.py +20 -0
  64. mlgidGUI/app/profiles/basic_profile.py +169 -0
  65. mlgidGUI/app/profiles/radial_profile.py +38 -0
  66. mlgidGUI/app/read_image.py +21 -0
  67. mlgidGUI/app/rois/__init__.py +4 -0
  68. mlgidGUI/app/rois/new_roi_dict.py +670 -0
  69. mlgidGUI/app/rois/roi.py +194 -0
  70. mlgidGUI/app/rois/roi_colors.py +76 -0
  71. mlgidGUI/app/rois/roi_data.py +177 -0
  72. mlgidGUI/app/rois/roi_dict.py +466 -0
  73. mlgidGUI/app/rois/roi_meta_data.py +149 -0
  74. mlgidGUI/app/structures/__init__.py +6 -0
  75. mlgidGUI/app/structures/crystal_ring.py +19 -0
  76. mlgidGUI/app/structures/crystals_holders.py +144 -0
  77. mlgidGUI/app/structures/custom_crystal.py +45 -0
  78. mlgidGUI/app/structures/get_ring_list.py +89 -0
  79. mlgidGUI/app/transformations.py +82 -0
  80. mlgidGUI/app/update/__init__.py +3 -0
  81. mlgidGUI/app/update/check_version.py +51 -0
  82. mlgidGUI/app/update/launch_program.py +15 -0
  83. mlgidGUI/app/update/script_update.py +64 -0
  84. mlgidGUI/app/utils.py +124 -0
  85. mlgidGUI/gui/__init__.py +3 -0
  86. mlgidGUI/gui/background_tasks.py +41 -0
  87. mlgidGUI/gui/background_update.py +87 -0
  88. mlgidGUI/gui/basic_widgets/__init__.py +12 -0
  89. mlgidGUI/gui/basic_widgets/buttons.py +144 -0
  90. mlgidGUI/gui/basic_widgets/labels.py +51 -0
  91. mlgidGUI/gui/basic_widgets/mouse_events.py +119 -0
  92. mlgidGUI/gui/basic_widgets/path_line.py +162 -0
  93. mlgidGUI/gui/basic_widgets/plots_1d.py +365 -0
  94. mlgidGUI/gui/basic_widgets/plots_2d.py +224 -0
  95. mlgidGUI/gui/basic_widgets/popups.py +164 -0
  96. mlgidGUI/gui/basic_widgets/progress_bar.py +127 -0
  97. mlgidGUI/gui/basic_widgets/setup_widgets.py +138 -0
  98. mlgidGUI/gui/basic_widgets/sliders.py +616 -0
  99. mlgidGUI/gui/basic_widgets/spinner.py +65 -0
  100. mlgidGUI/gui/basic_widgets/toolbars.py +19 -0
  101. mlgidGUI/gui/debug_widgets.py +388 -0
  102. mlgidGUI/gui/dock_area.py +115 -0
  103. mlgidGUI/gui/exception_message.py +42 -0
  104. mlgidGUI/gui/fitting/__init__.py +2 -0
  105. mlgidGUI/gui/fitting/fit_widget.py +966 -0
  106. mlgidGUI/gui/fitting/inplace_fit.py +536 -0
  107. mlgidGUI/gui/fitting/selected_fit_widget.py +286 -0
  108. mlgidGUI/gui/gui_main.py +349 -0
  109. mlgidGUI/gui/image_viewer.py +323 -0
  110. mlgidGUI/gui/init_window.py +170 -0
  111. mlgidGUI/gui/load_window/__init__.py +2 -0
  112. mlgidGUI/gui/load_window/load_folder.py +61 -0
  113. mlgidGUI/gui/load_window/load_h5.py +73 -0
  114. mlgidGUI/gui/notifications.py +68 -0
  115. mlgidGUI/gui/polar_image_viewer.py +153 -0
  116. mlgidGUI/gui/profiles/__init__.py +1 -0
  117. mlgidGUI/gui/profiles/angular_profile_widget.py +62 -0
  118. mlgidGUI/gui/profiles/radial_profile_widget.py +164 -0
  119. mlgidGUI/gui/project_manager/__init__.py +17 -0
  120. mlgidGUI/gui/project_manager/cif_files_widget.py +196 -0
  121. mlgidGUI/gui/project_manager/cif_results.py +146 -0
  122. mlgidGUI/gui/project_manager/metadata_widget.py +15 -0
  123. mlgidGUI/gui/project_manager/project_viewer.py +151 -0
  124. mlgidGUI/gui/project_manager/roi_widget.py +171 -0
  125. mlgidGUI/gui/roi_widgets/__init__.py +6 -0
  126. mlgidGUI/gui/roi_widgets/abstract_roi_holder.py +189 -0
  127. mlgidGUI/gui/roi_widgets/abstract_roi_widget.py +111 -0
  128. mlgidGUI/gui/roi_widgets/cif_file_widget.py +16 -0
  129. mlgidGUI/gui/roi_widgets/cif_peak_widget.py +43 -0
  130. mlgidGUI/gui/roi_widgets/confidence_level_widget.py +105 -0
  131. mlgidGUI/gui/roi_widgets/roi_1d_widget.py +136 -0
  132. mlgidGUI/gui/roi_widgets/roi_2d_rect_widget.py +98 -0
  133. mlgidGUI/gui/roi_widgets/roi_2d_ring_widget.py +203 -0
  134. mlgidGUI/gui/roi_widgets/rois_context_menu.py +150 -0
  135. mlgidGUI/gui/roi_widgets/select_roi_color_widget.py +58 -0
  136. mlgidGUI/gui/save_window/__init__.py +152 -0
  137. mlgidGUI/gui/save_window/format_box.py +33 -0
  138. mlgidGUI/gui/save_window/num_selected_widget.py +45 -0
  139. mlgidGUI/gui/save_window/options_widgets.py +105 -0
  140. mlgidGUI/gui/save_window/save_mode_box.py +30 -0
  141. mlgidGUI/gui/save_window/select_images.py +198 -0
  142. mlgidGUI/gui/tools.py +179 -0
  143. mlgidGUI/static/__init__.py +0 -0
  144. mlgidGUI/static/icons/__init__.py +0 -0
  145. mlgidGUI/static/icons/add.png +0 -0
  146. mlgidGUI/static/icons/add_yellow.png +0 -0
  147. mlgidGUI/static/icons/angular_profile.png +0 -0
  148. mlgidGUI/static/icons/arrow.png +0 -0
  149. mlgidGUI/static/icons/baseline.png +0 -0
  150. mlgidGUI/static/icons/center.png +0 -0
  151. mlgidGUI/static/icons/confirm.png +0 -0
  152. mlgidGUI/static/icons/control_widget.png +0 -0
  153. mlgidGUI/static/icons/data.png +0 -0
  154. mlgidGUI/static/icons/delete.png +0 -0
  155. mlgidGUI/static/icons/delete_yellow.png +0 -0
  156. mlgidGUI/static/icons/error.png +0 -0
  157. mlgidGUI/static/icons/find.png +0 -0
  158. mlgidGUI/static/icons/fit.png +0 -0
  159. mlgidGUI/static/icons/fix_all.png +0 -0
  160. mlgidGUI/static/icons/flip_horizontal.png +0 -0
  161. mlgidGUI/static/icons/flip_vertical.png +0 -0
  162. mlgidGUI/static/icons/folder.png +0 -0
  163. mlgidGUI/static/icons/fromfullscreen.png +0 -0
  164. mlgidGUI/static/icons/h5_folder.png +0 -0
  165. mlgidGUI/static/icons/h5_group_folder.png +0 -0
  166. mlgidGUI/static/icons/info.png +0 -0
  167. mlgidGUI/static/icons/interpolate.png +0 -0
  168. mlgidGUI/static/icons/item.png +0 -0
  169. mlgidGUI/static/icons/properties.png +0 -0
  170. mlgidGUI/static/icons/radial_profile.png +0 -0
  171. mlgidGUI/static/icons/roi_item.png +0 -0
  172. mlgidGUI/static/icons/rotate.png +0 -0
  173. mlgidGUI/static/icons/rotate_image.png +0 -0
  174. mlgidGUI/static/icons/rotate_right.png +0 -0
  175. mlgidGUI/static/icons/setup.png +0 -0
  176. mlgidGUI/static/icons/setup_white.png +0 -0
  177. mlgidGUI/static/icons/tofullscreen.png +0 -0
  178. mlgidGUI/static/icons/unfix_all.png +0 -0
  179. mlgidGUI/static/icons/update.png +0 -0
  180. mlgidGUI/static/icons/update_suggested.png +0 -0
  181. mlgidGUI/static/icons/window_icon.png +0 -0
  182. mlgidGUI/static/icons/window_icon_256.png +0 -0
  183. mlgidGUI/utils/__init__.py +1 -0
  184. mlgidGUI/utils/project2h5.py +11 -0
  185. mlgidgui-0.4.1.dist-info/METADATA +119 -0
  186. mlgidgui-0.4.1.dist-info/RECORD +202 -0
  187. mlgidgui-0.4.1.dist-info/WHEEL +5 -0
  188. mlgidgui-0.4.1.dist-info/entry_points.txt +5 -0
  189. mlgidgui-0.4.1.dist-info/licenses/LICENSE +674 -0
  190. mlgidgui-0.4.1.dist-info/top_level.txt +4 -0
  191. tests/__init__.py +0 -0
  192. tests/conftest.py +1 -0
  193. tests/fixures/__init__.py +2 -0
  194. tests/fixures/projects.py +102 -0
  195. tests/func/__init__.py +1 -0
  196. tests/func/test_loading_state.py +21 -0
  197. tests/func/test_parse_project_data.py +23 -0
  198. tests/func/test_save.py +62 -0
  199. tests/unit/__init__.py +0 -0
  200. tests/unit/rois/__init__.py +0 -0
  201. tests/unit/rois/test_basic_operations.py +18 -0
  202. tests/unit/test_add_data.py +33 -0
mlgidGUI/__init__.py ADDED
@@ -0,0 +1,52 @@
1
+ import sys
2
+ import argparse
3
+ import logging
4
+
5
+ from PyQt5.QtWidgets import QApplication
6
+ from PyQt5.QtCore import Qt
7
+
8
+ from mlgidGUI.app import App, launch_detached
9
+ from mlgidGUI.gui import GIWAXSMainController, UncaughtHook, DebugWindow
10
+ from mlgidGUI.__version import __version__
11
+
12
+
13
+ __author__ = 'Vladimir Starostin'
14
+ __email__ = 'v.starostin.m@gmail.com'
15
+
16
+
17
+ def run(logging_level: int = logging.ERROR):
18
+ for log in (logging.getLogger(name) for name in logging.root.manager.loggerDict):
19
+ log.setLevel(logging_level)
20
+
21
+ QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
22
+ q_app = QApplication([])
23
+
24
+ giwaxs_app = GIWAXSMainController()
25
+ return q_app.exec_()
26
+
27
+
28
+ def main():
29
+ parser = argparse.ArgumentParser(description='Program for GIWAXS Annotation')
30
+
31
+ parser.add_argument('-d', '--debug', action='store_true', help='open program in debug mode')
32
+ parser.add_argument('--version', action='store_true', help='show the installed version')
33
+
34
+ args = parser.parse_args()
35
+
36
+ if args.version:
37
+ print(__version__)
38
+ return
39
+
40
+ level: int = logging.DEBUG if args.debug else logging.ERROR
41
+
42
+ exit_code: int = run(level)
43
+
44
+ if exit_code == GIWAXSMainController.EXIT_CODE_REBOOT:
45
+ launch_detached()
46
+ return 0
47
+
48
+ return exit_code
49
+
50
+
51
+ if __name__ == '__main__':
52
+ sys.exit(main())
mlgidGUI/__main__.py ADDED
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from mlgidGUI import main
4
+
5
+
6
+ if __name__ == '__main__':
7
+ main()
mlgidGUI/__version.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = '0.4.1'
@@ -0,0 +1,8 @@
1
+ from .app import App
2
+ from .geometry import Geometry
3
+ from .rois.roi_data import RoiData
4
+ from .rois.roi import Roi, RoiTypes
5
+ from .fitting import FitObject
6
+ from .debug_tracker import TrackQObjects
7
+ from .update import launch_detached
8
+ from .edf_reader import read_edf
@@ -0,0 +1 @@
1
+ # -*- coding: utf-8 -*-
mlgidGUI/app/app.py ADDED
@@ -0,0 +1,67 @@
1
+ import logging
2
+
3
+ from .rois.roi_dict import RoiDict
4
+ from .file_manager import FileManager, ImageKey
5
+ from .utils import SingletonMeta
6
+ from .geometry import Geometry
7
+ from .geometry_holder import GeometryHolder
8
+ from .image_holder import ImageHolder
9
+ from .profiles import RadialProfile, AngularProfile
10
+ from .debug_tracker import TrackQObjects
11
+ from .data_manager import DataManager
12
+
13
+
14
+ class App(metaclass=SingletonMeta):
15
+ log = logging.getLogger(__name__)
16
+
17
+ def __init__(self, parent, *, _connect: bool = True):
18
+ self.parent = parent
19
+ self.fm: FileManager = FileManager()
20
+ self.geometry_holder: GeometryHolder = GeometryHolder(self.fm)
21
+ self.roi_dict: RoiDict = RoiDict(self.fm, self.geometry_holder)
22
+ self.image_holder: ImageHolder = ImageHolder(self.fm, self.geometry_holder, self.roi_dict)
23
+ self.radial_profile: RadialProfile = RadialProfile(self.image_holder, self.fm)
24
+ self.angular_profile: AngularProfile = AngularProfile(self.image_holder)
25
+ self.data_manager: DataManager = DataManager(self.fm, self.image_holder)
26
+
27
+ if _connect:
28
+ self._connect_app()
29
+
30
+ self.debug_tracker: TrackQObjects or None = None
31
+ if self.log.level <= logging.DEBUG:
32
+ self.debug_tracker = TrackQObjects()
33
+
34
+ def save_state(self):
35
+ self.geometry_holder.save_state()
36
+ self.roi_dict.save_state()
37
+ # self.radial_profile.save_state()
38
+
39
+ @property
40
+ def image(self):
41
+ return self.image_holder.image
42
+
43
+ @property
44
+ def polar_image(self):
45
+ return self.image_holder.polar_image
46
+
47
+ @property
48
+ def geometry(self) -> Geometry:
49
+ return self.geometry_holder.geometry
50
+
51
+ @property
52
+ def current_image_key(self) -> ImageKey or None:
53
+ return self.fm.current_key
54
+
55
+ def close(self):
56
+ self.fm.close()
57
+
58
+ def _connect_app(self):
59
+ self.image_holder.sigPolarImageChanged.connect(self.radial_profile.update)
60
+ self.image_holder.sigPolarImageChanged.connect(self.angular_profile.update)
61
+
62
+ self.geometry_holder.sigScaleChanged.connect(self.roi_dict.on_scale_changed)
63
+ self.geometry_holder.sigRingBoundsChanged.connect(self.roi_dict.change_ring_bounds)
64
+
65
+ self.fm.sigActiveImageChanged.connect(self.image_holder.change_image)
66
+ self.fm.sigProjectIsClosing.connect(self.save_state)
67
+ self.fm.sigActiveFolderChanged.connect(self.roi_dict.change_folder)
File without changes
@@ -0,0 +1,57 @@
1
+ import numpy as np
2
+
3
+ from .cif_simulation.giwaxs_sim import GIWAXSFromCif
4
+ from .cif_simulation.experiment import ExpParameters
5
+ from ..rois.roi import CIFPeakRoi
6
+
7
+ cif_results = {}
8
+
9
+ def calculate_cif_peaks(project_root_key, image_key):
10
+ cif_results.clear()
11
+ if image_key is not None:
12
+ for file_nr, cif_file_key in enumerate(project_root_key._cif_files):
13
+ if cif_file_key.is_visible():
14
+ try:
15
+ params = ExpParameters(image_key.get_q_range()[0], image_key.get_q_range()[1], en=cif_file_key.en)
16
+ el = GIWAXSFromCif(cif_file_key.path, params)
17
+ orientation = np.array(cif_file_key.orientation)
18
+
19
+ if cif_file_key.powder_diffraction:
20
+ orientation = None
21
+ q_2d, intensities, mi_indices = el.giwaxs.giwaxs_sim(orientation, return_mi = True)
22
+ #normalizes to 1 - 3
23
+ intensities_perc = np.argsort(np.argsort(intensities))/len(intensities)
24
+ intensities_raw = intensities
25
+ intensities = np.clip(np.ceil(((intensities - intensities.min()) / (intensities.max() - intensities.min()))*3), a_min = 1, a_max=3)
26
+ except Exception as e:
27
+ return cif_file_key
28
+
29
+ if cif_file_key.powder_diffraction:
30
+ q_z = q_2d.squeeze().tolist()
31
+ q_xy = [0]*len(q_z)
32
+ else:
33
+ q_z = q_2d.squeeze()[0].tolist()
34
+ q_xy = q_2d.squeeze()[1].tolist()
35
+
36
+ i = 0
37
+ is_powder = [cif_file_key.powder_diffraction]*len(q_z)
38
+ for cif_peak in zip(is_powder, q_xy, q_z, intensities, intensities_raw, intensities_perc, mi_indices):
39
+ cif_results[cif_file_key.name + 'p' + str(i)] = CIFPeakRoi(
40
+ radius = 0,
41
+ width = 0,
42
+ angle = 0,
43
+ angle_std = 0,
44
+ key = cif_file_key.name + 'p' + str(i),
45
+ name = cif_file_key.name + str(i),
46
+ movable = False,
47
+ cif_file_nr = file_nr,
48
+ cif_file=cif_file_key.name,
49
+ is_powder = cif_file_key.powder_diffraction,
50
+ q_xy = cif_peak[1],
51
+ q_z = cif_peak[2],
52
+ intensity = cif_peak[3],
53
+ intensity_raw = cif_peak[4],
54
+ intensity_perc = cif_peak[5],
55
+ miller_id = cif_peak[6],
56
+ )
57
+ i += 1
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ # 213 atoms
2
+ atoms_list = ['Dummy', 'H', 'H.', 'H1-', 'He', 'Li', 'Li1+', 'Be', 'Be2+', 'B', 'C', 'C.', 'N', 'O', 'O1-',
3
+ 'O2-.', 'F', 'F1-', 'Ne', 'Na', 'Na1+', 'Mg', 'Mg2+', 'Al', 'Al3+', 'Si', 'Si.', 'Si4+', 'P', 'S',
4
+ 'Cl', 'Cl1-', 'Ar', 'K', 'K1+', 'Ca', 'Ca2+', 'Sc', 'Sc3+', 'Ti', 'Ti2+', 'Ti3+', 'Ti4+', 'V', 'V2+', 'V3+',
5
+ 'V5+', 'Cr', 'Cr2+', 'Cr3+', 'Mn', 'Mn2+', 'Mn3+', 'Mn4+', 'Fe', 'Fe2+', 'Fe3+', 'Co', 'Co2+', 'Co3+', 'Ni',
6
+ 'Ni2+', 'Ni3+', 'Cu', 'Cu1+', 'Cu2+', 'Zn', 'Zn2+', 'Ga', 'Ga3+', 'Ge', 'Ge4+', 'As', 'Se', 'Br', 'Br1-', 'Kr',
7
+ 'Rb', 'Rb1+', 'Sr', 'Sr2+', 'Y', 'Y3+', 'Zr', 'Zr4+', 'Nb', 'Nb3+', 'Nb5+', 'Mo', 'Mo3+', 'Mo5+', 'Mo6+', 'Tc',
8
+ 'Ru', 'Ru3+', 'Rh', 'Rh3+', 'Rh4+', 'Pd', 'Pd2+', 'Pd4+', 'Ag', 'Ag1+', 'Ag2+', 'Cd', 'Cd2+', 'In', 'In3+',
9
+ 'Sn', 'Sn2+', 'Sn4+', 'Sb', 'Sb3+', 'Sb5+', 'Te', 'I', 'I1-', 'Xe', 'Cs', 'Cs1+', 'Ba', 'Ba2+', 'La', 'La3+', 'Ce',
10
+ 'Ce3+', 'Ce4+', 'Pr', 'Pr3+', 'Pr4+', 'Nd', 'Nd3+', 'Pm', 'Pm3+', 'Sm', 'Sm3+', 'Eu', 'Eu2+', 'Eu3+', 'Gd', 'Gd3+',
11
+ 'Tb', 'Tb3+', 'Dy', 'Dy3+', 'Ho', 'Ho3+', 'Er', 'Er3+', 'Tm', 'Tm3+', 'Yb', 'Yb2+', 'Yb3+', 'Lu', 'Lu3+', 'Hf',
12
+ 'Hf4+', 'Ta', 'Ta5+', 'W', 'W6+', 'Re', 'Os', 'Os4+', 'Ir', 'Ir3+', 'Ir4+', 'Pt', 'Pt2+', 'Pt4+', 'Au', 'Au1+',
13
+ 'Au3+', 'Hg', 'Hg1+', 'Hg2+', 'Tl', 'Tl1+', 'Tl3+', 'Pb', 'Pb2+', 'Pb4+', 'Bi', 'Bi3+', 'Bi5+', 'Po', 'At', 'Rn',
14
+ 'Fr', 'Ra', 'Ra2+', 'Ac', 'Ac3+', 'Th', 'Th4+', 'Pa', 'U', 'U3+', 'U4+', 'U6+', 'Np', 'Np3+', 'Np4+', 'Np6+', 'Pu',
15
+ 'Pu3+', 'Pu4+', 'Pu6+', 'Am', 'Cm', 'Bk', 'Cf']
@@ -0,0 +1,28 @@
1
+ import numpy as np
2
+ import xrayutilities as xu
3
+ from datetime import datetime
4
+ from .atoms import atoms_list
5
+
6
+ def calculateFF(en=18000, # energy in kEv
7
+ q_range=np.arange(0, 10, 0.001)
8
+ ):
9
+ """
10
+ Calculate and save form-factors for each possible atom in atom_list
11
+ """
12
+ # export ff for all possible atoms
13
+ # ff_dict = dict() #
14
+ result_shape = (len(atoms_list), len(q_range))
15
+ full_ff_matrix = np.empty(result_shape, dtype='complex128')
16
+
17
+ for idx, atom in enumerate(atoms_list):
18
+ ff = xu.materials.atom.Atom(atom, 1).f(q_range, en=en) # form factor
19
+ # ff_dict[atom] = ff
20
+ full_ff_matrix[idx] = ff
21
+
22
+ return full_ff_matrix, np.array(atoms_list),
23
+
24
+ if __name__ == "__main__":
25
+ start = datetime.now()
26
+ ff_dict = calculateFF(en=18000, # energy in kEv
27
+ q_range=np.arange(0, 10, 0.001))
28
+ print(datetime.now() - start)
@@ -0,0 +1,57 @@
1
+ import math
2
+ import numpy as np
3
+ from .data.export_database import calculateFF
4
+
5
+
6
+ class Database:
7
+ """
8
+ A class to represent the form-factors matrix for all possible atoms
9
+ ...
10
+ Attributes
11
+ ----------
12
+ full_atom_list : list
13
+ list of all possible atoms - len = 98
14
+ full_ff_matrix : np.ndarray
15
+ form-factors (ff) matrix for en=18000eV in q_range = (0, 10, 0.001)
16
+ shape = (98, 10000), 98 - number of elements, 10000 - calculated ff in q_range
17
+ """
18
+
19
+ def __init__(self, en):
20
+ self.full_ff_matrix, self.full_atom_list = calculateFF(en)
21
+
22
+
23
+ class ExpParameters:
24
+ """
25
+ A class to represent the experiment parameters
26
+ ...
27
+ Attributes
28
+ ----------
29
+ q_xy_max : float
30
+ maximum value for the q in xy direction, Å^{-1}
31
+ q_z_max : float
32
+ maximum value for the q in z direction, Å^{-1}
33
+ ai : float
34
+ incidence angle, deg
35
+ wavelength : float
36
+ beam wavelength, Å
37
+ database: Database
38
+ database with form-factors
39
+ """
40
+
41
+ def __init__(self,
42
+ q_xy_max=2.7, # Å^{-1}
43
+ q_z_max=2.7, # Å^{-1}
44
+ ai=0.3, # Incidence angle, deg
45
+ en=18000, # Energy, eV
46
+ ):
47
+ self.q_xy_max = q_xy_max
48
+ self.q_z_max = q_z_max
49
+ self.q_max = math.sqrt(q_xy_max ** 2 + q_z_max ** 2)
50
+ self.ai = ai
51
+ self.wavelength = 12398 / en
52
+
53
+ self.database = Database(en=int(en))
54
+
55
+
56
+ if __name__ == "__main__":
57
+ db = ExpParameters().database
@@ -0,0 +1,286 @@
1
+ import numpy as np
2
+ from typing import Union
3
+
4
+ from xrayutilities.materials.cif import CIFFile
5
+ from xrayutilities.materials.spacegrouplattice import SGLattice
6
+
7
+ from .experiment import ExpParameters
8
+ from .q_sim import QPos
9
+ from .int_sim import Intensity
10
+
11
+
12
+ class Crystal:
13
+ """
14
+ A class to represent the crystal structure
15
+ ...
16
+ Attributes
17
+ ----------
18
+ spgr : int
19
+ space group number (1-230)
20
+ cr_group : int
21
+ crystal group number (1-7)
22
+ lat_par : np.ndarray
23
+ lattice parameters tensor([a,b,c,α,β,γ])
24
+ param_SGL : np.ndarray
25
+ unique lattice parameters that are needed to receive miller indices
26
+ atoms : np.ndarray
27
+ list of elements in the structure
28
+ atoms_positions: np.ndarray
29
+ relative atom coordinates (related with the atoms attribute)
30
+ """
31
+
32
+ def __init__(self,
33
+ spgr: Union[str, int], # 1-230
34
+ lat_par: np.ndarray, # np.array([a,b,c,α,β,γ], dtype=np.float32)
35
+ atoms: Union[np.ndarray, None] = None, # list of elements in the structure,
36
+ atoms_positions: Union[np.ndarray, None] = None # relative atom coordinates, dtype=np.float32
37
+ ):
38
+ self.spgr = spgr
39
+ self.cr_group = self._cr_group()
40
+ self.lat_par = lat_par
41
+ self.param_SGL = self._parameters_for_SGLattice()
42
+ self.atoms = atoms
43
+ self.atoms_positions = atoms_positions
44
+
45
+ def _cr_group(self) -> Union[str, int]:
46
+ """ Returns the crystal group from the space group """
47
+ cr_list = [(1, 2), (3, 15), (16, 74), (75, 142), (143, 167), (168, 194), (195, 230)]
48
+ spgr_list = str(self.spgr).split(':')
49
+ spgr_num = int(spgr_list[0])
50
+ for idx, (start, end) in enumerate(cr_list):
51
+ if spgr_num <= end:
52
+ if (end == 167) and len(spgr_list) > 1 and spgr_list[1] == 'R': # trigonal RHOMB
53
+ return '5:R'
54
+ return idx + 1
55
+ raise AttributeError('space group should be in range 1-231')
56
+
57
+ def _parameters_for_SGLattice(self) -> np.ndarray:
58
+ """ Returns the unique lattice parameters that are needed to receive miller indices """
59
+
60
+ parameters_for_hkl = {1: [0, 1, 2, 3, 4, 5], # return [a, b, c, alpha, beta, gamma] - triclinic
61
+ 2: [0, 1, 2, 4], # return [a, b, c, beta] - monoclinic
62
+ 3: [0, 1, 2], # return [a, b, c] - orthorhombic
63
+ 4: [0, 2], # return [a, c] - tetragonal
64
+ 5: [0, 2], # return [a, с] - trigonal - HEX
65
+ '5:R': [0, 3], # return [a, alpha] - trigonal - RHOMB
66
+ 6: [0, 2], # return [a, c] - hexagonal
67
+ 7: [0]} # return [a] - cubic
68
+
69
+ return self.lat_par[parameters_for_hkl[self.cr_group]]
70
+
71
+
72
+ class GIWAXS:
73
+ """
74
+ A class to calculate the giwaxs image from the crystal structure and experimental parameters
75
+ ...
76
+ Attributes
77
+ ----------
78
+ crystal : Crystal
79
+ crystal structure representation
80
+ exp : ExpParameters
81
+ experiment parameters representation
82
+
83
+ Methods
84
+ -------
85
+ giwaxs_sim(rotate=True, orientation='random'):
86
+ calculates the GIWAXS image
87
+ get_mi(q_max):
88
+ returns allowed miller indices
89
+ """
90
+
91
+ def __init__(self, crystal: Crystal, exp_par: ExpParameters):
92
+ self.crystal = crystal
93
+ self.exp = exp_par
94
+
95
+ self._mi = self.get_mi(self.exp.q_max)
96
+ self._q_sim = QPos(self.crystal.lat_par, self._mi)
97
+ self.q_3d = self._q_sim.q_3d
98
+ self.q_abs = np.linalg.norm(self.q_3d, axis=-1)
99
+
100
+ def giwaxs_sim(self,
101
+ orientation: Union[str, np.ndarray] = np.array([0., 0., 1.]), # e.g. None, 'random' or np.array([0., 1., 0.]),
102
+ return_mi = False
103
+ ):
104
+ """
105
+ Calculates peak positions and their intensities in the GIWAXS image
106
+
107
+ Parameters
108
+ ----------
109
+ orientation : Union[str, np.ndarray], optional
110
+ orientation of the crystal growth (e.g. 'random' or np.array([0., 1., 0.]),
111
+ default = np.array([0., 0., 1.])
112
+ if None - no orientation (powder diffraction)
113
+ return_mi : bool, optional
114
+ return miller indices if True, default=False
115
+
116
+ Returns
117
+ -------
118
+ q_2d (np.ndarray): peak positions
119
+ int_sum (np.ndarray): peak intensities
120
+ """
121
+ if (self.crystal.atoms is None) or (self.crystal.atoms_positions is None):
122
+ intensity = None
123
+ else:
124
+ intensity = Intensity(self.crystal.atoms,
125
+ self.crystal.atoms_positions,
126
+ self.q_3d,
127
+ self._mi,
128
+ self.exp.wavelength,
129
+ self.exp.ai,
130
+ self.exp.database
131
+ ).get_intensities()
132
+
133
+ if orientation is None:
134
+ if not return_mi:
135
+ q_1d, int_sum, mi_sum = self.giwaxs_1d(self.q_abs, intensity, None)
136
+ return q_1d, int_sum
137
+ else:
138
+ q_1d, int_sum, mi_sum = self.giwaxs_1d(self.q_abs, intensity, self._mi)
139
+ return q_1d, int_sum, mi_sum
140
+ else:
141
+ q_3d_rot = self._q_sim.rotate_vect(orientation)
142
+ if not return_mi:
143
+ q_2d, int_sum, mi_sum = self.giwaxs_2d(q_3d_rot, intensity, None)
144
+ return q_2d, int_sum
145
+ else:
146
+ q_2d, int_sum, mi_sum = self.giwaxs_2d(q_3d_rot, intensity, self._mi)
147
+ return q_2d, int_sum, mi_sum
148
+
149
+
150
+ @staticmethod
151
+ def giwaxs_1d(q_1d, intensity, mi):
152
+ x = q_1d[np.newaxis]
153
+ X = np.repeat(x, len(q_1d), axis=0)
154
+ Y = X.T
155
+
156
+ closest = np.isclose(X, Y, rtol=1e-04, atol=1e-04).astype(np.int32)
157
+ closest = np.triu(closest)
158
+
159
+ indices_sum = np.zeros(len(q_1d), dtype=np.int32)
160
+ all_indices = np.arange(len(q_1d))
161
+
162
+ for a, b in zip(*np.where(closest == 1)):
163
+ if a not in all_indices:
164
+ continue # means that we matched this peak with another one
165
+ indices_sum[b] = np.where(all_indices == a)[0][0]
166
+ if a != b:
167
+ # remove b element from all_indices
168
+ index = np.where(all_indices == b)[0][0]
169
+ all_indices = np.delete(all_indices, index)
170
+ q_1d_fin = q_1d[all_indices]
171
+ if intensity is None:
172
+ int_fin = np.ones_like(q_1d_fin)
173
+ else:
174
+ int_fin = np.bincount(indices_sum, weights=intensity)
175
+ int_fin = int_fin / q_1d_fin**2
176
+
177
+ if mi is not None:
178
+ mi_new = []
179
+ for idx, idx_sum in enumerate(indices_sum):
180
+ if len(mi_new) > idx_sum:
181
+ mi_new[int(idx_sum)] = np.concatenate((mi_new[int(idx_sum)], mi[idx][np.newaxis]), axis=0)
182
+ continue
183
+ mi_new.append(mi[idx][np.newaxis])
184
+ return q_1d_fin, int_fin, mi_new
185
+
186
+ return q_1d_fin, int_fin, mi
187
+
188
+ @staticmethod
189
+ def giwaxs_2d(q_3d, intensity, mi):
190
+ """ Convert 3d pattern to 2d space with summation the intensities """
191
+ # q_3d.shape - (points_num, 3)
192
+ q_xy = np.sqrt(q_3d[..., 0] ** 2 + q_3d[..., 1] ** 2) # shape (points_num,)
193
+ q_z = q_3d[..., 2]
194
+ q_2d = np.stack((q_xy, q_z)) # shape (2, points_num)
195
+
196
+ x = q_2d[np.newaxis] # (1, 2, points_num)
197
+ X = np.repeat(x, x.shape[2], axis=0) # (points_num, 2, points_num)
198
+ # Y = np.repeat(x.transpose((2, 1, 0)), x.shape[2], axis=2) # (points_num, 2, points_num)
199
+ Y = X.transpose((2, 1, 0))
200
+
201
+ # find close points, that could be matched together
202
+ closest = np.isclose(X, Y, rtol=1e-04, atol=1e-04).sum(axis=1)
203
+ closest[closest < 2] = 0
204
+ closest = np.triu(closest)
205
+
206
+ indices_sum = np.zeros(len(closest), dtype=np.int32)
207
+ all_indices = np.arange(len(closest))
208
+
209
+ for a, b in zip(*np.where(closest == 2)):
210
+ if a not in all_indices:
211
+ continue # means that we matched this peak with another one
212
+ indices_sum[b] = np.where(all_indices == a)[0][0]
213
+ if a != b:
214
+ # remove b element from all_indices
215
+ index = np.where(all_indices == b)[0][0]
216
+ all_indices = np.delete(all_indices, index)
217
+
218
+ q_2d_fin = q_2d[..., all_indices] # shape (2, points_num)
219
+ if intensity is None:
220
+ int_fin = np.ones_like(q_2d_fin[0])
221
+ else:
222
+ int_fin = np.bincount(indices_sum.astype(np.int32), weights=intensity)
223
+
224
+ # take only positive part for z-direction
225
+ idxs_pos = np.where(q_2d_fin[1] >= 0)[0]
226
+ q_2d_pos = q_2d_fin[:, idxs_pos]
227
+ int_pos = int_fin[idxs_pos]
228
+
229
+ if mi is not None:
230
+ mi_new = []
231
+ for idx, idx_sum in enumerate(indices_sum):
232
+ if len(mi_new) > idx_sum:
233
+ mi_new[int(idx_sum)] = np.concatenate((mi_new[int(idx_sum)], mi[idx][np.newaxis]), axis=0)
234
+ continue
235
+ mi_new.append(mi[idx][np.newaxis])
236
+ mi_pos = [mi_new[i] for i in idxs_pos]
237
+ return q_2d_pos, int_pos, mi_pos
238
+
239
+ return q_2d_pos, int_pos, mi
240
+
241
+ # # take only positive part for z-direction
242
+ # idxs = np.where(q_2d_fin[1] >= 0)
243
+ # q_2d_pos = q_2d_fin[:, idxs]
244
+ # int_pos = int_fin[idxs]
245
+ # mi_pos = [mi_new[i] for i in idxs[0]]
246
+ #
247
+ # return q_2d_pos, int_pos, mi_pos
248
+
249
+ def get_mi(self, q_max):
250
+ """ Returns allowed miller indices"""
251
+ mi = SGLattice(self.crystal.spgr, *self.crystal.param_SGL).get_allowed_hkl(qmax=q_max)
252
+ return np.array(list(mi), dtype=np.float32)
253
+
254
+
255
+ class GIWAXSFromCif:
256
+ """
257
+ A class to calculate the GIWAXS image from the CIF
258
+ ...
259
+ Attributes
260
+ ----------
261
+ crystal : Crystal
262
+ crystal structure representation
263
+ exp : ExpParameters
264
+ experiment parameters representation
265
+ giwaxs : GIWAXS
266
+ """
267
+
268
+ def __init__(self, path, exp_par: ExpParameters):
269
+ el = CIFFile(path)
270
+ name = el.default_dataset
271
+ if name is None:
272
+ name = list(el.data.keys())[0]
273
+
274
+ lat_par = (np.append(el.data[name].lattice_const, el.data[name].lattice_angles)).astype(np.float32)
275
+ if hasattr(el.data[name], 'sgrp'):
276
+ spgr = el.data[name].sgrp # str type
277
+ else:
278
+ spgr = '1'
279
+
280
+ atoms, atoms_positions = zip(*[(atom[0].basename, atom[1]) for atom in el.SGLattice().base()])
281
+ atoms = np.array(atoms)
282
+ atoms_positions = np.array(atoms_positions, dtype=np.float32)
283
+
284
+ self.crystal = Crystal(spgr, lat_par, atoms, atoms_positions)
285
+ self.exp = exp_par
286
+ self.giwaxs = GIWAXS(self.crystal, self.exp)