Skip to content

Commit 76f7545

Browse files
committed
change from multilayer to base_assembly
1 parent 6a3b3c2 commit 76f7545

File tree

5 files changed

+85
-79
lines changed

5 files changed

+85
-79
lines changed

EasyReflectometry/calculators/calculator_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from easyCore.Objects.Inferface import ItemContainer
88

99
from EasyReflectometry.experiment.model import Model
10+
from EasyReflectometry.sample import BaseAssembly
1011
from EasyReflectometry.sample import Layer
1112
from EasyReflectometry.sample import Material
1213
from EasyReflectometry.sample import MaterialMixture
@@ -97,7 +98,7 @@ def create(self, model: Material | Layer | Multilayer | Model) -> list[ItemConta
9798
)
9899
)
99100
self.assign_material_to_layer(model.material.uid, key)
100-
elif issubclass(t_, Multilayer):
101+
elif issubclass(t_, BaseAssembly):
101102
key = model.uid
102103
self._wrapper.create_item(key)
103104
r_list.append(

EasyReflectometry/sample/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from .assemblies.base_assembly import BaseAssembly
12
from .assemblies.gradient_layer import GradientLayer
23
from .assemblies.multilayer import Multilayer
34
from .assemblies.repeating_multilayer import RepeatingMultilayer
@@ -11,6 +12,7 @@
1112
from .sample import Sample
1213

1314
__all__ = (
15+
BaseAssembly,
1416
GradientLayer,
1517
Multilayer,
1618
RepeatingMultilayer,

EasyReflectometry/sample/assemblies/surfactant_layer.py

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -72,60 +72,60 @@ def default(cls, interface=None) -> SurfactantLayer:
7272
@classmethod
7373
def from_pars(
7474
cls,
75-
layer1_chemical_structure: str,
76-
layer1_thickness: float,
77-
layer1_solvent: Material,
78-
layer1_solvation: float,
79-
layer1_area_per_molecule: float,
80-
layer1_roughness: float,
81-
layer2_chemical_structure: str,
82-
layer2_thickness: float,
83-
layer2_solvent: Material,
84-
layer2_solvation: float,
85-
layer2_area_per_molecule: float,
86-
layer2_roughness: float,
75+
top_layer_chemical_structure: str,
76+
top_layer_thickness: float,
77+
top_layer_solvent: Material,
78+
top_layer_solvation: float,
79+
top_layer_area_per_molecule: float,
80+
top_layer_roughness: float,
81+
bottom_layer_chemical_structure: str,
82+
bottom_layer_thickness: float,
83+
bottom_layer_solvent: Material,
84+
bottom_layer_solvation: float,
85+
bottom_layer_area_per_molecule: float,
86+
bottom_layer_roughness: float,
8787
name: str = 'EasySurfactantLayer',
8888
interface=None,
8989
) -> SurfactantLayer:
9090
"""
9191
Constructor for the surfactant layer where the parameters are known,
92-
:py:attr:`layer1` is that which the neutrons interact with first.
92+
:py:attr:`top_layer` is that which the neutrons interact with first.
9393
94-
:param layer1_chemical_structure: Chemical formula for first layer
95-
:param layer1_thickness: Thicknkess of first layer
96-
:param layer1_solvent: Solvent in first layer
97-
:param layer1_solvation: Fractional solvation of first layer by
98-
:py:attr:`layer1_solvent`
99-
:param layer1_area_per_molecule: Area per molecule of first layer
100-
:param layer1_roughness: Roughness of first layer
101-
:param layer2_chemical_structure: Chemical formula for second layer
102-
:param layer2_thickness: Thicknkess of second layer
103-
:param layer2_solvent: Solvent in second layer
104-
:param layer2_solvation: Fractional solvation of second layer by
105-
:py:attr:`layer2_solvent`
106-
:param layer2_area_per_molecule: Area per molecule of second layer
107-
:param layer2_roughness: Roughness of second layer
94+
:param top_layer_chemical_structure: Chemical formula for first layer
95+
:param top_layer_thickness: Thicknkess of first layer
96+
:param top_layer_solvent: Solvent in first layer
97+
:param top_layer_solvation: Fractional solvation of first layer by
98+
:py:attr:`top_layer_solvent`
99+
:param top_layer_area_per_molecule: Area per molecule of first layer
100+
:param top_layer_roughness: Roughness of first layer
101+
:param bottom_layer_chemical_structure: Chemical formula for second layer
102+
:param bottom_layer_thickness: Thicknkess of second layer
103+
:param bottom_layer_solvent: Solvent in second layer
104+
:param bottom_layer_solvation: Fractional solvation of second layer by
105+
:py:attr:`bottom_layer_solvent`
106+
:param bottom_layer_area_per_molecule: Area per molecule of second layer
107+
:param bottom_layer_roughness: Roughness of second layer
108108
:param name: Name for surfactant layer
109109
"""
110-
layer1 = LayerApm.from_pars(
111-
layer1_chemical_structure,
112-
layer1_thickness,
113-
layer1_solvent,
114-
layer1_solvation,
115-
layer1_area_per_molecule,
116-
layer1_roughness,
117-
name=name + ' Layer 1',
110+
top_layer = LayerApm.from_pars(
111+
top_layer_chemical_structure,
112+
top_layer_thickness,
113+
top_layer_solvent,
114+
top_layer_solvation,
115+
top_layer_area_per_molecule,
116+
top_layer_roughness,
117+
name=name + ' Top Layer',
118118
)
119-
layer2 = LayerApm.from_pars(
120-
layer2_chemical_structure,
121-
layer2_thickness,
122-
layer2_solvent,
123-
layer2_solvation,
124-
layer2_area_per_molecule,
125-
layer2_roughness,
126-
name=name + ' Layer 2',
119+
bottom_layer = LayerApm.from_pars(
120+
bottom_layer_chemical_structure,
121+
bottom_layer_thickness,
122+
bottom_layer_solvent,
123+
bottom_layer_solvation,
124+
bottom_layer_area_per_molecule,
125+
bottom_layer_roughness,
126+
name=name + ' Bottom Layer',
127127
)
128-
return cls([layer1, layer2], name, interface)
128+
return cls([top_layer, bottom_layer], name, interface)
129129

130130
@property
131131
def constrain_apm(self) -> bool:
@@ -178,54 +178,56 @@ def constrain_solvent_roughness(self, solvent_roughness: Parameter):
178178
def constain_multiple_contrast(
179179
self,
180180
another_contrast: 'SurfactantLayer',
181-
layer1_thickness: bool = True,
182-
layer2_thickness: bool = True,
183-
layer1_area_per_molecule: bool = True,
184-
layer2_area_per_molecule: bool = True,
185-
layer1_fraction: bool = True,
186-
layer2_fraction: bool = True,
181+
top_layer_thickness: bool = True,
182+
bottom_layer_thickness: bool = True,
183+
top_layer_area_per_molecule: bool = True,
184+
bottom_layer_area_per_molecule: bool = True,
185+
top_layer_fraction: bool = True,
186+
bottom_layer_fraction: bool = True,
187187
):
188188
"""
189189
Constrain structural parameters between surfactant layer objects.
190190
191191
:param another_contrast: The surfactant layer to constrain
192192
"""
193-
if layer1_thickness:
194-
layer1_thickness_constraint = ObjConstraint(self.top_layer.thickness, '', another_contrast.top_layer.thickness)
195-
another_contrast.top_layer.thickness.user_constraints[f'{another_contrast.name}'] = layer1_thickness_constraint
196-
if layer2_thickness:
197-
layer2_thickness_constraint = ObjConstraint(
193+
if top_layer_thickness:
194+
top_layer_thickness_constraint = ObjConstraint(self.top_layer.thickness, '', another_contrast.top_layer.thickness)
195+
another_contrast.top_layer.thickness.user_constraints[f'{another_contrast.name}'] = top_layer_thickness_constraint
196+
if bottom_layer_thickness:
197+
bottom_layer_thickness_constraint = ObjConstraint(
198198
self.bottom_layer.thickness, '', another_contrast.bottom_layer.thickness
199199
)
200-
another_contrast.bottom_layer.thickness.user_constraints[f'{another_contrast.name}'] = layer2_thickness_constraint
201-
if layer1_area_per_molecule:
202-
layer1_area_per_molecule_constraint = ObjConstraint(
200+
another_contrast.bottom_layer.thickness.user_constraints[
201+
f'{another_contrast.name}'
202+
] = bottom_layer_thickness_constraint
203+
if top_layer_area_per_molecule:
204+
top_layer_area_per_molecule_constraint = ObjConstraint(
203205
self.top_layer.area_per_molecule, '', another_contrast.top_layer.area_per_molecule
204206
)
205207
another_contrast.top_layer.area_per_molecule.user_constraints[
206208
f'{another_contrast.name}'
207-
] = layer1_area_per_molecule_constraint
208-
if layer2_area_per_molecule:
209-
layer2_area_per_molecule_constraint = ObjConstraint(
209+
] = top_layer_area_per_molecule_constraint
210+
if bottom_layer_area_per_molecule:
211+
bottom_layer_area_per_molecule_constraint = ObjConstraint(
210212
self.bottom_layer.area_per_molecule, '', another_contrast.bottom_layer.area_per_molecule
211213
)
212214
another_contrast.bottom_layer.area_per_molecule.user_constraints[
213215
f'{another_contrast.name}'
214-
] = layer2_area_per_molecule_constraint
215-
if layer1_fraction:
216-
layer1_fraction_constraint = ObjConstraint(
216+
] = bottom_layer_area_per_molecule_constraint
217+
if top_layer_fraction:
218+
top_layer_fraction_constraint = ObjConstraint(
217219
self.top_layer.material.fraction, '', another_contrast.top_layer.material.fraction
218220
)
219221
another_contrast.top_layer.material.fraction.user_constraints[
220222
f'{another_contrast.name}'
221-
] = layer1_fraction_constraint
222-
if layer2_fraction:
223-
layer2_fraction_constraint = ObjConstraint(
223+
] = top_layer_fraction_constraint
224+
if bottom_layer_fraction:
225+
bottom_layer_fraction_constraint = ObjConstraint(
224226
self.bottom_layer.material.fraction, '', another_contrast.bottom_layer.material.fraction
225227
)
226228
another_contrast.bottom_layer.material.fraction.user_constraints[
227229
f'{another_contrast.name}'
228-
] = layer2_fraction_constraint
230+
] = bottom_layer_fraction_constraint
229231

230232
@property
231233
def _dict_repr(self) -> dict:

EasyReflectometry/sample/sample.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,25 @@
55
import yaml
66
from easyCore.Objects.Groups import BaseCollection
77

8-
from . import Layer
9-
from . import Multilayer
8+
from .assemblies.base_assembly import BaseAssembly
9+
from .assemblies.multilayer import Multilayer
10+
from .elements.layers.layer import Layer
1011

1112

1213
class Sample(BaseCollection):
1314
def __init__(
1415
self,
15-
*args: list[Layer | Multilayer],
16+
*args: list[Layer | BaseAssembly],
1617
name: str = 'EasySample',
1718
interface=None,
1819
**kwargs,
1920
):
2021
new_items = []
21-
for i in args:
22-
if issubclass(type(i), Layer):
23-
new_items.append(Multilayer.from_pars(i, name=i.name))
24-
elif issubclass(type(i), Multilayer):
25-
new_items.append(i)
22+
for layer_like in args:
23+
if issubclass(type(layer_like), Layer):
24+
new_items.append(Multilayer.from_pars(layer_like, name=layer_like.name))
25+
elif issubclass(type(layer_like), BaseAssembly):
26+
new_items.append(layer_like)
2627
else:
2728
raise ValueError('The items must be either a Layer or an Assembly.')
2829
super().__init__(name, *new_items, **kwargs)

tests/sample/assemblies/test_surfactant_layer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ def test_from_pars(self):
3838
40,
3939
3,
4040
name='A Test')
41-
assert p.layers[0].name == 'A Test Layer 1'
41+
assert p.layers[0].name == 'A Test Top Layer'
4242
assert p.layers[0].chemical_structure == 'C8O10H12P'
4343
assert p.layers[0].thickness.raw_value == 12
4444
assert p.layers[0].solvent.as_data_dict() == h2o.as_data_dict()
4545
assert p.layers[0].solvation.raw_value == 0.5
4646
assert p.layers[0].area_per_molecule.raw_value == 50
4747
assert p.layers[0].roughness.raw_value == 2
48-
assert p.layers[1].name == 'A Test Layer 2'
48+
assert p.layers[1].name == 'A Test Bottom Layer'
4949
assert p.layers[1].chemical_structure == 'C10H24'
5050
assert p.layers[1].thickness.raw_value == 10
5151
assert p.layers[1].solvent.as_data_dict() == noth2o.as_data_dict()

0 commit comments

Comments
 (0)