I would like to identify the atom that used to participate in a bond before the molecule was modified by MoleculeModify[mol, {"DeleteBond", {idx1, idx2}}]
.
According to the official documentation of MoleculeModify
:
When removing or replacing an atom, the number of explicit hydrogen atoms may be adjusted to maintain proper valence. Disconnected hydrogen atoms will be removed.
This suggests to me that I should be able to find the formerly participating atom in the connected component by finding the current bond that features the highest atomic index (mol // AtomList // Length
).
My questions are:
Is the new hydrogen atom, added to balance out the valences, always guaranteed to have the highest index in the list of atoms of the connected component? (In other words, is such an approach robust?)
Is there a better way to do this?
EDIT
As per Jason's request, here is some code to better illustrate the question.
ClearAll[mol];
mol = Molecule[
"O=C1C(Cc2ccc(O)cc2)N2C(=O)CCN(C(=O)Nc3ccccc3)C2CN1Cc1cccc2ccccc12"
];
ClearAll[getIdxOfAtomInDeletedBond];
getIdxOfAtomInDeletedBond[mol_] := mol // (
{
BondList,
Bond[{OrderlessPatternSequence[Length @ AtomList @ #, _]}, _] &
} /* Through /* Apply[Cases] /*
{First, #[[1, 1]] & /* Min} /* Through
);
mol //
{
(* Original molecule *)
MoleculePlot[#, {Bond[{30, 31}]}] &,
(* Randomly selected component after the deletion of the bond *)
MoleculeModify[#, {"DeleteBond", {30, 31}}] & /*
WLBugFix`connectedMolComps /* RandomChoice /*
(MoleculePlot[#, getIdxOfAtomInDeletedBond[#]] &)
} // Through
Please note that WLBugFix``connectedMolComps
is the temporary bug fix for ConnectedMoleculeComponents
as per this question.
Here is a sample output (sample because there is a random selection from the connected components):
In the code above, the indices {30, 31}
are provided, but in the actual run of the application, the indices are determined by a number of different probabilistic factors.
In the general case, we cannot expect the same range of atomic indices to be available in the selected component after the deletion of the bond. This is illustrated here by the fact that the molecule on the right cannot possibly have atoms with indices 30 or 31.
However, I would still like to know which atom on the right used to participate in the deleted bond in the parent molecule. It is shown in blue here, and computed by the means detailed in the code.
I just wanted to know if this is a robust way of calculating this, or if there is indeed a better way.
getIdxOfAtomInDeletedBond
a bit difficult to read. The combination of right-composition infix operators with postfix andThrough
is very unfamiliar to me. I personally find something using modules like this to be more digestible when reading code I didn't write. Lastly, you useLength @ AtomList @ mol
whereAtomCount
is more direct. $\endgroup$