Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.

Commit 742a82c

Browse files
Merge pull request #10 from Quantum-Accelerators/cifcharge
Add support for framework charges
2 parents 7b44ae7 + d764e01 commit 742a82c

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ classifiers = [
2525
"Operating System :: MacOS",
2626
]
2727
requires-python = ">=3.9, <3.13"
28-
dependencies = ["ase", "numpy", "pymatgen"]
28+
dependencies = ["ase", "numpy", "pymatgen>=2024.2.8"]
2929

3030
[project.optional-dependencies]
3131
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"]

src/raspa_ase/utils/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def write_frameworks(frameworks: list[Atoms], directory: str | Path) -> None:
7171
name = f"framework{i}"
7272

7373
structure = AseAtomsAdaptor.get_structure(framework)
74-
structure.to(str(Path(directory, name + ".cif")))
74+
structure.to(str(Path(directory, name + ".cif")), write_site_properties=True)
7575

7676

7777
def parse_output(filepath: str | Path) -> dict[str, Any]:

src/raspa_ase/utils/params.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def get_framework_params(frameworks: list[Atoms]) -> dict[str, Any]:
2525
dict
2626
The framework-related parameters.
2727
"""
28-
# TODO: Add support for writing charges to CIF
29-
# with _atom_site_charge and in RASPA set UseChargesFromCIFFile yes
28+
3029
parameters = {}
3130
for i, framework in enumerate(frameworks):
3231
if framework == Atoms():
@@ -36,13 +35,21 @@ def get_framework_params(frameworks: list[Atoms]) -> dict[str, Any]:
3635
cutoff = get_parameter(parameters, "CutOff", default=12.0)
3736
n_cells = get_suggested_cells(framework, cutoff)
3837

38+
framework_params = {
39+
"FrameworkName": name,
40+
"UnitCells": n_cells,
41+
}
42+
43+
if framework.has("initial_charges"):
44+
framework_params = merge_parameters(
45+
framework_params, {"UseChargesFromCIFFile": True}
46+
)
47+
3948
parameters[f"Framework {i}"] = merge_parameters(
40-
{
41-
"FrameworkName": name,
42-
"UnitCells": n_cells,
43-
},
49+
framework_params,
4450
framework.info,
4551
)
52+
4653
return parameters
4754

4855

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
https://gitlab.com/ase/ase/-/archive/master/ase-master.zip
22
numpy==1.26.3
3-
pymatgen==2023.12.18
3+
pymatgen==2024.2.23

tests/test_calculator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def test_raspa_functional1(tmp_path):
128128

129129
def test_raspa_functional2(tmp_path):
130130
atoms = bulk("Cu")
131+
atoms.set_initial_charges([1.0] * len(atoms))
131132
atoms.calc = Raspa(
132133
directory=tmp_path,
133134
boxes=[{"BoxLengths": [1, 2, 3]}, {"BoxLengths": [4, 5, 6]}],
@@ -145,7 +146,7 @@ def test_raspa_functional2(tmp_path):
145146
assert Path(tmp_path, "simulation.input").exists()
146147
assert (
147148
Path(tmp_path / "simulation.input").read_text()
148-
== "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"
149+
== "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"
149150
)
150151

151152

0 commit comments

Comments
 (0)