From 07dc36842e5093df7d16daa225aaeaa6e8d14fe8 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:52:11 -0800 Subject: [PATCH 1/5] update: start arrays in basis from 0 --- express/parsers/structure.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/express/parsers/structure.py b/express/parsers/structure.py index 2b213dd6..62a01ce6 100644 --- a/express/parsers/structure.py +++ b/express/parsers/structure.py @@ -158,8 +158,8 @@ def basis(self): """ return { "units": "crystal", - "elements": [{"id": i + 1, "value": v.species_string} for i, v in enumerate(self.structure.sites)], - "coordinates": [{"id": i + 1, "value": v.frac_coords.tolist()} for i, v in enumerate(self.structure.sites)], + "elements": [{"id": i, "value": v.species_string} for i, v in enumerate(self.structure.sites)], + "coordinates": [{"id": i, "value": v.frac_coords.tolist()} for i, v in enumerate(self.structure.sites)], } def space_group_symbol(self): From 4aeb0ab6789267e43c1114f476003008467a3d29 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 20 Feb 2024 16:48:16 -0800 Subject: [PATCH 2/5] chore: id 1,2 -> id 0,1 --- express/parsers/apps/espresso/formats/txt.py | 16 ++++++++-------- .../apps/espresso/formats/xml/xml_base.py | 4 ++-- .../apps/espresso/formats/xml/xml_pre64.py | 4 ++-- express/parsers/apps/vasp/formats/txt.py | 8 ++++---- express/parsers/apps/vasp/formats/xml.py | 4 ++-- express/parsers/mixins/ionic.py | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/express/parsers/apps/espresso/formats/txt.py b/express/parsers/apps/espresso/formats/txt.py index f58f6fac..60186bda 100644 --- a/express/parsers/apps/espresso/formats/txt.py +++ b/express/parsers/apps/espresso/formats/txt.py @@ -333,8 +333,8 @@ def initial_basis(self, text): Example: { 'units': 'angstrom', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [2.1095228, 1.49165, 3.6538]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [2.1095228, 1.49165, 3.6538]}] } """ alat = self._get_alat(text) @@ -436,14 +436,14 @@ def _basis_convergence(self, text): [ { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] }, ... { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] } ] """ @@ -462,8 +462,8 @@ def _extract_basis_from_bfgs_blocks(self, text): Example: { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] } """ basis = {"units": "crystal", "elements": [], "coordinates": []} diff --git a/express/parsers/apps/espresso/formats/xml/xml_base.py b/express/parsers/apps/espresso/formats/xml/xml_base.py index ccd45747..297a8f2b 100644 --- a/express/parsers/apps/espresso/formats/xml/xml_base.py +++ b/express/parsers/apps/espresso/formats/xml/xml_base.py @@ -139,8 +139,8 @@ def final_basis(self): Example: { 'units': 'angstrom', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] } """ pass diff --git a/express/parsers/apps/espresso/formats/xml/xml_pre64.py b/express/parsers/apps/espresso/formats/xml/xml_pre64.py index 84e8dc98..aa598128 100644 --- a/express/parsers/apps/espresso/formats/xml/xml_pre64.py +++ b/express/parsers/apps/espresso/formats/xml/xml_pre64.py @@ -165,8 +165,8 @@ def final_basis(self): Example: { 'units': 'angstrom', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] } """ elements, coordinates = [], [] diff --git a/express/parsers/apps/vasp/formats/txt.py b/express/parsers/apps/vasp/formats/txt.py index 7801b386..f70ec876 100644 --- a/express/parsers/apps/vasp/formats/txt.py +++ b/express/parsers/apps/vasp/formats/txt.py @@ -111,14 +111,14 @@ def _basis_convergence(self, text, atom_names): [ { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] }, ... { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.0, 0.0, 0.0]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.0, 0.0, 0.0]}] } ] """ diff --git a/express/parsers/apps/vasp/formats/xml.py b/express/parsers/apps/vasp/formats/xml.py index 797a803c..db12dd7b 100644 --- a/express/parsers/apps/vasp/formats/xml.py +++ b/express/parsers/apps/vasp/formats/xml.py @@ -292,8 +292,8 @@ def final_basis(self): Example: { 'units': 'angstrom', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [1.11, 0.78, 1.93]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [1.11, 0.78, 1.93]}] } """ lattice = self.final_lattice_vectors() diff --git a/express/parsers/mixins/ionic.py b/express/parsers/mixins/ionic.py index 272e80ae..8b4adc8e 100644 --- a/express/parsers/mixins/ionic.py +++ b/express/parsers/mixins/ionic.py @@ -42,8 +42,8 @@ def initial_basis(self): Example: { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.25, 0.25, 0.25]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.25, 0.25, 0.25]}] } """ pass @@ -81,8 +81,8 @@ def final_basis(self): Example: { 'units': 'crystal', - 'elements': [{'id': 1, 'value': 'Si'}, {'id': 2, 'value': 'Si'}], - 'coordinates': [{'id': 1, 'value': [0.0, 0.0, 0.0]}, {'id': 2, 'value': [0.25, 0.25, 0.25]}] + 'elements': [{'id': 0, 'value': 'Si'}, {'id': 1, 'value': 'Si'}], + 'coordinates': [{'id': 0, 'value': [0.0, 0.0, 0.0]}, {'id': 1, 'value': [0.25, 0.25, 0.25]}] } """ pass From e015cea552b6e502e1e07c4f4686c116792b9300 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:01:06 -0800 Subject: [PATCH 3/5] fix: patch only one os function, not the whole module The problem was in os.path receiving a Mock object in tests instead of just a string, leading to the failed schema validation --- tests/unit/properties/non_scalar/test_workflow.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/properties/non_scalar/test_workflow.py b/tests/unit/properties/non_scalar/test_workflow.py index e6ce4392..99a85ff5 100644 --- a/tests/unit/properties/non_scalar/test_workflow.py +++ b/tests/unit/properties/non_scalar/test_workflow.py @@ -13,9 +13,9 @@ def setUp(self): def tearDown(self): super().setUp() - @mock.patch("express.properties.workflow.os") - def test_pyml_workflow(self, mock_os): - mock_os.listdir.return_value = MOCK_BASENAMES + @mock.patch("express.properties.workflow.os.listdir") + def test_pyml_workflow(self, mock_os_listdir): + mock_os_listdir.return_value = MOCK_BASENAMES name = NAME parser = PARSER From 249ef899ba9c82ba090dd199cb1fddfb9e5307c6 Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:13:08 -0800 Subject: [PATCH 4/5] chore: change the id logic to start from 0 instead of 1 in test fixtures --- tests/fixtures/data.py | 2 +- tests/fixtures/espresso/v5_4/references.py | 2 +- tests/fixtures/nwchem/references.py | 8 ++++---- tests/unit/properties/non_scalar/test_atomic_forces.py | 2 +- tests/unit/properties/non_scalar/test_magnetic_moments.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/fixtures/data.py b/tests/fixtures/data.py index 99aecca4..d25c9c15 100644 --- a/tests/fixtures/data.py +++ b/tests/fixtures/data.py @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1b5922e129683c921c2ab96ff9d4e6d26b7701c95587a8f67b19c536c4ae2011 +oid sha256:c6dfc86c91e91091a18ae8006cb9ba5d6d7e0935111273d1396ca78be82297df size 23287 diff --git a/tests/fixtures/espresso/v5_4/references.py b/tests/fixtures/espresso/v5_4/references.py index 2fece7f4..2fc9f2ea 100644 --- a/tests/fixtures/espresso/v5_4/references.py +++ b/tests/fixtures/espresso/v5_4/references.py @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:daa02db7be6eae56bbe3dabb3326e97014240de97e71aa26acedf97ff3656122 +oid sha256:25cb7690bac1b36a0ed787cfca62706d58614c2a1cbdb7ad5774c010bec9b072 size 144655 diff --git a/tests/fixtures/nwchem/references.py b/tests/fixtures/nwchem/references.py index e8e18760..839085da 100644 --- a/tests/fixtures/nwchem/references.py +++ b/tests/fixtures/nwchem/references.py @@ -14,10 +14,10 @@ BASIS = { "units": "angstrom", - "elements": [{"id": 1, "value": "O"}, {"id": 2, "value": "H"}, {"id": 3, "value": "H"}], + "elements": [{"id": 0, "value": "O"}, {"id": 1, "value": "H"}, {"id": 2, "value": "H"}], "coordinates": [ - {"id": 1, "value": [0.00000000, 0.00000000, 0.22143053]}, - {"id": 2, "value": [0.00000000, 1.43042809, -0.88572213]}, - {"id": 3, "value": [0.00000000, -1.43042809, -0.88572213]}, + {"id": 0, "value": [0.00000000, 0.00000000, 0.22143053]}, + {"id": 1, "value": [0.00000000, 1.43042809, -0.88572213]}, + {"id": 2, "value": [0.00000000, -1.43042809, -0.88572213]}, ], } diff --git a/tests/unit/properties/non_scalar/test_atomic_forces.py b/tests/unit/properties/non_scalar/test_atomic_forces.py index f68f47ed..50e7b95e 100644 --- a/tests/unit/properties/non_scalar/test_atomic_forces.py +++ b/tests/unit/properties/non_scalar/test_atomic_forces.py @@ -5,7 +5,7 @@ ATOMIC_FORCES = { "units": "eV/angstrom", "name": "atomic_forces", - "values": [{"id": 1, "value": [-3.9e-07, -2.4e-07, 0.0]}, {"id": 2, "value": [3.9e-07, 2.4e-07, 0.0]}], + "values": [{"id": 0, "value": [-3.9e-07, -2.4e-07, 0.0]}, {"id": 1, "value": [3.9e-07, 2.4e-07, 0.0]}], } diff --git a/tests/unit/properties/non_scalar/test_magnetic_moments.py b/tests/unit/properties/non_scalar/test_magnetic_moments.py index 89a7325c..0a8ca5de 100644 --- a/tests/unit/properties/non_scalar/test_magnetic_moments.py +++ b/tests/unit/properties/non_scalar/test_magnetic_moments.py @@ -5,7 +5,7 @@ MAGNETIC_MOMENTS = { "units": "uB", "name": "magnetic_moments", - "values": [{"id": 1, "value": [0, 0, 1.235]}, {"id": 2, "value": [0, 0, -1.235]}], + "values": [{"id": 0, "value": [0, 0, 1.235]}, {"id": 1, "value": [0, 0, -1.235]}], } From e33900def9e3341fa350ef3dce4916220712db3a Mon Sep 17 00:00:00 2001 From: VsevolodX <79542055+VsevolodX@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:25:07 -0800 Subject: [PATCH 5/5] chore: change the indexing from + 1 to normal --- express/properties/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/express/properties/utils.py b/express/properties/utils.py index 0307564d..d91d4892 100644 --- a/express/properties/utils.py +++ b/express/properties/utils.py @@ -26,4 +26,4 @@ def to_array_with_ids(array): Returns: list """ - return [{"id": index + 1, "value": value} for index, value in enumerate(array)] + return [{"id": index, "value": value} for index, value in enumerate(array)]