Skip to content

Commit 3e0d72a

Browse files
committed
Simplify For Now
1 parent d45ba9d commit 3e0d72a

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/pals/kinds/BeamLine.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .all_elements import get_all_elements_as_annotation
55
from .mixin import BaseElement
6+
from ..functions import load_file_to_dict, store_dict_to_file
67

78

89
class BeamLine(BaseElement):
@@ -25,3 +26,14 @@ def model_dump(self, *args, **kwargs):
2526
from pals.kinds.mixin.all_element_mixin import dump_element_list
2627

2728
return dump_element_list(self, "line", *args, **kwargs)
29+
30+
@staticmethod
31+
def from_file(filename: str) -> "BeamLine":
32+
"""Load a BeamLine from a text file"""
33+
pals_dict = load_file_to_dict(filename)
34+
return BeamLine(**pals_dict)
35+
36+
def to_file(self, filename: str):
37+
"""Save a BeamLine to a text file"""
38+
pals_dict = self.model_dump()
39+
store_dict_to_file(filename, pals_dict)

src/pals/kinds/Lattice.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from pydantic import model_validator
2-
from typing import List, Literal
1+
from pydantic import model_validator, Field
2+
from typing import Annotated, List, Literal, Union
33

4-
from .all_elements import get_all_elements_as_annotation
4+
from .BeamLine import BeamLine
55
from .mixin import BaseElement
66
from ..functions import load_file_to_dict, store_dict_to_file
77

0 commit comments

Comments
 (0)