I am trying to download properties of compounds from PubChem using ServiceExecute. However, I only possess names of compounds as strings. It appears that ServiceExecute exits completely even if the one of compound lookups fails and returns no output for the rest that worked out. I wonder if there is a way to change this behavior, so that I can get the data for the compounds that worked correctly. A minimal example is shown below:

chems = {"(+)-a-pinene", "(+)-camphene", "(-)-a-pinene", "(-)-b-citronellol", "(-)-camphene"};

ServiceExecute["PubChem", "CompoundProperties", {"Name" -> chems[[2]]}]

This works because camphene is interpreted correctly. However, if I try the entire list of names,

ServiceExecute["PubChem", "CompoundProperties", {"Name" -> chems}]

I get the following error message

During evaluation of In[131]:= ServiceExecute::serrormsg: Server error. Error message: No CID found Server error. Error message: No CID found

Is there a way to get ServiceExecute to keep going when it encounters an error and return the properties for which the call worked?


Version Information: Running Mathematica v13 on Linux box (Ubuntu 20.04 LTS).

  • 2
    $\begingroup$ My very naive and simple solution is to map over every single compound name: ServiceExecute["PubChem", "CompoundProperties", {"Name" -> #}] & /@ chems. $\endgroup$
    – Domen
    Jan 27, 2022 at 16:02
  • $\begingroup$ Yes, that is a workaround. However, I am hoping that there is a cleaner way to use ServiceExecute. $\endgroup$
    – bhopshang
    Jan 27, 2022 at 16:17

1 Answer 1


Another workaround:


(* "13.0.0 for Mac OS X x86 (64-bit) (December 3, 2021)" *)


Look for interpreter types related to chemistry

 Length@StringCases[#, "chem", IgnoreCase -> True] > 0 &]

(* {"Chemical", "ChemicalClass", "ComputedChemical", \
"ComputedFamousChemistryProblem", "FamousChemistryProblem"} *)

chems = {"(+)-a-pinene", "(+)-camphene", "(-)-a-pinene", "(-)-b-citronellol", 

Select elements of chems that are interpreted as computed chemicals.

chems2 = Select[chems, 
   FreeQ[Interpreter["ComputedChemical"][#], Failure] &] //

(* {"(+)-camphene", "(-)-camphene"} *)


ServiceExecute["PubChem", "CompoundProperties", {"Name" -> chems2}]
  • $\begingroup$ Thank you, I have accepted your answer. However, I still hope that ServiceExecute turns out to have a better error handling mechanism. $\endgroup$
    – bhopshang
    Jan 28, 2022 at 10:51

Your Answer

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

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