Skip to content

Commit

Permalink
minor adjustments to model and sample
Browse files Browse the repository at this point in the history
  • Loading branch information
andped10 committed Nov 13, 2024
1 parent 3d3b404 commit 063feb6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
9 changes: 3 additions & 6 deletions src/easyreflectometry/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from easyreflectometry.model import ModelCollection
from easyreflectometry.model import PercentageFhwm
from easyreflectometry.sample import Layer
from easyreflectometry.sample import MaterialCollection
from easyreflectometry.sample import Material
from easyreflectometry.sample import MaterialCollection
from easyreflectometry.sample import Multilayer
from easyreflectometry.sample import Sample
from easyreflectometry.sample.collections.base_collection import BaseCollection
Expand Down Expand Up @@ -284,18 +284,15 @@ def default_model(self):

layers = [
Layer(material=self._materials[0], thickness=0.0, roughness=0.0, name='Vacuum Layer'),
Layer(material=self._materials[1], thickness=100.0, roughness=3.0, name='Multi-layer'),
Layer(material=self._materials[1], thickness=100.0, roughness=3.0, name='D2O Layer'),
Layer(material=self._materials[2], thickness=0.0, roughness=1.2, name='Si Layer'),
]
assemblies = [
Multilayer(layers[0], name='Superphase'),
Multilayer(layers[1], name='Multi-layer'),
Multilayer(layers[1], name='D2O'),
Multilayer(layers[2], name='Subphase'),
]
sample = Sample(*assemblies)
sample[0].layers[0].thickness.enabled = False
sample[0].layers[0].roughness.enabled = False
sample[-1].layers[-1].thickness.enabled = False
model = Model(sample=sample)
self.models = ModelCollection([model])

Expand Down
1 change: 1 addition & 0 deletions src/easyreflectometry/sample/collections/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(
if not issubclass(type(assembly), BaseAssembly):
raise ValueError('The elements must be an Assembly.')
super().__init__(name, interface, unique_name=unique_name, *assemblies, **kwargs)
self._disable_changes_to_outermost_layers()

def add_assembly(self, assembly: Optional[BaseAssembly] = None):
"""Add an assembly to the sample.
Expand Down
2 changes: 1 addition & 1 deletion tests/sample/collections/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_add_assembly(self):
# Expect
assert_equal(p[0].name, 'EasyMultilayer')
assert_equal(p[1].name, 'EasyMultilayer')
assert_equal(p[2].name, 'New EasyMultilayer')
assert_equal(p[2].name, 'EasyMultilayer added')
assert_equal(p[3].name, 'EasySurfactantLayer')
p._enable_changes_to_outermost_layers.assert_called()
p._disable_changes_to_outermost_layers.assert_called()
Expand Down
26 changes: 13 additions & 13 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def test_constructor(self):

# Expect
assert project._info == {
'name': 'Example Project',
'short_description': 'reflectometry, 1D',
'name': 'ExampleProject',
'short_description': 'Reflectometry, 1D',
'samples': 'None',
'experiments': 'None',
'modified': datetime.datetime.now().strftime('%d.%m.%Y %H:%M'),
Expand Down Expand Up @@ -78,8 +78,8 @@ def test_reset(self):

# Expect
assert project._info == {
'name': 'Example Project',
'short_description': 'reflectometry, 1D',
'name': 'ExampleProject',
'short_description': 'Reflectometry, 1D',
'samples': 'None',
'experiments': 'None',
'modified': datetime.datetime.now().strftime('%d.%m.%Y %H:%M'),
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_path_json(self, tmp_path):
project.set_path_project_parent(tmp_path)

# Then Expect
assert project.path_json == Path(tmp_path) / 'Example Project' / 'project.json'
assert project.path_json == Path(tmp_path) / 'ExampleProject' / 'project.json'

def test_add_material(self):
# When
Expand Down Expand Up @@ -270,8 +270,8 @@ def test_default_info(self):

# Expect
assert info == {
'name': 'Example Project',
'short_description': 'reflectometry, 1D',
'name': 'ExampleProject',
'short_description': 'Reflectometry, 1D',
'samples': 'None',
'experiments': 'None',
'modified': datetime.datetime.now().strftime('%d.%m.%Y %H:%M'),
Expand All @@ -294,8 +294,8 @@ def test_as_dict(self):
'with_experiments',
]
assert project_dict['info'] == {
'name': 'Example Project',
'short_description': 'reflectometry, 1D',
'name': 'ExampleProject',
'short_description': 'Reflectometry, 1D',
'samples': 'None',
'experiments': 'None',
'modified': datetime.datetime.now().strftime('%d.%m.%Y %H:%M'),
Expand Down Expand Up @@ -491,19 +491,19 @@ def test_create(self, tmp_path):
project = Project()
project.set_path_project_parent(tmp_path)
project._info['modified'] = 'modified'
project._info['name'] = 'Test Project'
project._info['name'] = 'TestProject'

# Then
project.create()

# Expect
assert project.path == tmp_path / 'Test Project'
assert project.path == tmp_path / 'TestProject'
assert project.path.exists()
assert (project.path / 'experiments').exists()
assert project.created is True
assert project._info == {
'name': 'Test Project',
'short_description': 'reflectometry, 1D',
'name': 'TestProject',
'short_description': 'Reflectometry, 1D',
'samples': 'None',
'experiments': 'None',
'modified': datetime.datetime.now().strftime('%d.%m.%Y %H:%M'),
Expand Down

0 comments on commit 063feb6

Please sign in to comment.