diff --git a/arc/common.py b/arc/common.py index b504f5d567..04633a9580 100644 --- a/arc/common.py +++ b/arc/common.py @@ -1864,3 +1864,16 @@ def calculate_arrhenius_rate_coefficient(A: Union[int, float, Sequence[float], n raise ValueError("All temperature values must be positive") exp_arg = -Ea_arr / (R * T_arr) return A_arr * np.power(T_arr, n_arr) * np.exp(exp_arg) + + +def fill_in_the_blanks(folder_name: str): + """ + Adding backslashes before spaces in the folder name. + + Args: + folder_name (str): The string directory we want to modify. + + Returns: + str: Modified folder name. + """ + return folder_name.replace(" ", "\ ") diff --git a/arc/common_test.py b/arc/common_test.py index 2a5c9b417a..aca01e0c18 100644 --- a/arc/common_test.py +++ b/arc/common_test.py @@ -1391,6 +1391,19 @@ def test_calculate_arrhenius_rate_coefficient(self): with self.assertRaises(ValueError): common.calculate_arrhenius_rate_coefficient(A=1e12, n=0.5, Ea=10, T=bad_T, Ea_units='kJ/mol') + def test_fill_in_the_blanks(self): + """Test the fill_in_the_blanks() function""" + ex1 = "name" + ex2 = "name1 name2" + ex3 = "name 1 name2" + ex4 = "name 1 name2" + ex5 = "/home/user/Code/ARC/Projects/project name/calcs/file.sh" + self.assertEqual(common.fill_in_the_blanks(ex1), "name") + self.assertEqual(common.fill_in_the_blanks(ex2), "name1\\ name2") + self.assertEqual(common.fill_in_the_blanks(ex3), "name\\ 1\\ name2") + self.assertEqual(common.fill_in_the_blanks(ex4), "name\\ 1\\ \\ name2") + self.assertEqual(common.fill_in_the_blanks(ex5), "/home/user/Code/ARC/Projects/project\\ name/calcs/file.sh") + @classmethod def tearDownClass(cls): """ diff --git a/arc/main.py b/arc/main.py index e8c68a8057..1bf93ada17 100644 --- a/arc/main.py +++ b/arc/main.py @@ -21,6 +21,7 @@ ARC_PATH, check_ess_settings, delete_check_files, + fill_in_the_blanks, get_logger, globalize_path, initialize_job_types, @@ -280,6 +281,7 @@ def __init__(self, self.verbose = verbose self.project_directory = project_directory if project_directory is not None \ else os.path.join(ARC_PATH, 'Projects', self.project) + self.project_directory = fill_in_the_blanks(self.project_directory) if not os.path.exists(self.project_directory): os.makedirs(self.project_directory) self.output = output