Skip to content

Commit af103f3

Browse files
committed
TMP
1 parent bc9cad4 commit af103f3

11 files changed

Lines changed: 336 additions & 201 deletions

File tree

arc/job/adapters/ts/linear.py

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -221,40 +221,41 @@ def execute_incore(self):
221221
)
222222

223223
t0_0 = datetime.datetime.now()
224-
xyz_0 = interpolate(rxn=rxn, use_weights=False)
224+
xyzs_0 = interpolate(rxn=rxn, use_weights=False)
225225
t_ex_0 = datetime.datetime.now() - t0_0
226226

227227
t0_1 = datetime.datetime.now()
228-
xyz_1 = interpolate(rxn=rxn, use_weights=True)
228+
xyzs_1 = interpolate(rxn=rxn, use_weights=True)
229229
t_ex_1 = datetime.datetime.now() - t0_1
230230

231-
for method_index, (xyz, t0, t_ex) in enumerate(zip([xyz_0, xyz_1], [t0_0, t0_1], [t_ex_0, t_ex_1])):
232-
if colliding_atoms(xyz):
233-
continue
234-
unique = True
235-
for other_tsg in rxn.ts_species.ts_guesses:
236-
if almost_equal_coords(xyz, other_tsg.initial_xyz):
237-
if 'linear' not in other_tsg.method.lower():
238-
other_tsg.method += f' and Linear {method_index}'
239-
unique = False
240-
break
241-
if unique:
242-
ts_guess = TSGuess(method=f'linear {method_index}',
243-
index=len(rxn.ts_species.ts_guesses),
244-
method_index=method_index,
245-
t0=t0,
246-
execution_time=t_ex,
247-
success=True,
248-
family=family_label,
249-
xyz=xyz,
250-
)
251-
rxn.ts_species.ts_guesses.append(ts_guess)
252-
save_geo(xyz=xyz,
253-
path=self.local_path,
254-
filename=f'Linear {method_index}',
255-
format_='xyz',
256-
comment=f'Linear {method_index}, family: {family_label}',
257-
)
231+
for method_index, (xyzs, t0, t_ex) in enumerate(zip([xyzs_0, xyzs_1], [t0_0, t0_1], [t_ex_0, t_ex_1])):
232+
for xyz in xyzs:
233+
if colliding_atoms(xyz):
234+
continue
235+
unique = True
236+
for other_tsg in rxn.ts_species.ts_guesses:
237+
if almost_equal_coords(xyz, other_tsg.initial_xyz):
238+
if 'linear' not in other_tsg.method.lower():
239+
other_tsg.method += f' and Linear {method_index}'
240+
unique = False
241+
break
242+
if unique:
243+
ts_guess = TSGuess(method=f'linear {method_index}',
244+
index=len(rxn.ts_species.ts_guesses),
245+
method_index=method_index,
246+
t0=t0,
247+
execution_time=t_ex,
248+
success=True,
249+
family=family_label,
250+
xyz=xyz,
251+
)
252+
rxn.ts_species.ts_guesses.append(ts_guess)
253+
save_geo(xyz=xyz,
254+
path=self.local_path,
255+
filename=f'Linear {method_index}',
256+
format_='xyz',
257+
comment=f'Linear {method_index}, family: {family_label}',
258+
)
258259

259260
if len(self.reactions) < 5:
260261
successes = len([tsg for tsg in rxn.ts_species.ts_guesses if tsg.success and 'linear' in tsg.method])
@@ -275,7 +276,7 @@ def execute_queue(self):
275276

