generated from lukasturcani/python-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from SimoneMartino98/main
@SimoneMartino98 added normalization options to compute_rdf function
- Loading branch information
Showing
14 changed files
with
103 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from dataclasses import dataclass | ||
from typing import Literal | ||
|
||
|
||
@dataclass(frozen=True, slots=True) | ||
class RDFCaseData: | ||
topology_filename: str | ||
trajectory_filename: str | ||
expected_bins: str | ||
expected_rdf: str | ||
norm: Literal["rdf", "density", "none"] | ||
name: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
|
||
from .case_data import RDFCaseData | ||
|
||
|
||
@pytest.fixture( | ||
scope="session", | ||
params=( | ||
lambda name: RDFCaseData( | ||
topology_filename="test_coex.gro", | ||
trajectory_filename="test_coex.xtc", | ||
expected_bins="test_bins_rdf.npy", | ||
expected_rdf="test_rdf_rdf.npy", | ||
norm="rdf", | ||
name=name, | ||
), | ||
lambda name: RDFCaseData( | ||
topology_filename="test_coex.gro", | ||
trajectory_filename="test_coex.xtc", | ||
expected_bins="test_bins_density.npy", | ||
expected_rdf="test_rdf_density.npy", | ||
norm="density", | ||
name=name, | ||
), | ||
lambda name: RDFCaseData( | ||
topology_filename="test_coex.gro", | ||
trajectory_filename="test_coex.xtc", | ||
expected_bins="test_bins_none.npy", | ||
expected_rdf="test_rdf_none.npy", | ||
norm="none", | ||
name=name, | ||
), | ||
), | ||
) | ||
def case_data(request: pytest.FixtureRequest) -> RDFCaseData: | ||
return request.param( | ||
f"{request.fixturename}{request.param_index}", # type: ignore [attr-defined] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Pytest for dynsight.analysis.compute_rdf.""" | ||
|
||
from pathlib import Path | ||
|
||
import MDAnalysis | ||
import numpy as np | ||
import pytest | ||
|
||
from dynsight.analysis import compute_rdf | ||
from tests.analysis.rdf.case_data import RDFCaseData | ||
|
||
|
||
def test_compute_rdf(case_data: RDFCaseData) -> None: | ||
original_dir = Path(__file__).resolve().parent | ||
topology_file = ( | ||
original_dir / "../../systems/coex" / case_data.topology_filename | ||
) | ||
trajectory_file = ( | ||
original_dir / "../../systems/coex" / case_data.trajectory_filename | ||
) | ||
expected_bins = original_dir / "test_rdf" / case_data.expected_bins | ||
expected_rdf = original_dir / "test_rdf" / case_data.expected_rdf | ||
|
||
u = MDAnalysis.Universe(topology_file, trajectory_file) | ||
|
||
selection = "type O" | ||
|
||
test_bins, test_rdf = compute_rdf( | ||
universe=u, | ||
s1=selection, | ||
s2=selection, | ||
distances_range=[0.0, 5.0], | ||
norm=case_data.norm, | ||
) | ||
|
||
if not expected_bins.exists() or not expected_rdf.exists(): | ||
np.save(expected_bins, test_bins) | ||
np.save(expected_rdf, test_rdf) | ||
pytest.fail("RDF test files were not present. They have been created.") | ||
|
||
exp_bins = np.load(expected_bins) | ||
exp_rdf = np.load(expected_rdf) | ||
assert np.array_equal(exp_rdf, test_rdf) | ||
assert np.array_equal(exp_bins, test_bins) |
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Binary file not shown.