Tb2Ti2O7 - single-crystal neutron CW - anisotropic ADPs¶
Verifies calculated F2 values for a no-extinction neutron single-crystal reference with anisotropic ADPs.
Refinement: the overall scale only; all other parameters are taken from the FullProf reference.
In [2]:
Copied!
import easydiffraction as edi
from easydiffraction import ExperimentFactory
from easydiffraction import StructureFactory
from easydiffraction.analysis import verification as verify
import easydiffraction as edi
from easydiffraction import ExperimentFactory
from easydiffraction import StructureFactory
from easydiffraction.analysis import verification as verify
Build the project¶
In [3]:
Copied!
project = edi.Project()
project = edi.Project()
Define the structure¶
In [4]:
Copied!
structure = StructureFactory.from_scratch(name='tbti')
structure.space_group.name_h_m = 'F d -3 m' # FullProf Space group symbol
structure.cell.length_a = 10.130 # FullProf a
# Anisotropic sites carry the FullProf beta tensor directly: ``adp_type``
# is set to ``'beta'`` and the dimensionless beta components are assigned
# verbatim. F d -3 m is cubic, so site symmetry links the remaining beta
# components and only the independent ones are set. FullProf occupancy is
# the site multiplicity over the general multiplicity; CIF/EasyDiffraction
# use 1.0 for a fully occupied site.
structure.atom_sites.create(
id='Tb', # FullProf Atom
type_symbol='Tb', # FullProf Typ
fract_x=0.5, # FullProf X
fract_y=0.5, # FullProf Y
fract_z=0.5, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['Tb']
aniso.adp_11 = 0.00098991673 # FullProf beta11
aniso.adp_12 = -0.00047650724 # FullProf beta12
structure.atom_sites.create(
id='Ti', # FullProf Atom
type_symbol='Ti', # FullProf Typ
fract_x=0.0, # FullProf X
fract_y=0.0, # FullProf Y
fract_z=0.0, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['Ti']
aniso.adp_11 = 0.00090989727 # FullProf beta11
aniso.adp_12 = -0.00016990340 # FullProf beta12
structure.atom_sites.create(
id='O1', # FullProf Atom
type_symbol='O', # FullProf Typ
fract_x=0.32804, # FullProf X
fract_y=0.125, # FullProf Y
fract_z=0.125, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['O1']
aniso.adp_11 = 0.0012294180 # FullProf beta11
aniso.adp_22 = 0.00078215479 # FullProf beta22
aniso.adp_23 = 0.00041246481 # FullProf beta23
structure.atom_sites.create(
id='O2', # FullProf Atom
type_symbol='O', # FullProf Typ
fract_x=0.375, # FullProf X
fract_y=0.375, # FullProf Y
fract_z=0.375, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['O2']
aniso.adp_11 = 0.00060762477 # FullProf beta11
project.structures.add(structure)
structure = StructureFactory.from_scratch(name='tbti')
structure.space_group.name_h_m = 'F d -3 m' # FullProf Space group symbol
structure.cell.length_a = 10.130 # FullProf a
# Anisotropic sites carry the FullProf beta tensor directly: ``adp_type``
# is set to ``'beta'`` and the dimensionless beta components are assigned
# verbatim. F d -3 m is cubic, so site symmetry links the remaining beta
# components and only the independent ones are set. FullProf occupancy is
# the site multiplicity over the general multiplicity; CIF/EasyDiffraction
# use 1.0 for a fully occupied site.
structure.atom_sites.create(
id='Tb', # FullProf Atom
type_symbol='Tb', # FullProf Typ
fract_x=0.5, # FullProf X
fract_y=0.5, # FullProf Y
fract_z=0.5, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['Tb']
aniso.adp_11 = 0.00098991673 # FullProf beta11
aniso.adp_12 = -0.00047650724 # FullProf beta12
structure.atom_sites.create(
id='Ti', # FullProf Atom
type_symbol='Ti', # FullProf Typ
fract_x=0.0, # FullProf X
fract_y=0.0, # FullProf Y
fract_z=0.0, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['Ti']
aniso.adp_11 = 0.00090989727 # FullProf beta11
aniso.adp_12 = -0.00016990340 # FullProf beta12
structure.atom_sites.create(
id='O1', # FullProf Atom
type_symbol='O', # FullProf Typ
fract_x=0.32804, # FullProf X
fract_y=0.125, # FullProf Y
fract_z=0.125, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['O1']
aniso.adp_11 = 0.0012294180 # FullProf beta11
aniso.adp_22 = 0.00078215479 # FullProf beta22
aniso.adp_23 = 0.00041246481 # FullProf beta23
structure.atom_sites.create(
id='O2', # FullProf Atom
type_symbol='O', # FullProf Typ
fract_x=0.375, # FullProf X
fract_y=0.375, # FullProf Y
fract_z=0.375, # FullProf Z
adp_type='beta', # FullProf beta tensor
)
aniso = structure.atom_site_aniso['O2']
aniso.adp_11 = 0.00060762477 # FullProf beta11
project.structures.add(structure)
In [5]:
Copied!
structure.show_as_text()
structure.show_as_text()
Structure 🧩 'tbti' as text
| Edi | |
|---|---|
| 1 | data_tbti |
| 2 | |
| 3 | _cell.length_a 10.13 |
| 4 | _cell.length_b 10.13 |
| 5 | _cell.length_c 10.13 |
| 6 | _cell.angle_alpha 90. |
| 7 | _cell.angle_beta 90. |
| 8 | _cell.angle_gamma 90. |
| 9 | |
| 10 | _space_group.name_h_m "F d -3 m" |
| 11 | _space_group.coord_system_code 2 |
| 12 | |
| 13 | _geom.min_bond_distance_cutoff 0. |
| 14 | _geom.bond_distance_inc 0.25 |
| 15 | |
| 16 | loop_ |
| 17 | _atom_site.id |
| 18 | _atom_site.type_symbol |
| 19 | _atom_site.fract_x |
| 20 | _atom_site.fract_y |
| 21 | _atom_site.fract_z |
| 22 | _atom_site.wyckoff_letter |
| 23 | _atom_site.multiplicity |
| 24 | _atom_site.occupancy |
| 25 | _atom_site.adp_iso |
| 26 | _atom_site.adp_type |
| 27 | Tb Tb 0.5 0.5 0.5 d 16 1. 0.00514621 beta |
| 28 | Ti Ti 0. 0. 0. c 16 1. 0.00473022 beta |
| 29 | O1 O 0.32804 0.125 0.125 f 48 1. 0.00484119 beta |
| 30 | O2 O 0.375 0.375 0.375 b 8 1. 0.00315882 beta |
| 31 | |
| 32 | loop_ |
| 33 | _atom_site_aniso.id |
| 34 | _atom_site_aniso.adp_11 |
| 35 | _atom_site_aniso.adp_22 |
| 36 | _atom_site_aniso.adp_33 |
| 37 | _atom_site_aniso.adp_12 |
| 38 | _atom_site_aniso.adp_13 |
| 39 | _atom_site_aniso.adp_23 |
| 40 | Tb 0.00098992 0.00098992 0.00098992 -0.00047651 -0.00047651 -0.00047651 |
| 41 | Ti 0.0009099 0.0009099 0.0009099 -0.0001699 -0.0001699 -0.0001699 |
| 42 | O1 0.00122942 0.00078215 0.00078215 0. 0. 0.00041246 |
| 43 | O2 0.00060762 0.00060762 0.00060762 0. 0. 0. |
Load the FullProf reference¶
In [6]:
Copied!
FULLPROF_PROJECT_DIR = 'sc-neut-cwl_tbti_anisotropic-adp'
FULLPROF_OUT_FILE = 'tbti.out'
FULLPROF_SCALE = 0.28749475 # FullProf Scale
FULLPROF_WAVELENGTH = 0.7930 # FullProf Lambda
f2calc = verify.load_fullprof_sc_f2calc(FULLPROF_PROJECT_DIR, FULLPROF_OUT_FILE)
FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_OUT_FILE)
FULLPROF_PROJECT_DIR = 'sc-neut-cwl_tbti_anisotropic-adp'
FULLPROF_OUT_FILE = 'tbti.out'
FULLPROF_SCALE = 0.28749475 # FullProf Scale
FULLPROF_WAVELENGTH = 0.7930 # FullProf Lambda
f2calc = verify.load_fullprof_sc_f2calc(FULLPROF_PROJECT_DIR, FULLPROF_OUT_FILE)
FULLPROF_LABEL = verify.fullprof_label(FULLPROF_PROJECT_DIR, FULLPROF_OUT_FILE)
Create the experiment¶
In [7]:
Copied!
experiment = ExperimentFactory.from_scratch(
name='tbti',
sample_form='single crystal',
beam_mode='constant wavelength',
radiation_probe='neutron',
scattering_type='bragg',
)
experiment.linked_structure.structure_id = 'tbti'
experiment.linked_structure.scale = FULLPROF_SCALE
experiment.instrument.setup_wavelength = FULLPROF_WAVELENGTH
verify.set_reference_reflections(experiment, f2calc)
project.experiments.add(experiment)
experiment = ExperimentFactory.from_scratch(
name='tbti',
sample_form='single crystal',
beam_mode='constant wavelength',
radiation_probe='neutron',
scattering_type='bragg',
)
experiment.linked_structure.structure_id = 'tbti'
experiment.linked_structure.scale = FULLPROF_SCALE
experiment.instrument.setup_wavelength = FULLPROF_WAVELENGTH
verify.set_reference_reflections(experiment, f2calc)
project.experiments.add(experiment)
edi-cryspy VS FullProf¶
In [8]:
Copied!
calc_ed_cryspy = verify.calculate_reflections(project, experiment, 'cryspy')
LABEL_ED_CRYSPY = verify.engine_label('cryspy')
reference, candidate = verify.align_reflections(f2calc, calc_ed_cryspy)
project.display.reflection_comparison(
'tbti',
reference=reference,
candidate=candidate,
reference_label=FULLPROF_LABEL,
candidate_label=LABEL_ED_CRYSPY,
)
calc_ed_cryspy = verify.calculate_reflections(project, experiment, 'cryspy')
LABEL_ED_CRYSPY = verify.engine_label('cryspy')
reference, candidate = verify.align_reflections(f2calc, calc_ed_cryspy)
project.display.reflection_comparison(
'tbti',
reference=reference,
candidate=candidate,
reference_label=FULLPROF_LABEL,
candidate_label=LABEL_ED_CRYSPY,
)
Calculator for experiment 'tbti' already set to
cryspy
Loading plot…
Fit edi-cryspy to FullProf¶
In [9]:
Copied!
experiment.calculator.type = 'cryspy'
experiment.linked_structure.scale.free = True
project.analysis.fit()
project.display.fit.results()
calc_ed_cryspy_refined = verify.calculate_reflections(project, experiment, 'cryspy')
LABEL_ED_CRYSPY_REFINED = verify.engine_label('cryspy', note='scale only')
reference_refined, candidate_refined = verify.align_reflections(f2calc, calc_ed_cryspy_refined)
project.display.reflection_comparison(
'tbti',
reference=reference_refined,
candidate=candidate_refined,
reference_label=FULLPROF_LABEL,
candidate_label=LABEL_ED_CRYSPY_REFINED,
)
verify.report_refinement_closeness(
reference,
candidate,
candidate_refined,
)
experiment.calculator.type = 'cryspy'
experiment.linked_structure.scale.free = True
project.analysis.fit()
project.display.fit.results()
calc_ed_cryspy_refined = verify.calculate_reflections(project, experiment, 'cryspy')
LABEL_ED_CRYSPY_REFINED = verify.engine_label('cryspy', note='scale only')
reference_refined, candidate_refined = verify.align_reflections(f2calc, calc_ed_cryspy_refined)
project.display.reflection_comparison(
'tbti',
reference=reference_refined,
candidate=candidate_refined,
reference_label=FULLPROF_LABEL,
candidate_label=LABEL_ED_CRYSPY_REFINED,
)
verify.report_refinement_closeness(
reference,
candidate,
candidate_refined,
)
Calculator for experiment 'tbti' already set to
cryspy
Standard fitting
📋 Using experiment 🔬 'tbti' for 'single' fitting
🚀 Starting fit process with 'lmfit (leastsq)'...
📈 Goodness-of-fit progress:
| iteration | time (s) | χ² | change / status | |
|---|---|---|---|---|
| 1 | 1 | 0.04 | 516632.99 | |
| 2 | 5 | 0.19 | 0.02 | 100.0% ↓ |
| 3 | 8 | 0.31 | 0.02 |
🏆 Best goodness-of-fit (reduced χ²) is 0.02 at iteration 5
✅ Fitting complete.
⚙️ Settings used:
| Name | Value | Description | |
|---|---|---|---|
| 1 | max_iterations | 1000 | Maximum solver iterations. |
📋 Least-squares fit results:
| Metric | Value | |
|---|---|---|
| 1 | 🧪 Minimizer | lmfit (leastsq) |
| 2 | ✅ Overall status | success |
| 3 | ⏱️ Fitting time (seconds) | 0.31 |
| 4 | 🔁 Iterations | 5 |
| 5 | 📏 Goodness-of-fit (reduced χ²) | 0.02 |
| 6 | 📏 R-factor (Rf, %) | 0.02 |
| 7 | 📏 R-factor squared (Rf², %) | 0.02 |
| 8 | 📏 Weighted R-factor (wR, %) | 0.02 |
📈 Refined parameters:
| datablock | category | entry | parameter | units | start | value | s.u. | change | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | tbti | linked_structure | scale | 0.2875 | 2.3007 | 0.0000 | 700.27 % ↑ |
• start = parameter value before refinement
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
• value = refined value from least-squares minimization
• s.u. = standard uncertainty (one sigma), from the covariance matrix
• change = relative change from start, in %; ↑ = increase, ↓ = decrease
Calculator for experiment 'tbti' already set to
cryspy
Loading plot…
| Metric | Before | After | |
|---|---|---|---|
| 1 | Profile diff (%) | 87.50 | 0.02 |
| 2 | Max deviation (%) | 87.51 | 0.03 |
| 3 | Area ratio | 0.1250 | 1.0001 |
| 4 | Shape correlation | 1.0000 | 1.0000 |
Agreement check¶
In [10]:
Copied!
verify.assert_patterns_agree([
(f'{LABEL_ED_CRYSPY_REFINED} vs {FULLPROF_LABEL}', reference_refined, candidate_refined),
])
verify.assert_patterns_agree([
(f'{LABEL_ED_CRYSPY_REFINED} vs {FULLPROF_LABEL}', reference_refined, candidate_refined),
])
| Comparison | Metric | Expected | Actual | OK | |
|---|---|---|---|---|---|
| 1 | edi 0.19.0 (cryspy 0.12.1, scale only) vs FullProf 8.40 | Profile diff (%) | < 2.5 | 0.02 | ✅ |
| 2 | Max deviation (%) | < 6 | 0.03 | ✅ | |
| 3 | Area ratio | 0.99 to 1.01 | 1.0001 | ✅ | |
| 4 | Shape correlation | > 0.999 | 1.0000 | ✅ |
Out[10]:
True