4
$\begingroup$

I want to place a number on each atom (on a sphere) upon 3D plotting a molecule. For example, from:

mol = Molecule["h2co"]; MoleculePlot3D[m, {1, 2, 3, 4}, PlotLegends -> {"1", "2", "3", "4"}]

I get this:

enter image description here

But, this is not what I want. Instead of having this legend, I would like to have labels on the atoms themselves, like this:

enter image description here.

Any ideas on how to do this?

$\endgroup$

1 Answer 1

8
$\begingroup$
 mol = Molecule["Formaldehyde"];

You can use the option AtomLabels (Introduced in version 13.0):

MoleculePlot3D[mol, {1, 2, 3, 4}, 
 AtomLabels -> Thread[Placed[ {"1", "2", "3", "4"}, Center]],
 PlotLegends -> {"1", "2", "3", "4"}] 

enter image description here

Alternatively, you can construct a Graphics3D object using mol["AtomCoordinates"]["Magnitudes"] as Text positions and combine it with MoleculePlot[...] using Show:

 Show[MoleculePlot3D[mol], 
  Graphics3D[MapThread[Text, 
    {Style[#, 16] & /@ Range[4], mol["AtomCoordinates"]["Magnitudes"]}]]] 

enter image description here

$\endgroup$

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.