Skip to content

Commit

Permalink
Enhance GaussianAdapter to support integral algorithm in job type and…
Browse files Browse the repository at this point in the history
… update TRSH keyword handling. Refactor find_crest_executable for improved version parsing and comparison.
  • Loading branch information
calvinp0 committed Dec 25, 2024
1 parent f46e696 commit c093709
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
3 changes: 3 additions & 0 deletions arc/job/adapters/gaussian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})"

Expand Down
3 changes: 2 additions & 1 deletion arc/job/trsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion arc/job/trsh_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
59 changes: 41 additions & 18 deletions arc/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()

0 comments on commit c093709

Please sign in to comment.