Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 of 3 tasks
shwetaphd opened this issue Jun 1, 2024 · 0 comments
Open
1 of 3 tasks
Labels

Comments

@shwetaphd
Copy link

Email (Optional)

[email protected]

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
@shwetaphd shwetaphd added the bug label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant