Skip to content

Commit

Permalink
🐛 FIX: get_pymatgen_version (#4796)
Browse files Browse the repository at this point in the history
In version 2022.0.3 it was moved
  • Loading branch information
chrisjsewell authored Mar 9, 2021
1 parent 765f05e commit 4b7febe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
8 changes: 6 additions & 2 deletions aiida/orm/nodes/data/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ def get_pymatgen_version():
"""
if not has_pymatgen():
return None
import pymatgen
return pymatgen.__version__
try:
from pymatgen import __version__
except ImportError:
# this was changed in version 2022.0.3
from pymatgen.core import __version__
return __version__


def has_spglib():
Expand Down
18 changes: 8 additions & 10 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
from aiida.common.utils import Capturing
from aiida.orm import load_node
from aiida.orm import CifData, StructureData, KpointsData, BandsData, ArrayData, TrajectoryData, Dict
from aiida.orm.nodes.data.structure import (
ase_refine_cell, get_formula, get_pymatgen_version, has_ase, has_pymatgen, has_spglib
)
from aiida.orm.nodes.data.structure import Kind, Site


Expand Down Expand Up @@ -51,11 +54,15 @@ def simplify(string):
return '\n'.join(s.strip() for s in string.split())


@pytest.mark.skipif(not has_pymatgen(), reason='pymatgen not installed')
def test_get_pymatgen_version():
assert isinstance(get_pymatgen_version(), str)


class TestCifData(AiidaTestCase):
"""Tests for CifData class."""
from distutils.version import StrictVersion
from aiida.orm.nodes.data.cif import has_pycifrw
from aiida.orm.nodes.data.structure import has_ase, has_pymatgen, has_spglib, get_pymatgen_version

valid_sample_cif_str = '''
data_test
Expand Down Expand Up @@ -1038,7 +1045,6 @@ class TestStructureData(AiidaTestCase):
Tests the creation of StructureData objects (cell and pbc).
"""
# pylint: disable=too-many-public-methods
from aiida.orm.nodes.data.structure import has_ase, has_spglib
from aiida.orm.nodes.data.cif import has_pycifrw

def test_cell_ok_and_atoms(self):
Expand Down Expand Up @@ -1512,7 +1518,6 @@ def test_kind_8(self):
Test the ase_refine_cell() function
"""
# pylint: disable=too-many-statements
from aiida.orm.nodes.data.structure import ase_refine_cell
import ase
import math
import numpy
Expand Down Expand Up @@ -1593,8 +1598,6 @@ def test_get_formula(self):
"""
Tests the generation of formula
"""
from aiida.orm.nodes.data.structure import get_formula

self.assertEqual(get_formula(['Ba', 'Ti'] + ['O'] * 3), 'BaO3Ti')
self.assertEqual(get_formula(['Ba', 'Ti', 'C'] + ['O'] * 3, separator=' '), 'C Ba O3 Ti')
self.assertEqual(get_formula(['H'] * 6 + ['C'] * 6), 'C6H6')
Expand Down Expand Up @@ -1622,8 +1625,6 @@ def test_get_formula_unknown(self):
"""
Tests the generation of formula, including unknown entry.
"""
from aiida.orm.nodes.data.structure import get_formula

self.assertEqual(get_formula(['Ba', 'Ti'] + ['X'] * 3), 'BaTiX3')
self.assertEqual(get_formula(['Ba', 'Ti', 'C'] + ['X'] * 3, separator=' '), 'C Ba Ti X3')
self.assertEqual(get_formula(['X'] * 6 + ['C'] * 6), 'C6X6')
Expand Down Expand Up @@ -1916,7 +1917,6 @@ def test_clone(self):

class TestStructureDataFromAse(AiidaTestCase):
"""Tests the creation of Sites from/to a ASE object."""
from aiida.orm.nodes.data.structure import has_ase

@unittest.skipIf(not has_ase(), 'Unable to import ase')
def test_ase(self):
Expand Down Expand Up @@ -2103,7 +2103,6 @@ class TestStructureDataFromPymatgen(AiidaTestCase):
Tests the creation of StructureData from a pymatgen Structure and
Molecule objects.
"""
from aiida.orm.nodes.data.structure import has_pymatgen, get_pymatgen_version

@unittest.skipIf(not has_pymatgen(), 'Unable to import pymatgen')
def test_1(self):
Expand Down Expand Up @@ -2296,7 +2295,6 @@ def test_multiple_kinds_alloy():
class TestPymatgenFromStructureData(AiidaTestCase):
"""Tests the creation of pymatgen Structure and Molecule objects from
StructureData."""
from aiida.orm.nodes.data.structure import has_ase, has_pymatgen, get_pymatgen_version

@unittest.skipIf(not has_pymatgen(), 'Unable to import pymatgen')
def test_1(self):
Expand Down

0 comments on commit 4b7febe

Please sign in to comment.