nomad-coe/nomad

replace deprecated ase.atoms.get_number_of_atoms() by ase.atoms.get_global_number_of_atoms()

Closed this issue · 3 comments

Usage of ase.Atoms.get_number_of_atoms() as for example in

https://github.com/nomad-coe/nomad/blob/develop/nomad/normalizing/common.py#L153

raises a warning:

/scratch/AnacondaEnvironments/anaconda3/envs/nomad/lib/python3.9/site-packages/ase/atoms.py:920: VisibleDeprecationWarning: Use get_global_number_of_atoms() instead
  warnings.warn('Use get_global_number_of_atoms() instead',

on a fresh install of nomad package. for example:

https://github.com/nomad-coe/nomad/blob/develop/nomad/normalizing/common.py#L153

this fixes:

develop...mdforti:nomad:develop

In a similar manner, I am also getting this warnings,

/scratch/AnacondaEnvironments/anaconda3/envs/nomad/lib/python3.9/site-packages/ase/cell.py:97: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  cell = np.array(cell, float)

and

/scratch/AnacondaEnvironments/anaconda3/envs/nomad/lib/python3.9/site-packages/ase/atoms.py:424: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
  a = np.array(a, dtype, order='C')

but still need to track down the origin - the warning message do not show the exact line causing this and warnings filter in my scripts are not working for some reason.

Thanks @mdforti for reporting these!

Indeed you are right in both cases. We can handle these two issues (#71 and #72) in one go. I would, however, do slight changes to your suggested fixes:

  • Instead of get_number_of_atoms, we can simply use len(atoms) as suggested in the ASE docs.
  • Instead of array.to(ureg.angstrom)._magnitude, we can use array.to(ureg.angstrom).magnitude, which is the public attribute for getting the unitless numpy array.

I will prepare a fix and let you know.

This is now fixed in the develop branch by this commit.