analysis
analysis
Analysis
High-level orchestration of analysis tasks for a Project.
This class wires calculators and minimizers, exposes a compact interface for parameters, constraints and results, and coordinates computations across the project's structures and experiments.
Source code in src/easydiffraction/analysis/analysis.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | |
__init__(project)
Create a new Analysis instance bound to a project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project
|
object
|
The project that owns models and experiments. |
required |
Source code in src/easydiffraction/analysis/analysis.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
aliases_type
property
writable
Tag of the active aliases collection type.
apply_constraints()
Apply currently defined constraints to the project.
Source code in src/easydiffraction/analysis/analysis.py
570 571 572 573 574 575 576 577 578 | |
as_cif()
Serialize the analysis section to a CIF string.
Returns:
| Type | Description |
|---|---|
str
|
The analysis section represented as a CIF document string. |
Source code in src/easydiffraction/analysis/analysis.py
784 785 786 787 788 789 790 791 792 793 794 795 796 | |
constraints_type
property
writable
Tag of the active constraints collection type.
current_minimizer
property
writable
The identifier of the active minimizer, if any.
fit(verbosity=None)
Execute fitting for all experiments.
This method performs the optimization but does not display
results automatically. Call :meth:show_fit_results after
fitting to see a summary of the fit quality and parameter
values.
In 'single' mode, fits each experiment independently. In 'joint' mode, performs a simultaneous fit across experiments with weights.
Sets :attr:fit_results on success, which can be accessed
programmatically (e.g.,
analysis.fit_results.reduced_chi_square).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbosity
|
str | None
|
Console output verbosity: |
None
|
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the fit mode is not |
Source code in src/easydiffraction/analysis/analysis.py
580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 | |
fit_mode
property
Fit-mode category item holding the active strategy.
fit_mode_type
property
writable
Tag of the active fit-mode category type.
help()
Print a summary of analysis properties and methods.
Source code in src/easydiffraction/analysis/analysis.py
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 | |
how_to_access_parameters()
Show Python access paths for all parameters.
The output explains how to reference specific parameters in code.
Source code in src/easydiffraction/analysis/analysis.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
joint_fit_experiments
property
Per-experiment weight collection for joint fitting.
show_all_params()
Print all parameters for structures and experiments.
Source code in src/easydiffraction/analysis/analysis.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
show_as_cif()
Render the analysis section as CIF in console.
Source code in src/easydiffraction/analysis/analysis.py
798 799 800 801 802 803 | |
show_available_minimizers()
staticmethod
Print available minimizer drivers on this system.
Source code in src/easydiffraction/analysis/analysis.py
474 475 476 477 | |
show_constraints()
Print a table of all user-defined symbolic constraints.
Source code in src/easydiffraction/analysis/analysis.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
show_current_aliases_type()
Print the currently used aliases collection type.
Source code in src/easydiffraction/analysis/analysis.py
158 159 160 161 | |
show_current_constraints_type()
Print the currently used constraints collection type.
Source code in src/easydiffraction/analysis/analysis.py
199 200 201 202 | |
show_current_fit_mode_type()
Print the currently used fit-mode category type.
Source code in src/easydiffraction/analysis/analysis.py
539 540 541 542 | |
show_current_minimizer()
Print the name of the currently selected minimizer.
Source code in src/easydiffraction/analysis/analysis.py
469 470 471 472 | |
show_fit_results()
Display a summary of the fit results.
Renders the fit quality metrics (reduced χ², R-factors) and a table of fitted parameters with their starting values, final values, and uncertainties.
This method should be called after :meth:fit completes. If no
fit has been performed yet, a warning is logged.
Example::
project.analysis.fit() project.analysis.show_fit_results()
Source code in src/easydiffraction/analysis/analysis.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | |
show_fittable_params()
Print all fittable parameters.
Source code in src/easydiffraction/analysis/analysis.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
show_free_params()
Print only currently free (varying) parameters.
Source code in src/easydiffraction/analysis/analysis.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
show_parameter_cif_uids()
Show CIF unique IDs for all parameters.
The output explains which unique identifiers are used when creating CIF-based constraints.
Source code in src/easydiffraction/analysis/analysis.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
show_supported_aliases_types()
Print a table of supported aliases collection types.
Source code in src/easydiffraction/analysis/analysis.py
154 155 156 | |
show_supported_constraints_types()
Print a table of supported constraints collection types.
Source code in src/easydiffraction/analysis/analysis.py
195 196 197 | |
show_supported_fit_mode_types()
Print a table of supported fit-mode category types.
Source code in src/easydiffraction/analysis/analysis.py
535 536 537 | |
calculators
base
CalculatorBase
Bases: ABC
Base API for diffraction calculation engines.
Source code in src/easydiffraction/analysis/calculators/base.py
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 | |
calculate_pattern(structure, experiment, called_by_minimizer)
abstractmethod
Calculate diffraction pattern for one structure-experiment pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structures
|
The structure object. |
required |
experiment
|
ExperimentBase
|
The experiment object. |
required |
called_by_minimizer
|
bool
|
Whether the calculation is called by a minimizer. Default is False. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The calculated diffraction pattern as a NumPy array. |
Source code in src/easydiffraction/analysis/calculators/base.py
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 | |
calculate_structure_factors(structure, experiment, called_by_minimizer)
abstractmethod
Calculate structure factors for one experiment.
Source code in src/easydiffraction/analysis/calculators/base.py
29 30 31 32 33 34 35 36 37 | |
engine_imported
abstractmethod
property
True if the underlying calculation library is available.
name
abstractmethod
property
Short identifier of the calculation engine.
crysfml
CrysfmlCalculator
Bases: CalculatorBase
Wrapper for Crysfml library.
Source code in src/easydiffraction/analysis/calculators/crysfml.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
calculate_pattern(structure, experiment, called_by_minimizer=False)
Calculate the diffraction pattern using Crysfml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structures
|
The structure to calculate the pattern for. |
required |
experiment
|
ExperimentBase
|
The experiment associated with the structure. |
required |
called_by_minimizer
|
bool
|
Whether the calculation is called by a minimizer. |
False
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, List[float]]
|
The calculated diffraction pattern as a NumPy array or a list of floats. |
Source code in src/easydiffraction/analysis/calculators/crysfml.py
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 | |
calculate_structure_factors(structures, experiments)
Call Crysfml to calculate structure factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
Structures
|
The structures to calculate structure factors for. |
required |
experiments
|
Experiments
|
The experiments associated with the sample models. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
HKL calculation is not implemented for CrysfmlCalculator. |
Source code in src/easydiffraction/analysis/calculators/crysfml.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
name
property
Short identifier of this calculator engine.
cryspy
CryspyCalculator
Bases: CalculatorBase
Cryspy-based diffraction calculator.
Converts EasyDiffraction models into Cryspy objects and computes patterns.
Source code in src/easydiffraction/analysis/calculators/cryspy.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | |
calculate_pattern(structure, experiment, called_by_minimizer=False)
Calculate the diffraction pattern using Cryspy.
We only recreate the cryspy_obj if this method is - NOT called by the minimizer, or - the cryspy_dict is NOT yet created. In other cases, we are modifying the existing cryspy_dict This allows significantly speeding up the calculation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to calculate the pattern for. |
required |
experiment
|
ExperimentBase
|
The experiment associated with the structure. |
required |
called_by_minimizer
|
bool
|
Whether the calculation is called by a minimizer. |
False
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, List[float]]
|
The calculated diffraction pattern as a NumPy array or a list of floats. |
Source code in src/easydiffraction/analysis/calculators/cryspy.py
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 | |
calculate_structure_factors(structure, experiment, called_by_minimizer=False)
Raise NotImplementedError as HKL calculation is not implemented.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure to calculate structure factors for. |
required |
experiment
|
ExperimentBase
|
The experiment associated with the sample models. |
required |
called_by_minimizer
|
bool
|
Whether the calculation is called by a minimizer. |
False
|
Source code in src/easydiffraction/analysis/calculators/cryspy.py
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 | |
name
property
Short identifier of this calculator engine.
factory
Calculator factory — delegates to FactoryBase.
Overrides _supported_map to filter out calculators whose engines are
not importable in the current environment.
CalculatorFactory
Bases: FactoryBase
Factory for creating calculation engine instances.
Only calculators whose engine_imported flag is True are
available for creation.
Source code in src/easydiffraction/analysis/calculators/factory.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
pdffit
PDF calculation backend using diffpy.pdffit2 if available.
The class adapts the engine to EasyDiffraction calculator interface and silences stdio on import to avoid noisy output in notebooks and logs.
PdffitCalculator
Bases: CalculatorBase
Wrapper for Pdffit library.
Source code in src/easydiffraction/analysis/calculators/pdffit.py
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 | |
calculate_pattern(structure, experiment, called_by_minimizer=False)
Calculate the PDF pattern using PDFfit2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structure
|
Structure
|
The structure object supplying atom sites and cell parameters. |
required |
experiment
|
ExperimentBase
|
The experiment object supplying instrument and peak parameters. |
required |
called_by_minimizer
|
bool
|
Unused; kept for interface consistency. |
False
|
Source code in src/easydiffraction/analysis/calculators/pdffit.py
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 | |
calculate_structure_factors(structures, experiments)
Return an empty list; PDF does not compute structure factors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
object
|
Unused; kept for interface consistency. |
required |
experiments
|
object
|
Unused; kept for interface consistency. |
required |
Returns:
| Type | Description |
|---|---|
list
|
An empty list. |
Source code in src/easydiffraction/analysis/calculators/pdffit.py
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 | |
name
property
Short identifier of this calculator engine.
categories
aliases
default
Alias category for mapping friendly names to parameter UIDs.
Defines a small record type used by analysis configuration to refer to parameters via readable labels instead of raw unique identifiers.
Alias
Bases: CategoryItem
Single alias entry.
Maps a human-readable label to a concrete param_uid used by
the engine.
Source code in src/easydiffraction/analysis/categories/aliases/default.py
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 | |
label
property
writable
...
Reading this property returns the underlying
StringDescriptor object. Assigning to it updates the
parameter value.
param_uid
property
writable
...
Reading this property returns the underlying
StringDescriptor object. Assigning to it updates the
parameter value.
Aliases
Bases: CategoryCollection
Collection of :class:Alias items.
Source code in src/easydiffraction/analysis/categories/aliases/default.py
90 91 92 93 94 95 96 97 98 99 100 101 | |
__init__()
Create an empty collection of aliases.
Source code in src/easydiffraction/analysis/categories/aliases/default.py
99 100 101 | |
factory
Aliases factory — delegates entirely to FactoryBase.
AliasesFactory
Bases: FactoryBase
Create alias collections by tag.
Source code in src/easydiffraction/analysis/categories/aliases/factory.py
10 11 12 13 14 15 | |
constraints
default
Simple symbolic constraint between parameters.
Represents an equation of the form lhs_alias = rhs_expr stored as a
single expression string. The left- and right-hand sides are derived by
splitting the expression at the = sign.
Constraint
Bases: CategoryItem
Single constraint item stored as lhs = rhs expression.
Source code in src/easydiffraction/analysis/categories/constraints/default.py
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 | |
expression
property
writable
Full constraint equation (e.g. 'occ_Ba = 1 - occ_La').
Reading this property returns the underlying
StringDescriptor object. Assigning to it updates the value.
lhs_alias
property
Left-hand side alias derived from the expression.
rhs_expr
property
Right-hand side expression derived from the expression.
Constraints
Bases: CategoryCollection
Collection of :class:Constraint items.
Source code in src/easydiffraction/analysis/categories/constraints/default.py
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 | |
__init__()
Create an empty constraints collection.
Source code in src/easydiffraction/analysis/categories/constraints/default.py
102 103 104 | |
create(*, expression)
Create a constraint from an expression string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
Constraint equation, e.g. |
required |
Source code in src/easydiffraction/analysis/categories/constraints/default.py
106 107 108 109 110 111 112 113 114 115 116 117 118 | |
factory
Constraints factory — delegates entirely to FactoryBase.
ConstraintsFactory
Bases: FactoryBase
Create constraint collections by tag.
Source code in src/easydiffraction/analysis/categories/constraints/factory.py
10 11 12 13 14 15 | |
fit_mode
enums
Enumeration for fit-mode values.
FitModeEnum
Bases: str, Enum
Fitting strategy for the analysis.
Source code in src/easydiffraction/analysis/categories/fit_mode/enums.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | |
default()
classmethod
Return the default fit mode (SINGLE).
Source code in src/easydiffraction/analysis/categories/fit_mode/enums.py
16 17 18 19 | |
description()
Return a human-readable description of this fit mode.
Source code in src/easydiffraction/analysis/categories/fit_mode/enums.py
21 22 23 24 25 26 | |
factory
Fit-mode factory — delegates entirely to FactoryBase.
FitModeFactory
Bases: FactoryBase
Create fit-mode category items by tag.
Source code in src/easydiffraction/analysis/categories/fit_mode/factory.py
10 11 12 13 14 15 | |
fit_mode
Fit-mode category item.
Stores the active fitting strategy as a CIF-serializable descriptor
validated by FitModeEnum.
FitMode
Bases: CategoryItem
Fitting strategy selector.
Holds a single mode descriptor whose value is one of
FitModeEnum members ('single' or 'joint').
Source code in src/easydiffraction/analysis/categories/fit_mode/fit_mode.py
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 | |
mode
property
writable
Fitting strategy.
Reading this property returns the underlying
StringDescriptor object. Assigning to it updates the
parameter value.
joint_fit_experiments
default
Joint-fit experiment weighting configuration.
Stores per-experiment weights to be used when multiple experiments are fitted simultaneously.
JointFitExperiment
Bases: CategoryItem
A single joint-fit entry.
Source code in src/easydiffraction/analysis/categories/joint_fit_experiments/default.py
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 | |
id
property
writable
Experiment identifier.
Reading this property returns the underlying
StringDescriptor object. Assigning to it updates the
parameter value.
weight
property
writable
Weight factor.
Reading this property returns the underlying
NumericDescriptor object. Assigning to it updates the
parameter value.
JointFitExperiments
Bases: CategoryCollection
Collection of :class:JointFitExperiment items.
Source code in src/easydiffraction/analysis/categories/joint_fit_experiments/default.py
89 90 91 92 93 94 95 96 97 98 99 100 | |
__init__()
Create an empty joint-fit experiments collection.
Source code in src/easydiffraction/analysis/categories/joint_fit_experiments/default.py
98 99 100 | |
factory
Joint-fit-experiments factory — delegates to FactoryBase.
JointFitExperimentsFactory
Bases: FactoryBase
Create joint-fit experiment collections by tag.
Source code in src/easydiffraction/analysis/categories/joint_fit_experiments/factory.py
10 11 12 13 14 15 | |
fit_helpers
metrics
calculate_r_factor(y_obs, y_calc)
Calculate the R-factor between observed and calculated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
Returns:
| Type | Description |
|---|---|
float
|
R-factor value. |
Source code in src/easydiffraction/analysis/fit_helpers/metrics.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
calculate_r_factor_squared(y_obs, y_calc)
Calculate the R-factor squared between observed and calculated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
Returns:
| Type | Description |
|---|---|
float
|
R-factor squared value. |
Source code in src/easydiffraction/analysis/fit_helpers/metrics.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
calculate_rb_factor(y_obs, y_calc)
Calculate the Bragg R-factor between observed and calculated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Bragg R-factor value. |
Source code in src/easydiffraction/analysis/fit_helpers/metrics.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
calculate_reduced_chi_square(residuals, num_parameters)
Calculate the reduced chi-square statistic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residuals
|
ndarray
|
Residuals between observed and calculated data. |
required |
num_parameters
|
int
|
Number of free parameters used in the model. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Reduced chi-square value. |
Source code in src/easydiffraction/analysis/fit_helpers/metrics.py
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 | |
calculate_weighted_r_factor(y_obs, y_calc, weights)
Calculate weighted R-factor between observed and calculated data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_obs
|
ndarray
|
Observed data points. |
required |
y_calc
|
ndarray
|
Calculated data points. |
required |
weights
|
ndarray
|
Weights for each data point. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Weighted R-factor value. |
Source code in src/easydiffraction/analysis/fit_helpers/metrics.py
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 | |
get_reliability_inputs(structures, experiments)
Collect observed and calculated data for reliability calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
Structures
|
Collection of structures. |
required |
experiments
|
Experiments
|
Collection of experiments. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Observed values. |
ndarray
|
Calculated values. |
Optional[ndarray]
|
Error values, or None if not available. |
Source code in src/easydiffraction/analysis/fit_helpers/metrics.py
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 198 | |
reporting
FitResults
Container for results of a single optimization run.
Holds success flag, chi-square metrics, iteration counts, timing, and parameter objects. Provides a printer to summarize key indicators and a table of fitted parameters.
Source code in src/easydiffraction/analysis/fit_helpers/reporting.py
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 | |
__init__(success=False, parameters=None, chi_square=None, reduced_chi_square=None, message='', iterations=0, engine_result=None, starting_parameters=None, fitting_time=None, **kwargs)
Initialize FitResults with the given parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
success
|
bool
|
Indicates if the fit was successful. |
False
|
parameters
|
Optional[List[object]]
|
List of parameters used in the fit. |
None
|
chi_square
|
Optional[float]
|
Chi-square value of the fit. |
None
|
reduced_chi_square
|
Optional[float]
|
Reduced chi-square value of the fit. |
None
|
message
|
str
|
Message related to the fit. |
''
|
iterations
|
int
|
Number of iterations performed. |
0
|
engine_result
|
Optional[object]
|
Result from the fitting engine. |
None
|
starting_parameters
|
Optional[List[object]]
|
Initial parameters for the fit. |
None
|
fitting_time
|
Optional[float]
|
Time taken for the fitting process. |
None
|
**kwargs
|
object
|
Additional engine-specific fields. If |
{}
|
Source code in src/easydiffraction/analysis/fit_helpers/reporting.py
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 | |
display_results(y_obs=None, y_calc=None, y_err=None, f_obs=None, f_calc=None)
Render a human-readable summary of the fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_obs
|
Optional[List[float]]
|
Observed intensities for pattern R-factor metrics. |
None
|
y_calc
|
Optional[List[float]]
|
Calculated intensities for pattern R-factor metrics. |
None
|
y_err
|
Optional[List[float]]
|
Standard deviations of observed intensities for wR. |
None
|
f_obs
|
Optional[List[float]]
|
Observed structure-factor magnitudes for Bragg R. |
None
|
f_calc
|
Optional[List[float]]
|
Calculated structure-factor magnitudes for Bragg R. |
None
|
Source code in src/easydiffraction/analysis/fit_helpers/reporting.py
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 | |
tracking
FitProgressTracker
Track and report reduced chi-square during optimization.
The tracker keeps iteration counters, remembers the best observed reduced chi-square and when it occurred, and can display progress as a table in notebooks or a text UI in terminals.
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
add_tracking_info(row)
Append a formatted row to the progress display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
List[str]
|
Columns corresponding to DEFAULT_HEADERS. |
required |
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
best_chi2
property
Best recorded reduced chi-square value or None.
best_iteration
property
Iteration index at which the best chi-square was observed.
finish_tracking()
Finalize progress display and print best result summary.
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
fitting_time
property
Elapsed time of the last run in seconds, if available.
iteration
property
Current iteration counter.
reset()
Reset internal state before a new optimization run.
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
111 112 113 114 115 116 117 118 119 | |
start_timer()
Begin timing of a fit run.
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
210 211 212 | |
start_tracking(minimizer_name)
Initialize display and headers and announce the minimizer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minimizer_name
|
str
|
Name of the minimizer used for the run. |
required |
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
stop_timer()
Stop timing and store elapsed time for the run.
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
214 215 216 217 | |
track(residuals, parameters)
Update progress with current residuals and parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
residuals
|
ndarray
|
Residuals between measured and calculated data. |
required |
parameters
|
List[float]
|
Current free parameters being fitted. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Residuals unchanged, for optimizer consumption. |
Source code in src/easydiffraction/analysis/fit_helpers/tracking.py
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 | |
fitting
Fitter
Handles the fitting workflow using a pluggable minimizer.
Source code in src/easydiffraction/analysis/fitting.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
fit(structures, experiments, weights=None, analysis=None, verbosity=VerbosityEnum.FULL)
Run the fitting process.
This method performs the optimization but does not display
results. Use :meth:show_fit_results on the Analysis object to
display the fit results after fitting is complete.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
structures
|
Structures
|
Collection of structures. |
required |
experiments
|
Experiments
|
Collection of experiments. |
required |
weights
|
Optional[array]
|
Optional weights for joint fitting. |
None
|
analysis
|
object
|
Optional Analysis object to update its categories during fitting. |
None
|
verbosity
|
VerbosityEnum
|
Console output verbosity. |
VerbosityEnum.FULL
|
Source code in src/easydiffraction/analysis/fitting.py
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 | |
minimizers
base
MinimizerBase
Bases: ABC
Abstract base for concrete minimizers.
Contract: - Subclasses must implement _prepare_solver_args,
_run_solver, _sync_result_to_parameters and
_check_success. - The fit method orchestrates the full
workflow and returns :class:FitResults.
Source code in src/easydiffraction/analysis/minimizers/base.py
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 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | |
fit(parameters, objective_function, verbosity=VerbosityEnum.FULL)
Run the full minimization workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameters
|
List[object]
|
Free parameters to optimize. |
required |
objective_function
|
Callable[..., object]
|
Callable returning residuals for a given set of engine arguments. |
required |
verbosity
|
VerbosityEnum
|
Console output verbosity. |
VerbosityEnum.FULL
|
Returns:
| Type | Description |
|---|---|
FitResults
|
FitResults with success flag, best chi2 and timing. |
Source code in src/easydiffraction/analysis/minimizers/base.py
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 | |
dfols
DfolsMinimizer
Bases: MinimizerBase
Minimizer using DFO-LS (derivative-free least-squares).
Source code in src/easydiffraction/analysis/minimizers/dfols.py
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 | |
factory
Minimizer factory — delegates to FactoryBase.
MinimizerFactory
Bases: FactoryBase
Factory for creating minimizer instances.
Source code in src/easydiffraction/analysis/minimizers/factory.py
10 11 12 13 14 15 | |
lmfit
LmfitMinimizer
Bases: MinimizerBase
Minimizer using the lmfit package.
Source code in src/easydiffraction/analysis/minimizers/lmfit.py
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 | |