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

AseAtomsAdaptor.get_atoms(structure, **kwargs) compares numpy boolean array wtith python nested list. #3011

Closed
chiang-yuan opened this issue May 24, 2023 · 1 comment · Fixed by #3012
Labels
bug io Input/output functionality

Comments

@chiang-yuan
Copy link
Contributor

Describe the bug

AseAtomsAdaptor.get_atoms(structure, **kwargs) checks numpy boolean array against python nested list. This is a bug similar to my previous PR (#2951).

pymatgen/pymatgen/io/ase.py

Lines 107 to 111 in 2330701

if site_prop not in [[True, True, True], [False, False, False]]:
raise ValueError(
"ASE FixAtoms constraint does not support selective dynamics in only some dimensions."
"Remove the selective dynamics and try again if you do not need them."
)

The ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() can be reproduced by reading CONTCAR with selective_dynamics.

This can be bypassed temporarily by converting poscar.selective_dynamics back to nested list poscar.selective_dynamics = [list(x) for x in poscar.selective_dynamics] Will look into this and submit pr later.

@janosh
Copy link
Member

janosh commented May 24, 2023

Thanks for reporting! Minimal code to trigger the error:

import numpy as np

from pymatgen.core import Lattice, Structure
from pymatgen.io.ase import AseAtomsAdaptor

structure = Structure(
    lattice=Lattice.cubic(5),
    species=("Fe", "O"),
    coords=((0, 0, 0), (0.5, 0.5, 0.5)),
    site_properties={"selective_dynamics": np.array([True, True, True])},
)

ase_atoms = AseAtomsAdaptor.get_atoms(structure)
>>> ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Should be easy to fix using np.all and not np.any instead of list comparisons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug io Input/output functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants