Skip to content

Commit

Permalink
Added cut_species_based_on_atom_indices function
Browse files Browse the repository at this point in the history
This function uses the new, faster and more accurate method for performing the scissoring for atom mapping. Instead of assigning the BDE's to the relevant species, which causes issues when further scissions are performed, this function uses the atom indices to perform the scission.
  • Loading branch information
kfir4444 committed Sep 22, 2023
1 parent 5f0fc69 commit 51bd1ec
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions arc/mapping/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,3 +1255,39 @@ def determine_bdes_indices_based_on_atom_labels(spc, bde):
return atoms[1] in atoms[0].bonds.keys()
else:
return False


def cut_species_based_on_atom_indices(species: List["ARCSpecies"], bdes: List[Tuple[int, int]]) -> List["ARCSpecies"]:
"""
A function for scissoring species based on their atom indices.
Args:
species (List[ARCSpecies]): The species list that requires scission.
bdes (List[Tuple[int, int]]): A list of the atoms between which the bond should be scissored. The atoms are described using the atom labels, and not the actuall atom positions.
Returns:
List[ARCSpecies]: The species after scission.
"""
if not bdes:
return species

for bde in bdes:
for index, spc in enumerate(species):
if determine_bdes_indices_based_on_atom_labels(spc, bde):
candidate = species.pop(index)
candidate.final_xyz = candidate.get_xyz()
if candidate.mol.copy(deep=True).smiles == "[H][H]":
labels = [atom.label for atom in candidate.mol.copy(deep=True).atoms]
try:
H1 = candidate.scissors()[0]
except SpeciesError:
return None
H2 = H1.copy()
H2.mol.atoms[0].label = labels[0] if H1.mol.atoms[0].label != labels[0] else labels[1]
species += [H1, H2]
else:
try:
species += candidate.scissors()
except SpeciesError as e:
print(e)
break

return species

0 comments on commit 51bd1ec

Please sign in to comment.