Modeling lab
CH-315
Introduction to Python
Page content
Setup
You do not need to set up anything for the course. All relevant packages are pre-installed for you on noto.epfl.ch (Link to the relevant noto notebook is this).
Expected Learning Outcome
For the other modules, we expect that you know some basics of Python:
- How to interact with Jupyter notebooks
- How to write for loops and if/else statements
- How you can import other modules
- What the basic datatypes are (string, float, integer, objects, dictionary, list)
Recommended Resources
- If you feel super uncomfortable with programming, we recommend you follow an in-depth MOOC (which you can audit for free) or tutorial.
- If you want a quick-and-dirty start, you can follow our screencast. The notebook we produced during the screencast can be found here as notebook and as pdf.
----------
Additional Resources
- For some easy to start tutorials visit Kaggle.
- If you want to learn more about how to use a computer effectively, we highly recommend the course "The Missing Semester of Your CS Education" from MIT.
- If you want some project ideas, automate the boring stuff.
- If you want to watch some Python talks, look for Raymond Hettinger and James Powell.
- If you want to learn about some issues with Jupyter Notebooks, watch this talk on YouTube.
- If you want to learn reproducible science, give The Turing Way a look.
- If you want to program a web app, this blog can help.
- If you want a project or some code-review, let us know.
- For a deeper dive, you can visit O'reilly publications for good books on many topics.
- If you want to learn more about the algorithms and math behind machine learning. We recommend this YouTube channel.
Additional exercise: Implement a basic kinetic Monte Carlo simulation
Kinetic Monte Carlo (KMC) is a Monte Carlo method used for simulating evolving systems based on a stochastic process. At each step, to all possible transitions is assigned a weight (probability). This probability is calculated based on kinetic attributes of the system. The idea is that all transitions are allowed, but faster transitions, transitions with more favourably kinetics, are more likely to occur. For chemical systems this translates to using the kinetic constants of specific reaction steps. In physical systems, the rate of a given step might instead be determined by the physics of the system. Either way we have that
Associated with this equation, are two rate constants: kf and kr, denoting the forwards and reverse reaction rate constants respectively. Mathematically we can now assign probabilities to the forward and reverse reaction according to the rates:


where ρ is a random number between 0 and 1, rj is the rate of the transition and N the total number of transitions.
Understanding the parameter ρ requires a brief discussion of Metropolis Monte Carlo. This method may be thought of as randomly picking possible steps, and subsequently testing if that step is accepted according to an acceptance probability pacc. In Kinetic Monte Carlo, any step that is picked is automatically accepted. The value ρ in equation is a manifestation of the Metropolis acceptance probability.
Task 1: Using KMC to study the time evolution of a chemical reaction
1. Complete the code or write it from scratch.
2. Start with NA = NB = 1000 and NC = 0. Let this simulation run for 10000 transitions. Can you identify when the simulation reaches equilibrium?
3. Run the program again, but with different values for NA, NB, and NC. Run these simulations until equilibrium is reached, instead of using a given number of transitions. What did you use as an equilibrium condition? Why is this valid?
4. Lastly, change the parameters kf and kr relative to each other. How does this affect the final balance of particles?
Task 2: Expansion of a Two-Dimensional Gas on a Surface
Consider a 2-dimensional lattice, upon which rest n non-interacting particles. These particles are bound to the surface but are free to move around on the surface. In this task, you will write code that implements KMC on this system and visualize the evolution of the system as the particles move from one side of the lattice to spread out across it. In this model, a KMC transition is the movement of a particle to an empty, neighboring, lattice site. A basic assumption in this model is that the particles are non-interacting, and therefore all transitions have the same rate and therefore the same probability of occurring.
2. Begin by running the simulation on a small lattice, 20x20 with 5 particles and 1000 steps. Study the entropy plot. Can you identify where in this plot the system seems to reach equilibrium?
Project Idea: Chatbot for the ELN
We started developing a Telegram chatbot for the ELN. This can be refactored and functionality can be added---but it could also be a template for you to develop your own chatbot.


