-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
44 additions
and
58 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/easyreflectometry/sample/collections/base_collection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from copy import deepcopy | ||
from typing import List | ||
|
||
from easyscience.Objects.Groups import BaseCollection as EasyBaseCollection | ||
|
||
from easyreflectometry.parameter_utils import yaml_dump | ||
|
||
|
||
class BaseCollection(EasyBaseCollection): | ||
def __init__( | ||
self, | ||
name: str, | ||
interface, | ||
*args, | ||
**kwargs, | ||
): | ||
super().__init__(name, *args, **kwargs) | ||
self.interface = interface | ||
|
||
def __repr__(self) -> str: | ||
""" | ||
String representation of the collection. | ||
:return: a string representation of the collection | ||
""" | ||
return yaml_dump(self._dict_repr) | ||
|
||
@property | ||
def _dict_repr(self) -> dict: | ||
""" | ||
A simplified dict representation. | ||
:return: Simple dictionary | ||
""" | ||
return {self.name: [i._dict_repr for i in self]} | ||
|
||
def _make_defalut_collection(self, default_collection: List, interface): | ||
elements = deepcopy(default_collection) | ||
for element in elements: | ||
element.interface = interface | ||
return elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters