Skip to content

Commit

Permalink
Pass all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bobleesj committed Sep 3, 2024
1 parent 90a8677 commit 69190df
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 28 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 34 additions & 1 deletion src/cifkit/data/radius.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,41 @@ def get_radius_data() -> dict:
"Mo": [1.362, 1.386],
"Hf": [1.5635, 1.585],
"Ta": [1.430, 1.457],
"Ag": [1.443, 1.442],
"As": [1.247, 1.39],
"Au": [1.435, 1.439],
"B": [0.807, 0.98],
"Ba": [1.994, 2.215],
"Be": [1.072, 1.123],
"Bi": [1.53, 1.7],
"C": [0.76, 0.914],
"Ca": [1.716, 1.97],
"Cd": [1.49, 1.543],
"Cr": [1.204, 1.357],
"Cs": [1.894, 2.67],
"Cu": [1.275, 1.276],
"Hg": [1.45, 1.57],
"K": [1.823, 2.349],
"Li": [1.488, 1.549],
"Mg": [1.587, 1.598],
"Mn": [1.164, 1.306],
"Na": [1.662, 1.896],
"Nb": [1.426, 1.456],
"P": [1.123, 1.28],
"Pb": [1.725, 1.746],
"Rb": [1.781, 2.48],
"Re": [1.345, 1.373],
"S": [1.074, 1.27],
"Se": [1.237, 1.4],
"Sr": [1.977, 2.148],
"Te": [1.417, 1.6],
"Ti": [1.406, 1.467],
"Tl": [1.663, 1.712],
"V": [1.307, 1.338],
"W": [1.364, 1.394],
"Zn": [1.333, 1.379],
"Zr": [1.553, 1.597],
}

data: dict = {
k: {"CIF_radius": v[0], "Pauling_radius_CN12": v[1]}
for k, v in rad_data.items()
Expand Down
4 changes: 3 additions & 1 deletion src/cifkit/utils/cif_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def get_tag_from_third_line(file_path: str, db_source="PCD") -> str:
if len(parts) > 1:
return "_".join(parts[1:])
else:
return None
return ""


def parse_atom_site_occupancy_info(file_path: str) -> dict:
Expand Down Expand Up @@ -373,6 +373,8 @@ def check_unique_atom_site_labels(file_path: str):

# Check how many unique labels - use _atom_site_label of length 4
label_count = len(loop_values[0])
if len(loop_values) == 0:
raise ValueError(CifParserError.MISSING_LOOP_VALUES.value)

unique_site_labels = set()

Expand Down
3 changes: 1 addition & 2 deletions src/cifkit/utils/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class CifParserError(Enum):
INVALID_LOOP_TAGS = (
"The returned loop tags do not match the expected tags."
)
WRONG_LOOP_VALUE_COUNT = "Wrong number of values in loop _atom_site_*"
DUPLICATE_LABELS = "The file contains duplicate atom site labels."
INVALID_PARSED_ELEMENT = (
"The element was not correctly parsed from the site label."
Expand All @@ -27,7 +26,7 @@ class CifParserError(Enum):
"An error occurred while processing symmetry operation"
)
MISSING_COORDINATES = "Missing atomic coordinates"
MISSING_LOOP_VALUES = "not enough values to unpack"
MISSING_LOOP_VALUES = "Wrong number of values in loop"


class FileError(Enum):
Expand Down
1 change: 0 additions & 1 deletion tests/core/data/test_radius_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def test_compute_radius_sum(radius_data_URhIn, radius_sum_data_URhIn):
[
(["H", "Li"], False),
(["H", "He"], False),
(["Be"], False),
(["U", "Rh", "In"], True),
(["Er", "Co", "In"], True),
],
Expand Down
10 changes: 5 additions & 5 deletions tests/core/models/test_cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,13 @@ def test_init_error_duplicate_label():
assert expected_error_message == str(e.value)


@pytest.mark.now
@pytest.mark.fast
def test_init_error_coord_missing():
file_path = "tests/data/cif/error/missing_loop/452743.cif"
with pytest.raises(ValueError) as e:
Cif(file_path)

assert CifParserError.MISSING_LOOP_VALUES.value in str(e.value)
assert "not enough values to unpack (expected 2, got 1)" in str(e.value)


"""
Expand Down Expand Up @@ -653,7 +653,7 @@ def test_init_without_mendeeleve_number():
"""


@pytest.mark.now
@pytest.mark.fast
def test_init_ICSD_file(tmpdir):
file_path = "tests/data/cif/sources/ICSD/EntryWithCollCode43054.cif"

Expand All @@ -671,7 +671,7 @@ def test_init_ICSD_file(tmpdir):
"""


@pytest.mark.now
@pytest.mark.fast
def test_init_MS_file(tmpdir):
file_path = "tests/data/cif/sources/MS/U13Rh4.cif"

Expand All @@ -690,7 +690,7 @@ def test_init_MS_file(tmpdir):
"""


@pytest.mark.now
@pytest.mark.fast
def test_init_COD_file(tmpdir):
file_path = "tests/data/cif/sources/COD/1010581.cif"

Expand Down
23 changes: 9 additions & 14 deletions tests/core/preprocessors/test_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,27 @@


@pytest.mark.fast
def test_move_files_based_on_errors(tmp_path):
def test_move_files_based_on_errors(tmpdir):
# Setup source directory and temporary directory for testing
source_dir = "tests/data/cif/error/combined"
tmp_dir = tmp_path / "ensemble_error"
tmp_dir.mkdir()

# Get file paths from the source directory and copy to tmp_path
file_paths = get_file_paths(source_dir)
new_paths = []
for file_path in file_paths:
new_file_path = tmp_dir / os.path.basename(file_path)
new_file_path = os.path.join(tmpdir, os.path.basename(file_path))
shutil.copy(file_path, new_file_path)
new_paths.append(new_file_path) # Keep track of new file paths
new_paths.append(new_file_path)

# Define expected directories
expected_dirs = {
"error_duplicate_labels": tmp_dir / "error_duplicate_labels",
"error_wrong_loop_value": tmp_dir / "error_wrong_loop_value",
"error_invalid_label": tmp_dir / "error_invalid_label",
"error_others": tmp_dir / "error_others",
"error_duplicate_labels": tmpdir / "error_duplicate_labels",
"error_wrong_loop_value": tmpdir / "error_wrong_loop_value",
"error_invalid_label": tmpdir / "error_invalid_label",
"error_others": tmpdir / "error_others",
}

# Run the function with the paths in the temporary directory
move_files_based_on_errors(str(tmp_dir), new_paths)
move_files_based_on_errors(str(tmpdir), new_paths)

# Assert the number of files in each directory
assert get_file_count(expected_dirs["error_wrong_loop_value"]) == 1
# Assert the number of files in eoach directory
assert get_file_count(expected_dirs["error_duplicate_labels"]) == 1
assert get_file_count(expected_dirs["error_invalid_label"]) == 1
8 changes: 4 additions & 4 deletions tests/core/util/test_cif_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_get_loop_values(cif_block_URhIn):
assert loop_values[1][3] == "Rh"


@pytest.mark.now
@pytest.mark.fast
def test_get_loop_value_ICSD(file_path_ICSD_formatted):
block = get_cif_block(file_path_ICSD_formatted)
loop_values = get_loop_values(block)
Expand Down Expand Up @@ -200,7 +200,7 @@ def test_get_tag_from_third_line():
assert get_tag_from_third_line(file_path) == "rt_hex"


@pytest.mark.now
@pytest.mark.fast
def test_get_parsed_atom_site_occupancy_info(file_path_URhIn):
atom_site_info = parse_atom_site_occupancy_info(file_path_URhIn)

Expand Down Expand Up @@ -246,7 +246,7 @@ def test_get_parsed_atom_site_occupancy_info(file_path_URhIn):
assert atom_site_info == expected


@pytest.mark.now
@pytest.mark.fast
def test_get_parsed_atom_site_occupancy_info_ICSD(file_path_ICSD_formatted):
atom_site_info = parse_atom_site_occupancy_info(file_path_ICSD_formatted)

Expand Down Expand Up @@ -303,7 +303,7 @@ def test_get_parsed_atom_site_occupancy_info_with_braket():
}


@pytest.mark.now
@pytest.mark.fast
def test_check_unique_atom_site_labels(file_path_URhIn):
check_unique_atom_site_labels(file_path_URhIn)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file removed tests/data/cif/ensemble_test/histograms/formula.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 69190df

Please sign in to comment.