Skip to content

Commit

Permalink
Merge pull request #253 from BertJorissen/develop
Browse files Browse the repository at this point in the history
Fix SlotPickleMixin import error
  • Loading branch information
gmatteo authored Sep 29, 2022
2 parents eb5163d + 0de790e commit 71d5e6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion abipy/core/kpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from monty.functools import lazy_property
from monty.string import marquee
from pymatgen.core.lattice import Lattice
from pymatgen.util.serialization import pmg_serialize, SlotPickleMixin
from pymatgen.util.serialization import pmg_serialize
from abipy.iotools import ETSF_Reader
from abipy.tools.derivatives import finite_diff
from abipy.tools.numtools import add_periodic_replicas, is_diagonal
from abipy.core.mixins import SlotPickleMixin

import logging
logger = logging.getLogger(__name__)
Expand Down
15 changes: 15 additions & 0 deletions abipy/core/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"Has_PhononBands",
"NotebookWriter",
"Has_Header",
"SlotPickleMixin"
]


Expand Down Expand Up @@ -949,3 +950,17 @@ def hdr(self):
return self.reader.read_abinit_hdr()

#def compare_hdr(self, other_hdr):


class SlotPickleMixin:
"""
This mixin makes it possible to pickle/unpickle objects with __slots__
defined.
"""

def __getstate__(self):
return {slot: getattr(self, slot) for slot in self.__slots__ if hasattr(self, slot)}

def __setstate__(self, state):
for slot, value in state.items():
setattr(self, slot, value)
2 changes: 1 addition & 1 deletion abipy/core/symmetries.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from monty.termcolor import cprint
from monty.collections import dict2namedtuple
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.util.serialization import SlotPickleMixin
from abipy.core.kpoints import wrap_to_ws, issamek, has_timrev_from_kptopt
from abipy.core.mixins import SlotPickleMixin


__all__ = [
Expand Down

0 comments on commit 71d5e6c

Please sign in to comment.