|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import numpy as np |
2 | 4 | import pytest |
| 5 | +import yaml |
3 | 6 |
|
| 7 | +import tests.regression.helpers as Helpers |
| 8 | +from CodeEntropy.config.runtime import CodeEntropyRunner |
| 9 | +from CodeEntropy.levels.mda import UniverseOperations |
4 | 10 | from CodeEntropy.levels.search import Search |
5 | 11 |
|
6 | 12 | # some dummy atom positions |
|
11 | 17 | e = np.array([0, 11, 11]) |
12 | 18 | dimensions = np.array([10, 10, 10]) |
13 | 19 |
|
| 20 | +DEFAULT_TESTDATA_BASE_URL = "https://www.ccpbiosim.ac.uk/file-store/codeentropy-testing" |
| 21 | + |
| 22 | + |
| 23 | +def test_get_RAD_neighbors(tmp_path: Path): |
| 24 | + """ |
| 25 | + Args: |
| 26 | + tmp_path: Pytest provided temporatry directory |
| 27 | + """ |
| 28 | + args = {} |
| 29 | + search = Search() |
| 30 | + system = "methane" |
| 31 | + repo_root = Path(__file__).resolve().parents[4] |
| 32 | + config_path = ( |
| 33 | + repo_root / "tests" / "regression" / "configs" / system / "config.yaml" |
| 34 | + ) |
| 35 | + |
| 36 | + tmp_path.mkdir(parents=True, exist_ok=True) |
| 37 | + |
| 38 | + raw = yaml.safe_load(config_path.read_text()) |
| 39 | + if not isinstance(raw, dict): |
| 40 | + raise ValueError( |
| 41 | + f"Config must parse to a dict. Got {type(raw)} from {config_path}" |
| 42 | + ) |
| 43 | + |
| 44 | + cooked = Helpers._abspathify_config_paths(raw, base_dir=config_path.parent) |
| 45 | + required: list[Path] = [] |
| 46 | + run1 = cooked.get("run1") |
| 47 | + if isinstance(run1, dict): |
| 48 | + ff = run1.get("force_file") |
| 49 | + if isinstance(ff, str) and ff: |
| 50 | + required.append(Path(ff)) |
| 51 | + for p in run1.get("top_traj_file") or []: |
| 52 | + if isinstance(p, str) and p: |
| 53 | + required.append(Path(p)) |
| 54 | + |
| 55 | + if required: |
| 56 | + Helpers.ensure_testdata_for_system(system, required_paths=required) |
| 57 | + |
| 58 | + runner = CodeEntropyRunner(tmp_path) |
| 59 | + parser = runner._config_manager.build_parser() |
| 60 | + args, _ = parser.parse_known_args() |
| 61 | + args.end = run1.get("end") |
| 62 | + args.top_traj_file = run1.get("top_traj_file") |
| 63 | + args.file_format = run1.get("file_format") |
| 64 | + assert args.end == 1 |
| 65 | + |
| 66 | + universe_operations = UniverseOperations() |
| 67 | + universe = CodeEntropyRunner._build_universe(args, universe_operations) |
| 68 | + |
| 69 | + neighbors = search.get_RAD_neighbors(universe=universe, mol_id=0) |
| 70 | + |
| 71 | + assert neighbors == [151, 3, 75, 219, 229, 488, 460, 118, 230, 326] |
| 72 | + |
14 | 73 |
|
15 | 74 | def test_get_angle(): |
16 | 75 | search = Search() |
|
0 commit comments