# Is it possible to simulate Brownian motion in Blender?

https://en.wikipedia.org/wiki/File:Translational_motion.gif

I want to simulate some molecular dynamics. For that I want some area to fill up with some lipids. All these lipids would be considered as a cylinder object standing vertical in a space. In the best case, all objects should be hanging in the defined area and are wobbling (inner dynamics: like atomic motion) and are colliding with other residues like in the link above.

Any hints or suggestions. Particle physics provide collision but they are not holding objects in the space.

You can use particles to control your object's vertices, and induce Brownian motion in these particles:

To achieve this, you need to make sure every vertex of your particle controlled object is assigned a particle. These are the settings I've used for the example above:

You also need to turn off gravity in the Scene tab in the tools panel:

Then, once you have a particle per vertex, you need to run this code to make sure the vertices coordinates are linked to the particle locations:

import bpy

def update_particles( scene ):
''' This function runs before every frame change, and it updates the cube's
vertices' coordiantes with the location values of its particles
'''

cube = bpy.data.objects['Cube']
for vert, particle in zip( cube.data.vertices, cube.particle_systems[0].particles ):
vert.co = particle.location

# Add vertex --> particle function to frame change app handlers
bpy.app.handlers.frame_change_pre.append( update_particles )


This example isn't a direct solution for what you're aiming for, but rather a direction. To adapt it to your needs, you actually need to manipulate the lipid through some mesh skeleton (or you can rig it and control the pose bones' locations the same way I've manipulated the vertices). This would be easiest and most directly translatable if your lipids are actually simple wireframes with a Skin modifier (you'll need to make sure the Skin modifier is below the particle system modifier though).

Since your scene probably has a lot of molecules, it will likely be more feasible to write a script that automates the generation and setup of particle systems. You'll also need to include all these objects in the frame change handler function.

Not a trivial project, but not unattainable :)

• Will this render too, or does the script just update the viewport? – Scott Milner May 4 '17 at 3:42
• @ScottMilner, This affects the mesh itself, and updates it before each frame change, so yes - it will render (in the example above both the mesh and the particles, which are set to render as icospheres). – TLousky May 4 '17 at 5:41

I was able to achieve an effect very similar to the GIF you linked by using the Molecular Script addon. First, download and install Molecular from here: Molecular Script Download (Instructions how to install here).

1. Start a new blender file and make sure that Object: Molecular Script is enabled under Addons in the User Preferences.
2. In Object Mode, scale the default cube to .025 along the Z axis (S > Z > .025), then, in Edit Mode, delete the top and bottom faces.
3. In Object Mode, add a new cube (Shift + A > Mesh > Cube) and scale it to 1.5 along the X and Y Axes (S > Shift + Z > 1.5) and .053 along the Z Axis (S > Z > .053).
4. Under Display on the Object Properties tab, set both cubes to a Maximum Draw Type of Wire.
5. With the larger outside cube selected, enable Collision on the Physics tab.
6. Select the smaller inside cube with the deleted faces and under the Particles tab create a new particle system. (You should also notice the Molecular Script panel added to this tab).
7. Under Emission set the Number to 25, the End to 1, and Lifetime to 250. Enable Size Deflect under Physics. Also make sure Emit From is set to Faces. Under the Velocity panel, set Random to 0.250 (this is not shown below but it helps with particle motion).
8. Add a new Cylinder mesh and move it to layer 2 (Shift + A > Mesh > Cylinder > M > 2).
9. Back on the particle settings for your inside cube, under Render, set the method to Object and set the Dupli Object to your cylinder. The object Size should be 0.050.
10. Still on the Particles tab, scroll down to the Molecular Script panel and enable Molecular Script. The fundamental function of this addon (in a nutshell) is to allow particle collisions.
11. Under Density, check Calculate particles weight by density; under Collision, check Activate Self Collision and set both Friction and Damping to 0 (unless you want your molecule motion to decay.)
12. Now scroll down and click Start Molecular Simulation (Icon with radioactive symbol) - in the top view you should already see the result you want.

You now have a basic simulation running. Just remember a couple things:

1. Before rendering, need to turn off Emitter under the Render tab of your particle system so that the emitter does not show up in your render, and you will also have to restrict rendering on the collision object by unchecking its camera in the Outliner.
2. To change the initial motion, play around with the particle Velocity Random value that we set earlier, and also the Friction and Damping under the Molecular Script panel.

Here is a final .Blend file for you to play with as well:

• Hi, I'm the developer behind Blend-Exchange. Could you give me some details on whats not working so we can fix it? – GiantCowFilms May 6 '17 at 15:56
• @GiantCowFilms I dug around a little and found my problem, because it was intermittent - the website does not function correctly in InPrivate Browsing IE11. Here is what happens: On the website, I click to select a blender file. Then, I enter the URL of the question. Next I click upload, and the upload bar scrolls across. Then the webpage goes completely white, stays on the same webpage, and I have no access to the uploaded .blend. Could this be due to lack of cookie utilization in InPrivate? – CGEffex May 9 '17 at 13:01
• its most likely caused by IE11 being a terrible browser. I will look into this bug in the coming days, but support IE is very difficult. – GiantCowFilms May 9 '17 at 17:27