From 0e9a01a898e6efd67e309dc39abbee7710ef2b0f Mon Sep 17 00:00:00 2001 From: Andrew-S-Rosen Date: Sat, 13 Jan 2024 16:55:06 -0800 Subject: [PATCH 1/8] Add support for charges --- docs/examples.md | 4 ---- src/raspa_ase/utils/io.py | 2 +- src/raspa_ase/utils/params.py | 17 +++++++++++------ tests/test_calculator.py | 3 ++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/docs/examples.md b/docs/examples.md index 9d2c9dd..25a3b33 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -157,10 +157,6 @@ atoms.get_potential_energy() ## Example 8: Adsorption isotherm of CO2 in Cu-BTC -!!! Note - - This example is not ready yet since support for charges is ongoing. - ```python from ase.io import read from raspa_ase import Raspa diff --git a/src/raspa_ase/utils/io.py b/src/raspa_ase/utils/io.py index d2baf36..35bd668 100644 --- a/src/raspa_ase/utils/io.py +++ b/src/raspa_ase/utils/io.py @@ -70,7 +70,7 @@ def write_frameworks(frameworks: list[Atoms], directory: str | Path) -> None: name = f"framework{i}" structure = AseAtomsAdaptor.get_structure(framework) - structure.to(str(Path(directory, name + ".cif"))) + structure.to(str(Path(directory, name + ".cif")), write_site_properties=True) def _iterable_to_str(v: list[Any]) -> str: diff --git a/src/raspa_ase/utils/params.py b/src/raspa_ase/utils/params.py index 3970478..51191cb 100644 --- a/src/raspa_ase/utils/params.py +++ b/src/raspa_ase/utils/params.py @@ -25,8 +25,7 @@ def get_framework_params(frameworks: list[Atoms]) -> dict[str, Any]: dict The framework-related parameters. """ - # TODO: Add support for writing charges to CIF - # with _atom_site_charge and in RASPA set UseChargesFromCIFFile yes + parameters = {} for i, framework in enumerate(frameworks): if framework == Atoms(): @@ -36,13 +35,19 @@ def get_framework_params(frameworks: list[Atoms]) -> dict[str, Any]: cutoff = get_parameter(parameters, "CutOff", default=12.0) n_cells = get_suggested_cells(framework, cutoff) + framework_params = { + "FrameworkName": name, + "UnitCells": n_cells, + } + + if framework.has("initial_charges"): + framework_params |= {"UseChargesFromCIFFile": True} + parameters[f"Framework {i}"] = merge_parameters( - { - "FrameworkName": name, - "UnitCells": n_cells, - }, + framework_params, framework.info, ) + return parameters diff --git a/tests/test_calculator.py b/tests/test_calculator.py index b8fe91d..13aeaab 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -108,6 +108,7 @@ def test_raspa_functional1(tmp_path): def test_raspa_functional2(tmp_path): atoms = bulk("Cu") + atoms.set_initial_charges([1.0] * len(atoms)) atoms.calc = Raspa( directory=tmp_path, boxes=[{"BoxLengths": [1, 2, 3]}, {"BoxLengths": [4, 5, 6]}], @@ -125,5 +126,5 @@ def test_raspa_functional2(tmp_path): assert Path(tmp_path, "simulation.input").exists() assert ( Path(tmp_path / "simulation.input").read_text() - == "CutOff 12.8\nComponent 0 MoleculeName N2\n MoleculeDefinition ExampleDefinition\nComponent 1 MoleculeName CO2\n MoleculeDefinition ExampleDefinition\n TranslationProbability 1.0\nBox 0\n BoxLengths 1 2 3\nBox 1\n BoxLengths 4 5 6\nFramework 0\n FrameworkName framework0\n UnitCells 12 12 12\n" + == "CutOff 12.8\nComponent 0 MoleculeName N2\n MoleculeDefinition ExampleDefinition\nComponent 1 MoleculeName CO2\n MoleculeDefinition ExampleDefinition\n TranslationProbability 1.0\nBox 0\n BoxLengths 1 2 3\nBox 1\n BoxLengths 4 5 6\nFramework 0\n FrameworkName framework0\n UnitCells 12 12 12\n UseChargesFromCIFFile Yes" ) From e231a3d08ef73b92e3348a0b53fcc7c620b4f301 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sat, 13 Jan 2024 17:05:12 -0800 Subject: [PATCH 2/8] Update requirements.txt --- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 3011f46..d4690e2 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,3 @@ https://gitlab.com/ase/ase/-/archive/master/ase-master.zip numpy==1.26.3 -pymatgen==2023.12.18 +git+https://github.com/materialsproject/pymatgen.git@refs/pull/3550/merge From 34de2611e55fe36ff801fc2a2b89138a39da1840 Mon Sep 17 00:00:00 2001 From: Andrew-S-Rosen Date: Sat, 13 Jan 2024 17:08:02 -0800 Subject: [PATCH 3/8] fix --- tests/test_calculator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 13aeaab..3d08ba4 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -126,5 +126,5 @@ def test_raspa_functional2(tmp_path): assert Path(tmp_path, "simulation.input").exists() assert ( Path(tmp_path / "simulation.input").read_text() - == "CutOff 12.8\nComponent 0 MoleculeName N2\n MoleculeDefinition ExampleDefinition\nComponent 1 MoleculeName CO2\n MoleculeDefinition ExampleDefinition\n TranslationProbability 1.0\nBox 0\n BoxLengths 1 2 3\nBox 1\n BoxLengths 4 5 6\nFramework 0\n FrameworkName framework0\n UnitCells 12 12 12\n UseChargesFromCIFFile Yes" + == "CutOff 12.8\nComponent 0 MoleculeName N2\n MoleculeDefinition ExampleDefinition\nComponent 1 MoleculeName CO2\n MoleculeDefinition ExampleDefinition\n TranslationProbability 1.0\nBox 0\n BoxLengths 1 2 3\nBox 1\n BoxLengths 4 5 6\nFramework 0\n FrameworkName framework0\n UnitCells 12 12 12\n UseChargesFromCIFFile Yes\n" ) From ba34ba9bc4f3e4cfabbb4c63aa049dbc62c0b59a Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sat, 13 Jan 2024 18:51:06 -0800 Subject: [PATCH 4/8] Update params.py --- src/raspa_ase/utils/params.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/raspa_ase/utils/params.py b/src/raspa_ase/utils/params.py index 51191cb..0343a3e 100644 --- a/src/raspa_ase/utils/params.py +++ b/src/raspa_ase/utils/params.py @@ -41,7 +41,7 @@ def get_framework_params(frameworks: list[Atoms]) -> dict[str, Any]: } if framework.has("initial_charges"): - framework_params |= {"UseChargesFromCIFFile": True} + framework_params = merge_parameters(framework_params, {"UseChargesFromCIFFile": True}) parameters[f"Framework {i}"] = merge_parameters( framework_params, From 6aa742013b677136444a23513647ce45ed24acfe Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Sun, 14 Jan 2024 02:51:17 +0000 Subject: [PATCH 5/8] style: format code with Black, isort and Prettier This commit fixes the style issues introduced in ba34ba9 according to the output from Black, isort and Prettier. Details: https://github.com/Quantum-Accelerators/raspa_ase/pull/10 --- src/raspa_ase/utils/params.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/raspa_ase/utils/params.py b/src/raspa_ase/utils/params.py index 0343a3e..6391f3e 100644 --- a/src/raspa_ase/utils/params.py +++ b/src/raspa_ase/utils/params.py @@ -41,7 +41,9 @@ def get_framework_params(frameworks: list[Atoms]) -> dict[str, Any]: } if framework.has("initial_charges"): - framework_params = merge_parameters(framework_params, {"UseChargesFromCIFFile": True}) + framework_params = merge_parameters( + framework_params, {"UseChargesFromCIFFile": True} + ) parameters[f"Framework {i}"] = merge_parameters( framework_params, From 3cd427ee0ec37745a0676dff6618e9f316b43768 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Sun, 14 Jan 2024 15:40:18 -0800 Subject: [PATCH 6/8] Update requirements.txt --- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index d4690e2..6673afd 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,3 @@ https://gitlab.com/ase/ase/-/archive/master/ase-master.zip numpy==1.26.3 -git+https://github.com/materialsproject/pymatgen.git@refs/pull/3550/merge +git+https://github.com/materialsproject/pymatgen.git From e0cd660ee490a03ab94ed49ad662931b071e8d24 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 26 Feb 2024 17:46:26 -0800 Subject: [PATCH 7/8] Update requirements.txt --- tests/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 6673afd..e32b473 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,3 +1,3 @@ https://gitlab.com/ase/ase/-/archive/master/ase-master.zip numpy==1.26.3 -git+https://github.com/materialsproject/pymatgen.git +pymatgen==2024.2.23 From fe4c426295e0a14466a60bd92b04adfbcba13e94 Mon Sep 17 00:00:00 2001 From: "Andrew S. Rosen" Date: Mon, 26 Feb 2024 17:46:50 -0800 Subject: [PATCH 8/8] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5e4d9c2..9b199d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ "Operating System :: MacOS", ] requires-python = ">=3.9, <3.13" -dependencies = ["ase", "numpy", "pymatgen"] +dependencies = ["ase", "numpy", "pymatgen>=2024.2.8"] [project.optional-dependencies] dev = ["black>=23.7.0", "docformatter>=1.7.5", "isort>=5.12.0", "pytest>=7.4.0", "pytest-cov>=3.0.0", "ruff>=0.0.285"]