Skip to content

Commit

Permalink
add exception test for pdb writer
Browse files Browse the repository at this point in the history
  • Loading branch information
daico007 committed Aug 19, 2024
1 parent 0dd052b commit dea1acd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
CRYST1 9.879 8.003 6.628 90.00 90.00 90.00 P 1
HETATM 1 C1 RES 1 0.000 0.000 0.000 0.00 0.00 C
HETATM 2 C2 RES 1 -1.500 0.000 0.000 0.00 0.00 C
HETATM 3 C3 RES 1 -2.200 1.212 0.000 0.00 0.00 C
HETATM 4 O1 RES 1 0.700 -1.212 -0.000 0.00 0.00 O
HETATM 5 O2 RES 1 0.771 1.169 0.000 0.00 0.00 O
HETATM 6 H1 RES 1 -1.813 1.790 0.713 0.00 0.00 H
HETATM 7 H2 RES 1 -1.967 1.754 -0.813 0.00 0.00 H
HETATM 8 H3 RES 1 -1.820 -0.485 -0.814 0.00 0.00 H
HETATM 9 H4 RES 1 -1.820 -0.485 0.814 0.00 0.00 H
HETATM 10 H5 RES 1 -3.197 1.252 0.096 0.00 0.00 H
HETATM 11 H6 RES 1 1.682 -1.022 -0.000 0.00 0.00 H
END
CRYST1 9.879 8.003 6.628 90.00 90.00 90.00 P 1
HETATM 1 C1 RES 1 0.000 0.000 0.000 0.00 0.00
HETATM 2 C2 RES 1 -1.500 0.000 0.000 0.00 0.00
HETATM 3 C3 RES 1 -2.200 1.212 0.000 0.00 0.00
HETATM 4 O1 RES 1 0.700 -1.212 -0.000 0.00 0.00
HETATM 5 O2 RES 1 0.771 1.169 0.000 0.00 0.00
HETATM 6 H1 RES 1 -1.813 1.790 0.713 0.00 0.00
HETATM 7 H2 RES 1 -1.967 1.754 -0.813 0.00 0.00
HETATM 8 H3 RES 1 -1.820 -0.485 -0.814 0.00 0.00
HETATM 9 H4 RES 1 -1.820 -0.485 0.814 0.00 0.00
HETATM 10 H5 RES 1 -3.197 1.252 0.096 0.00 0.00
HETATM 11 H6 RES 1 1.682 -1.022 -0.000 0.00 0.00
END
8 changes: 8 additions & 0 deletions mosdef_dihedral_fit/tests/test_file_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ def test_get_from_pdb(self):
"H",
"H",
]
error_fn = "with_errors/CT_CT_C_3_OH_with_errors.pdb"
full_error_fn = self.get_fn(error_fn)
error_msg = (
"ERROR: The provided pdb format is not the required PDB format "
"or the pdb file has zero \(0\) atoms or beads in it."
)
with pytest.raises(TypeError, match=error_msg):
get_atom_names_and_elements_from_pdb(full_error_fn)

def test_write_xyz_file_from_gaussian(self):
atom_namesList = [
Expand Down
9 changes: 6 additions & 3 deletions mosdef_dihedral_fit/utils/file_read_and_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ def get_atom_names_and_elements_from_pdb(pdb_directory_and_filename):
if element_name_str_space_iter != " ":
element_name_j += element_name_str_space_iter

atom_name_list.append(atom_name_j)
element_name_list.append(element_name_j)
if atom_name_j != "":
atom_name_list.append(atom_name_j)
if element_name_j != "":
element_name_list.append(element_name_j)

if len(split_line_m) > 0 and str(split_line_m[0]) in ["CRYST1"]:
get_atom_type_bool = True

if len(atom_name_list) == 0:
print(element_name_list)
if len(element_name_list) == 0:
raise TypeError(
"ERROR: The provided pdb format is not the required PDB format "
"or the pdb file has zero (0) atoms or beads in it."
Expand Down

0 comments on commit dea1acd

Please sign in to comment.