Skip to content

[Bug]: ValueError: zero-size array to reduction operation maximum which has no identity #390

Description

@shwetaphd

Email (Optional)

shweta_c@cy.iitr.ac.in

Version

2024.3.1

Which OS(es) are you using?

  • MacOS
  • Windows
  • Linux

What happened?

I am attempting to plot the van hove correlation for bulk Na metal:

`analyzer = collections.OrderedDict()

for temp, xdatcar_path in temp_path.items():
if temp == 300:
ionicstep_start = 10764
elif temp == 600:
ionicstep_start = 4943

st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
print(len(st))
analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)`

It give me below error:

10000

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 16
    14 st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
    15 print(len(st))
---> 16 analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:703, in DiffusionAnalyzer.from_structures(cls, structures, specie, temperature, time_step, step_skip, initial_disp, initial_structure, **kwargs)
   700 if initial_disp is not None:
   701     disp += initial_disp[:, None, :]
--> 703 return cls(
   704     structure,
   705     disp,
   706     specie,
   707     temperature,
   708     time_step,
   709     step_skip=step_skip,
   710     lattices=l,
   711     **kwargs,
   712 )

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:411, in DiffusionAnalyzer.__init__(self, structure, displacements, specie, temperature, time_step, step_skip, smoothed, min_obs, avg_nsteps, lattices, c_ranges, c_range_include_edge, structures)
   409 self.corrected_displacements = dc
   410 self.max_ion_displacements = np.max(np.sum(dc**2, axis=-1) ** 0.5, axis=1)
--> 411 self.max_framework_displacement = np.max(
   412     self.max_ion_displacements[framework_indices]
   413 )
   414 self.msd = msd
   415 self.mscd = mscd

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:2810, in max(a, axis, out, keepdims, initial, where)
  2692 @array_function_dispatch(_max_dispatcher)
  2693 @set_module('numpy')
  2694 def max(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
  2695          where=np._NoValue):
  2696     """
  2697     Return the maximum of an array or maximum along an axis.
  2698 
  (...)
  2808     5
  2809     """
-> 2810     return _wrapreduction(a, np.maximum, 'max', axis, None, out,
  2811                           keepdims=keepdims, initial=initial, where=where)

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
    85         else:
    86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation maximum which has no identity
```


I am unable to understand that the XDATCAR file is not empty then why it is unable to read? Kindly @shyuep 
Thanks in advance!

### Code snippet

```python
st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
print(len(st))
analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)`
```


### Log output

```shell
10000

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 16
   14 st = Xdatcar(xdatcar_path, ionicstep_start=ionicstep_start).structures
   15 print(len(st))
---> 16 analyzer[temp] = DiffusionAnalyzer.from_structures(st, specie="Na", temperature=temp, time_step=1, step_skip=1, smoothed=False)

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:703, in DiffusionAnalyzer.from_structures(cls, structures, specie, temperature, time_step, step_skip, initial_disp, initial_structure, **kwargs)
  700 if initial_disp is not None:
  701     disp += initial_disp[:, None, :]
--> 703 return cls(
  704     structure,
  705     disp,
  706     specie,
  707     temperature,
  708     time_step,
  709     step_skip=step_skip,
  710     lattices=l,
  711     **kwargs,
  712 )

File ~/.repos/venv/py312/lib/python3.11/site-packages/pymatgen/analysis/diffusion/analyzer.py:411, in DiffusionAnalyzer.__init__(self, structure, displacements, specie, temperature, time_step, step_skip, smoothed, min_obs, avg_nsteps, lattices, c_ranges, c_range_include_edge, structures)
  409 self.corrected_displacements = dc
  410 self.max_ion_displacements = np.max(np.sum(dc**2, axis=-1) ** 0.5, axis=1)
--> 411 self.max_framework_displacement = np.max(
  412     self.max_ion_displacements[framework_indices]
  413 )
  414 self.msd = msd
  415 self.mscd = mscd

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:2810, in max(a, axis, out, keepdims, initial, where)
 2692 @array_function_dispatch(_max_dispatcher)
 2693 @set_module('numpy')
 2694 def max(a, axis=None, out=None, keepdims=np._NoValue, initial=np._NoValue,
 2695          where=np._NoValue):
 2696     """
 2697     Return the maximum of an array or maximum along an axis.
 2698 
 (...)
 2808     5
 2809     """
-> 2810     return _wrapreduction(a, np.maximum, 'max', axis, None, out,
 2811                           keepdims=keepdims, initial=initial, where=where)

File ~/.repos/venv/py312/lib/python3.11/site-packages/numpy/core/fromnumeric.py:88, in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
   85         else:
   86             return reduction(axis=axis, out=out, **passkwargs)
---> 88 return ufunc.reduce(obj, axis, dtype, out, **passkwargs)

ValueError: zero-size array to reduction operation maximum which has no identity



I am unable to understand when the XDATCAR file is not empty then why it is unable to read? Kindly @shyuep 
Thanks in advance!
```


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions