Skip to content

Commit

Permalink
handle empty sample
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Sep 25, 2024
1 parent 9a0b0cb commit 800d318
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/easyreflectometry/sample/collections/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,20 @@ def _enable_changes_to_outermost_layers(self):
Superphase can change thickness and roughness.
Subphase can change thickness.
"""
self.superphase.thickness.enabled = True
self.superphase.roughness.enabled = True
self.subphase.thickness.enabled = True
if len(self) != 0:
self.superphase.thickness.enabled = True
self.superphase.roughness.enabled = True
self.subphase.thickness.enabled = True

def _disable_changes_to_outermost_layers(self):
"""No allowed to change the outermost layers of the sample.
Superphase can change thickness and roughness.
Subphase can change thickness.
"""
self.superphase.thickness.enabled = False
self.superphase.roughness.enabled = False
self.subphase.thickness.enabled = False
if len(self) != 0:
self.superphase.thickness.enabled = False
self.superphase.roughness.enabled = False
self.subphase.thickness.enabled = False

# Representation
def as_dict(self, skip: Optional[List[str]] = None) -> dict:
Expand Down
21 changes: 21 additions & 0 deletions tests/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,27 @@ def test_remove_assembly_with_interface_refl1d(self):
# assert_equal(len(mod.interface()._wrapper.storage['item']), 1)
# assert_equal(len(mod.interface()._wrapper.storage['layer']), 2)

def test_remove_all_assemblies(self):
# when
# m1 = Material(6.908, -0.278, 'Boron')
# m2 = Material(0.487, 0.000, 'Potassium')
# l1 = Layer(m1, 5.0, 2.0, 'thinBoron')
# l2 = Layer(m2, 50.0, 1.0, 'thickPotassium')
# ls1 = LayerCollection(l1, l2, name='twoLayer1')
# ls2 = LayerCollection(l2, l1, name='twoLayer2')
# o1 = RepeatingMultilayer(ls1, 2.0, 'twoLayerItem1')
# o2 = RepeatingMultilayer(ls2, 1.0, 'oneLayerItem2')
# d = Sample(o1, o2, name='myModel')
# resolution_function = PercentageFhwm(2.0)
mod = Model()

# Then
mod.remove_assembly(0)
mod.remove_assembly(0)

# Expect
assert_equal(len(mod.sample), 0)

def test_resolution_function(self):
mock_resolution_function = MagicMock()
interface = CalculatorFactory()
Expand Down

0 comments on commit 800d318

Please sign in to comment.