Define a model¶
This example shows how to define a model of a crystal structure in EasyDiffraction.
Import EasyDiffraction¶
In [2]:
Copied!
import easydiffraction as ed
import easydiffraction as ed
Create a job¶
Create a job — the main object to store all the information
In [3]:
Copied!
job = ed.Job()
job = ed.Job()
In [4]:
Copied!
phase = ed.Phase(name='nacl')
phase = ed.Phase(name='nacl')
Set space group
In [5]:
Copied!
phase.space_group.name_hm_alt = 'F m -3 m'
phase.space_group.name_hm_alt = 'F m -3 m'
Set cell parameters
In [6]:
Copied!
phase.cell.length_a = 5.691694
phase.cell.length_a = 5.691694
Add atoms
In [7]:
Copied!
phase.atom_sites.append(label='Na',
type_symbol='Na',
fract_x=0,
fract_y=0,
fract_z=0,
occupancy=1,
b_iso_or_equiv=0.5)
phase.atom_sites.append(label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.5,
occupancy=1,
b_iso_or_equiv=0.5)
phase.atom_sites.append(label='Na',
type_symbol='Na',
fract_x=0,
fract_y=0,
fract_z=0,
occupancy=1,
b_iso_or_equiv=0.5)
phase.atom_sites.append(label='Cl',
type_symbol='Cl',
fract_x=0,
fract_y=0,
fract_z=0.5,
occupancy=1,
b_iso_or_equiv=0.5)
Add phase to the job object
In [8]:
Copied!
job.add_phase(phase=phase)
print(job.phases)
job.add_phase(phase=phase)
print(job.phases)
Collection of 1 phases: ['nacl']
Show phase info in CIF format
In [9]:
Copied!
phase = job.phases['nacl']
print(phase.cif)
phase = job.phases['nacl']
print(phase.cif)
data_nacl _cell_length_a 5.691694 _cell_length_b 5.691694 _cell_length_c 5.691694 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'F m -3 m' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_B_iso_or_equiv Na Na 0.00000000 0.00000000 0.00000000 1.00000000 Biso 0.5 Cl Cl 0.00000000 0.00000000 0.5 1.00000000 Biso 0.5
Display the crystal structure of a given model
In [10]:
Copied!
job.show_crystal_structure(id='nacl')
job.show_crystal_structure(id='nacl')
3Dmol.js failed to load for some reason. Please check your browser console for error messages.
Load from CIF¶
Download the CIF file from the EasyDiffraction repository on GitHub
In [11]:
Copied!
ed.download_from_repository('lbco.cif', destination='data')
ed.download_from_repository('lbco.cif', destination='data')
Load a phase from the downloaded CIF file
In [12]:
Copied!
job.add_phase_from_file('data/lbco.cif')
print(job.phases)
job.add_phase_from_file('data/lbco.cif')
print(job.phases)
Collection of 2 phases: ['nacl', 'lbco']
Show phase info in CIF format
In [13]:
Copied!
print(job.phases['lbco'].cif)
print(job.phases['lbco'].cif)
data_lbco _cell_length_a 3.88 _cell_length_b 3.88 _cell_length_c 3.88 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _space_group_name_H-M_ref 'P m -3 m' loop_ _atom_site_label _atom_site_type_symbol _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy _atom_site_adp_type _atom_site_B_iso_or_equiv La La 0.00000000 0.00000000 0.00000000 0.5 Biso 0.1 Ba Ba 0.00000000 0.00000000 0.00000000 0.5 Biso 0.1 Co Co 0.5 0.5 0.5 1.00000000 Biso 0.1 O O 0.00000000 0.5 0.5 1.00000000 Biso 0.1
Display the crystal structure of a given model
In [14]:
Copied!
job.show_crystal_structure(id='lbco')
job.show_crystal_structure(id='lbco')
3Dmol.js failed to load for some reason. Please check your browser console for error messages.