Showing gas diffusion through solids

What would be the best approach to create pressure from the left side of my simulation, to increase the rate of diffusion of the gas (helium) through the solid (glass)?

This simulation is for teaching purposes and not meant to be accurate to reality. The criteria for success is how easily a person can observe the diffusion process, and as of right now, I don’t think the results are very easy to see on first glance.

Video link: Dropbox - diffusion.mov - Simplify your life

Open to all advice on how to improve this sim. Thanks!

units lj
dimension 2
atom_style atomic
boundary f f p # Non-periodic boundaries in x and y, periodic in z

# Define simulation box
region box block 0 20 -5 15 -0.5 0.5
create_box 2 box

# Define regions for helium and glass
region left_side block 0 6 -5 15 -0.5 0.5
region glass block 7 12 -5 15 -0.5 0.5
region right_side block 13 20 -5 15 -0.5 0.5

# Create helium atoms
lattice sq2 1.7 # Greater = more He atoms
create_atoms 1 region left_side

# Create a less dense glass barrier by increasing lattice spacing
lattice sq2 0.65 # Increased atomic spacing for glass atoms
create_atoms 2 region glass

# Output settings
thermo 100
dump 1 all atom 100 dump.helium

# Set mass for atom types
mass 1 0.000001 # Smaller helium particles
mass 2 0.5 # Glass

# Define interactions
pair_style lj/cut 2.5
pair_coeff 1 1 0.5 1.0 2.0 # Smaller Helium-Helium interaction
pair_coeff 1 2 1.0 0.4 3.0 # Helium-Glass
pair_coeff 2 2 1.0 1.0 2.5 # Glass-Glass

# Define groups
group helium type 1
group glass type 2

# Apply Brownian dynamics fix to helium
fix 1 helium brownian 3.0 12345 gamma_t 1.0

# Apply Langevin thermostat and NVE integration to glass atoms
fix 3 glass langevin 1.0 1.0 40.0 12345 # Increase damping coefficient
fix 4 glass nve

# Apply a spring force to keep glass atoms near their initial positions
fix 5 glass spring/self 5000.0 # Increase spring constant

# Apply reflective walls to prevent helium atoms from crossing boundaries
fix wall_left all wall/reflect xlo EDGE
fix wall_right all wall/reflect xhi EDGE
fix wall_bottom all wall/reflect ylo EDGE
fix wall_top all wall/reflect yhi EDGE

# Run the simulation
timestep 0.00003
run 50000

If what you need is an animation, then … make an animation.

You don’t need LAMMPS for that. :grinning: Modern AI is much faster at stealing code and violating license writing boilerplate JavaScript than humans. I generated this with a few prompts (in dropdowns below) in Claude (Sonnet 3.5) in about 5 minutes:

Interactive Particle Diffusion Animation

Claude Prompts

Create an interactive animation showing how particles will diffuse from one side of a partition with a small gap to the other side in ReactJS. There should be sliders to control the initial number of particles on either side and buttons to start, pause, and restart the animation.

Add a line graph on the bottom to show the numbers of particles on both sides of the partition over time, and another slider to control the width of the gap

Please make the gap slider control the height of the gap and not the width. Add one more slider to control the particles’ initial average speed.

I had tried some other AI approaches but the results were not even close. The script I have now was written by ChatGPT and then tweaked by me. Perplexity had a harder time getting the LAMMPS script to work at all.

I want this illustration to show how the gas particles migrate through the solid, so I think the simulation results are very close to what I need. Given that this result is so close to the objective, I think it makes the most sense to stick with this approach rather than scrap it and start from scratch.

I’ll add two general comments – but it’s not easy to see how to help you unless you can make a more specific request for help.

My first comment is that all models are wrong, and most models are useless. (Call it Xob’s Reflection.) Dynamic visualisations are dangerous for giving students (and scientists!) a false sense of competence unless clear visual model changes, theoretical quantitative predictions, and experimental verification are all aligned.

In your first post you said

but … what exactly do you want the students to see that is currently not being seen? Is there a number (or visual impression of a number) that doesn’t look right? A qualitative trend that doesn’t carry through to the simulations? We can’t help with a problem if you don’t define it.

My second comment is that molecular models, in particular, are very tricky to use in teaching students physical chemistry, and that is because molecular models are often far too small for the usual physical chemistry models to apply.

Last year I spent a while building a LAMMPS “piston and thermal gas” for illustrating the ideal gas law. It really … didn’t work. Any system that is small enough to show the atomic nature of individual gas-piston collision is also small enough that fast changes are severely dissipative while slow changes exceed the equilibration time, and thus PV = nRT is not obeyed. (They’re fantastic models for third year students to reflect on the irreversibility of finite-time protocols!)

So be very, very aware that demonstrating most phys chem results through atom-wise animations is very fraught. I can barely get an animated reactor to properly display zeroth-order and second-order kinetics.

Beyond that, I’ll be happy to help further if you have specific things you want to try doing and are not sure how to.

One last comment:

Most AIs can generate meaningful JavaScript because it is widely taught and used, including simple particle animations with specular reflections.

As such, the JavaScript code base is sufficiently large for brute-force statistical training to extract meaningful trends.

The set of “all LAMMPS scripts ever written” is much, much smaller. Meanwhile, LAMMPS scripts are (usually) not as complex as actual program code but they are significantly more structurally diverse than, say, GROMACS or VASP inputs. So the language training challenge is much harder, and I would not trust a language model to get very far in the next few years.

That is not surprising because MD driven diffusion through solids is extremely slow, which also applies to people trying to do science on this topic. One method to speed up the diffusion would be to switch from pure MD to a hybrid MD/MC method which you regularly do MC displacement moves (e.g. via fix gcmc without insertions/deletions) or via swapping atoms (e.g. via fix atom/swap), but of course this modifies your time axis in difficult to determine ways.

I was able to get something satisfactory by simply applying a force (left to right) to my gas particles after the first 1,000 time steps.

My problem with the previous setup was that, for the benefit of the viewer’s perception, the diffusion process is too fast in the first frames of the video and too slow in the final frames. This is probably physically correct but for my audience it impedes their ability to see how gas particles migrate through a solid, exhibiting Brownian motion. That’s really all I’m trying to show.

The viewers are a general audience, not students. If this were for science students, then I would focus more on physical correctness.