276277
def interpolate(rxn: 'ARCReaction',
277278
use_weights: bool = False,
278-
) -> Optional[dict]:
279+
) -> Optional[List[dict]]:
279280
"""
280281
Search for a TS by interpolating internal coords.
281282
@@ -284,7 +285,7 @@ def interpolate(rxn: 'ARCReaction',
284285
use_weights (bool, optional): Whether to use the well energies to determine relative interpolation weights.
285286
286287
Returns:
287-
Optional[dict]: The XYZ coordinates guess.
288+
Optional[List[dict]]: Entries are the XYZ coordinate guesses.
288289
"""
289290
if rxn.is_isomerization():
290291
return interpolate_isomerization(rxn=rxn, use_weights=use_weights)
@@ -295,7 +296,7 @@ def interpolate(rxn: 'ARCReaction',
295296

296297
def interpolate_isomerization(rxn: 'ARCReaction',
297298
use_weights: bool = False,
298-
) -> Optional[dict]:
299+
) -> Optional[List[dict]]:
299300
"""
300301
Search for a TS of an isomerization reaction by interpolating internal coords.
301302
@@ -304,23 +305,25 @@ def interpolate_isomerization(rxn: 'ARCReaction',
304305
use_weights (bool, optional): Whether to use the well energies to determine relative interpolation weights.
305306
306307
Returns:
307-
Optional[dict]: The XYZ coordinates guess.
308+
Optional[List[dict]]: Entries are the XYZ coordinate guesses.
308309
"""
309310
rxn.r_species[0].get_xyz()
310311
rxn.p_species[0].get_xyz()
311312
r_zmat = xyz_to_zmat(xyz=rxn.r_species[0].get_xyz(),
312313
consolidate=False,
313314
atom_order=list(range(sum(r.number_of_atoms for r in rxn.r_species))))
314-
p_zmat = xyz_to_zmat(xyz=rxn.p_species[0].get_xyz(),
315-
consolidate=False,
316-
atom_order=rxn.atom_map)
317315
weight = get_rxn_weight(rxn) if use_weights else 0.5
318-
if weight is None:
319-
return None
320-
ts_zmat = average_zmat_params(zmat_1=r_zmat, zmat_2=p_zmat, weight=weight)
321-
if ts_zmat is None:
316+
if weight is None or rxn.atom_maps is None:
322317
return None
323-
return zmat_to_xyz(ts_zmat)
318+
ts_xyzs = list()
319+
for atom_map in rxn.atom_maps:
320+
p_zmat = xyz_to_zmat(xyz=rxn.p_species[0].get_xyz(),
321+
consolidate=False,
322+
atom_order=atom_map)
323+
ts_zmat = average_zmat_params(zmat_1=r_zmat, zmat_2=p_zmat, weight=weight)
324+
if ts_zmat is not None:
325+
ts_xyzs.append(zmat_to_xyz(ts_zmat))
326+
return ts_xyzs
324327

325328

326329
def average_zmat_params(zmat_1: dict,

arc/job/adapters/ts/linear_test.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
from arc.species.zmat import _compare_zmats
2323

2424

25-
class TestHeuristicsAdapter(unittest.TestCase):
25+
class TestLinearAdapter(unittest.TestCase):
2626
"""
27-
Contains unit tests for the HeuristicsAdapter class.
27+
Contains unit tests for the LinearAdapter class.
2828
"""
2929

3030
@classmethod
@@ -129,7 +129,7 @@ def test_get_rxn_weight(self):
129129
rxn_1.ts_species.e0 = 391.6
130130
self.assertAlmostEquals(get_rxn_weight(rxn_1), 0.3417832)
131131

132-
def test_interpolate_isomerization(self):
132+
def test_interpolate_intra_h_migration(self):
133133
"""Test the interpolate_isomerization() function."""
134134
nc3h7_xyz = """C 0.00375165 -0.48895802 -1.20586379
135135
C 0.00375165 -0.48895802 0.28487510
@@ -164,8 +164,9 @@ def test_interpolate_isomerization(self):
164164
H 0.76979130 1.33747945 0.33815513
165165
H -0.04544494 0.70455273 1.77835334
166166
H -1.00071642 1.24557408 0.38839197""")
167-
ts_xyz = interpolate_isomerization(rxn, use_weights=False)
168-
self.assertTrue(almost_equal_coords(ts_xyz, expected_ts_xyz))
167+
ts_xyzs = interpolate_isomerization(rxn, use_weights=False)
168+
self.assertEqual(len(ts_xyzs), 2)
169+
self.assertTrue(almost_equal_coords(ts_xyzs[0], expected_ts_xyz))
169170

