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

Replace site.species_and_occu with site.species property for compatible pymatgen versions #3480

16 changes: 13 additions & 3 deletions aiida/orm/nodes/data/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@ def set_pymatgen_structure(self, struct):
:raise ValueError: if there are partial occupancies together with spins.
"""

from pkg_resources import parse_version

def build_kind_name(species_and_occu):
"""
Build a kind name from a pymatgen Composition, including an additional ordinal if spin is included,
Expand Down Expand Up @@ -896,16 +898,24 @@ def build_kind_name(species_and_occu):
self.pbc = [True, True, True]
self.clear_kinds()

required_pmg_version = parse_version('2019.3.13')
current_pmg_version = parse_version(get_pymatgen_version())
for site in struct.sites:

# site.species property first introduced in pymatgen version 2019.3.13
if current_pmg_version < required_pmg_version:
species_and_occu = site.species_and_occu
else:
species_and_occu = site.species

if 'kind_name' in site.properties:
kind_name = site.properties['kind_name']
else:
kind_name = build_kind_name(site.species_and_occu)
kind_name = build_kind_name(species_and_occu)

inputs = {
'symbols': [x.symbol for x in site.species_and_occu.keys()],
'weights': [x for x in site.species_and_occu.values()],
'symbols': [x.symbol for x in species_and_occu.keys()],
'weights': [x for x in species_and_occu.values()],
'position': site.coords.tolist()
}

Expand Down