dkriegner / xrayutilities

xrayutilities - a package with useful scripts for X-ray diffraction physicists
http://xrayutilities.sourceforge.io
GNU General Public License v2.0
81 stars 29 forks source link

xrayutilities error when reading cif file with "O-" as element type #122

Closed AinomN closed 3 years ago

AinomN commented 3 years ago

I am trying to simulate the powder x-ray pattern from a cif file.

My python code is grab from internet, LaScCoO3_xrd.py

# From pymagten and xrayutilities
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pymatgen as mg
from pymatgen import Lattice, Structure
import numpy as np
import xrayutilities as xu
from xrayutilities.materials.cif import CIFFile
from xrayutilities.materials.material import Crystal
import re
import math

font = {#'family' : 'Palatino',
        #'weight' : 'bold',
        'size'   : 18}
mpl.rc('font', **font)

mpl.rcParams['legend.fontsize'] = 14
mpl.rcParams['legend.frameon'] = False
plt.rcParams.update({'font.size': 18})
fig_size = [8, 4]
plt.rcParams["figure.figsize"] = fig_size

# Read cif file
ZnO = mg.Structure.from_file("ICSD_CollCode60763.cif")

# ZnO
temp_cif = NamedTemporaryFile(delete=False)
ZnO.to("cif", temp_cif.name)
xu_cif_ZnO = CIFFile(temp_cif.name)
xu_crystal_ZnO = Crystal(name=r"ZnO", lat=xu_cif_ZnO.SGLattice())
temp_cif.close()

# Angles
two_theta = np.arange(10, 70, 0.1)

ZnO_powder = xu.simpack.smaterials.Powder(xu_crystal_ZnO, 1)
ZnO_pm = xu.simpack.PowderModel(ZnO_powder, I0=100) #100
ZnO_intensities = ZnO_pm.simulate(two_theta)

plt.plot(two_theta, ZnO_intensities, label=r'ZnO')
plt.show()

My cif file is from the ISCD database:

#(C) 2020 by FIZ Karlsruhe - Leibniz Institute for Information Infrastructure.  All rights reserved.
data_60763-ICSD
_database_code_ICSD 60763
_audit_creation_date 1988-02-22
_audit_update_record 2007-08-01
_chemical_name_common 'Zinc peroxide'
_chemical_formula_structural 'Zn O2'
_chemical_formula_sum 'O2 Zn1'
_chemical_name_structure_type Pyrite#FeS2(cP12)
_exptl_crystal_density_diffrn 5.6
_citation_title 'On the peroxides of zinc and cadmium'
loop_
_citation_id
_citation_journal_full
_citation_year
_citation_journal_volume
_citation_page_first
_citation_page_last
_citation_journal_id_ASTM
primary 'Croatica Chemica Acta' 1985 58 283 288 CCACAA
loop_
_citation_author_citation_id
_citation_author_name
primary 'Puselj, M.'
primary 'Ban, Z.'
primary 'Morvaj, J.'
_cell_length_a 4.871
_cell_length_b 4.871
_cell_length_c 4.871
_cell_angle_alpha 90.
_cell_angle_beta 90.
_cell_angle_gamma 90.
_cell_volume 115.57
_cell_formula_units_Z 4
_space_group_name_H-M_alt 'P a -3'
_space_group_IT_number 205
loop_
_space_group_symop_id
_space_group_symop_operation_xyz
1 '-z+1/2, x+1/2, y'
2 'z+1/2, x, -y+1/2'
3 'z, -x+1/2, y+1/2'
4 '-z, -x, -y'
5 'y, -z+1/2, x+1/2'
6 '-y+1/2, z+1/2, x'
7 'y+1/2, z, -x+1/2'
8 '-y, -z, -x'
9 'x+1/2, y, -z+1/2'
10 'x, -y+1/2, z+1/2'
11 '-x+1/2, y+1/2, z'
12 '-x, -y, -z'
13 'z+1/2, -x+1/2, -y'
14 '-z+1/2, -x, y+1/2'
15 '-z, x+1/2, -y+1/2'
16 'z, x, y'
17 '-y, z+1/2, -x+1/2'
18 'y+1/2, -z+1/2, -x'
19 '-y+1/2, -z, x+1/2'
20 'y, z, x'
21 '-x+1/2, -y, z+1/2'
22 '-x, y+1/2, -z+1/2'
23 'x+1/2, -y+1/2, -z'
24 'x, y, z'
loop_
_atom_type_symbol
_atom_type_oxidation_number
Zn2+ 2
O1- -1
loop_
_atom_site_label
_atom_site_type_symbol
_atom_site_symmetry_multiplicity
_atom_site_Wyckoff_symbol
_atom_site_fract_x
_atom_site_fract_y
_atom_site_fract_z
_atom_site_B_iso_or_equiv
_atom_site_occupancy
Zn1 Zn2+ 4 a 0 0 0 1.02 1.
O1 O1- 8 c 0.413 0.413 0.413 1.61 1.
#End of TTdata_60763-ICSD

