dkriegner / xrayutilities

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

xrayutilities error on reading COD database cif #50

Closed marcoscleison closed 6 years ago

marcoscleison commented 6 years ago

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

My python code is grab from internet:

#from pymatgen import Lattice, Structure
import numpy
import xrayutilities as xru
#from xrayutilities.materials.cif import CIFFile
from xrayutilities.materials import CIFFile
from xrayutilities.materials.material import Crystal
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib

matplotlib.rcParams.update({'font.size': 18})
fig_size = [15, 12]
plt.rcParams["figure.figsize"] = fig_size

xu_cif = CIFFile("bifeo3.cif")

xu_crystal = Crystal(name="BiFeO3", lat=xu_cif.SGLattice())

two_theta = numpy.arange(0, 80, 0.01)
powder = xru.simpack.smaterials.Powder(xu_crystal, 1)
pm = xru.simpack.PowderModel(powder, I0=100)
intensities = pm.simulate(two_theta)
plt.plot(two_theta,intensities)
plt.xlim(0,80)
ax = plt.axes()
ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
ax.yaxis.set_major_formatter(ticker.FormatStrFormatter('%.4f'))
plt.title("XRD Pattern for " + xu_crystal.name)
plt.xlabel("2 theta (degrees)")
plt.ylabel("Intensity")
plt.show()

My cif test if from COD database:

#------------------------------------------------------------------------------
#$Date: 2016-02-18 17:37:37 +0200 (Thu, 18 Feb 2016) $
#$Revision: 176729 $
#$URL: svn://www.crystallography.net/cod/cif/1/00/10/1001090.cif $
#------------------------------------------------------------------------------
#
# This file is available in the Crystallography Open Database (COD),
# http://www.crystallography.net/
#
# All data on this site have been placed in the public domain by the
# contributors.
#
data_1001090
loop_
_publ_author_name
'Moreau, J M'
'Michel, C'
'Gerson, R'
'James, W J'
_publ_section_title
;
Ferroelectric Bi Fe O~3~ X-Ray and neutron diffraction study
;
_journal_coden_ASTM              JPCSAW
_journal_name_full               'Journal of Physics and Chemistry of Solids'
_journal_page_first              1315
_journal_page_last               1320
_journal_paper_doi               10.1016/S0022-3697(71)80189-0
_journal_volume                  32
_journal_year                    1971
_chemical_formula_structural     'Bi Fe O3'
_chemical_formula_sum            'Bi Fe O3'
_chemical_name_systematic        'Bismuth iron(III) oxide'
_space_group_IT_number           161
_symmetry_cell_setting           trigonal
_symmetry_space_group_name_Hall  'R 3 -2"c'
_symmetry_space_group_name_H-M   'R 3 c :H'
_cell_angle_alpha                90
_cell_angle_beta                 90
_cell_angle_gamma                120
_cell_formula_units_Z            6
_cell_length_a                   5.5876(3)
_cell_length_b                   5.5876(3)
_cell_length_c                   13.867(1)
_cell_volume                     374.9
_refine_ls_R_factor_all          0.09
_cod_original_sg_symbol_H-M      'R 3 c H'
_cod_database_code               1001090
loop_
_symmetry_equiv_pos_as_xyz
x,y,z
-y,x-y,z
y-x,-x,z
-y,-x,1/2+z
x,x-y,1/2+z
y-x,y,1/2+z
1/3+x,2/3+y,2/3+z
2/3+x,1/3+y,1/3+z
1/3-y,2/3+x-y,2/3+z
2/3-y,1/3+x-y,1/3+z
1/3-x+y,2/3-x,2/3+z
2/3-x+y,1/3-x,1/3+z
1/3-y,2/3-x,1/6+z
2/3-y,1/3-x,5/6+z
1/3+x,2/3+x-y,1/6+z
2/3+x,1/3+x-y,5/6+z
1/3-x+y,2/3+y,1/6+z
2/3-x+y,1/3+y,5/6+z
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_occupancy
_atom_site_attached_hydrogens
_atom_site_calc_flag
Bi1 Bi3+ 6 a 0. 0. 0. 1. 0 d
Fe1 Fe3+ 6 a 0. 0. 0.2212(15) 1. 0 d
O1 O2- 18 b 0.443(2) 0.012(4) 0.9543(20) 1. 0 d
loop_
_atom_type_symbol
_atom_type_oxidation_number
Bi3+ 3.000
Fe3+ 3.000
O2- -2.000

This gives an Output error:

Traceback (most recent call last):
  File "main.py", line 15, in <module>
    xu_cif = CIFFile("bifeo3.cif")
  File "lib/python3.6/site-packages/xrayutilities/materials/cif.py", line 180, in __init__
    self.SymStruct()
  File "lib/python3.6/site-packages/xrayutilities/materials/cif.py", line 378, in SymStruct
    element = getattr(elements, el)
AttributeError: module 'xrayutilities.materials.elements' has no attribute 'Bi+'

When I remove the + sign of the chage in the cif, the library works.

Please, guide me to solve this issue. Congratulation for the work and thanks for the attention.

dkriegner commented 6 years ago

The problem is that the CIF parser does not treat/read correctly the oxidation state of the elements. I will look into that.

dkriegner commented 6 years ago

commit 24cf42bb1286b46a0618e63e984467d17ac214b0 should fix the described issue. So when you install the newest GIT master it should work.

The solution is not ideal, but should work. The problem with the oxidation states in the cif files is that not for all different oxidation states the corresponding atomic scattering factors are tabulated. In your case for Oxygen the neutral atom is used which is indicated when reading the file. Let me know if this solution is acceptable!

you could slightly simplify your code by using bfo = xu.materials.Crystal.fromCIF("BFO.cif")

marcoscleison commented 6 years ago

@dkriegner thank you very much! I will test it.