From 9fcebe4c62ce8d64c3daa8dad1fc112aef6700ad Mon Sep 17 00:00:00 2001 From: Alon Grinberg Dana Date: Sun, 27 Oct 2024 21:21:29 +0200 Subject: [PATCH] Added converter.add_bond_order_to_s_mol() --- arc/species/converter.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arc/species/converter.py b/arc/species/converter.py index adf59fb45d..856d6ca2c5 100644 --- a/arc/species/converter.py +++ b/arc/species/converter.py @@ -1670,6 +1670,34 @@ def order_atoms(ref_mol, mol): raise SanitizationError('Could not map non isomorphic molecules') +def add_bond_order_to_s_mol(s_mol: Molecule, + bo_mol: Molecule, + ) -> Molecule: + """ + Add bond orders to a molecule with only single bonds. + + Args: + s_mol (Molecule): The RMG Molecule object with only single bonds. + bo_mol (Molecule): The RMG Molecule object with bond orders. + + Returns: + Molecule: The respective Molecule object with atom order as in s)mol and with bond orders as in bo_mol. + """ + s_mol_copy = s_mol.copy(deep=True) + order_atoms(ref_mol=s_mol_copy, mol=bo_mol) + for s_atom, b_atom in zip(s_mol_copy.atoms, bo_mol.atoms): + s_atom.radical_electrons = b_atom.radical_electrons + s_atom.lone_pairs = b_atom.lone_pairs + s_atom.charge = b_atom.charge + for b_bond in b_atom.bonds.values(): + s_mol_copy.get_bond(s_mol_copy.atoms[bo_mol.atoms.index(b_bond.atom1)], s_mol_copy.atoms[bo_mol.atoms.index(b_bond.atom2)]).set_order_num(b_bond.get_order_num()) + try: + s_mol_copy.update_atomtypes(raise_exception=False) + except KeyError: + logger.debug('Could not update atom types for the species') + return s_mol_copy + + def update_molecule(mol: Molecule, to_single_bonds: bool=False, ) -> Optional[Molecule]: