Skip to content

summary

Summary

Generates reports and exports results from the project.

This class collects and presents all relevant information about the fitted model, experiments, and analysis results.

Source code in src/easydiffraction/summary.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
class Summary:
    """
    Generates reports and exports results from the project.

    This class collects and presents all relevant information
    about the fitted model, experiments, and analysis results.
    """

    def __init__(self, project) -> None:
        """
        Initialize the summary with a reference to the project.

        Args:
            project: The Project instance this summary belongs to.
        """
        self.project = project

    # ------------------------------------------
    #  Report Generation
    # ------------------------------------------

    def show_report(self) -> None:
        self.show_project_info()
        self.show_crystallographic_data()
        self.show_experimental_data()
        self.show_fitting_details()

    def show_project_info(self) -> None:
        """
        Print the project title and description.
        """
        print(section('Project info'))

        print(paragraph('Title'))
        print(self.project.info.title)

        if self.project.info.description:
            print(paragraph('Description'))
            print('\n'.join(wrap(self.project.info.description, width=60)))

    def show_crystallographic_data(self) -> None:
        """
        Print crystallographic data including phase datablocks,
        space groups, cell parameters, and atom sites.
        """
        print(section('Crystallographic data'))

        for model in self.project.sample_models._models.values():
            print(paragraph('Phase datablock'))
            print(f'🧩 {model.name}')

            print(paragraph('Space group'))
            print(model.space_group.name_h_m.value)

            print(paragraph('Cell parameters'))
            columns_alignment: List[str] = ['left', 'right']
            cell_data = [[k.replace('length_', '').replace('angle_', ''), f'{v:.5f}'] for k, v in model.cell.as_dict().items()]
            render_table(
                columns_alignment=columns_alignment,
                columns_data=cell_data,
            )

            print(paragraph('Atom sites'))
            columns_headers = [
                'Label',
                'Type',
                'fract_x',
                'fract_y',
                'fract_z',
                'Occupancy',
                'B_iso',
            ]
            columns_alignment = [
                'left',
                'left',
                'right',
                'right',
                'right',
                'right',
                'right',
            ]
            atom_table = []
            for site in model.atom_sites:
                atom_table.append(
                    [
                        site.label.value,
                        site.type_symbol.value,
                        f'{site.fract_x.value:.5f}',
                        f'{site.fract_y.value:.5f}',
                        f'{site.fract_z.value:.5f}',
                        f'{site.occupancy.value:.5f}',
                        f'{site.b_iso.value:.5f}',
                    ]
                )
            render_table(
                columns_headers=columns_headers,
                columns_alignment=columns_alignment,
                columns_data=atom_table,
            )

    def show_experimental_data(self) -> None:
        """
        Print experimental data including experiment datablocks,
        types, instrument settings, and peak profile information.
        """
        print(section('Experiments'))

        for expt in self.project.experiments._experiments.values():
            print(paragraph('Experiment datablock'))
            print(f'🔬 {expt.name}')

            print(paragraph('Experiment type'))
            print(f'{expt.type.sample_form.value}, {expt.type.radiation_probe.value}, {expt.type.beam_mode.value}')

            if hasattr(expt, 'instrument'):
                if hasattr(expt.instrument, 'setup_wavelength'):
                    print(paragraph('Wavelength'))
                    print(f'{expt.instrument.setup_wavelength.value:.5f}')
                if hasattr(expt.instrument, 'calib_twotheta_offset'):
                    print(paragraph('2θ offset'))
                    print(f'{expt.instrument.calib_twotheta_offset.value:.5f}')

            if hasattr(expt, 'peak_profile_type'):
                print(paragraph('Profile type'))
                print(expt.peak_profile_type)

            if hasattr(expt, 'peak'):
                if hasattr(expt.peak, 'broad_gauss_u'):
                    print(paragraph('Peak broadening (Gaussian)'))
                    columns_alignment = ['left', 'right']
                    columns_data = [
                        ['U', f'{expt.peak.broad_gauss_u.value:.5f}'],
                        ['V', f'{expt.peak.broad_gauss_v.value:.5f}'],
                        ['W', f'{expt.peak.broad_gauss_w.value:.5f}'],
                    ]
                    render_table(
                        columns_alignment=columns_alignment,
                        columns_data=columns_data,
                    )
                if hasattr(expt.peak, 'broad_lorentz_x'):
                    print(paragraph('Peak broadening (Lorentzian)'))
                    columns_alignment = ['left', 'right']
                    columns_data = [
                        ['X', f'{expt.peak.broad_lorentz_x.value:.5f}'],
                        ['Y', f'{expt.peak.broad_lorentz_y.value:.5f}'],
                    ]
                    render_table(
                        columns_alignment=columns_alignment,
                        columns_data=columns_data,
                    )

    def show_fitting_details(self) -> None:
        """
        Print fitting details including calculation and minimization engines,
        and fit quality metrics.
        """
        print(section('Fitting'))

        print(paragraph('Calculation engine'))
        print(self.project.analysis.current_calculator)

        print(paragraph('Minimization engine'))
        print(self.project.analysis.current_minimizer)

        print(paragraph('Fit quality'))
        columns_alignment = ['left', 'right']
        fit_metrics = [
            [
                'Goodness-of-fit (reduced χ²)',
                f'{self.project.analysis.fit_results.reduced_chi_square:.2f}',
            ]
        ]
        render_table(
            columns_alignment=columns_alignment,
            columns_data=fit_metrics,
        )

    # ------------------------------------------
    #  Exporting
    # ------------------------------------------

    def as_cif(self) -> str:
        """
        Export the final fitted data and analysis results as CIF format.
        """
        return 'To be added...'

