Try   HackMD

Shirts Group Meeting: Visualization

tags: ResearchNote

1. Animations of advanced sampling methods

Here I provide some Python codes for generating animations showing the concepts of advanced sampling methods. Examples codes are hosted on sampling_visuals repository on my GitHub. The codes need to be generalized/refactored for more flexibility (will be done in the near future!) but they are at least sufficient to generate the animations in this section.

1-1. Metadynamics (MetaD)

  • Command the replicate the animation: python metadynamics.py
  • Description
    • Below is an animation showing the concept of a standard metadynamics. metadynamics.py performs the Metropolis-Hastings algorithm to decide where the system (the yellow circle) should go while accumulating Gaussiang biasing potential.
    • It takes about 3 minutes to generate an animation (500 MC steps).
    • The random seed has been fixed, so using the command above should reproduce exactly the same animation below.
    • Along the simulation trajectory, the code outputs the snapshot of the configuration at different times and uses imageio to convert a bunch of .png files into a .gif file, which is the final product of the code.
    • The code could be extended by adding an argument parser so that the user can adjust relevant parameters of metadynamics, including the width and height of the biasing potential, temperature, or the bias factor.
  • Animation
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

1-2. Multiple walkers metadynamics (multi-MetaD)

  • Command to replicate the animation: python multi_metaD.py -N 4
  • Description
    • Below is an animation of a standard metadynamics with 4 walkers. Similar to metadynamics.py, multi_metaD.py runs
      N
      MC simulations at the same time, recording the positions where each walker has deposited Gaussian potentials such that it can accumulate all the biasing potential simultaneously and decide the probability of the system moving from on CV value to another. Again, the random seem is fixed so the animation below is reproducible.
    • It takes about 3 minutes to generate an animation (500 MC steps).
    • Similarly, we use imageio to convert a series of .png files into a .gif file.
    • multi_metaD.py is more flexible than metadynamics.py, characterizing different parameters that can be specified through the flags by the user. (Note that the well-tempered version has not been implemented, i.e. BIASF is not available yet.) Below is the help message printed by python multi_metaD.py:
      ​​​​​​​​This program generates animations to illustrate metadynamics given specified parameters.
      
      ​​​​​​​​optional arguments:
      ​​​​​​​​  -h, --help            show this help message and exit
      ​​​​​​​​  -N WALKERS, --walkers WALKERS
      ​​​​​​​​                        Number of walkers
      ​​​​​​​​  -n NSTEPS, --nsteps NSTEPS
      ​​​​​​​​                        Number of Monte Carlo steps of each walker
      ​​​​​​​​  -b BIASF, --biasf BIASF
      ​​​​​​​​                        biasing factor for well-tempered metaD. Dafault:
      ​​​​​​​​  -s SIGMA, --sigma SIGMA
      ​​​​​​​​                        Width of the Gaussian potentials. Default: 0.4
      ​​​​​​​​  -ht HEIGHT, --height HEIGHT
      ​​​​​​​​                        Height of the Gaussian potentials. Default: 0.05
      ​​​​​​​​  -d DMAX, --dmax DMAX  Max displacement. Default: 0.8
      
    • Animation
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

1-3. Expanded ensemble (EXE)

  • Below is an animation exported from a PowerPoint slide showing the principles of an expanded ensemble simulation.
  • Matplotlib has been having problems with correctly showing the relative positions of surfaces in the 3D space. That is, at a certain angle, a point with a higher
    z
    values is not always on the top of the surface. This problem happens in the animation in Section 1.4 as well.
  • To solve the issue mentioned above, I generated two figures which respectively corresponds to the free energy surface before and after the Wang-Landau weights are added, by running python expanded_ensemble.py. Then, I used PowerPoint to draw the black circle and animated it with "Custom Path" in PowerPoint such that the circle stayed right on the surface.
  • Note that the weights added in the simulation/animation are actually not produced by the Wang-Landau algorithm but just some constants making the surface flatter. The Wang-Landau algorithm could be implemented in the future for a better visualization though.
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

