EasyScience / EasyDiffractionLib

Diffraction data analysis library
https://easydiffraction.org
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

Weird behaviour of add_atom() #87

Open rozyczko opened 1 year ago

rozyczko commented 1 year ago

While testing, Celine encountered an interesting issue with add_atom.

The normal signature looks like add_atom('H', 'H', 0.0, 0.0, 0.0) with atom type and label as strings and fractional positions inside the cell as floats. However, one can pass property objects as fractional positions, e.g. add_atom('H', 'H', atom.fract_x, atom.fract_y, atom.fract_z) and the method happily accepts these types, assigning proper values. However, in the process, some attributes get mixed and we get

[<Parameter 'fract_x': 0.0+/-0 (fixed), bounds=[-inf:inf]>,
  <Parameter 'fract_y': 0.0+/-0 (fixed), bounds=[-inf:inf]>,
  <Parameter 'fract_z': 0.0+/-0 (fixed), bounds=[-inf:inf]>,
  <Parameter 'fract_z': 0.0+/-0 (fixed), bounds=[-inf:inf]>]

as the atom parameter list. Notice the lack of occupancy and doubly specified fract_z.

rozyczko commented 1 year ago

reproduced by

from easyDiffractionLib import Phase

phase = Phase(name="salt")

phase.add_atom('Na', 'Na', 0.0, 0.0, 0.0)
phase.add_atom('O', 'O', phase.atoms[0].fract_x, phase.atoms[0].fract_y, phase.atoms[0].fract_z)

print(phase.atoms[0].name, phase.atoms[0].get_parameters())
print(phase.atoms[1].name, phase.atoms[1].get_parameters())