__init__(project)

Initialize the summary with a reference to the project.

Parameters:

Name Type Description Default
project

The Project instance this summary belongs to.

required
Source code in src/easydiffraction/summary.py
20
21
22
23
24
25
26
27
def __init__(self, project) -> None:
    """
    Initialize the summary with a reference to the project.

    Args:
        project: The Project instance this summary belongs to.
    """
    self.project = project

as_cif()

Export the final fitted data and analysis results as CIF format.

Source code in src/easydiffraction/summary.py
193
194
195
196
197
def as_cif(self) -> str:
    """
    Export the final fitted data and analysis results as CIF format.
    """
    return 'To be added...'

show_crystallographic_data()

Print crystallographic data including phase datablocks, space groups, cell parameters, and atom sites.

Source code in src/easydiffraction/summary.py
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def show_crystallographic_data(self) -> None:
    """
    Print crystallographic data including phase datablocks,
    space groups, cell parameters, and atom sites.
    """
    print(section('Crystallographic data'))

    for model in self.project.sample_models._models.values():
        print(paragraph('Phase datablock'))
        print(f'🧩 {model.name}')

        print(paragraph('Space group'))
        print(model.space_group.name_h_m.value)

        print(paragraph('Cell parameters'))
        columns_alignment: List[str] = ['left', 'right']
        cell_data = [[k.replace('length_', '').replace('angle_', ''), f'{v:.5f}'] for k, v in model.cell.as_dict().items()]
        render_table(
            columns_alignment=columns_alignment,
            columns_data=cell_data,
        )

        print(paragraph('Atom sites'))
        columns_headers = [
            'Label',
            'Type',
            'fract_x',
            'fract_y',
            'fract_z',
            'Occupancy',
            'B_iso',
        ]
        columns_alignment = [
            'left',
            'left',
            'right',
            'right',
            'right',
            'right',
            'right',
        ]
        atom_table = []
        for site in model.atom_sites:
            atom_table.append(
                [
                    site.label.value,
                    site.type_symbol.value,
                    f'{site.fract_x.value:.5f}',
                    f'{site.fract_y.value:.5f}',
                    f'{site.fract_z.value:.5f}',
                    f'{site.occupancy.value:.5f}',
                    f'{site.b_iso.value:.5f}',
                ]
            )
        render_table(
            columns_headers=columns_headers,
            columns_alignment=columns_alignment,
            columns_data=atom_table,
        )

