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"] diff --git a/src/raspa_ase/utils/io.py b/src/raspa_ase/utils/io.py index bbcb55a..807d712 100644 --- a/src/raspa_ase/utils/io.py +++ b/src/raspa_ase/utils/io.py @@ -71,7 +71,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 parse_output(filepath: str | Path) -> dict[str, Any]: diff --git a/src/raspa_ase/utils/params.py b/src/raspa_ase/utils/params.py index 3970478..6391f3e 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,21 @@ 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 = merge_parameters( + 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/requirements.txt b/tests/requirements.txt index 3011f46..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 -pymatgen==2023.12.18 +pymatgen==2024.2.23 diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 4b02222..6b2703b 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -128,6 +128,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]}], @@ -145,7 +146,7 @@ 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\n" )