Skip to content

Commit

Permalink
Merge pull request #10 from Quantum-Accelerators/cifcharge
Browse files Browse the repository at this point in the history
Add support for framework charges
  • Loading branch information
Andrew-S-Rosen authored Feb 27, 2024
2 parents 7b44ae7 + d764e01 commit 742a82c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion src/raspa_ase/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
19 changes: 13 additions & 6 deletions src/raspa_ase/utils/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/test_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}],
Expand All @@ -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"
)


Expand Down

0 comments on commit 742a82c

Please sign in to comment.