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

fix pymatgen imports #4794

Merged
merged 1 commit into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions aiida/orm/nodes/data/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ def _get_object_pymatgen_structure(self, **kwargs):
.. note:: Requires the pymatgen module (version >= 3.0.13, usage
of earlier versions may cause errors)
"""
from pymatgen import Structure
from pymatgen.core.structure import Structure

if self.pbc != (True, True, True):
raise ValueError('Periodic boundary conditions must apply in all three dimensions of real space')
Expand All @@ -1862,7 +1862,7 @@ def _get_object_pymatgen_structure(self, **kwargs):

if (kwargs.pop('add_spin', False) and any([n.endswith('1') or n.endswith('2') for n in self.get_kind_names()])):
# case when spins are defined -> no partial occupancy allowed
from pymatgen import Specie
from pymatgen.core.periodic_table import Specie
oxidation_state = 0 # now I always set the oxidation_state to zero
for site in self.sites:
kind = self.get_kind(site.kind_name)
Expand Down Expand Up @@ -1907,7 +1907,7 @@ def _get_object_pymatgen_molecule(self, **kwargs):
.. note:: Requires the pymatgen module (version >= 3.0.13, usage
of earlier versions may cause errors)
"""
from pymatgen import Molecule
from pymatgen.core.structure import Molecule

if kwargs:
raise ValueError(f'Unrecognized parameters passed to pymatgen converter: {kwargs.keys()}')
Expand Down
2 changes: 1 addition & 1 deletion aiida/tools/dbimporters/plugins/materialsproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import os
import requests

from pymatgen import MPRester
from pymatgen.ext.matproj import MPRester

from aiida.tools.dbimporters.baseclasses import CifEntry, DbImporter, DbSearchResults

Expand Down
44 changes: 24 additions & 20 deletions tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2227,25 +2227,27 @@ def test_partial_occ_and_spin(self):
Tests pymatgen -> StructureData, with partial occupancies and spins.
This should raise a ValueError.
"""
import pymatgen

Fe_spin_up = pymatgen.Specie('Fe', 0, properties={'spin': 1})
Mn_spin_up = pymatgen.Specie('Mn', 0, properties={'spin': 1})
Fe_spin_down = pymatgen.Specie('Fe', 0, properties={'spin': -1})
Mn_spin_down = pymatgen.Specie('Mn', 0, properties={'spin': -1})
FeMn1 = pymatgen.Composition({Fe_spin_up: 0.5, Mn_spin_up: 0.5})
FeMn2 = pymatgen.Composition({Fe_spin_down: 0.5, Mn_spin_down: 0.5})
a = pymatgen.Structure(
from pymatgen.core.periodic_table import Specie
from pymatgen.core.composition import Composition
from pymatgen.core.structure import Structure

Fe_spin_up = Specie('Fe', 0, properties={'spin': 1})
Mn_spin_up = Specie('Mn', 0, properties={'spin': 1})
Fe_spin_down = Specie('Fe', 0, properties={'spin': -1})
Mn_spin_down = Specie('Mn', 0, properties={'spin': -1})
FeMn1 = Composition({Fe_spin_up: 0.5, Mn_spin_up: 0.5})
FeMn2 = Composition({Fe_spin_down: 0.5, Mn_spin_down: 0.5})
a = Structure(
lattice=[[4, 0, 0], [0, 4, 0], [0, 0, 4]], species=[FeMn1, FeMn2], coords=[[0, 0, 0], [0.5, 0.5, 0.5]]
)

with self.assertRaises(ValueError):
StructureData(pymatgen=a)

# same, with vacancies
Fe1 = pymatgen.Composition({Fe_spin_up: 0.5})
Fe2 = pymatgen.Composition({Fe_spin_down: 0.5})
a = pymatgen.Structure(
Fe1 = Composition({Fe_spin_up: 0.5})
Fe2 = Composition({Fe_spin_down: 0.5})
a = Structure(
lattice=[[4, 0, 0], [0, 4, 0], [0, 0, 4]], species=[Fe1, Fe2], coords=[[0, 0, 0], [0.5, 0.5, 0.5]]
)

Expand All @@ -2257,12 +2259,13 @@ def test_partial_occ_and_spin(self):
def test_multiple_kinds_partial_occupancies():
"""Tests that a structure with multiple sites with the same element but different
partial occupancies, get their own unique kind name."""
import pymatgen
from pymatgen.core.composition import Composition
from pymatgen.core.structure import Structure

Mg1 = pymatgen.Composition({'Mg': 0.50})
Mg2 = pymatgen.Composition({'Mg': 0.25})
Mg1 = Composition({'Mg': 0.50})
Mg2 = Composition({'Mg': 0.25})

a = pymatgen.Structure(
a = Structure(
lattice=[[4, 0, 0], [0, 4, 0], [0, 0, 4]], species=[Mg1, Mg2], coords=[[0, 0, 0], [0.5, 0.5, 0.5]]
)

Expand All @@ -2275,12 +2278,13 @@ def test_multiple_kinds_alloy():
Tests that a structure with multiple sites with the same alloy symbols but different
weights, get their own unique kind name
"""
import pymatgen
from pymatgen.core.composition import Composition
from pymatgen.core.structure import Structure

alloy_one = pymatgen.Composition({'Mg': 0.25, 'Al': 0.75})
alloy_two = pymatgen.Composition({'Mg': 0.45, 'Al': 0.55})
alloy_one = Composition({'Mg': 0.25, 'Al': 0.75})
alloy_two = Composition({'Mg': 0.45, 'Al': 0.55})

a = pymatgen.Structure(
a = Structure(
lattice=[[4, 0, 0], [0, 4, 0], [0, 0, 4]],
species=[alloy_one, alloy_two],
coords=[[0, 0, 0], [0.5, 0.5, 0.5]]
Expand Down