show_experimental_data()

Print experimental data including experiment datablocks, types, instrument settings, and peak profile information.

Source code in src/easydiffraction/summary.py
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def show_experimental_data(self) -> None:
    """
    Print experimental data including experiment datablocks,
    types, instrument settings, and peak profile information.
    """
    print(section('Experiments'))

    for expt in self.project.experiments._experiments.values():
        print(paragraph('Experiment datablock'))
        print(f'🔬 {expt.name}')

        print(paragraph('Experiment type'))
        print(f'{expt.type.sample_form.value}, {expt.type.radiation_probe.value}, {expt.type.beam_mode.value}')

        if hasattr(expt, 'instrument'):
            if hasattr(expt.instrument, 'setup_wavelength'):
                print(paragraph('Wavelength'))
                print(f'{expt.instrument.setup_wavelength.value:.5f}')
            if hasattr(expt.instrument, 'calib_twotheta_offset'):
                print(paragraph('2θ offset'))
                print(f'{expt.instrument.calib_twotheta_offset.value:.5f}')

        if hasattr(expt, 'peak_profile_type'):
            print(paragraph('Profile type'))
            print(expt.peak_profile_type)

        if hasattr(expt, 'peak'):
            if hasattr(expt.peak, 'broad_gauss_u'):
                print(paragraph('Peak broadening (Gaussian)'))
                columns_alignment = ['left', 'right']
                columns_data = [
                    ['U', f'{expt.peak.broad_gauss_u.value:.5f}'],
                    ['V', f'{expt.peak.broad_gauss_v.value:.5f}'],
                    ['W', f'{expt.peak.broad_gauss_w.value:.5f}'],
                ]
                render_table(
                    columns_alignment=columns_alignment,
                    columns_data=columns_data,
                )
            if hasattr(expt.peak, 'broad_lorentz_x'):
                print(paragraph('Peak broadening (Lorentzian)'))
                columns_alignment = ['left', 'right']
                columns_data = [
                    ['X', f'{expt.peak.broad_lorentz_x.value:.5f}'],
                    ['Y', f'{expt.peak.broad_lorentz_y.value:.5f}'],
                ]
                render_table(
                    columns_alignment=columns_alignment,
                    columns_data=columns_data,
                )

show_fitting_details()

Print fitting details including calculation and minimization engines, and fit quality metrics.

Source code in src/easydiffraction/summary.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
def show_fitting_details(self) -> None:
    """
    Print fitting details including calculation and minimization engines,
    and fit quality metrics.
    """
    print(section('Fitting'))

    print(paragraph('Calculation engine'))
    print(self.project.analysis.current_calculator)

    print(paragraph('Minimization engine'))
    print(self.project.analysis.current_minimizer)

    print(paragraph('Fit quality'))
    columns_alignment = ['left', 'right']
    fit_metrics = [
        [
            'Goodness-of-fit (reduced χ²)',
            f'{self.project.analysis.fit_results.reduced_chi_square:.2f}',
        ]
    ]
    render_table(
        columns_alignment=columns_alignment,
        columns_data=fit_metrics,
    )

show_project_info()

Print the project title and description.

Source code in src/easydiffraction/summary.py
39
40
41
42
43
44
45
46
47
48
49
50
def show_project_info(self) -> None:
    """
    Print the project title and description.
    """
    print(section('Project info'))

    print(paragraph('Title'))
    print(self.project.info.title)

    if self.project.info.description:
        print(paragraph('Description'))
        print('\n'.join(wrap(self.project.info.description, width=60)))