This gives an output error:

Traceback (most recent call last):
  File "LaScCoO3_xrd.py", line 238, in <module>
    main()
  File "LaScCoO3_xrd.py", line 149, in main
    xu_cif_ZnO = CIFFile(temp_cif.name)
  File "/Users/monia/miniconda/envs/python/lib/python3.8/site-packages/xrayutilities/materials/cif.py", line 111, in __init__
    self.Parse()
  File "/Users/monia/miniconda/envs/python/lib/python3.8/site-packages/xrayutilities/materials/cif.py", line 137, in Parse
    self.data[name] = CIFDataset(self.fid, name, self.digits)
  File "/Users/monia/miniconda/envs/python/lib/python3.8/site-packages/xrayutilities/materials/cif.py", line 199, in __init__
    self.Parse(fid)
  File "/Users/monia/miniconda/envs/python/lib/python3.8/site-packages/xrayutilities/materials/cif.py", line 384, in Parse
    atom = get_element(asplit[alab_idx])
  File "/Users/monia/miniconda/envs/python/lib/python3.8/site-packages/xrayutilities/materials/cif.py", line 234, in get_element
    raise ValueError("XU.materials: element ('%s') could not"
ValueError: XU.materials: element ('O-') could not be identified as chemical element. Only abbreviations of element names are supported.

I am sorry, but I don't really understand the error. Any help trying to understand this is very much appreciated. And thanks for the great work.

dkriegner commented 3 years ago

The code fails to identify the charge state of your oxygen atom. It seems to me that at the moment only the element name "O1-" is understood. If you put that instead to your cif-file it should work.

But I agree that this should be more flexible and also recognize "O-". I will fix this in future versions

AinomN commented 3 years ago

Thank you for the help and the quick answer

dkriegner commented 3 years ago

I only now had time to test this. Actually you already had as name "O1-" in the CIF-file. I overlooked this. I can not reproduce your problem with xrayutilities master branch.

So I think the question is if you are running the latest version of xrayutilities?

Or is the code you execute here:

# Read cif file
ZnO = mg.Structure.from_file("ICSD_CollCode60763.cif")

# ZnO
temp_cif = NamedTemporaryFile(delete=False)
ZnO.to("cif", temp_cif.name)

changing the CIF file?

For the purpose of xrayutilities you could just do xu_crystal_ZnO = Crystal.fromCIF("ICSD_CollCode60763.cif") and safe some lines of code.

I still shall make the parsing of the atom type more flexible because the CIF syntax explicitly allows "O-" https://www.iucr.org/__data/iucr/cifdic_html/1/cif_core.dic/Iatom_site_type_symbol.html

dkriegner commented 3 years ago

The mentioned commit should fix the reported issue. @AinomN could you test if that also fixes it for you?

AinomN commented 3 years ago

It is now tested, and the solution mentioned in the comment fixed the issue. Thanks.