def get_truncated_ts(reaction, bond_rearr): """Get the TS of a truncated reactant and product complex""" # Truncate the reactant and product complex to the core atoms so the full # TS can be template-d f_reactant = reaction.reactant.copy() f_product = reaction.product.copy() # Set the truncated reactant and product for this reaction reaction.reactant = get_truncated_complex(f_reactant, bond_rearr) reaction.product = get_truncated_complex(f_product, bond_rearr) # Re-find the bond rearrangements, which should exist reaction.name += '_truncated' bond_rearrangs = get_bond_rearrangs(reaction.reactant, reaction.product, name=reaction.name) if bond_rearrangs is None: logger.error('Truncation generated a complex with 0 rearrangements') return None # Find all the possible TSs for bond_rearr in bond_rearrangs: get_ts(reaction, reaction.reactant, bond_rearr, is_truncated=True) # Reset the reactant, product and name of the full reaction reaction.reactant = f_reactant reaction.product = f_product reaction.name = reaction.name.rstrip('_truncated') logger.info('Done with truncation') return None
def test_enone_truncation(): enone = Reactant(name='enone', smiles='CC(O)=CC(=O)OC') reactant = ReactantComplex(enone) bond_rearr = BondRearrangement(breaking_bonds=[(2, 11)], forming_bonds=[(11, 5)]) truncated = get_truncated_complex(reactant, bond_rearr) assert truncated.n_atoms == 10 assert truncated.graph.number_of_edges() == 9
def test_product_complex_truncation(): # H atom transfer from methane to ethene bond_rearr = BondRearrangement(breaking_bonds=[(0, 1)], forming_bonds=[(1, 5)]) methane_ethene = ReactantComplex(methane, ethene, name='product_complex') # Should retain all atoms truncated = get_truncated_complex(methane_ethene, bond_rearr) assert truncated.n_atoms == 11
def test_reactant_complex_truncation(): # Non-sensical bond rearrangement bond_rearr = BondRearrangement(forming_bonds=[(0, 1)], breaking_bonds=[(0, 5)]) methane_dimer = ReactantComplex(methane, methane) # Should not truncate methane dimer at all truncated = get_truncated_complex(methane_dimer, bond_rearr) assert truncated.n_atoms == 10
def test_two_component_truncation(): propylbromide = Reactant(name='RBr', atoms=xyz_file_to_atoms('RBr.xyz')) chloride = Reactant(name='Cl', smiles='[Cl-]') mol = ReactantComplex(chloride, propylbromide) bond_rearr = BondRearrangement(forming_bonds=[(0, 3)], breaking_bonds=[(3, 4)]) truncated = get_truncated_complex(r_complex=mol, bond_rearrangement=bond_rearr) # Should truncate to ethylbromide + Cl- assert truncated.n_atoms == 9
def test_large_truncation(): mol = ReactantComplex( Reactant(name='product', atoms=xyz_file_to_atoms('product.xyz'))) bond_rearr = BondRearrangement(breaking_bonds=[(7, 8), (14, 18)]) assert mol.n_atoms == 50 truncated = get_truncated_complex(r_complex=mol, bond_rearrangement=bond_rearr) assert truncated.n_atoms == 27 assert truncated.graph.number_of_edges() == 28
def test_core_strip(): bond_rearr = BondRearrangement() bond_rearr.active_atoms = [0] stripped = get_truncated_complex(methane, bond_rearr) # Should not strip any atoms if the carbon is designated as active assert stripped.n_atoms == 5 stripped = get_truncated_complex(ethene, bond_rearr) assert stripped.n_atoms == 6 bond_rearr.active_atoms = [1] # Propene should strip to ethene if the terminal C=C is the active atom stripped = get_truncated_complex(propene, bond_rearr) assert stripped.n_atoms == 6 assert is_isomorphic(stripped.graph, ethene.graph) # But-1-ene should strip to ethene if the terminal C=C is the active atom stripped = get_truncated_complex(but1ene, bond_rearr) assert stripped.n_atoms == 6 assert is_isomorphic(stripped.graph, ethene.graph) # Benzene shouldn't be truncated at all stripped = get_truncated_complex(benzene, bond_rearr) assert stripped.n_atoms == 12 bond_rearr.active_atoms = [0] # Ethanol with the terminal C as the active atom should not replace the OH # with a H stripped = get_truncated_complex(ethanol, bond_rearr) assert stripped.n_atoms == 9 # Ether with the terminal C as the active atom should replace the OMe with # OH stripped = get_truncated_complex(methlyethylether, bond_rearr) assert stripped.n_atoms == 9 assert is_isomorphic(stripped.graph, ethanol.graph)