diff --git a/docs/src/tutorials/fitting/repeating.ipynb b/docs/src/tutorials/fitting/repeating.ipynb index 074fed86..f31f5d13 100644 --- a/docs/src/tutorials/fitting/repeating.ipynb +++ b/docs/src/tutorials/fitting/repeating.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "29d5d62d-af4a-416d-bbe2-1338d32b30f5", "metadata": {}, "outputs": [], @@ -45,8 +45,9 @@ "from easyreflectometry.sample import Sample\n", "from easyreflectometry.sample import Material\n", "from easyreflectometry.sample import RepeatingMultilayer\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.sample import Multilayer\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.calculators import CalculatorFactory\n", "from easyreflectometry.fitting import Fitter\n", "from easyreflectometry.plot import plot\n", @@ -87,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "7121c7e9", "metadata": {}, "outputs": [], @@ -141,7 +142,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "0f95d620-35b7-4b47-a3b4-9e33d5525b50", "metadata": {}, "outputs": [], @@ -154,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "9a0b37ed-8714-4614-b49f-1e86ac232ac1", "metadata": {}, "outputs": [], @@ -195,13 +196,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "fed8d60f-a4a7-40f1-8063-eb975bfa6115", "metadata": {}, "outputs": [], "source": [ "resolution_function = PercentageFhwm(0)\n", - "sample = Sample(superphase, rep_multilayer, subphase, name='Multilayer Structure')\n", + "sample = Sample(Multilayer(superphase), rep_multilayer, Multilayer(subphase), name='Multilayer Structure')\n", "model = Model(\n", " sample=sample,\n", " scale=1,\n", @@ -221,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "db1e3df9-d0fa-421a-a959-a8b2fe483310", "metadata": {}, "outputs": [], @@ -340,7 +341,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/docs/src/tutorials/fitting/simple_fitting.ipynb b/docs/src/tutorials/fitting/simple_fitting.ipynb index dab3008d..0b34c68d 100644 --- a/docs/src/tutorials/fitting/simple_fitting.ipynb +++ b/docs/src/tutorials/fitting/simple_fitting.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "f026d35c-6a4a-4e9d-889c-d23ea6ee7adc", "metadata": {}, "outputs": [], @@ -39,8 +39,8 @@ "from easyreflectometry.sample import Sample\n", "from easyreflectometry.sample import Material\n", "from easyreflectometry.sample import Multilayer\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.calculators import CalculatorFactory\n", "from easyreflectometry.fitting import Fitter\n", "from easyreflectometry.plot import plot" @@ -79,7 +79,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "7d851064-605c-4f80-a510-197bcdbff2ea", "metadata": {}, "outputs": [], @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "1fd5d9ba-a912-40f1-96a9-8d8d85c35c18", "metadata": {}, "outputs": [], @@ -196,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "bfd2d8a1-35fe-4a6c-aeee-93f1b4066b61", "metadata": {}, "outputs": [], @@ -235,7 +235,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "a6508395-d292-4338-9fbe-77e19b011ae6", "metadata": {}, "outputs": [], @@ -253,12 +253,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "2a0aee2a-e77e-4558-a8b0-ef2d1cffd4d0", "metadata": {}, "outputs": [], "source": [ - "sample = Sample(superphase, film_layer, subphase, name='Film Structure')" + "sample = Sample(superphase, Multilayer(film_layer), Multilayer(subphase), name='Film Structure')" ] }, { @@ -301,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "8646c977-28b4-4cd4-adbd-fc263359ca1c", "metadata": {}, "outputs": [], @@ -347,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "id": "a4d3eae5-ec8d-4a7f-91ef-fcce3cc5a5ed", "metadata": {}, "outputs": [], @@ -373,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "7e2d7b81-7b49-4831-9508-75e0e234f15f", "metadata": {}, "outputs": [], @@ -400,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "cdbe172a-1283-4cdc-8fb2-d3383b8d21b3", "metadata": {}, "outputs": [], @@ -439,7 +439,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "3648873e-16bb-449d-b90d-8b1bd4f05eb6", "metadata": {}, "outputs": [], @@ -458,7 +458,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "9762fc0b-c4c2-4f92-8560-079ea248dfca", "metadata": {}, "outputs": [], @@ -537,7 +537,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/docs/src/tutorials/magnetism.ipynb b/docs/src/tutorials/magnetism.ipynb index 28589ddc..b1bd0e60 100644 --- a/docs/src/tutorials/magnetism.ipynb +++ b/docs/src/tutorials/magnetism.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "29d5d62d-af4a-416d-bbe2-1338d32b30f5", "metadata": {}, "outputs": [], @@ -38,8 +38,8 @@ "import easyreflectometry\n", "\n", "from easyreflectometry.calculators import CalculatorFactory\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.sample import Layer\n", "from easyreflectometry.sample import Material\n", "from easyreflectometry.sample import Multilayer\n", @@ -91,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "0f95d620-35b7-4b47-a3b4-9e33d5525b50", "metadata": {}, "outputs": [], @@ -119,13 +119,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "2af8c30b", "metadata": {}, "outputs": [], "source": [ "two_layers = Multilayer([sld_4_layer, sld_8_layer], name='SLD 4/8 Layer')\n", - "sample = Sample(superphase, two_layers, subphase, name='Two Layer Sample')\n", + "sample = Sample(Multilayer(superphase), two_layers, Multilayer(subphase), name='Two Layer Sample')\n", "model = Model(\n", " sample=sample,\n", " scale=1,\n", @@ -144,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "b0259cd0", "metadata": {}, "outputs": [], @@ -175,7 +175,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "f1500603-d85d-4e16-b697-e1bf16502991", "metadata": {}, "outputs": [], @@ -194,7 +194,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "18010202", "metadata": {}, "outputs": [], @@ -569,7 +569,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/docs/src/tutorials/sample/material_solvated.ipynb b/docs/src/tutorials/sample/material_solvated.ipynb index 39197d94..03d71c36 100644 --- a/docs/src/tutorials/sample/material_solvated.ipynb +++ b/docs/src/tutorials/sample/material_solvated.ipynb @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "88c86e82-88dd-4c2d-ad99-826f409ec7b7", "metadata": {}, "outputs": [], @@ -45,8 +45,8 @@ "from easyreflectometry.sample import Material\n", "from easyreflectometry.sample import MaterialSolvated\n", "from easyreflectometry.sample import Multilayer\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.calculators import CalculatorFactory\n", "from easyreflectometry.fitting import Fitter\n", "from easyreflectometry.plot import plot" @@ -85,7 +85,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "a95a39dd-d0eb-4029-9dc8-41e6e7918f66", "metadata": {}, "outputs": [], @@ -110,7 +110,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "60e5a3c5-58a8-429a-a446-a115f489af0f", "metadata": {}, "outputs": [], @@ -132,12 +132,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "f2b910db-530f-49c5-907a-67712ba939d2", "metadata": {}, "outputs": [], "source": [ - "solvated_film = MaterialSolvated(\n", + "solvated_film_material = MaterialSolvated(\n", " material=film,\n", " solvent=d2o,\n", " solvent_fraction=0.25,\n", @@ -165,7 +165,7 @@ "metadata": {}, "outputs": [], "source": [ - "solvated_film" + "solvated_film_material" ] }, { @@ -178,7 +178,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "f1ea2e41-f50e-4fbb-989f-aecc0e3e9860", "metadata": {}, "outputs": [], @@ -187,12 +187,12 @@ "sio2_layer = Layer(material=sio2, thickness=30, roughness=3, name='SiO2 layer')\n", "superphase = Multilayer([si_layer, sio2_layer], name='Si/SiO2 Superphase')\n", "\n", - "solvated_film_layer = Layer(material=solvated_film, thickness=250, roughness=3, name='Film Layer')\n", + "solvated_film = Layer(material=solvated_film_material, thickness=250, roughness=3, name='Film Layer')\n", "\n", "subphase = Layer(material=d2o, thickness=0, roughness=3, name='D2O Subphase')\n", "\n", "resolution_function = PercentageFhwm(0.02)\n", - "sample = Sample(superphase, solvated_film_layer, subphase, name='Film Structure')\n", + "sample = Sample(superphase, Multilayer(solvated_film), Multilayer(subphase), name='Film Structure')\n", "model = Model(\n", " sample=sample,\n", " scale=1,\n", @@ -216,7 +216,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "f99fba34-268d-40ee-a74d-982bb2805b11", "metadata": {}, "outputs": [], @@ -231,12 +231,12 @@ "metadata": {}, "outputs": [], "source": [ - "print(solvated_film_layer.material.sld)" + "print(solvated_film.material.sld)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "0e872a4d-f468-4e5a-8938-9cb50d16c460", "metadata": {}, "outputs": [], @@ -251,7 +251,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(solvated_film_layer.material.sld)" + "print(solvated_film.material.sld)" ] }, { @@ -264,17 +264,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "id": "79c3dc7a-b4cd-4eea-b098-08c962d747e6", "metadata": {}, "outputs": [], "source": [ "# Thicknesses\n", "sio2_layer.thickness.bounds = (15, 50)\n", - "solvated_film_layer.thickness.bounds = (200, 300)\n", + "solvated_film.thickness.bounds = (200, 300)\n", "# Roughnesses\n", "sio2_layer.roughness.bounds = (1, 15)\n", - "solvated_film_layer.roughness.bounds = (1, 15)\n", + "solvated_film.roughness.bounds = (1, 15)\n", "subphase.roughness.bounds = (1, 15)\n", "# Scattering length density\n", "film.sld.bounds = (0.1, 3)\n", @@ -296,7 +296,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "3e24b615-cb32-41f8-95e5-5998072c7868", "metadata": {}, "outputs": [], @@ -340,7 +340,7 @@ "metadata": {}, "outputs": [], "source": [ - "solvated_film" + "solvated_film_material" ] }, { @@ -368,7 +368,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/docs/src/tutorials/sample/monolayer.ipynb b/docs/src/tutorials/sample/monolayer.ipynb index 514673f3..533b3413 100644 --- a/docs/src/tutorials/sample/monolayer.ipynb +++ b/docs/src/tutorials/sample/monolayer.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "id": "619bb767-475a-408b-b576-552f0bc4f2a7", "metadata": {}, "outputs": [], @@ -41,9 +41,10 @@ "from easyreflectometry.sample import SurfactantLayer\n", "from easyreflectometry.sample import LayerAreaPerMolecule\n", "from easyreflectometry.sample import Layer\n", + "from easyreflectometry.sample import Multilayer\n", "from easyreflectometry.sample import Sample\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.fitting import Fitter\n", "from easyreflectometry.plot import plot\n", "from easyscience.fitting import AvailableMinimizers\n" @@ -131,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "80c8d71f-d309-4104-bae6-3941daa525d3", "metadata": {}, "outputs": [], @@ -163,7 +164,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "3ad9adef-8845-486d-8075-9ad6bb81ea6f", "metadata": {}, "outputs": [], @@ -182,7 +183,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "a39a0eca-97d6-44d7-8796-a5e98d024788", "metadata": {}, "outputs": [], @@ -201,7 +202,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "204144c3-a3e7-4ab1-9a6c-6aca8241f69e", "metadata": {}, "outputs": [], @@ -220,7 +221,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "e39cf91b-e049-4619-a5cd-4bdf8492252d", "metadata": {}, "outputs": [], @@ -281,7 +282,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "c17ecc32-c578-4a22-a12c-da13af1e0347", "metadata": {}, "outputs": [], @@ -301,7 +302,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "f17762ca-33c5-48bb-88a2-bc2568bb18f7", "metadata": {}, "outputs": [], @@ -319,13 +320,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "216bfe40-a97c-4437-a2f9-8bc7966ae58d", "metadata": {}, "outputs": [], "source": [ "resolution_function = PercentageFhwm(5)\n", - "sample = Sample(air_layer, dspc, d2o_layer)\n", + "sample = Sample(Multilayer(air_layer), dspc, Multilayer(d2o_layer))\n", "model = Model(\n", " sample=sample,\n", " scale=1,\n", @@ -348,7 +349,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "d30eaa0f-be7f-4cbe-a7d6-11f43512f014", "metadata": {}, "outputs": [], @@ -370,7 +371,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "id": "bc61b31f-11bf-43e1-9fd9-d697ded79196", "metadata": {}, "outputs": [], @@ -487,7 +488,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/docs/src/tutorials/sample/multi_contrast.ipynb b/docs/src/tutorials/sample/multi_contrast.ipynb index fab42c39..d38770eb 100644 --- a/docs/src/tutorials/sample/multi_contrast.ipynb +++ b/docs/src/tutorials/sample/multi_contrast.ipynb @@ -39,10 +39,11 @@ "from easyreflectometry.sample import Material\n", "from easyreflectometry.sample import SurfactantLayer\n", "from easyreflectometry.sample import Layer\n", + "from easyreflectometry.sample import Multilayer\n", "from easyreflectometry.sample import LayerAreaPerMolecule\n", "from easyreflectometry.sample import Sample\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.calculators import CalculatorFactory\n", "from easyreflectometry.fitting import Fitter\n", "from easyscience.fitting import AvailableMinimizers\n", @@ -65,7 +66,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "694b4e5e-2d1a-402e-aa3f-a26cc82f7774", "metadata": {}, "outputs": [], @@ -124,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "7834b80e-1dc9-47b8-923a-dec58e3494be", "metadata": {}, "outputs": [], @@ -143,7 +144,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "58855c68-c95b-40de-9fee-a662771c247b", "metadata": {}, "outputs": [], @@ -162,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "id": "08112c21-2027-47ba-845b-a3135439d862", "metadata": {}, "outputs": [], @@ -180,7 +181,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "e7caedc2-8305-4f3b-bad2-c042bacb363b", "metadata": {}, "outputs": [], @@ -200,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "id": "74e19578-03d4-4295-b6e2-a65fb2508c78", "metadata": {}, "outputs": [], @@ -223,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "c4aa6c00", "metadata": {}, "outputs": [], @@ -263,7 +264,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "16a970d8", "metadata": {}, "outputs": [], @@ -303,7 +304,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "id": "021272e0-7abb-4703-a4cd-92daed10ae50", "metadata": {}, "outputs": [], @@ -346,7 +347,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "id": "24808923-ba02-4a7d-9be3-8d717b08aa8e", "metadata": {}, "outputs": [], @@ -381,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "id": "e31a4807-c6f4-4bfd-986e-749955aa7e49", "metadata": {}, "outputs": [], @@ -411,16 +412,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "id": "6e92498a-581b-445d-94cd-dda6474f1984", "metadata": {}, "outputs": [], "source": [ "resolution_function = PercentageFhwm(5)\n", "\n", - "d13d2o_sample = Sample(air_layer, d13d2o, d2o_layer)\n", - "d70d2o_sample = Sample(air_layer, d70d2o, d2o_layer)\n", - "d83acmw_sample = Sample(air_layer, d83acmw, acmw_layer)\n", + "d13d2o_sample = Sample(Multilayer(air_layer), d13d2o, Multilayer(d2o_layer))\n", + "d70d2o_sample = Sample(Multilayer(air_layer), d70d2o, Multilayer(d2o_layer))\n", + "d83acmw_sample = Sample(Multilayer(air_layer), d83acmw, Multilayer(acmw_layer))\n", "d13d2o_model = Model(\n", " sample=d13d2o_sample,\n", " scale=0.1,\n", @@ -455,7 +456,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "id": "cf35ee97-2d64-4a0f-9212-7cca8bb2dcfc", "metadata": {}, "outputs": [], @@ -486,7 +487,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "id": "dc8e7f8f-6b4b-45ce-a38c-274dea683df4", "metadata": {}, "outputs": [], @@ -506,7 +507,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "id": "ce890544-f3cf-4a74-b927-d19dc292e12c", "metadata": {}, "outputs": [], @@ -517,7 +518,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "0cb9d7b4-aa04-4c73-a700-4ff5af7e6f47", "metadata": {}, "outputs": [], @@ -570,7 +571,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/docs/src/tutorials/sample/resolution_functions.ipynb b/docs/src/tutorials/sample/resolution_functions.ipynb index 63f3d7c7..26037dfd 100644 --- a/docs/src/tutorials/sample/resolution_functions.ipynb +++ b/docs/src/tutorials/sample/resolution_functions.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "29d5d62d-af4a-416d-bbe2-1338d32b30f5", "metadata": {}, "outputs": [], @@ -43,9 +43,9 @@ "\n", "from easyreflectometry.calculators import CalculatorFactory\n", "from easyreflectometry.data import load\n", - "from easyreflectometry.experiment import Model\n", - "from easyreflectometry.experiment import LinearSpline\n", - "from easyreflectometry.experiment import PercentageFhwm\n", + "from easyreflectometry.model import Model\n", + "from easyreflectometry.model import LinearSpline\n", + "from easyreflectometry.model import PercentageFhwm\n", "from easyreflectometry.sample import Layer\n", "from easyreflectometry.sample import Material\n", "from easyreflectometry.sample import Multilayer\n", @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "609174e5-1371-412d-a29f-cb05bfe36df0", "metadata": {}, "outputs": [], @@ -157,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "0f95d620-35b7-4b47-a3b4-9e33d5525b50", "metadata": {}, "outputs": [], @@ -170,7 +170,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "9a0b37ed-8714-4614-b49f-1e86ac232ac1", "metadata": {}, "outputs": [], @@ -210,12 +210,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "id": "2af8c30b", "metadata": {}, "outputs": [], "source": [ - "sample = Sample(superphase, two_layers, subphase, name='Two Layer Sample')\n", + "sample = Sample(Multilayer(superphase), two_layers, Multilayer(subphase), name='Two Layer Sample')\n", "model = Model(\n", " sample=sample,\n", " scale=1,\n", @@ -258,7 +258,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "880d10d7-b655-4ef1-b376-21b2e4394160", "metadata": {}, "outputs": [], @@ -394,7 +394,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.9" + "version": "3.12.5" } }, "nbformat": 4, diff --git a/src/easyreflectometry/calculators/bornagain/calculator.py b/src/easyreflectometry/calculators/bornagain/calculator.py index 3a17caef..205cf935 100644 --- a/src/easyreflectometry/calculators/bornagain/calculator.py +++ b/src/easyreflectometry/calculators/bornagain/calculator.py @@ -3,7 +3,7 @@ import numpy as np from easyscience.Objects.Inferface import ItemContainer -from easyreflectometry.experiment import Model +from easyreflectometry.model import Model from easyreflectometry.sample import Layer from easyreflectometry.sample import Material from easyreflectometry.sample import MaterialMixture diff --git a/src/easyreflectometry/calculators/calculator_base.py b/src/easyreflectometry/calculators/calculator_base.py index 122e3cbc..8811b7c3 100644 --- a/src/easyreflectometry/calculators/calculator_base.py +++ b/src/easyreflectometry/calculators/calculator_base.py @@ -7,7 +7,7 @@ from easyscience.Objects.core import ComponentSerializer from easyscience.Objects.Inferface import ItemContainer -from easyreflectometry.experiment import Model +from easyreflectometry.model import Model from easyreflectometry.sample import BaseAssembly from easyreflectometry.sample import Layer from easyreflectometry.sample import Material diff --git a/src/easyreflectometry/calculators/refl1d/wrapper.py b/src/easyreflectometry/calculators/refl1d/wrapper.py index 020801b7..9817dfb7 100644 --- a/src/easyreflectometry/calculators/refl1d/wrapper.py +++ b/src/easyreflectometry/calculators/refl1d/wrapper.py @@ -6,7 +6,7 @@ from refl1d import model from refl1d import names -from easyreflectometry.experiment.resolution_functions import PercentageFhwm +from easyreflectometry.model import PercentageFhwm from ..wrapper_base import WrapperBase diff --git a/src/easyreflectometry/calculators/refnx/wrapper.py b/src/easyreflectometry/calculators/refnx/wrapper.py index 3ab62a9b..0cfded10 100644 --- a/src/easyreflectometry/calculators/refnx/wrapper.py +++ b/src/easyreflectometry/calculators/refnx/wrapper.py @@ -5,7 +5,7 @@ import numpy as np from refnx import reflect -from easyreflectometry.experiment.resolution_functions import PercentageFhwm +from easyreflectometry.model import PercentageFhwm from ..wrapper_base import WrapperBase diff --git a/src/easyreflectometry/calculators/wrapper_base.py b/src/easyreflectometry/calculators/wrapper_base.py index 8f9440ee..56f90a16 100644 --- a/src/easyreflectometry/calculators/wrapper_base.py +++ b/src/easyreflectometry/calculators/wrapper_base.py @@ -2,8 +2,8 @@ import numpy as np -from easyreflectometry.experiment import PercentageFhwm -from easyreflectometry.experiment import ResolutionFunction +from easyreflectometry.model import PercentageFhwm +from easyreflectometry.model import ResolutionFunction class WrapperBase: diff --git a/src/easyreflectometry/fitting.py b/src/easyreflectometry/fitting.py index 92f7794a..89e4eb64 100644 --- a/src/easyreflectometry/fitting.py +++ b/src/easyreflectometry/fitting.py @@ -5,7 +5,7 @@ from easyscience.fitting import AvailableMinimizers from easyscience.fitting.multi_fitter import MultiFitter as easyFitter -from easyreflectometry.experiment import Model +from easyreflectometry.model import Model class Fitter: diff --git a/src/easyreflectometry/experiment/__init__.py b/src/easyreflectometry/model/__init__.py similarity index 100% rename from src/easyreflectometry/experiment/__init__.py rename to src/easyreflectometry/model/__init__.py diff --git a/src/easyreflectometry/experiment/model.py b/src/easyreflectometry/model/model.py similarity index 82% rename from src/easyreflectometry/experiment/model.py rename to src/easyreflectometry/model/model.py index e340fb82..98214ed6 100644 --- a/src/easyreflectometry/experiment/model.py +++ b/src/easyreflectometry/model/model.py @@ -14,8 +14,6 @@ from easyreflectometry.parameter_utils import get_as_parameter from easyreflectometry.parameter_utils import yaml_dump from easyreflectometry.sample import BaseAssembly -from easyreflectometry.sample import Layer -from easyreflectometry.sample import LayerCollection from easyreflectometry.sample import Sample from .resolution_functions import PercentageFhwm @@ -93,51 +91,37 @@ def __init__( # Must be set after resolution function self.interface = interface - def add_item(self, *assemblies: list[BaseAssembly]) -> None: + def add_assemblies(self, *assemblies: list[BaseAssembly]) -> None: """Add a layer or item to the model sample. :param assemblies: Assemblies to add to model sample. """ - for arg in assemblies: - if issubclass(arg.__class__, BaseAssembly): - self.sample.append(arg) + for assembly in assemblies: + if issubclass(assembly.__class__, BaseAssembly): + self.sample.add_assembly(assembly) if self.interface is not None: - self.interface().add_item_to_model(arg.unique_name, self.unique_name) + self.interface().add_item_to_model(assembly.unique_name, self.unique_name) else: - raise ValueError(f'Object {arg} is not a valid type, must be a child of BaseAssembly.') + raise ValueError(f'Object {assembly} is not a valid type, must be a child of BaseAssembly.') - def duplicate_item(self, idx: int) -> None: + def duplicate_assembly(self, index: int) -> None: """Duplicate a given item or layer in a sample. :param idx: Index of the item or layer to duplicate """ - to_duplicate = self.sample[idx] - duplicate_layers = [] - for i in to_duplicate.layers: - duplicate_layers.append( - Layer( - material=i.material, - thickness=i.thickness.value, - roughness=i.roughness.value, - name=i.name + ' duplicate', - interface=i.interface, - ) - ) - duplicate = to_duplicate.__class__( - LayerCollection(*duplicate_layers, name=to_duplicate.layers.name + ' duplicate'), - name=to_duplicate.name + ' duplicate', - ) - self.add_item(duplicate) + self.sample.duplicate_assembly(index) + if self.interface is not None: + self.interface().add_item_to_model(self.sample[-1].unique_name, self.unique_name) - def remove_item(self, idx: int) -> None: - """Remove an item from the model. + def remove_assembly(self, index: int) -> None: + """Remove an assembly from the model. :param idx: Index of the item to remove. """ - item_unique_name = self.sample[idx].unique_name - del self.sample[idx] + assembly_unique_name = self.sample[index].unique_name + self.sample.remove_assembly(index) if self.interface is not None: - self.interface().remove_item_from_model(item_unique_name, self.unique_name) + self.interface().remove_item_from_model(assembly_unique_name, self.unique_name) @property def resolution_function(self) -> ResolutionFunction: diff --git a/src/easyreflectometry/experiment/model_collection.py b/src/easyreflectometry/model/model_collection.py similarity index 92% rename from src/easyreflectometry/experiment/model_collection.py rename to src/easyreflectometry/model/model_collection.py index cdf610a4..5788afe0 100644 --- a/src/easyreflectometry/experiment/model_collection.py +++ b/src/easyreflectometry/model/model_collection.py @@ -5,8 +5,8 @@ from typing import List from typing import Tuple -from easyreflectometry.sample.base_element_collection import SIZE_DEFAULT_COLLECTION -from easyreflectometry.sample.base_element_collection import BaseElementCollection +from easyreflectometry.sample.collections.base_element_collection import SIZE_DEFAULT_COLLECTION +from easyreflectometry.sample.collections.base_element_collection import BaseElementCollection from .model import Model diff --git a/src/easyreflectometry/experiment/resolution_functions.py b/src/easyreflectometry/model/resolution_functions.py similarity index 100% rename from src/easyreflectometry/experiment/resolution_functions.py rename to src/easyreflectometry/model/resolution_functions.py diff --git a/src/easyreflectometry/sample/__init__.py b/src/easyreflectometry/sample/__init__.py index 903fffad..7bb988dd 100644 --- a/src/easyreflectometry/sample/__init__.py +++ b/src/easyreflectometry/sample/__init__.py @@ -3,15 +3,15 @@ from .assemblies.multilayer import Multilayer from .assemblies.repeating_multilayer import RepeatingMultilayer from .assemblies.surfactant_layer import SurfactantLayer +from .collections.layer_collection import LayerCollection +from .collections.material_collection import MaterialCollection +from .collections.sample import Sample from .elements.layers.layer import Layer from .elements.layers.layer_area_per_molecule import LayerAreaPerMolecule -from .elements.layers.layer_collection import LayerCollection from .elements.materials.material import Material -from .elements.materials.material_collection import MaterialCollection from .elements.materials.material_density import MaterialDensity from .elements.materials.material_mixture import MaterialMixture from .elements.materials.material_solvated import MaterialSolvated -from .sample import Sample __all__ = ( BaseAssembly, diff --git a/src/easyreflectometry/sample/assemblies/base_assembly.py b/src/easyreflectometry/sample/assemblies/base_assembly.py index 1c0f2807..7d0af4b8 100644 --- a/src/easyreflectometry/sample/assemblies/base_assembly.py +++ b/src/easyreflectometry/sample/assemblies/base_assembly.py @@ -4,8 +4,8 @@ from easyscience.Constraints import ObjConstraint from ..base_core import BaseCore +from ..collections.layer_collection import LayerCollection from ..elements.layers.layer import Layer -from ..elements.layers.layer_collection import LayerCollection class BaseAssembly(BaseCore): diff --git a/src/easyreflectometry/sample/assemblies/gradient_layer.py b/src/easyreflectometry/sample/assemblies/gradient_layer.py index 4f5a29bb..8be219a9 100644 --- a/src/easyreflectometry/sample/assemblies/gradient_layer.py +++ b/src/easyreflectometry/sample/assemblies/gradient_layer.py @@ -3,8 +3,8 @@ from easyscience import global_object from numpy import arange +from ..collections.layer_collection import LayerCollection from ..elements.layers.layer import Layer -from ..elements.layers.layer_collection import LayerCollection from ..elements.materials.material import Material from .base_assembly import BaseAssembly diff --git a/src/easyreflectometry/sample/assemblies/multilayer.py b/src/easyreflectometry/sample/assemblies/multilayer.py index d57d78b3..320ba1df 100644 --- a/src/easyreflectometry/sample/assemblies/multilayer.py +++ b/src/easyreflectometry/sample/assemblies/multilayer.py @@ -3,10 +3,10 @@ from typing import Optional from typing import Union -from easyreflectometry.sample.base_element_collection import SIZE_DEFAULT_COLLECTION +from easyreflectometry.sample.collections.base_element_collection import SIZE_DEFAULT_COLLECTION +from ..collections.layer_collection import LayerCollection from ..elements.layers.layer import Layer -from ..elements.layers.layer_collection import LayerCollection from .base_assembly import BaseAssembly @@ -103,7 +103,4 @@ def from_dict(cls, data: dict) -> Multilayer: :return: Multilayer """ multilayer = super().from_dict(data) - # Remove the default materials - for i in range(SIZE_DEFAULT_COLLECTION): - del multilayer.layers[0] return multilayer diff --git a/src/easyreflectometry/sample/assemblies/repeating_multilayer.py b/src/easyreflectometry/sample/assemblies/repeating_multilayer.py index ba26fef6..5aa9d697 100644 --- a/src/easyreflectometry/sample/assemblies/repeating_multilayer.py +++ b/src/easyreflectometry/sample/assemblies/repeating_multilayer.py @@ -5,10 +5,10 @@ from easyscience.Objects.new_variable import Parameter from easyreflectometry.parameter_utils import get_as_parameter -from easyreflectometry.sample.base_element_collection import SIZE_DEFAULT_COLLECTION +from easyreflectometry.sample.collections.base_element_collection import SIZE_DEFAULT_COLLECTION +from ..collections.layer_collection import LayerCollection from ..elements.layers.layer import Layer -from ..elements.layers.layer_collection import LayerCollection from .multilayer import Multilayer DEFAULTS = { diff --git a/src/easyreflectometry/sample/assemblies/surfactant_layer.py b/src/easyreflectometry/sample/assemblies/surfactant_layer.py index 7dfcda5b..e0db9c59 100644 --- a/src/easyreflectometry/sample/assemblies/surfactant_layer.py +++ b/src/easyreflectometry/sample/assemblies/surfactant_layer.py @@ -5,8 +5,8 @@ from easyscience.Constraints import ObjConstraint from easyscience.Objects.new_variable import Parameter +from ..collections.layer_collection import LayerCollection from ..elements.layers.layer_area_per_molecule import LayerAreaPerMolecule -from ..elements.layers.layer_collection import LayerCollection from ..elements.materials.material import Material from .base_assembly import BaseAssembly diff --git a/src/easyreflectometry/sample/base_element_collection.py b/src/easyreflectometry/sample/collections/base_element_collection.py similarity index 100% rename from src/easyreflectometry/sample/base_element_collection.py rename to src/easyreflectometry/sample/collections/base_element_collection.py diff --git a/src/easyreflectometry/sample/elements/layers/layer_collection.py b/src/easyreflectometry/sample/collections/layer_collection.py similarity index 81% rename from src/easyreflectometry/sample/elements/layers/layer_collection.py rename to src/easyreflectometry/sample/collections/layer_collection.py index 69c481fb..a72b7871 100644 --- a/src/easyreflectometry/sample/elements/layers/layer_collection.py +++ b/src/easyreflectometry/sample/collections/layer_collection.py @@ -2,8 +2,8 @@ from typing import Optional -from ...base_element_collection import BaseElementCollection -from .layer import Layer +from ..elements.layers.layer import Layer +from .base_element_collection import BaseElementCollection class LayerCollection(BaseElementCollection): diff --git a/src/easyreflectometry/sample/elements/materials/material_collection.py b/src/easyreflectometry/sample/collections/material_collection.py similarity index 81% rename from src/easyreflectometry/sample/elements/materials/material_collection.py rename to src/easyreflectometry/sample/collections/material_collection.py index 7901327b..07833090 100644 --- a/src/easyreflectometry/sample/elements/materials/material_collection.py +++ b/src/easyreflectometry/sample/collections/material_collection.py @@ -2,10 +2,10 @@ from typing import Tuple from typing import Union -from ...base_element_collection import SIZE_DEFAULT_COLLECTION -from ...base_element_collection import BaseElementCollection -from .material import Material -from .material_mixture import MaterialMixture +from ..elements.materials.material import Material +from ..elements.materials.material_mixture import MaterialMixture +from .base_element_collection import SIZE_DEFAULT_COLLECTION +from .base_element_collection import BaseElementCollection class MaterialCollection(BaseElementCollection): diff --git a/src/easyreflectometry/sample/collections/sample.py b/src/easyreflectometry/sample/collections/sample.py new file mode 100644 index 00000000..d5505ce9 --- /dev/null +++ b/src/easyreflectometry/sample/collections/sample.py @@ -0,0 +1,166 @@ +from __future__ import annotations + +__author__ = 'github.com/arm61' + +from typing import List +from typing import Optional + +from easyscience.Objects.Groups import BaseCollection + +from easyreflectometry.parameter_utils import yaml_dump + +from ..assemblies.base_assembly import BaseAssembly +from ..assemblies.multilayer import Multilayer +from ..assemblies.repeating_multilayer import RepeatingMultilayer +from ..assemblies.surfactant_layer import SurfactantLayer +from ..elements.layers.layer import Layer + +NR_DEFAULT_ASSEMBLIES = 2 + + +class Sample(BaseCollection): + """A sample is a collection of assemblies that represent the structure for which experimental measurements exist.""" + + def __init__( + self, + *list_assemblies: Optional[List[BaseAssembly]], + name: str = 'EasySample', + interface=None, + populate_if_none: bool = True, + **kwargs, + ): + """Constructor. + + :param args: The assemblies in the sample. + :param name: Name of the sample, defaults to 'EasySample'. + :param interface: Calculator interface, defaults to `None`. + """ + if not list_assemblies: + if populate_if_none: + list_assemblies = [Multilayer(interface=interface) for _ in range(NR_DEFAULT_ASSEMBLIES)] + else: + list_assemblies = [] + # Needed to ensure an empty list is created when saving and instatiating the object as_dict -> from_dict + # Else collisions might occur in global_object.map + self.populate_if_none = False + + for assembly in list_assemblies: + if not issubclass(type(assembly), BaseAssembly): + raise ValueError('The elements must be an Assembly.') + super().__init__(name, *list_assemblies, **kwargs) + self.interface = interface + + def add_assembly(self, assembly: Optional[BaseAssembly] = None): + """Add an assembly to the sample. + + :param assembly: Assembly to add. + """ + if assembly is None: + assembly = Multilayer(name='New EasyMultilayer', interface=self.interface) + self._enable_changes_to_outermost_layers() + self.append(assembly) + self._disable_changes_to_outermost_layers() + + def duplicate_assembly(self, index: int): + """Add an assembly to the sample. + + :param assembly: Assembly to add. + """ + self._enable_changes_to_outermost_layers() + to_be_duplicated = self[index] + if isinstance(to_be_duplicated, Multilayer): + duplicate = Multilayer.from_dict(to_be_duplicated.as_dict(skip=['unique_name'])) + elif isinstance(to_be_duplicated, RepeatingMultilayer): + duplicate = RepeatingMultilayer.from_dict(to_be_duplicated.as_dict(skip=['unique_name'])) + elif isinstance(to_be_duplicated, SurfactantLayer): + duplicate = SurfactantLayer.from_dict(to_be_duplicated.as_dict(skip=['unique_name'])) + duplicate.name = duplicate.name + ' duplicate' + self.append(duplicate) + self._disable_changes_to_outermost_layers() + + def move_assembly_up(self, index: int): + """Move the assembly at the given index up in the sample. + + :param index: Index of the assembly to move up. + """ + if index == 0: + return + self._enable_changes_to_outermost_layers() + self.insert(index - 1, self.pop(index)) + self._disable_changes_to_outermost_layers() + + def move_assembly_down(self, index: int): + """Move the assembly at the given index down in the sample. + + :param index: Index of the assembly to move down. + """ + if index == len(self) - 1: + return + self._enable_changes_to_outermost_layers() + self.insert(index + 1, self.pop(index)) + self._disable_changes_to_outermost_layers() + + def remove_assembly(self, index: int): + """Remove the assembly at the given index from the sample. + + :param index: Index of the assembly to remove. + """ + self._enable_changes_to_outermost_layers() + self.pop(index) + self._disable_changes_to_outermost_layers() + + @property + def superphase(self) -> Layer: + """The superphase of the sample.""" + return self[0].front_layer + + @property + def subphase(self) -> Layer: + """The subphase of the sample.""" + # This assembly only got one layer + if self[-1].back_layer is None: + return self[-1].front_layer + else: + return self[-1].back_layer + + def _enable_changes_to_outermost_layers(self): + """Allowed to change the outermost layers of the sample. + 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 + + 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 + + # Representation + @property + def _dict_repr(self) -> dict: + """A simplified dict representation.""" + return {self.name: [i._dict_repr for i in self]} + + def __repr__(self) -> str: + """String representation of the sample.""" + return yaml_dump(self._dict_repr) + + def as_dict(self, skip: list = None) -> dict: + """Produces a cleaned dict using a custom as_dict method to skip necessary things. + The resulting dict matches the parameters in __init__ + + :param skip: List of keys to skip, defaults to `None`. + """ + if skip is None: + skip = [] + this_dict = super().as_dict(skip=skip) + for i, assembly in enumerate(self.data): + this_dict['data'][i] = assembly.as_dict(skip=skip) + this_dict['populate_if_none'] = self.populate_if_none + return this_dict diff --git a/src/easyreflectometry/sample/sample.py b/src/easyreflectometry/sample/sample.py deleted file mode 100644 index a613b7d1..00000000 --- a/src/easyreflectometry/sample/sample.py +++ /dev/null @@ -1,77 +0,0 @@ -from __future__ import annotations - -__author__ = 'github.com/arm61' - -from typing import Union - -from easyscience.Objects.Groups import BaseCollection - -from easyreflectometry.parameter_utils import yaml_dump - -from .assemblies.base_assembly import BaseAssembly -from .assemblies.multilayer import Multilayer -from .elements.layers.layer import Layer - -NR_DEFAULT_LAYERS = 2 - - -class Sample(BaseCollection): - """Collection of assemblies that represent the sample for which experimental measurements exist.""" - - def __init__( - self, - *list_layer_like: list[Union[Layer, BaseAssembly]], - name: str = 'EasySample', - interface=None, - populate_if_none: bool = True, - **kwargs, - ): - """Constructor. - - :param args: The assemblies in the sample. - :param name: Name of the sample, defaults to 'EasySample'. - :param interface: Calculator interface, defaults to `None`. - """ - new_items = [] - if not list_layer_like: - if populate_if_none: - list_layer_like = [Multilayer(interface=interface) for _ in range(NR_DEFAULT_LAYERS)] - else: - list_layer_like = [] - # Needed to ensure an empty list is created when saving and instatiating the object as_dict -> from_dict - # Else collisions might occur in global_object.map - self.populate_if_none = False - - for layer_like in list_layer_like: - if issubclass(type(layer_like), Layer): - new_items.append(Multilayer(layer_like, name=layer_like.name)) - elif issubclass(type(layer_like), BaseAssembly): - new_items.append(layer_like) - else: - raise ValueError('The items must be either a Layer or an Assembly.') - super().__init__(name, *new_items, **kwargs) - self.interface = interface - - # Representation - @property - def _dict_repr(self) -> dict: - """A simplified dict representation.""" - return {self.name: [i._dict_repr for i in self]} - - def __repr__(self) -> str: - """String representation of the sample.""" - return yaml_dump(self._dict_repr) - - def as_dict(self, skip: list = None) -> dict: - """Produces a cleaned dict using a custom as_dict method to skip necessary things. - The resulting dict matches the parameters in __init__ - - :param skip: List of keys to skip, defaults to `None`. - """ - if skip is None: - skip = [] - this_dict = super().as_dict(skip=skip) - for i, layer in enumerate(self.data): - this_dict['data'][i] = layer.as_dict(skip=skip) - this_dict['populate_if_none'] = self.populate_if_none - return this_dict diff --git a/tests/calculators/refnx/test_refnx_wrapper.py b/tests/calculators/refnx/test_refnx_wrapper.py index de2a0027..093bfb2c 100644 --- a/tests/calculators/refnx/test_refnx_wrapper.py +++ b/tests/calculators/refnx/test_refnx_wrapper.py @@ -16,8 +16,8 @@ from refnx import reflect from easyreflectometry.calculators.refnx.wrapper import RefnxWrapper -from easyreflectometry.experiment import LinearSpline -from easyreflectometry.experiment import PercentageFhwm +from easyreflectometry.model import LinearSpline +from easyreflectometry.model import PercentageFhwm class TestRefnx(unittest.TestCase): diff --git a/tests/experiment/test_model.py b/tests/model/test_model.py similarity index 92% rename from tests/experiment/test_model.py rename to tests/model/test_model.py index 8ec73309..f0f3c496 100644 --- a/tests/experiment/test_model.py +++ b/tests/model/test_model.py @@ -15,9 +15,9 @@ from numpy.testing import assert_equal from easyreflectometry.calculators import CalculatorFactory -from easyreflectometry.experiment import LinearSpline -from easyreflectometry.experiment import Model -from easyreflectometry.experiment import PercentageFhwm +from easyreflectometry.model import LinearSpline +from easyreflectometry.model import Model +from easyreflectometry.model import PercentageFhwm from easyreflectometry.sample import Layer from easyreflectometry.sample import LayerCollection from easyreflectometry.sample import Material @@ -84,7 +84,7 @@ def test_from_pars(self): assert mod._resolution_function.smearing([1]) == 2.0 assert mod._resolution_function.smearing([100]) == 2.0 - def test_add_item(self): + def test_add_assemblies(self): m1 = Material(6.908, -0.278, 'Boron') m2 = Material(0.487, 0.000, 'Potassium') l1 = Layer(m1, 5.0, 2.0, 'thinBoron') @@ -99,24 +99,24 @@ def test_add_item(self): resolution_function = PercentageFhwm(2.0) mod = Model(d, 2, 1e-5, resolution_function, 'newModel') assert_equal(len(mod.sample), 1) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.sample), 2) assert_equal(mod.sample[1].name, 'oneLayerItem2') assert_equal(issubclass(mod.sample[1].__class__, RepeatingMultilayer), True) - mod.add_item(surfactant) + mod.add_assemblies(surfactant) assert_equal(len(mod.sample), 3) - mod.add_item(multilayer) + mod.add_assemblies(multilayer) assert_equal(len(mod.sample), 4) - def test_add_item_exception(self): + def test_add_assemblies_exception(self): # When mod = Model() # Then Expect with pytest.raises(ValueError): - mod.add_item('not an assembly') + mod.add_assemblies('not an assembly') - def test_add_item_with_interface_refnx(self): + def test_add_assemblies_with_interface_refnx(self): interface = CalculatorFactory() m1 = Material(6.908, -0.278, 'Boron') m2 = Material(0.487, 0.000, 'Potassium') @@ -131,11 +131,11 @@ def test_add_item_with_interface_refnx(self): mod = Model(d, 2, 1e-5, resolution_function, 'newModel', interface=interface) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.interface()._wrapper.storage['item']), 2) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - def test_add_item_with_interface_refl1d(self): + def test_add_assemblies_with_interface_refl1d(self): interface = CalculatorFactory() interface.switch('refl1d') m1 = Material(6.908, -0.278, 'Boron') @@ -151,11 +151,11 @@ def test_add_item_with_interface_refl1d(self): mod = Model(d, 2, 1e-5, resolution_function, 'newModel', interface=interface) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.interface()._wrapper.storage['item']), 2) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - # def test_add_item_with_interface_bornagain(self): + # def test_add_assemblies_with_interface_bornagain(self): # interface = CalculatorFactory() # interface.switch('BornAgain') # m1 = Material.from_pars(6.908, 0.278, 'Boron') @@ -170,11 +170,11 @@ def test_add_item_with_interface_refl1d(self): # mod = Model(d, 2, 1e-5, 2.0, 'newModel', interface=interface) # assert_equal(len(mod.interface()._wrapper.storage['item']), 1) # assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - # mod.add_item(o2) + # mod.add_assemblies(o2) # assert_equal(len(mod.interface()._wrapper.storage['item']), 2) # assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - def test_duplicate_item(self): + def test_duplicate_assembly(self): m1 = Material(6.908, -0.278, 'Boron') m2 = Material(0.487, 0.000, 'Potassium') l1 = Layer(m1, 5.0, 2.0, 'thinBoron') @@ -187,14 +187,14 @@ def test_duplicate_item(self): resolution_function = PercentageFhwm(2.0) mod = Model(d, 2, 1e-5, resolution_function, 'newModel') assert_equal(len(mod.sample), 1) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.sample), 2) - mod.duplicate_item(1) + mod.duplicate_assembly(1) assert_equal(len(mod.sample), 3) assert_equal(mod.sample[2].name, 'oneLayerItem2 duplicate') assert_equal(issubclass(mod.sample[2].__class__, RepeatingMultilayer), True) - def test_duplicate_item_with_interface_refnx(self): + def test_duplicate_assembly_with_interface_refnx(self): interface = CalculatorFactory() m1 = Material(6.908, -0.278, 'Boron') m2 = Material(0.487, 0.000, 'Potassium') @@ -208,12 +208,12 @@ def test_duplicate_item_with_interface_refnx(self): resolution_function = PercentageFhwm(2.0) mod = Model(d, 2, 1e-5, resolution_function, 'newModel', interface=interface) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.interface()._wrapper.storage['item']), 2) - mod.duplicate_item(1) + mod.duplicate_assembly(1) assert_equal(len(mod.interface()._wrapper.storage['item']), 3) - def test_duplicate_item_with_interface_refl1d(self): + def test_duplicate_assembly_with_interface_refl1d(self): interface = CalculatorFactory() interface.switch('refl1d') m1 = Material(6.908, -0.278, 'Boron') @@ -228,9 +228,9 @@ def test_duplicate_item_with_interface_refl1d(self): resolution_function = PercentageFhwm(2.0) mod = Model(d, 2, 1e-5, resolution_function, 'newModel', interface=interface) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.interface()._wrapper.storage['item']), 2) - mod.duplicate_item(1) + mod.duplicate_assembly(1) assert_equal(len(mod.interface()._wrapper.storage['item']), 3) # def test_duplicate_item_with_interface_bornagain(self): @@ -246,13 +246,13 @@ def test_duplicate_item_with_interface_refl1d(self): # o2 = RepeatingMultilayer.from_pars(ls2, 1.0, 'oneLayerItem2') # d = Sample.from_pars(o1, name='myModel') # mod = Model(d, 2, 1e-5, 2.0, 'newModel', interface=interface) - # assert_equal(len(mod.interface()._wrapper.storage['item']), 1) - # mod.add_item(o2) + # assert_equal(len(mod.interface()._wrapper.storage['assembly']), 1) + # mod.add_assemblies(o2) # assert_equal(len(mod.interface()._wrapper.storage['item']), 2) - # mod.duplicate_item(1) + # mod.duplicate_assembly(1) # assert_equal(len(mod.interface()._wrapper.storage['item']), 3) - def test_remove_item(self): + def test_remove_assembly(self): m1 = Material(6.908, -0.278, 'Boron') m2 = Material(0.487, 0.000, 'Potassium') l1 = Layer(m1, 5.0, 2.0, 'thinBoron') @@ -265,12 +265,12 @@ def test_remove_item(self): resolution_function = PercentageFhwm(2.0) mod = Model(d, 2, 1e-5, resolution_function, 'newModel') assert_equal(len(mod.sample), 1) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.sample), 2) - mod.remove_item(0) + mod.remove_assembly(0) assert_equal(len(mod.sample), 1) - def test_remove_item_with_interface_refnx(self): + def test_remove_assembly_with_interface_refnx(self): interface = CalculatorFactory() m1 = Material(6.908, -0.278, 'Boron') m2 = Material(0.487, 0.000, 'Potassium') @@ -285,14 +285,14 @@ def test_remove_item_with_interface_refnx(self): mod = Model(d, 2, 1e-5, resolution_function, 'newModel', interface=interface) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.interface()._wrapper.storage['item']), 2) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - mod.remove_item(0) + mod.remove_assembly(0) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - def test_remove_item_with_interface_refl1d(self): + def test_remove_assembly_with_interface_refl1d(self): interface = CalculatorFactory() interface.switch('refl1d') m1 = Material(6.908, -0.278, 'Boron') @@ -308,14 +308,14 @@ def test_remove_item_with_interface_refl1d(self): mod = Model(d, 2, 1e-5, resolution_function, 'newModel', interface=interface) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - mod.add_item(o2) + mod.add_assemblies(o2) assert_equal(len(mod.interface()._wrapper.storage['item']), 2) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - mod.remove_item(0) + mod.remove_assembly(0) assert_equal(len(mod.interface()._wrapper.storage['item']), 1) assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - # def test_remove_item_with_interface_bornagain(self): + # def test_remove_assembly_with_interface_bornagain(self): # interface = CalculatorFactory() # interface.switch('BornAgain') # m1 = Material.from_pars(6.908, 0.278, 'Boron') @@ -330,10 +330,10 @@ def test_remove_item_with_interface_refl1d(self): # mod = Model(d, 2, 1e-5, 2.0, 'newModel', interface=interface) # assert_equal(len(mod.interface()._wrapper.storage['item']), 1) # assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - # mod.add_item(o2) + # mod.add_assemblies(o2) # assert_equal(len(mod.interface()._wrapper.storage['item']), 2) # assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) - # mod.remove_item(0) + # mod.remove_assembly(0) # assert_equal(len(mod.interface()._wrapper.storage['item']), 1) # assert_equal(len(mod.interface()._wrapper.storage['layer']), 2) @@ -401,7 +401,7 @@ def test_dict_round_trip(interface): model = Model(interface=interface) model.resolution_function = resolution_function for additional_layer in [SurfactantLayer(), Multilayer(), RepeatingMultilayer()]: - model.add_item(additional_layer) + model.add_assemblies(additional_layer) src_dict = model.as_dict() global_object.map._clear() diff --git a/tests/experiment/test_model_collection.py b/tests/model/test_model_collection.py similarity index 95% rename from tests/experiment/test_model_collection.py rename to tests/model/test_model_collection.py index 02f0ec4b..8614efb8 100644 --- a/tests/experiment/test_model_collection.py +++ b/tests/model/test_model_collection.py @@ -1,7 +1,7 @@ from easyscience import global_object -from easyreflectometry.experiment.model import Model -from easyreflectometry.experiment.model_collection import ModelCollection +from easyreflectometry.model.model import Model +from easyreflectometry.model.model_collection import ModelCollection class TestModelCollection: diff --git a/tests/experiment/test_resolution_functions.py b/tests/model/test_resolution_functions.py similarity index 88% rename from tests/experiment/test_resolution_functions.py rename to tests/model/test_resolution_functions.py index ab8eb614..ff5b1816 100644 --- a/tests/experiment/test_resolution_functions.py +++ b/tests/model/test_resolution_functions.py @@ -2,10 +2,10 @@ import numpy as np -from easyreflectometry.experiment.resolution_functions import DEFAULT_RESOLUTION_FWHM_PERCENTAGE -from easyreflectometry.experiment.resolution_functions import LinearSpline -from easyreflectometry.experiment.resolution_functions import PercentageFhwm -from easyreflectometry.experiment.resolution_functions import ResolutionFunction +from easyreflectometry.model.resolution_functions import DEFAULT_RESOLUTION_FWHM_PERCENTAGE +from easyreflectometry.model.resolution_functions import LinearSpline +from easyreflectometry.model.resolution_functions import PercentageFhwm +from easyreflectometry.model.resolution_functions import ResolutionFunction class TestPercentageFhwm(unittest.TestCase): diff --git a/tests/sample/assemblies/test_multilayer.py b/tests/sample/assemblies/test_multilayer.py index c1ee3fd0..878c4c34 100644 --- a/tests/sample/assemblies/test_multilayer.py +++ b/tests/sample/assemblies/test_multilayer.py @@ -13,8 +13,8 @@ from easyreflectometry.calculators.factory import CalculatorFactory from easyreflectometry.sample.assemblies.multilayer import Multilayer +from easyreflectometry.sample.collections.layer_collection import LayerCollection from easyreflectometry.sample.elements.layers.layer import Layer -from easyreflectometry.sample.elements.layers.layer_collection import LayerCollection from easyreflectometry.sample.elements.materials.material import Material diff --git a/tests/sample/assemblies/test_repeating_multilayer.py b/tests/sample/assemblies/test_repeating_multilayer.py index ce585992..e3c173d2 100644 --- a/tests/sample/assemblies/test_repeating_multilayer.py +++ b/tests/sample/assemblies/test_repeating_multilayer.py @@ -14,8 +14,8 @@ from easyreflectometry.calculators import CalculatorFactory from easyreflectometry.sample.assemblies.repeating_multilayer import RepeatingMultilayer +from easyreflectometry.sample.collections.layer_collection import LayerCollection from easyreflectometry.sample.elements.layers.layer import Layer -from easyreflectometry.sample.elements.layers.layer_collection import LayerCollection from easyreflectometry.sample.elements.materials.material import Material diff --git a/tests/sample/elements/layers/test_layer_collection.py b/tests/sample/collections/test_layer_collection.py similarity index 97% rename from tests/sample/elements/layers/test_layer_collection.py rename to tests/sample/collections/test_layer_collection.py index c2c0bec2..2e17d3ab 100644 --- a/tests/sample/elements/layers/test_layer_collection.py +++ b/tests/sample/collections/test_layer_collection.py @@ -11,8 +11,8 @@ from numpy.testing import assert_equal from easyreflectometry.sample.assemblies.repeating_multilayer import RepeatingMultilayer +from easyreflectometry.sample.collections.layer_collection import LayerCollection from easyreflectometry.sample.elements.layers.layer import Layer -from easyreflectometry.sample.elements.layers.layer_collection import LayerCollection from easyreflectometry.sample.elements.materials.material import Material diff --git a/tests/sample/elements/materials/test_material_collection.py b/tests/sample/collections/test_material_collection.py similarity index 95% rename from tests/sample/elements/materials/test_material_collection.py rename to tests/sample/collections/test_material_collection.py index cdfc47b0..37c652b8 100644 --- a/tests/sample/elements/materials/test_material_collection.py +++ b/tests/sample/collections/test_material_collection.py @@ -9,8 +9,8 @@ from easyscience import global_object +from easyreflectometry.sample.collections.material_collection import MaterialCollection from easyreflectometry.sample.elements.materials.material import Material -from easyreflectometry.sample.elements.materials.material_collection import MaterialCollection class TestMaterialCollection(unittest.TestCase): diff --git a/tests/sample/collections/test_sample.py b/tests/sample/collections/test_sample.py new file mode 100644 index 00000000..92e5c1b8 --- /dev/null +++ b/tests/sample/collections/test_sample.py @@ -0,0 +1,305 @@ +""" +Tests for Sample class. +""" + +__author__ = 'github.com/arm61' +__version__ = '0.0.1' + +from unittest.mock import MagicMock + +import pytest +from easyscience import global_object +from numpy.testing import assert_equal + +from easyreflectometry.sample import Layer +from easyreflectometry.sample import LayerCollection +from easyreflectometry.sample import Material +from easyreflectometry.sample import Multilayer +from easyreflectometry.sample import RepeatingMultilayer +from easyreflectometry.sample import Sample +from easyreflectometry.sample import SurfactantLayer + + +class TestSample: + def test_default(self): + # When Then + p = Sample() + + # Expect + assert_equal(p.name, 'EasySample') + assert_equal(p.interface, None) + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + + def test_add_assembly(self): + # When + p = Sample() + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + surfactant = SurfactantLayer() + + # Then + p.add_assembly(surfactant) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + assert_equal(p[2].name, 'EasySurfactantLayer') + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + # Problems with parameterized tests START + def test_duplicate_assembly_multilayer(self): + # When + assembly_to_duplicate = Multilayer() + p = Sample() + p.add_assembly(assembly_to_duplicate) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.duplicate_assembly(2) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + assert_equal(p[2].name, assembly_to_duplicate.name) + assert_equal(p[3].name, assembly_to_duplicate.name + ' duplicate') + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + def test_duplicate_assembly_repeating_multilayer(self): + # When + assembly_to_duplicate = RepeatingMultilayer() + p = Sample() + p.add_assembly(assembly_to_duplicate) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.duplicate_assembly(2) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + assert_equal(p[2].name, assembly_to_duplicate.name) + assert_equal(p[3].name, assembly_to_duplicate.name + ' duplicate') + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + def test_duplicate_assembly_surfactant(self): + # When + assembly_to_duplicate = SurfactantLayer() + p = Sample() + p.add_assembly(assembly_to_duplicate) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.duplicate_assembly(2) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + assert_equal(p[2].name, assembly_to_duplicate.name) + assert_equal(p[3].name, assembly_to_duplicate.name + ' duplicate') + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + # Problems with parameterized tests END + + def test_move_assembly_up(self): + # When + p = Sample() + surfactant = SurfactantLayer() + p.add_assembly(surfactant) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.move_assembly_up(2) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, surfactant.name) + assert_equal(p[2].name, 'EasyMultilayer') + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + def test_move_assembly_up_index_0(self): + # When + p = Sample() + surfactant = SurfactantLayer() + p.add_assembly(surfactant) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.move_assembly_up(0) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + assert_equal(p[2].name, surfactant.name) + p._enable_changes_to_outermost_layers.assert_not_called() + p._disable_changes_to_outermost_layers.assert_not_called() + + def test_move_assembly_down(self): + # When + p = Sample() + surfactant = SurfactantLayer() + p.add_assembly(surfactant) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.move_assembly_down(1) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, surfactant.name) + assert_equal(p[2].name, 'EasyMultilayer') + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + def test_move_assembly_down_index_2(self): + # When + p = Sample() + surfactant = SurfactantLayer() + p.add_assembly(surfactant) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.move_assembly_down(2) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, 'EasyMultilayer') + assert_equal(p[2].name, surfactant.name) + p._enable_changes_to_outermost_layers.assert_not_called() + p._disable_changes_to_outermost_layers.assert_not_called() + + def test_remove_assembly(self): + # When + p = Sample() + surfactant = SurfactantLayer() + p.add_assembly(surfactant) + p._enable_changes_to_outermost_layers = MagicMock() + p._disable_changes_to_outermost_layers = MagicMock() + + # Then + p.remove_assembly(1) + + # Expect + assert_equal(p[0].name, 'EasyMultilayer') + assert_equal(p[1].name, surfactant.name) + p._enable_changes_to_outermost_layers.assert_called_once_with() + p._disable_changes_to_outermost_layers.assert_called_once_with() + + def test_subphase(self): + # When + p = Sample() + layer = Multilayer(Layer(name='new layer')) + p.add_assembly(layer) + + # Then + layer = p.subphase + + # Expect + assert_equal(layer.name, 'new layer') + + def test_superphase(self): + # When + p = Sample() + layer = Multilayer(Layer(name='new layer')) + p.add_assembly(layer) + p.move_assembly_up(2) + p.move_assembly_up(1) + + # Then + layer = p.superphase + + # Expect + assert_equal(layer.name, 'new layer') + + def test_enable_changes_to_outermost_layers(self): + # When + p = Sample() + p.superphase.thickness.enabled = False + p.superphase.roughness.enabled = False + p.subphase.thickness.enabled = False + + # Then + p._enable_changes_to_outermost_layers() + + # Expect + assert_equal(p.superphase.thickness.enabled, True) + assert_equal(p.superphase.roughness.enabled, True) + assert_equal(p.subphase.thickness.enabled, True) + + def test_disable_changes_to_outermost_layers(self): + # When + p = Sample() + p.superphase.thickness.enabled = True + p.superphase.roughness.enabled = True + p.subphase.thickness.enabled = True + + # Then + p._disable_changes_to_outermost_layers() + + # Expect + assert_equal(p.superphase.thickness.enabled, False) + assert_equal(p.superphase.roughness.enabled, False) + assert_equal(p.subphase.thickness.enabled, False) + + def test_from_pars(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') + + # Then + d = Sample(o1, o2, name='myModel') + + # Expect + assert_equal(d.name, 'myModel') + assert_equal(d.interface, None) + assert_equal(d[0].name, 'twoLayerItem1') + assert_equal(d[1].name, 'oneLayerItem2') + + def test_from_pars_error(self): + m1 = Material(6.908, -0.278, 'Boron') + + with pytest.raises(ValueError): + _ = Sample(m1, name='myModel') + + def test_repr(self): + p = Sample() + assert ( + p.__repr__() + == 'EasySample:\n- EasyMultilayer:\n EasyLayerCollection:\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n- EasyMultilayer:\n EasyLayerCollection:\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n' # noqa: E501 + ) + + def test_dict_round_trip(self): + # When + p = Sample() + surfactant = SurfactantLayer() + p.append(surfactant) + multilayer = Multilayer() + p.append(multilayer) + repeating = RepeatingMultilayer() + p.append(repeating) + p_dict = p.as_dict() + global_object.map._clear() + + # Then + q = Sample.from_dict(p_dict) + + # Expect + assert sorted(p.as_data_dict()) == sorted(q.as_data_dict()) diff --git a/tests/sample/test_sample.py b/tests/sample/test_sample.py deleted file mode 100644 index 0a916173..00000000 --- a/tests/sample/test_sample.py +++ /dev/null @@ -1,83 +0,0 @@ -""" -Tests for Sample class. -""" - -__author__ = 'github.com/arm61' -__version__ = '0.0.1' - -import unittest - -from easyscience import global_object -from numpy.testing import assert_equal - -from easyreflectometry.sample import Layer -from easyreflectometry.sample import LayerCollection -from easyreflectometry.sample import Material -from easyreflectometry.sample import Multilayer -from easyreflectometry.sample import RepeatingMultilayer -from easyreflectometry.sample import Sample -from easyreflectometry.sample import SurfactantLayer - - -class TestSample(unittest.TestCase): - def test_default(self): - p = Sample() - assert_equal(p.name, 'EasySample') - assert_equal(p.interface, None) - assert_equal(p[0].name, 'EasyMultilayer') - assert_equal(p[1].name, 'EasyMultilayer') - - def test_from_pars(self): - 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') - assert_equal(d.name, 'myModel') - assert_equal(d.interface, None) - assert_equal(d[0].name, 'twoLayerItem1') - assert_equal(d[1].name, 'oneLayerItem2') - - def test_from_pars_layers(self): - 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') - d = Sample(l1, l2, name='myModel') - assert_equal(d.name, 'myModel') - assert_equal(d.interface, None) - assert_equal(d[0].name, 'thinBoron') - assert_equal(d[1].name, 'thickPotassium') - - def test_from_pars_error(self): - m1 = Material(6.908, -0.278, 'Boron') - with self.assertRaises(ValueError): - _ = Sample(m1, name='myModel') - - def test_repr(self): - p = Sample() - assert ( - p.__repr__() - == 'EasySample:\n- EasyMultilayer:\n EasyLayerCollection:\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n- EasyMultilayer:\n EasyLayerCollection:\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n - EasyLayer:\n material:\n EasyMaterial:\n sld: 4.186e-6 1/Å^2\n isld: 0.000e-6 1/Å^2\n thickness: 10.000 Å\n roughness: 3.300 Å\n' # noqa: E501 - ) - - def test_dict_round_trip(self): - # When - p = Sample() - surfactant = SurfactantLayer() - p.append(surfactant) - multilayer = Multilayer() - p.append(multilayer) - repeating = RepeatingMultilayer() - p.append(repeating) - p_dict = p.as_dict() - global_object.map._clear() - - # Then - q = Sample.from_dict(p_dict) - - assert sorted(p.as_data_dict()) == sorted(q.as_data_dict()) diff --git a/tests/test_fitting.py b/tests/test_fitting.py index 42948feb..727c90a1 100644 --- a/tests/test_fitting.py +++ b/tests/test_fitting.py @@ -8,11 +8,12 @@ import easyreflectometry from easyreflectometry.calculators import CalculatorFactory from easyreflectometry.data import load -from easyreflectometry.experiment import Model -from easyreflectometry.experiment import PercentageFhwm from easyreflectometry.fitting import Fitter +from easyreflectometry.model import Model +from easyreflectometry.model import PercentageFhwm from easyreflectometry.sample import Layer from easyreflectometry.sample import Material +from easyreflectometry.sample import Multilayer from easyreflectometry.sample import Sample PATH_STATIC = os.path.join(os.path.dirname(easyreflectometry.__file__), '..', '..', 'tests', '_static') @@ -26,10 +27,10 @@ def test_fitting(minimizer): sio2 = Material(3.47, 0, 'SiO2') film = Material(2.0, 0, 'Film') d2o = Material(6.36, 0, 'D2O') - si_layer = Layer(si, 0, 0, 'Si layer') - sio2_layer = Layer(sio2, 30, 3, 'SiO2 layer') - film_layer = Layer(film, 250, 3, 'Film Layer') - superphase = Layer(d2o, 0, 3, 'D2O Subphase') + si_layer = Multilayer(Layer(si, 0, 0, 'Si layer')) + sio2_layer = Multilayer(Layer(sio2, 30, 3, 'SiO2 layer')) + film_layer = Multilayer(Layer(film, 250, 3, 'Film Layer')) + superphase = Multilayer(Layer(d2o, 0, 3, 'D2O Subphase')) sample = Sample( si_layer, sio2_layer, @@ -40,12 +41,12 @@ def test_fitting(minimizer): resolution_function = PercentageFhwm(0.02) model = Model(sample, 1, 1e-6, resolution_function, 'Film Model') # Thicknesses - sio2_layer.thickness.bounds = (15, 50) - film_layer.thickness.bounds = (200, 300) + sio2_layer.layers[0].thickness.bounds = (15, 50) + film_layer.layers[0].thickness.bounds = (200, 300) # Roughnesses - sio2_layer.roughness.bounds = (1, 15) - film_layer.roughness.bounds = (1, 15) - superphase.roughness.bounds = (1, 15) + sio2_layer.layers[0].roughness.bounds = (1, 15) + film_layer.layers[0].roughness.bounds = (1, 15) + superphase.layers[0].roughness.bounds = (1, 15) # Scattering length density film.sld.bounds = (0.1, 3) # Background diff --git a/tests/test_topmost_nesting.py b/tests/test_topmost_nesting.py index 585dc8da..a270b72d 100644 --- a/tests/test_topmost_nesting.py +++ b/tests/test_topmost_nesting.py @@ -8,8 +8,8 @@ from numpy.testing import assert_almost_equal from easyreflectometry.calculators import CalculatorFactory -from easyreflectometry.experiment import LinearSpline -from easyreflectometry.experiment import Model +from easyreflectometry.model import LinearSpline +from easyreflectometry.model import Model from easyreflectometry.sample import Multilayer from easyreflectometry.sample import RepeatingMultilayer from easyreflectometry.sample import SurfactantLayer @@ -20,8 +20,7 @@ def test_dict_skip_unique_name(): resolution_function = LinearSpline([0, 10], [0, 10]) model = Model(interface=CalculatorFactory()) model.resolution_function = resolution_function - for additional_layer in [SurfactantLayer(), Multilayer(), RepeatingMultilayer()]: - model.add_item(additional_layer) + model.add_assemblies(SurfactantLayer(), Multilayer(), RepeatingMultilayer()) # Then dict_no_unique_name = model.as_dict(skip=['unique_name']) @@ -35,8 +34,7 @@ def test_copy(): resolution_function = LinearSpline([0, 10], [0, 10]) model = Model(interface=CalculatorFactory()) model.resolution_function = resolution_function - for additional_layer in [SurfactantLayer(), Multilayer(), RepeatingMultilayer()]: - model.add_item(additional_layer) + model.add_assemblies(SurfactantLayer(), Multilayer(), RepeatingMultilayer()) # Then model_copy = copy(model)