170171
nc3h7.e0 = 101.55
171172
ic3h7.e0 = 88.91
@@ -182,8 +183,51 @@ def test_interpolate_isomerization(self):
182183
H 0.79813573 1.38347069 0.43772483
183184
H -0.03897336 0.76031233 1.86961141
184185
H -0.97425159 1.33180895 0.47825005""")
185-
ts_xyz = interpolate_isomerization(rxn, use_weights=True)
186-
self.assertTrue(almost_equal_coords(ts_xyz, expected_ts_xyz))
186+
ts_xyzs = interpolate_isomerization(rxn, use_weights=True)
187+
self.assertTrue(almost_equal_coords(ts_xyzs[0], expected_ts_xyz))
188+
189+
def test_interpolate_no2_ono_isomerization(self):
190+
"""Test the interpolate_isomerization() function."""
191+
c2h5no2_xyz = """C -1.12362739 -0.04664655 -0.08575959
192+
C 0.24488022 -0.51587553 0.36119196
193+
N 0.57726975 -1.77875156 -0.37104243
194+
O 1.16476543 -1.66382529 -1.45384186
195+
O 0.24561669 -2.84385320 0.16410116
196+
H -1.87655344 -0.80826847 0.13962125
197+
H -1.14729169 0.14493421 -1.16405294
198+
H -1.41423043 0.87863077 0.42354512
199+
H 1.02430791 0.21530309 0.12674144
200+
H 0.27058353 -0.73979548 1.43184405"""
201+
c2h5ono_xyz = """C -1.36894499 0.07118059 -0.24801399
202+
C -0.01369535 0.17184136 0.42591278
203+
O -0.03967083 -0.62462610 1.60609048
204+
N 1.23538512 -0.53558048 2.24863846
205+
O 1.25629155 -1.21389295 3.27993827
206+
H -2.16063255 0.41812452 0.42429392
207+
H -1.39509985 0.66980796 -1.16284741
208+
H -1.59800183 -0.96960842 -0.49986392
209+
H 0.19191326 1.21800574 0.68271847
210+
H 0.76371340 -0.19234475 -0.25650067"""
211+
c2h5no2 = ARCSpecies(label='C2H5NO2', smiles='CC[N+](=O)[O-]', xyz=c2h5no2_xyz)
212+
c2h5ono = ARCSpecies(label='C2H5ONO', smiles='CCON=O', xyz=c2h5ono_xyz)
213+
214+
rxn = ARCReaction(r_species=[c2h5no2], p_species=[c2h5ono])
215+
expected_ts_xyz = str_to_xyz("""C 0.01099731 -0.46789926 -1.15958911
216+
C 0.01099731 -0.46789926 0.33114978
217+
C 0.01099731 0.94103865 0.90031155
218+
H 0.57795661 -1.24174248 -1.65467180
219+
H -0.39690222 0.34527841 -1.69240298
220+
H -1.19440431 -1.28933062 -0.47327539
221+
H 0.89689057 -1.16420498 0.45967951
222+
H 0.76979130 1.33747945 0.33815513
223+
H -0.04544494 0.70455273 1.77835334
224+
H -1.00071642 1.24557408 0.38839197""")
225+
ts_xyzs = interpolate_isomerization(rxn, use_weights=False)
226+
for xyz in ts_xyzs:
227+
print('\n\n\n')
228+
print(xyz_to_str(xyz))
229+
self.assertEqual(len(ts_xyzs), 1)
230+
self.assertTrue(almost_equal_coords(ts_xyzs[0], expected_ts_xyz))
187231

188232
@classmethod
189233
def tearDownClass(cls):

arc/mapping/driver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,13 @@ def map_rxn(rxn: 'ARCReaction',
257257
logger.error(f"Could not find isomorphism for scissored species: {[cut.mol.smiles for cut in p_cuts]}")
258258
return None
259259

260-
atom_map = map_pairs(pairs_of_reactant_and_products)
261-
if atom_map is not None:
262-
atom_map = glue_maps(atom_map, pairs_of_reactant_and_products)
260+
atom_map_list = map_pairs(pairs_of_reactant_and_products)
261+
if isinstance(atom_map_list, list) and all(e is not None for e in atom_map_list):
262+
atom_map = glue_maps(atom_map_list, pairs_of_reactant_and_products)
263263
atom_maps.append(atom_map)
264264

265+
print(f'atom_maps: {atom_maps}')
266+
265267
return atom_maps
266268

267269

arc/mapping/driver_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,32 @@ def test_map_intra_h_migration(self):
10471047
self.assertIn(atom_map[7], [3, 4, 5, 8])
10481048
self.assertIn(atom_map[8], [3, 4, 5, 8])
10491049

1050+
ic3h7_xyz = """C -0.40735690 -0.74240205 -0.34312948
1051+
C 0.38155377 -0.25604705 0.82450968
1052+
C 0.54634593 1.25448345 0.81064511
1053+
H 0.00637731 -1.58836501 -0.88041673
1054+
H -0.98617584 -0.01198912 -0.89732723
1055+
H -1.29710684 -1.29092340 0.08598983
1056+
H 1.36955428 -0.72869684 0.81102246
1057+
H 1.06044877 1.58846788 -0.09702437
1058+
H 1.13774084 1.57830484 1.67308862
1059+
H -0.42424546 1.75989927 0.85794283"""
1060+
nc3h7_xyz = """C 0.00375165 -0.48895802 -1.20586379
1061+
C 0.00375165 -0.48895802 0.28487510
1062+
C 0.00375165 0.91997987 0.85403684
1063+
H 0.41748586 -1.33492098 -1.74315104
1064+
H -0.57506729 0.24145491 -1.76006154
1065+
H -0.87717095 -1.03203740 0.64280162
1066+
H 0.88948616 -1.02465371 0.64296621
1067+
H 0.88512433 1.48038223 0.52412379
1068+
H 0.01450405 0.88584135 1.94817394
1069+
H -0.88837301 1.47376959 0.54233121"""
1070+
rxn_1 = ARCReaction(r_species=[ARCSpecies(label='iC3H7', smiles='C[CH]C', xyz=ic3h7_xyz)],
1071+
p_species=[ARCSpecies(label='nC3H7', smiles='[CH2]CC', xyz=nc3h7_xyz)])
1072+
print('---------')
1073+
print(rxn_1.atom_maps[0])
1074+
self.assertEqual(rxn_1.atom_maps[0], [0, 1, 2, 6, 3, 4, 5, 7, 8, 9])
1075+
10501076
def test_map_isomerization_reaction(self):
10511077
"""Test the map_isomerization_reaction() function."""
10521078
reactant_xyz = """C -1.3087 0.0068 0.0318

arc/mapping/engine.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,23 +1088,18 @@ def make_bond_changes(rxn: 'ARCReaction',
10881088
def assign_labels_to_products(rxn: 'ARCReaction',
10891089
p_label_dict: dict):
10901090
"""
1091-
Add the indices to the reactants and products.
1091+
Add labels to the atoms of the reactants and products.
10921092
10931093
Args:
10941094
rxn: ARCReaction object to be mapped
10951095
p_label_dict: the labels of the products
1096-
Consider changing in rmgpy.
1097-
1098-
Returns:
1099-
Adding labels to the atoms of the reactants and products, to be identified later.
11001096
"""
1101-
11021097
atom_index = 0
1103-
for product in rxn.p_species:
1104-
for atom in product.mol.atoms:
1098+
for product_ in rxn.p_species:
1099+
for atom in product_.mol.atoms:
11051100
if atom_index in p_label_dict.values() and (atom.label is str or atom.label is None):
11061101
atom.label = key_by_val(p_label_dict,atom_index)
1107-
atom_index+=1
1102+
atom_index += 1
11081103

11091104

11101105
def update_xyz(spcs: List[ARCSpecies]) -> List[ARCSpecies]:
@@ -1169,7 +1164,7 @@ def pairing_reactants_and_products_for_mapping(r_cuts: List[ARCSpecies],
11691164

11701165
def map_pairs(pairs):
11711166
"""
1172-
A function that maps the mached species together
1167+
A function that maps the matched species together.
11731168
11741169
Args:
11751170
pairs: A list of the pairs of reactants and species
@@ -1181,7 +1176,6 @@ def map_pairs(pairs):
11811176
maps = list()
11821177
for pair in pairs:
11831178
maps.append(map_two_species(pair[0], pair[1]))
1184-
11851179
return maps
11861180

11871181

@@ -1196,20 +1190,23 @@ def label_species_atoms(spcs):
11961190
for spc in spcs:
11971191
for atom in spc.mol.atoms:
11981192
atom.label = str(index)
1199-
index+=1
1193+
index += 1
12001194

12011195

1202-
def glue_maps(maps, pairs_of_reactant_and_products):
1196+
def glue_maps(maps: List[List[int]],
1197+
pairs_of_reactant_and_products: List[Tuple[ARCSpecies, ARCSpecies]]
1198+
) -> List[int]:
12031199
"""
12041200
a function that joins together the maps from the parts of the reaction.
12051201
12061202
Args:
1207-
rxn: ARCReaction that requires atom mapping
1208-
maps: The list of all maps of the isomorphic cuts.
1203+
maps (List[List[int]]): The list of all maps of the isomorphic cuts.
1204+
pairs_of_reactant_and_products (List[Tuple[ARCSpecies, ARCSpecies]]): The list of all pairs of reactants and products.
12091205
12101206
Returns:
1211-
an Atom Map of the compleate reaction.
1207+
List[int]: An Atom Map of the complete reaction.
12121208
"""
1209+
# print(f'maps: {maps}, pairs_of_reactant_and_products: {pairs_of_reactant_and_products}')
12131210
am_dict = dict()
12141211
for _map, pair in zip(maps, pairs_of_reactant_and_products):
12151212
r_atoms = pair[0].mol.atoms
@@ -1221,16 +1218,16 @@ def glue_maps(maps, pairs_of_reactant_and_products):
12211218

12221219
def determine_bdes_on_spc_based_on_atom_labels(spc: "ARCSpecies", bde: Tuple[int, int]) -> bool:
12231220
"""
1224-
A function for determining whether or not the species in question containt the bond specified by the bond dissociation indices.
1221+
A function for determining whether the species in question contains the bond specified by the bond dissociation indices.
12251222
Also, assigns the correct BDE to the species.
12261223
12271224
Args:
12281225
spc (ARCSpecies): The species in question, with labels atom indices.
12291226
bde (Tuple[int, int]): The bde in question.
1230-
add_bdes (bool): Whether or not to add the bde to the species.
1227+
add_bdes (bool): Whether to add the bde to the species.
12311228
12321229
Returns:
1233-
bool: Whether or not the bde is based on the atom labels.
1230+
bool: Whether the bde is based on the atom labels.
12341231
"""
12351232
bde = convert_list_index_0_to_1(bde, direction=-1)
12361233
index1, index2 = bde[0], bde[1]

arc/mapping/engine_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def test_glue_maps(self):
698698
rxn_1_test.determine_family(self.db)
699699
rmg_reactions = get_rmg_reactions_from_arc_reaction(arc_reaction=rxn_1_test, backend="ARC")
700700
r_label_dict, p_label_dict = get_atom_indices_of_labeled_atoms_in_an_rmg_reaction(arc_reaction=rxn_1_test,
701-
rmg_reaction=rmg_reactions[0])
701+
rmg_reaction=rmg_reactions[0])
702702
assign_labels_to_products(rxn_1_test, p_label_dict)
703703
reactants, products = copy_species_list_for_mapping(rxn_1_test.r_species), copy_species_list_for_mapping(rxn_1_test.p_species)
704704
label_species_atoms(reactants), label_species_atoms(products)
@@ -709,7 +709,7 @@ def test_glue_maps(self):
709709
p_cuts = cut_species_based_on_atom_indices(products, p_bdes)
710710
pairs_of_reactant_and_products = pairing_reactants_and_products_for_mapping(r_cuts, p_cuts)
711711
maps = map_pairs(pairs_of_reactant_and_products)
712-
atom_map = glue_maps(maps,pairs_of_reactant_and_products)
712+
atom_map = glue_maps(maps, pairs_of_reactant_and_products)
713713
self.assertEqual(len(atom_map), self.r_1.mol.get_num_atoms() + self.r_2.mol.get_num_atoms())
714714
atoms_r = [atom for atom in self.r_1.mol.copy(deep=True).atoms] + [atom for atom in self.r_2.mol.copy(deep=True).atoms]
715715
atoms_p = [atom for atom in self.p_1.mol.copy(deep=True).atoms] + [atom for atom in self.p_2.mol.copy(deep=True).atoms]

0 commit comments

Comments
 (0)