Skip to content

Commit 93583a0

Browse files
crystal: Fixed crystal serialization
1 parent e9fce8f commit 93583a0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

xrdpattern/crystal/components/crystal.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import json
44
import logging
55
from dataclasses import dataclass, asdict
6+
from types import NoneType
67
from typing import Optional, Literal
78

89
from distlib.util import cached_property
910
from pymatgen.core import Structure, Lattice, Species, Element
1011
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
1112

12-
from xrdpattern.serialization import JsonDataclass
13+
from xrdpattern.serialization import JsonDataclass, Serializable
1314
from .atomic_site import AtomSite
1415
from .base import CrystalBasis
1516

@@ -149,4 +150,22 @@ def angles(self) -> tuple[float, float, float]:
149150

150151
@property
151152
def lengths(self) -> tuple[float, float, float]:
152-
return self.lattice.lengths
153+
return self.lattice.lengths
154+
155+
@staticmethod
156+
def make_basic(basic_cls, s: str):
157+
if basic_cls == Lattice:
158+
print(f's = {s}')
159+
arr = s[1:-1].split(',')
160+
params = [float(x) for x in arr]
161+
return Lattice.from_parameters(*params)
162+
else:
163+
return JsonDataclass.make_basic(basic_cls, s)
164+
165+
@staticmethod
166+
def get_basic_entry(obj):
167+
if isinstance(obj, Lattice):
168+
params = *obj.lengths, *obj.angles
169+
return str(params)
170+
else:
171+
return JsonDataclass.get_basic_entry(obj)

0 commit comments

Comments
 (0)