From 44d870daa08851b76112a31049a5fdaabae0fc94 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sat, 13 Jan 2024 20:12:25 -0800 Subject: [PATCH 01/10] Use RASPA for real in tests --- .github/workflows/tests.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bde46d2..c2e66a2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -39,6 +39,9 @@ jobs: pip install -r tests/requirements.txt pip install .[dev] + - name: Install conda packages + run: conda install -c conda-forge raspa2 + - name: Run tests with pytest run: pytest --cov=raspa_ase --cov-report=xml From 5401f9007cde0c0ce4537a3e4bc1db3a28d495e7 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sat, 13 Jan 2024 20:18:01 -0800 Subject: [PATCH 02/10] Update tests.yaml --- .github/workflows/tests.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c2e66a2..d70328f 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -42,8 +42,11 @@ jobs: - name: Install conda packages run: conda install -c conda-forge raspa2 + - name: Set up environment + run: export RASPA_DIR=/usr/share/miniconda + - name: Run tests with pytest - run: pytest --cov=raspa_ase --cov-report=xml + run: pytest --noconftest --cov=raspa_ase --cov-report=xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 From 7ab4156c43d12bf950c231d9f026e5a6a719d16c Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sat, 13 Jan 2024 20:20:53 -0800 Subject: [PATCH 03/10] Update tests.yaml --- .github/workflows/tests.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index d70328f..4f2dc14 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -43,7 +43,8 @@ jobs: run: conda install -c conda-forge raspa2 - name: Set up environment - run: export RASPA_DIR=/usr/share/miniconda + env: + RASPA_DIR: /usr/share/miniconda - name: Run tests with pytest run: pytest --noconftest --cov=raspa_ase --cov-report=xml From f2c3696e0e3c6966e09260618be1ca0cfe19d8df Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sat, 13 Jan 2024 20:24:06 -0800 Subject: [PATCH 04/10] Update tests.yaml --- .github/workflows/tests.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 4f2dc14..c80c4b7 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -43,8 +43,7 @@ jobs: run: conda install -c conda-forge raspa2 - name: Set up environment - env: - RASPA_DIR: /usr/share/miniconda + run: echo "RASPA_DIR=/usr/share/miniconda" >> "$GITHUB_ENV" - name: Run tests with pytest run: pytest --noconftest --cov=raspa_ase --cov-report=xml From ea953bb55757c586fa961e0faf330dfb701a1cd8 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 13 Jan 2024 23:18:56 -0800 Subject: [PATCH 05/10] fix --- tests/test_calculator.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index d1ef9c6..051cfde 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,3 +1,4 @@ +import os from pathlib import Path import pytest @@ -15,7 +16,10 @@ def test_profile_bad(monkeypatch): def test_profile(): profile = RaspaProfile() - assert profile.argv == ["./bin/simulate", "simulation.input"] + assert profile.argv == [ + f"{os.getenv('RASPA_DIR')}/bin/simulate", + "simulation.input", + ] def test_profile2(): @@ -25,7 +29,6 @@ def test_profile2(): def test_run(monkeypatch, tmp_path): monkeypatch.chdir(tmp_path) - monkeypatch.setenv("RASPA_DIR", "bad_dir") RaspaProfile().run(tmp_path, tmp_path / "simulation.input") @@ -38,7 +41,7 @@ def test_template(): def test_template_execute(monkeypatch, tmp_path): monkeypatch.chdir(tmp_path) template = RaspaTemplate() - template.execute("bad_dir", RaspaProfile()) + template.execute(tmp_path, RaspaProfile()) def test_template_write_input(monkeypatch, tmp_path): From d573b6015859fff85cb2143fe44b88acb1501b87 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 13 Jan 2024 23:28:56 -0800 Subject: [PATCH 06/10] fix --- src/raspa_ase/calculator.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/raspa_ase/calculator.py b/src/raspa_ase/calculator.py index 4a15cb0..d241a7b 100644 --- a/src/raspa_ase/calculator.py +++ b/src/raspa_ase/calculator.py @@ -80,10 +80,16 @@ class RaspaTemplate(CalculatorTemplate): RASPA template, used to define how to read and write RASPA files. """ - def __init__(self) -> None: + def __init__(self, frameworks: list[Atoms] | None = None) -> None: """ Initialize the RASPA template. + Parameters + ---------- + frameworks + The frameworks to use, to be used in place of the `Atoms` object + the calculator is applied to. + Returns ------- None @@ -96,6 +102,7 @@ def __init__(self) -> None: self.input_file = SIMULATION_INPUT self.output_file = f"{label}.out" + self.frameworks = frameworks def execute(self, directory: Path | str, profile: RaspaProfile) -> None: """ @@ -114,8 +121,8 @@ def execute(self, directory: Path | str, profile: RaspaProfile) -> None: """ profile.run(directory, self.output_file) - @staticmethod def write_input( + self, directory: Path | str, atoms: Atoms, parameters: dict[str, Any], @@ -142,7 +149,7 @@ def write_input( ------- None """ - frameworks = [atoms] + frameworks = self.frameworks if self.frameworks else [atoms] parameters = merge_parameters(parameters, get_framework_params([atoms])) write_simulation_input(parameters, directory / SIMULATION_INPUT) @@ -369,7 +376,7 @@ def __init__( parameters = merge_parameters(parameters, {f"Box {i}": box}) super().__init__( - template=RaspaTemplate(), + template=RaspaTemplate(frameworks=multiple_frameworks), profile=profile, directory=directory, parameters=parameters, From acfbcd270ca249722576003c47a0c75596b4c4e5 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 13 Jan 2024 23:30:04 -0800 Subject: [PATCH 07/10] fix --- src/raspa_ase/calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raspa_ase/calculator.py b/src/raspa_ase/calculator.py index d241a7b..f09c17b 100644 --- a/src/raspa_ase/calculator.py +++ b/src/raspa_ase/calculator.py @@ -55,7 +55,7 @@ def __init__(self, argv: list[str] | None = None) -> None: def run( self, directory: Path | str, - output_filename: Path | str, + output_filename: str, ) -> None: """ Run the RASPA calculation. From c31b0d96ba4e7dd5d7b498cf12b10a2a87f3e842 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 13 Jan 2024 23:32:27 -0800 Subject: [PATCH 08/10] fix test --- tests/test_calculator.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 051cfde..390a95d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -40,6 +40,8 @@ def test_template(): def test_template_execute(monkeypatch, tmp_path): monkeypatch.chdir(tmp_path) + with Path(tmp_path / "simulation.input").open(mode="w") as fd: + fd.write("") template = RaspaTemplate() template.execute(tmp_path, RaspaProfile()) From 49f7790db7193ecfb99f2f7120789c1a0bbb36e6 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 13 Jan 2024 23:34:24 -0800 Subject: [PATCH 09/10] fix --- tests/test_calculator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 390a95d..6f123d8 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -4,6 +4,7 @@ import pytest from ase import Atoms from ase.build import bulk +from ase.io import read from raspa_ase.calculator import Raspa, RaspaProfile, RaspaTemplate @@ -146,3 +147,7 @@ def test_multi_frameworks(tmp_path): Path(tmp_path / "simulation.input").read_text() == "Framework 0\n FrameworkName framework0\n UnitCells 12 12 12\n HeliumVoidFraction 0.75\nFramework 1\n FrameworkName framework1\n UnitCells 12 12 12\n" ) + assert Path(tmp_path / "framework0.cif").exists() + assert Path(tmp_path / "framework1.cif").exists() + assert read(tmp_path / "framework0.cif")[0].symbol == "Cu" + assert read(tmp_path / "framework1.cif")[0].symbol == "Fe" From 0cf10dd7e798bf9292fcc51f28ad8fc612e9bab0 Mon Sep 17 00:00:00 2001 From: Andrew Rosen Date: Sat, 13 Jan 2024 23:36:14 -0800 Subject: [PATCH 10/10] fix --- tests/test_calculator.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 6f123d8..f836347 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -140,12 +140,30 @@ def test_multi_frameworks(tmp_path): atoms1.info = {"HeliumVoidFraction": 0.75} atoms2 = bulk("Fe") atoms = Atoms() - atoms.calc = Raspa(directory=tmp_path, multiple_frameworks=[atoms1, atoms2]) + atoms.calc = Raspa( + directory=tmp_path, + multiple_frameworks=[atoms1, atoms2], + boxes=[{"BoxLengths": [1, 2, 3]}, {"BoxLengths": [4, 5, 6]}], + parameters={"CutOff": 12.8}, + components=[ + {"MoleculeName": "N2", "MoleculeDefinition": "ExampleDefinition"}, + { + "MoleculeName": "CO2", + "MoleculeDefinition": "ExampleDefinition", + "TranslationProbability": 1.0, + }, + ], + ) atoms.get_potential_energy() assert Path(tmp_path, "simulation.input").exists() + input_str = Path(tmp_path / "simulation.input").read_text() assert ( - Path(tmp_path / "simulation.input").read_text() - == "Framework 0\n FrameworkName framework0\n UnitCells 12 12 12\n HeliumVoidFraction 0.75\nFramework 1\n FrameworkName framework1\n UnitCells 12 12 12\n" + "Framework 0\n FrameworkName framework0\n UnitCells 12 12 12\n HeliumVoidFraction 0.75\n" + in input_str + ) + assert ( + "Framework 1\n FrameworkName framework1\n UnitCells 12 12 12\n" + in input_str ) assert Path(tmp_path / "framework0.cif").exists() assert Path(tmp_path / "framework1.cif").exists()