Skip to content

Commit c92d637

Browse files
committed
Some modifications to get generate_tree to run on families with own_reverse==True but don't have reverseMap defined in their groups.py file
1 parent b18deff commit c92d637

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

rmgpy/data/kinetics/family.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,111 @@ def fill_rules_by_averaging_up(self, verbose=False):
13351335
DeprecationWarning)
13361336
return
13371337
self.rules.fill_rules_by_averaging_up(self.get_root_template(), {}, verbose)
1338+
1339+
1340+
1341+
def make_reverse_map_for_family_with_own_reverse(self):
1342+
"""
1343+
Separating out the hardcoded relabeling of atoms that in apply_recipe. A reverse_map can now be created
1344+
for these specific families without calling apply_recipe.
1345+
"""
1346+
1347+
#check to make sure the family doesn't already have a reverse_map:
1348+
if self.reverse_map:
1349+
logging.error('Family already has reverse_map.')
1350+
return
1351+
1352+
1353+
1354+
label = self.label.lower()
1355+
1356+
# If reaction family is its own reverse, relabel atoms
1357+
# Unfortunately, reaction family info is
1358+
# hardcoded, so this must be updated if the database changes.
1359+
if not self.reverse_template:
1360+
1361+
# key: atom_labeling in forward direction, value: atom label in reverse direction
1362+
atom_labels = {}
1363+
1364+
1365+
if label in ('1,2_xy_interchange'):
1366+
# Labels for nodes are swapped
1367+
atom_labels['*1'] = '*4'
1368+
atom_labels['*4'] = '*1'
1369+
1370+
if label in ('h_abstraction','f_abstraction','cl_abstraction','br_abstraction'):
1371+
# '*2' is the H that migrates
1372+
# it moves from '*1' to '*3'
1373+
atom_labels['*1'] = '*3'
1374+
atom_labels['*3'] = '*1'
1375+
1376+
elif label == 'intra_h_migration':
1377+
# '*3' is the H that migrates
1378+
# swap the two ends between which the H moves
1379+
atom_labels['*1'] = '*2'
1380+
atom_labels['*2'] = '*1'
1381+
# reverse all the atoms in the chain between *1 and *2
1382+
highest = len(atom_labels)
1383+
if highest > 4:
1384+
# swap *4 with *5
1385+
atom_labels['*4'] = '*5'
1386+
atom_labels['*5'] = '*4'
1387+
if highest > 6:
1388+
# swap *6 with the highest, etc.
1389+
for i in range(6, highest + 1):
1390+
atom_labels['*{0:d}'.format(i)].label = '*{0:d}'.format(6 + highest - i)
1391+
1392+
elif label == 'intra_ene_reaction':
1393+
# Labels for nodes are swapped
1394+
atom_labels['*1'] = '*2'
1395+
atom_labels['*2'] = '*1'
1396+
atom_labels['*3'] = '*5'
1397+
atom_labels['*5'] = '*3'
1398+
1399+
elif label == '6_membered_central_c-c_shift':
1400+
# Labels for nodes are swapped
1401+
atom_labels['*1'] = '*3'
1402+
atom_labels['*3'] = '*1'
1403+
atom_labels['*4'] = '*6'
1404+
atom_labels['*6'] = '*4'
1405+
1406+
elif label == '1,2_shiftc':
1407+
# Labels for nodes are swapped
1408+
atom_labels['*2'] = '*3'
1409+
atom_labels['*3'] = '*2'
1410+
self.reverse_map = atom_labels
1411+
1412+
elif label == 'intra_r_add_exo_scission':
1413+
# Labels for nodes are swapped
1414+
atom_labels['*1'] = '*3'
1415+
atom_labels['*3'] = '*1'
1416+
1417+
elif label == 'intra_substitutions_isomerization':
1418+
# Swap *2 and *3
1419+
atom_labels['*2'] = '*3'
1420+
atom_labels['*3'] = '*2'
1421+
1422+
elif label == 'surface_abstraction':
1423+
atom_labels['*1'] = '*3'
1424+
atom_labels['*2'] = '*5'
1425+
atom_labels['*3'] = '*1'
1426+
atom_labels['*5'] = '*2'
1427+
1428+
elif label == 'surface_abstraction_single_vdw':
1429+
# *3 migrates from *2-*1 to *4-*5
1430+
# so swap *1 with *5, swap *2 with *4
1431+
atom_labels['*1'] = '*5'
1432+
atom_labels['*5'] = '*1'
1433+
atom_labels['*2'] = '*4'
1434+
atom_labels['*4'] = '*2'
1435+
1436+
if atom_labels == {}: #if this wasn't one of the families with hardcoded reverse mapping
1437+
logging.error('No hardcoded relabeling of atoms in for this family. Cannot generate a reverse map for this family.')
1438+
return
1439+
else:
1440+
self.reverse_map=atom_labels
1441+
return
1442+
13381443

13391444
def apply_recipe(self, reactant_structures, forward=True, unique=True, relabel_atoms=True):
13401445
"""
@@ -3286,6 +3391,10 @@ def generate_tree(self, rxns=None, obj=None, thermo_database=None, T=1000.0, npr
32863391
stratum_num: Number of strata used in stratified sampling scheme
32873392
max_rxns_to_reopt_node: Nodes with more matching reactions than this will not be pruned
32883393
"""
3394+
3395+
if self.own_reverse and not self.reverse_template:
3396+
self.make_reverse_map_for_family_with_own_reverse()
3397+
32893398
if rxns is None:
32903399
rxns = self.get_training_set(thermo_database=thermo_database, remove_degeneracy=True, estimate_thermo=True,
32913400
fix_labels=True, get_reverse=True, rxns_with_kinetics_only=True)

0 commit comments

Comments
 (0)