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

SimpleDefect class does not meet MSONable requiement #20

Open
zeyuan-ni opened this issue Oct 16, 2024 · 0 comments
Open

SimpleDefect class does not meet MSONable requiement #20

zeyuan-ni opened this issue Oct 16, 2024 · 0 comments

Comments

@zeyuan-ni
Copy link

zeyuan-ni commented Oct 16, 2024

  • Test code:
    from pydefect.input_maker.defect import SimpleDefect 
    
    sd = SimpleDefect(in_atom="A",out_atom="B",charge_list=[0,1,2])
    sd_dict = sd.as_dict()
    SimpleDefect.from_dict(sd_dict)
  • Result:
    ---------------------------------------------------------------------------
    KeyError                                  Traceback (most recent call last)
    Cell In[3], line 5
          3 sd = SimpleDefect(in_atom="A",out_atom="B",charge_list=[0,1,2])
          4 sd_dict = sd.as_dict()
    ----> 5 SimpleDefect.from_dict(sd_dict)
    
    File ~/packages_dev/vasp_workflows/.venv/lib/python3.9/site-packages/pydefect/input_maker/defect.py:18, in Defect.from_dict(cls, d)
         16 @classmethod
         17 def from_dict(cls, d):
    ---> 18     return cls(name=d["name"], charges=tuple(d["charges"]))
    
    KeyError: 'name'
  • Reason
    • SimpleDefect inherit from_dict() from parent Defect class, which is not compatible since SimpleDefect has a different __init__() method.
  • Possible fix plan (tested)
    class SimpleDefect_MSONable(SimpleDefect):
        @classmethod
        def from_dict(cls, d):
            _d = {k:v for k,v in d.items() if not "@" in k}
            return cls(**_d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant