Calculation Without Data: LBCO, CWL¶
This example shows how to calculate and plot a diffraction pattern without any measured data. Everything the calculation needs — the crystal structure, the instrument, the peak profile, and the background — is defined in code, and the pattern is computed over a calculation range instead of over loaded data points.
This is useful to preview what a candidate structure should look like, to teach, or to generate a synthetic pattern before any measurement exists. No data file is downloaded or loaded.
For this example, a constant-wavelength neutron powder experiment for La0.5Ba0.5CoO3 is used.
🛠️ Import Library¶
import easydiffraction as edi
📦 Define Project¶
project = edi.Project(name='lbco_simulation')
🧩 Define Structure¶
Download CIF file¶
structure_path = edi.download_data('struct-lbco', destination='data')
Getting data...
Data 'struct-lbco': La0.5Ba0.5CoO3 (crystal structure)
✅ Data 'struct-lbco' downloaded to '../../../data/struct-lbco.cif'
Add Structure from CIF¶
project.structures.add_from_cif_path(structure_path)
project.structures.show_names()
structure = project.structures['lbco']
Defined structures 🧩
['lbco']
Plot Structure¶
project.display.structure(struct_name='lbco')
Structure 🧩 'lbco' (Atom view type: 'covalent')
wheel = zoom
right-drag = pan
project.experiments.create(
name='sim',
sample_form='powder',
beam_mode='constant wavelength',
radiation_probe='neutron',
)
experiment = project.experiments['sim']
Set Instrument¶
experiment.instrument.setup_wavelength = 1.494
Set Peak Profile¶
experiment.peak.broad_gauss_u = 0.1
experiment.peak.broad_gauss_v = -0.1
experiment.peak.broad_gauss_w = 0.1
experiment.peak.broad_lorentz_y = 0.1
Set Background¶
experiment.background.create(id='1', position=10, intensity=20)
experiment.background.create(id='2', position=160, intensity=20)
Set Calculation Range¶
With no measured data, the x-grid to calculate on comes from the
data_range category. It already holds a sensible default window
derived from the instrument, so the experiment is calculable without
any setup. Here we change the default window as an example.
experiment.data_range.two_theta_min = 10.0
experiment.data_range.two_theta_max = 160.0
experiment.data_range.two_theta_inc = 0.05
Set Linked Structures¶
experiment.linked_structures.create(structure_id='lbco', scale=10.0)
project.display.pattern(expt_name='sim')
project.display.pattern(expt_name='sim', x_min=30, x_max=60)
Modify Parameters and Recalculate¶
structure.cell.length_a = 3.6
structure.atom_sites['O'].adp_iso = 1.2
experiment.peak.broad_lorentz_y = 0.9
project.analysis.calculate()
project.display.pattern(expt_name='sim', x_min=30, x_max=60)
💾 Save Project¶
project.save_as(dir_path='projects/simulate-lbco-cwl')
Saving project 📦 'lbco_simulation' to '../../../projects/simulate-lbco-cwl'
├── 📄 project.edi
├── 📁 structures/
│ └── 📄 lbco.edi
├── 📁 experiments/
│ └── 📄 sim.edi
├── 📁 analysis/
│ └── 📄 analysis.edi
└── 📁 reports/
└── 📄 lbco_simulation.html