How can molecules move?

My Analytical Chemistry class just started the module on spectroscopy, and I wanted to have a visualization that displayed the different types of motion (rotational, translational and stretching) that molecules can experience. It turned out, I was able to make an interactive (sort of) graphic with a few lines of Mathematica code:

The three general classes of molecular motion.

Here’s the code I used, in case you happen to have access to Mathematica and would like to try it out. It loads carbon dioxide from the Wolfram knowledgebase and then uses transformation functions to perform the translation, rotation and scaling operations. I take advantage of the structure of the GraphicsComplex to perform the transformations on just the coordinates instead of the actual objects (spheres in this case, which would get squished if the scaling transform was applied to the entire object. The dimensions of the graphic are hard coded for carbon dioxide, so a bit of work will be required to expand this tool to other molecules. Lastly, I create some DownValues that make it easy to use the Manipulate interface for swapping between the three types of motion.

With[{obj = Entity["Chemical", "CarbonDioxide"]["MoleculePlot"]},
 Manipulate[
  Show[obj /. 
    GraphicsComplex[pts_, gr__] :> 
     GraphicsComplex[f[motion, v][pts], gr], ImageSize -> 250,
   PlotRange -> {{-300, 300}, {-160, 160}, {-100, 100}}],
  {{v, 0, "motion"}, 0, 1},
  {{motion, ScalingTransform, ""}, {ScalingTransform -> "stretch", 
    RotationTransform -> "rotate", 
    TranslationTransform -> "translate"}},
  
  Initialization :> (
    f[ScalingTransform, var_] := 
     ScalingTransform[{Rescale[var, {0, 1}, {0.8, 1.2}], 1, 1}];
    f[RotationTransform, var_] := 
     RotationTransform[
      Rescale[var, {0, 1}, {0, 360}] Degree, {0, 0, 1}];
    f[TranslationTransform, var_] := 
     TranslationTransform[{Rescale[var, {0, 1}, {-100, 100}], 0, 0}];
    )]
 ]

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.