1-4. Expanded ensemble metadynamics (EXE-MetaD)

  • Command to replicate the animation: python expanded_MetaD.py
  • Below is a 2-dimensional metadynamics using the alchemical variable as one of the collective variables. The random seed is fixed to ensure a reproducible result. It takes about 2-3 minutes to generate an animation (200 MC steps). imageio is used to convert a series of snapshot into a .gif movie.
  • Animation
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

2. VMD with Tcl console

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Above is a VMD visualization of a host-guest binding complex with a transparent sphere highlighting the space of the binding cavity to estimate the number of water molecules inside it. To draw the sphere with a reasonable radius and center, we use the following script in Tk Console of VMD:

# Step 1: set up the geometric centers of the rings set small_ring [atomselect 0 "index 0 to 39"] set com1 [measure center $small_ring] set big_ring [atomselect 0 "index 56 to 111 or index 115 to 120 or index 122 to 127"] set com2 [measure center $big_ring] # Step 2: Write a procedure (proc) - inside_point proc inside_point {coef1 lst1 coef2 lst2 expr} { foreach item1 $lst1 item2 $lst2 { lappend r [expr [string map {%x $item1 %y $item2 %a $coef1 %b $coef2} $expr]] } return $r } # Step 3: Determine the radius and the center of the sphere inside_point 0.4 $com1 0.6 $com2 {%a * %x + %b * %y} draw color cyan draw material Transparent sphere $com radius 5

For the explanation of the Tcl script above, please see Section 3-2-2. in Water Exclusion Problem of OA-G3 Host-guest Binding Complex.

3. Some tricks in PowerPoint presentations

3-1. Draw a normal distribution using PowerPoint

From time to time, we might need to draw probability distributions for illustration purposes. Below is an example showing the principles analysis umbrella sampling, which is to run a series of vanilla simulations and stitch the distributions. For the method of drawing a normal distribution using PowerPoint, please refer to this YouTube video.


Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

3-3. "Wipe" animation in PowerPoint

As shown in the animation of umbrella sampling above, and the animations below, "Wipe" is a pretty useful kind of animation in PowerPoint for showing the flow of a process!

  • Example 1: Umbrella sampling
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
  • Example 2: Replica exchange molecular dynamics
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Example 3: Synchronous and asynchronous parallelization
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Example 4: Future work as a timeline
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

  • Example 5: Coupling layers in a Boltzmann generator
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

3-2. The shape subtract, shape union and the relevant tools in PowerPoint

As shown in the figure below, the scenario is as follows:
You just downloaded a picture from Wikipedia that you want to use in your PowerPoint slide. The background of the picture has been removed. Since you are using a dark background in your slide, you hope that the texts (including the legends, title, and the label of the axes) can be turned into white. However, simply adjust the brightness to 100% will turn the whole picture white, including the curves that were previously in different colors. Namely, as shown below, what you have is the figure on the left, while the figure on the right is what you want:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

To turn the figure on the left to the right one, follow the procedure below:

  • Step 1: Crop the plot (the grids and the curves) to separate it from the texts (the legends, title, and labels). This is the part that you don't want to change any colors.
  • Step 2: To get the rest parts of the figure (the texts and the legends), copy the original picture (let's call it Figure A.) and the picture you got in Step 1 (Figure B). Lay Figure B. on Figure A. and align them nicely. Then, first click on Figure A. then Figure B, and click on "Subtract". (The order of clicking matters!)
  • Step 3: Again, in the product of Step 2 (Figure C.), we want to keep the colors of the legends but turn the lines and the texts into white. Therefore, insert a rectangular (Figure D.) with an appropriate size, without background or borders. Lay and align Figure D. on Figure C., first click on Figure C. then D. and click on "Interset". This gives you Figure E. Then Click on Figure C. then D. and click on "Subtract" to get Figure F.
  • Step 4: At last, turn Figure F. into white by adjusting the brightness to 100%. Combine and align Figure F., Figure B., and Figure E. to get the final result!

The process seems somehow tedious but is actually very straightforward and fast! (This could be done in two minutes.) Note that if the background of the original figure has not been removed, I would recommend the following two tools: