Skip to content

Commit b7eb9f1

Browse files
committed
Merge branch 'crest' into crest_debug_statement
2 parents 40dbf34 + 04755cf commit b7eb9f1

File tree

2 files changed

+73
-19
lines changed

2 files changed

+73
-19
lines changed

arc/job/adapters/ts/heuristics.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from arc.job.adapters.common import _initialize_adapter, ts_adapters_by_rmg_family
3737
from arc.job.factory import register_job_adapter
3838
from arc.plotter import save_geo
39-
from arc.species.converter import compare_zmats, relocate_zmat_dummy_atoms_to_the_end, zmat_from_xyz, zmat_to_xyz, str_to_xyz, xyz_to_str
39+
from arc.species.converter import compare_zmats, relocate_zmat_dummy_atoms_to_the_end, zmat_from_xyz, zmat_to_xyz, str_to_xyz, xyz_to_str, str_to_str
4040
from arc.mapping.engine import map_arc_rmg_species, map_two_species
4141
from arc.species.species import ARCSpecies, TSGuess, colliding_atoms
4242
from arc.species.zmat import get_parameter_from_atom_indices, remove_1st_atom, up_param
@@ -1097,28 +1097,30 @@ def h_abstraction(arc_reaction: 'ARCReaction',
10971097
second_lowest = unique_sorted_values[1]
10981098
print(f"The second lowest unique value in H21 is: {second_lowest}")
10991099
cols_second_lowest = h_row[h_row == second_lowest].index.tolist()
1100-
else:
1101-
crest_run = False
1102-
print("H21 does not have a second lowest unique value. Will not do CREST")
1103-
1104-
if len(cols_second_lowest) == 1:
11051100

1106-
h_str = row_col_pairs[0][0] # 'H21'
1107-
print(f"h str = {h_str}")
1108-
b_str = row_col_pairs[0][1] # 'C14'
1109-
print(f"b str {b_str}")
1110-
a_str = cols_second_lowest[0] # 'C4'
1111-
print(f"a str {a_str}")
1101+
if len(cols_second_lowest) == 1:
1102+
1103+
h_str = row_col_pairs[0][0] # 'H21'
1104+
print(f"h str = {h_str}")
1105+
b_str = row_col_pairs[0][1] # 'C14'
1106+
print(f"b str {b_str}")
1107+
a_str = cols_second_lowest[0] # 'C4'
1108+
print(f"a str {a_str}")
11121109

1113-
h = int(re.findall(r'\d+', h_str)[0])
1114-
b = int(re.findall(r'\d+', b_str)[0])
1115-
a = int(re.findall(r'\d+', a_str)[0])
1110+
h = int(re.findall(r'\d+', h_str)[0])
1111+
b = int(re.findall(r'\d+', b_str)[0])
1112+
a = int(re.findall(r'\d+', a_str)[0])
11161113

1117-
# log info a, b, h1, h2, b_atom, a_atom, h_atom, val_inc
1118-
logger.info(f'a: {a}, b: {b}, h: {h}')
1114+
# log info a, b, h1, h2, b_atom, a_atom, h_atom, val_inc
1115+
logger.info(f'a: {a}, b: {b}, h: {h}')
1116+
else:
1117+
crest_run = False
1118+
print(f"Received more than one result for second lowest: {cols_second_lowest}")
11191119
else:
11201120
crest_run = False
1121-
print(f"Received more than one result for second lowest: {cols_second_lowest}")
1121+
print("H21 does not have a second lowest unique value. Will not do CREST")
1122+
1123+
11221124

11231125
####
11241126

arc/species/converter.py

+53-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,59 @@ def str_to_str(xyz_str: str,
7171
"""
7272
if not isinstance(xyz_str, str):
7373
raise ConverterError(f'Expected a string input, got {type(xyz_str)}')
74-
pass
74+
if project_directory is not None and os.path.isfile(os.path.join(project_directory, xyz_str)):
75+
xyz_str = os.path.join(project_directory, xyz_str)
76+
77+
78+
BOHR_TO_ANGSTROM = 0.529177
79+
ANGSTROM_TO_BOHR = 1.8897259886
80+
81+
if convert_to.lower() == 'angstrom':
82+
conversion_factor = BOHR_TO_ANGSTROM
83+
elif convert_to.lower() == 'bohr':
84+
conversion_factor = ANGSTROM_TO_BOHR
85+
else:
86+
raise ValueError("Invalid target unit. Choose 'angstrom' or 'bohr'.")
87+
88+
89+
processed_lines = list()
90+
# Split the string into lines
91+
lxyz = xyz_str.strip().split()
92+
93+
atom_first = False if is_str_float(lxyz[0]) else True
94+
lxyz = xyz_str.strip().splitlines()
95+
96+
for idx, item in enumerate(lxyz):
97+
parts = item.strip().split()
98+
99+
if len(parts) != 4:
100+
raise ConverterError(f'xyz_str has an incorrect format, expected 4 elements in each line, '
101+
f'got "{item}" in:\n{xyz_str}')
102+
if atom_first:
103+
atom, x_str, y_str, z_str = parts
104+
else:
105+
x_str, y_str, z_str, atom = parts
106+
107+
try:
108+
x = float(x_str) * conversion_factor
109+
y = float(y_str) * conversion_factor
110+
z = float(z_str) * conversion_factor
111+
112+
except ValueError:
113+
raise ConverterError(f'Could not convert {x_str}, {y_str}, or {z_str} to floats.')
114+
115+
if reverse_atoms and atom_first:
116+
formatted_line = f'{x} {y} {z} {atom}'
117+
elif reverse_atoms and not atom_first:
118+
formatted_line = f'{atom} {x} {y} {z}'
119+
elif not reverse_atoms and atom_first:
120+
formatted_line = f'{atom} {x} {y} {z}'
121+
elif not reverse_atoms and not atom_first:
122+
formatted_line = f'{x} {y} {z} {atom}'
123+
124+
processed_lines.append(formatted_line)
125+
126+
return '\n'.join(processed_lines)
75127

76128

77129
def str_to_xyz(xyz_str: str,

0 commit comments

Comments
 (0)