3
$\begingroup$

I would like to use an individual size and color for each atom in a molecule (independently of the atom types). Could you please help me how to achive this? My MWE is the following:

Mol = Import["test.xyz"];

(*File content:
4
X4
X 0.0 0.0  0.0
X 0.0 0.0 -1.0
X 0.0 0.0  1.0
X 2.5 0.0  0.0*)

MolPlot = MoleculePlot3D[Mol, AtomLabels -> {
     1 -> Placed[Style["M ", 30], Center], (*individual size and color here*)
     2 -> Placed[Style[Superscript["T", "\[Prime]"], 30], Center], (*individual size and color here*)
     3 -> 
      Placed[Style[Superscript["T", "\[Prime]\[Prime]"], 30], (*individual size and color here*)
       Center],
     4 -> Placed[Style[Rg, 30], Center]}]; (*individual size and color here*)


Show[MolPlot]
$\endgroup$
2
  • $\begingroup$ @Domen No, sorry. $\endgroup$
    – TobiR
    Commented Mar 5, 2023 at 16:45
  • 2
    $\begingroup$ Why not? The solutions there are exactly the same as presented in the Jason's answer below (ColorRules and manual replacement of spheres). $\endgroup$
    – Domen
    Commented Mar 5, 2023 at 17:01

1 Answer 1

7
$\begingroup$

Specifying a particular color for a particular atom is easily done using the ColorRules option. Specifying a per-atom size, rather than a per-element-type size, is not possible without post processing. Something like this:

myMoleculePlot3D[m_, colorRules_, sizeRules_, opts:OptionsPattern[]] := Module[
   {res},
   res = MoleculePlot3D[m,
      ColorRules -> colorRules,
      FilterRules[{opts}, Options @ MoleculePlot3D]
   ];
   (* split any multispheres in the graphics complex *)
   res = ReplaceAll[res,
      Sphere[n:{__Integer}, s_] :> Map[Function[Sphere[{#}, s]], n]
   ];
   (* apply the size rules and return *)
   ReplaceAll[res,
      Sphere[{n_Integer}| n_Integer, s_] :> Sphere[{n}, (n /. sizeRules) /. n -> s]
   ]
]
myMoleculePlot3D[
 Molecule["l-alanine"], {2 -> Purple, 3 -> Green}, {2 -> .6, 3 -> .2},
  AtomLabels -> {2 -> 
    Placed[Style["\[HBar]", FontSize -> 40, FontColor -> Red], 
     Above]}]

enter image description here

$\endgroup$
0

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