From c0937095e7214ec6b0c279cd51ab851a0205de3d Mon Sep 17 00:00:00 2001 From: Calvin Date: Wed, 25 Dec 2024 12:24:09 +0200 Subject: [PATCH] Enhance GaussianAdapter to support integral algorithm in job type and update TRSH keyword handling. Refactor find_crest_executable for improved version parsing and comparison. --- arc/job/adapters/gaussian.py | 3 ++ arc/job/trsh.py | 3 +- arc/job/trsh_test.py | 2 +- arc/settings/settings.py | 59 +++++++++++++++++++++++++----------- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/arc/job/adapters/gaussian.py b/arc/job/adapters/gaussian.py index 476af80e67..f75af27ca3 100644 --- a/arc/job/adapters/gaussian.py +++ b/arc/job/adapters/gaussian.py @@ -303,6 +303,9 @@ def write_input_file(self) -> None: keywords.extend(['tight', 'maxstep=5']) else: keywords.extend(['tight', 'maxstep=5', f'maxcycle={max_c}']) + else: + if integral_algorithm == 'Acc2E=14': + input_dict['job_type_1'] = input_dict['job_type_1'] + (f' integral=({integral_algorithm})') input_dict['job_type_1'] = "opt" if self.level.method_type not in ['dft', 'composite', 'wavefunction']\ else f"opt=({', '.join(key for key in keywords)})" diff --git a/arc/job/trsh.py b/arc/job/trsh.py index 15b9b5c603..10c5d7d79c 100644 --- a/arc/job/trsh.py +++ b/arc/job/trsh.py @@ -1937,7 +1937,8 @@ def trsh_keyword_opt_maxcycles(job_status, ess_trsh_methods, trsh_keyword, could new_opt_keyword = 'opt=(' + ','.join(filtered_methods) + ')' - trsh_keyword = [kw if not kw.startswith('opt') else new_opt_keyword for kw in trsh_keyword] + trsh_keyword = [kw for kw in trsh_keyword if not kw.startswith('opt')] + trsh_keyword.append(new_opt_keyword) return ess_trsh_methods, trsh_keyword, couldnt_trsh diff --git a/arc/job/trsh_test.py b/arc/job/trsh_test.py index 72513f495c..0a6e3c4fa0 100644 --- a/arc/job/trsh_test.py +++ b/arc/job/trsh_test.py @@ -398,7 +398,7 @@ def test_trsh_ess_job(self): num_heavy_atoms, cpu_cores, ess_trsh_methods) self.assertTrue(remove_checkfile) - self.assertEqual(ess_trsh_methods, ['change_node', 'int=(Acc2E=14)', 'checkfile=None', 'cartesian', 'NoSymm']) + self.assertEqual(ess_trsh_methods, ['change_node', 'int=(Acc2E=14)', 'checkfile=None', 'opt=(cartesian)', 'NoSymm']) self.assertEqual(trsh_keyword, ['opt=(cartesian)', 'int=(Acc2E=14)', 'nosymm'] ) # Gaussian: test 3 diff --git a/arc/settings/settings.py b/arc/settings/settings.py index 1514f16182..8924c1a431 100644 --- a/arc/settings/settings.py +++ b/arc/settings/settings.py @@ -817,28 +817,17 @@ def find_highest_version_in_directory(directory, name_contains): return None highest_version_path = None - highest_version = None + highest_version = () for folder in os.listdir(directory): file_path = os.path.join(directory, folder) if name_contains.lower() in folder.lower() and os.path.isdir(file_path): - # check if 'crest' is an executable file in the directory - crest_path = os.path.join(file_path, 'crest') - if os.path.isfile(crest_path) and os.access(crest_path, os.X_OK): - match = re.search(r"(\d+\.\d+(\.\d+)*)", folder) # Match version patterns like 1.0, 1.0.1 - if match: - version_str = match.group(1) - version = tuple(map(int, version_str.split('.'))) - if highest_version is None: - highest_version = version - highest_version_path = crest_path - elif version[0] > highest_version[0]: - highest_version = version - highest_version_path = crest_path - elif version[0] == highest_version[0] and version[1] > highest_version[1]: - highest_version = version - highest_version_path = crest_path - + crest_path = os.path.join(file_path, 'crest') + if os.path.isfile(crest_path) and os.access(crest_path, os.X_OK): + version = parse_version(folder) + if highest_version == () or version > highest_version: + highest_version = version + highest_version_path = crest_path return highest_version_path # Priority 1: Search in /Local/ce_dana for the highest version of 'crest' @@ -881,5 +870,39 @@ def find_highest_version_in_directory(directory, name_contains): # 'crest' not found return None, None +def parse_version(folder_name): + """ + Parses the version from the folder name and returns a tuple for comparison. + + Supports versions like: + - 3.0.2 + - v212 + - 2.1 + - 2 + + Args: + folder_name (str): The folder name containing the version. + + Returns: + tuple: A version tuple (major, minor, patch) + """ + version_regex = re.compile(r"(?:v?(\d+)(?:\.(\d+))?(?:\.(\d+))?)", re.IGNORECASE) + match = version_regex.search(folder_name) + if not match: + return (0, 0, 0) # Default version if none found + + major = int(match.group(1)) if match.group(1) else 0 + minor = int(match.group(2)) if match.group(2) else 0 + patch = int(match.group(3)) if match.group(3) else 0 + + # Handle specific cases + if major >= 100 and match.group(2) is None and match.group(3) is None: + # Example: v212 -> (2, 1, 2) + major = major // 100 + minor = (major % 100) // 10 + patch = major % 10 + + return (major, minor, patch) + CREST_PATH, CREST_ENV_PATH = find_crest_executable()