The following code used to work in Mathematica Version 12.1.1:

mol = Molecule["NC(Cc1ccc(O)c(I)c1)C(=O)O", IncludeHydrogens -> True];

{mol, {"DeleteAtom", 2}} //
Apply[MoleculeModify] //

The atom with index 2 is highlighted below:

enter image description here

In Mathematica Version 12.2.0, the code works up to the call to Apply[MoleculeModify]. But on invoking ConnectedMoleculeComponents I get the following errors:

During evaluation of In[415]:= KeyMap::invak: The argument >LibraryFunctionError[LIBRARY_FUNCTION_ERROR,6][atomPropertyAssociation] is not a >valid Association.

During evaluation of In[415]:= KeySort::invrl: The argument KeyMap[FromDigits][LibraryFunctionError[LIBRARY_FUNCTION_ERROR,6][atomPropertyAssociation]] is not a valid Association or a list of rules.

During evaluation of In[415]:= KeyValueMap::invak: The argument KeySort[KeyMap[FromDigits][LibraryFunctionError[LIBRARY_FUNCTION_ERROR,6][atomPropertyAssociation]]] is not a valid Association.

During evaluation of In[415]:= Molecule::nintrp: Unable to interpret LibraryFunctionError[LIBRARY_FUNCTION_ERROR,6][Atom[Missing[KeyAbsent,getAtomsList]]] as a name or chemical identifier.

Out[417]= MoleculeModify[Molecule[{ "N", "C", "C", "C", "C", "C", "O", "C", "I", "C", "C", "O", "O", "H", "H", "H", "H", "H", "H", "H", "H", "H"}, { Bond[{2, 3}, "Single"], Bond[{3, 4}, "Aromatic"], Bond[{4, 5}, "Aromatic"], Bond[{5, 6}, "Aromatic"], Bond[{6, 7}, "Single"], Bond[{6, 8}, "Aromatic"], Bond[{8, 9}, "Single"], Bond[{8, 10}, "Aromatic"], Bond[{11, 12}, "Double"], Bond[{11, 13}, "Single"], Bond[{10, 3}, "Aromatic"], Bond[{1, 14}, "Single"], Bond[{1, 15}, "Single"], Bond[{2, 16}, "Single"], Bond[{2, 17}, "Single"], Bond[{4, 18}, "Single"], Bond[{5, 19}, "Single"], Bond[{7, 20}, "Single"], Bond[{10, 21}, "Single"], Bond[{13, 22}, "Single"]}, {}], {"ExtractParts", {{2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 18, 19, 20, 21}, {11, 12, 13, 22}, {1, 14, 15}}}, ValenceErrorHandling -> False]

The last time I complained about breaking changes in the latest version, which was then Mathematica Version 12.1.0, I was admonished to first check the notice on incompatible changes. This time, I did check the link. But there is nothing at that link on ConnectedMoleculeComponents.

So, my questions are:

  1. Is there a workaround for this problem?
  2. Is there any hope of influencing Wolfram Research to publish a more thorough list of breaking changes, preferably weeks before the new version is out?

Thanks in advance for your help.

  • $\begingroup$ mathematica.meta.stackexchange.com/questions/190/… $\endgroup$
    – Jason B.
    Dec 17, 2020 at 23:45
  • $\begingroup$ An error spew like this is not an intentionally introduced change, it's a bug that I will try to fix. I'll post a workaround here later if no one else does it first. On your previous question you were not admonished to check that link, your question specifically asked where that information is posted. $\endgroup$
    – Jason B.
    Dec 18, 2020 at 0:11
  • $\begingroup$ @Jason B. thank you for adding the bugs tag. And I want to clarify that I meant "admonished" more as a recommendation than a reprimand. I was happy to learn of that list. It's just that I have a rather large code base that uses all of your chemistry packages extensively. But you've been very helpful in the past, so I don't doubt this will get fixed. $\endgroup$ Dec 18, 2020 at 1:23
  • $\begingroup$ you should take note of the change "AtomQ of Molecule objects now returns True." for 12.2. This means that you cannot use Part or First or similar functions on a Molecule, in the same way you cannot use those functions on a Graph. This was a good change going forward, but I am worried about its potential to break code. $\endgroup$
    – Jason B.
    Dec 18, 2020 at 2:30
  • $\begingroup$ I already did! I had a line like mol // {Apply[Sequence], myMolFunc} // Through, which I had to replace with mol // {{AtomList, BondList} /* Through /* Splice, myMolFunc} // Through. $\endgroup$ Dec 18, 2020 at 2:47

1 Answer 1


Until the bug is fixed, this should work as a replacement for ConnectedMoleculeComponents:

fixStereo[indices_, replacement_][stereo_] := If[
    SameQ[Complement[Select[Flatten @ Values @ stereo, IntegerQ], indices],
    replacement @ stereo, Nothing
moleculePart[mol_, indices_] := Module[
        atomlist = AtomList[mol, indices],
        bondlist = BondList[mol, indices],
        options = Options @ mol,
        fixIndices = ReplaceAll[Thread[indices -> Range[Length[indices]]]]
    options = Replace[
                HoldPattern[Rule[opt:AtomCoordinates | AtomDiagramCoordinates, x_]],
                opt -> Part[x, indices]
            HoldPattern[Rule[StereochemistryElements, x_List]] :> (StereochemistryElements -> Map[fixStereo[indices, fixIndices], x])
    Molecule[atomlist, fixIndices @ bondlist, options]
connectedMoleculeComponents[mol_] := Map[
    moleculePart[mol, #]&,
    ConnectedComponents @ MoleculeGraph @ mol

For the example it works just fine,

mol = Molecule["NC(Cc1ccc(O)c(I)c1)C(=O)O", IncludeHydrogens -> True] // 
    MoleculeModify[{"DeleteAtom", 2}] // connectedMoleculeComponents

enter image description here

  • $\begingroup$ Confirmed that this works for me. Thanks again, @Jason B. $\endgroup$ Dec 18, 2020 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.