MINI REVIEW article

Front. Ecol. Evol., 23 September 2026

Sec. Models in Ecology and Evolution

Volume 14 - 2026 | https://doi.org/10.3389/fevo.2026.1870197

Simulating evolution for everyone: a practical introduction to SLiM

  • Department of Biology, University of Mississippi, University, MS, United States

Abstract

Simulation is a fundamental tool for studying complex evolutionary and population-level processes that are difficult to address analytically. SLiM (Simulating Evolution with Selection and Linkage) is a flexible forward-time simulation framework that enables explicit modeling of evolutionary processes in population genetics. Despite its power, effective use of SLiM requires scripting in Eidos, a general-purpose scripting language, which may pose a substantial barrier for researchers without computational backgrounds. In this review, we provide conceptual explanations of SLiM, introductory coding guidance, and discussion of responsible AI-assisted learning approaches to help beginners develop a deeper understanding of evolutionary modeling with SLiM. This guide aims to lower the barrier to entry and enable a broader community of biologists to apply SLiM to their own research questions.

1 Introduction

Many biological and evolutionary processes involve complex interactions among selection, demography, recombination, and other evolutionary forces, making their outcomes difficult to predict using analytical approaches alone. In evolutionary genetics, simulations therefore play a central role in validating theoretical predictions and estimating parameters underlying observed genetic patterns (; ; ).

Techniques in simulation are broadly divided into backward-time (coalescent-based) and forward-time frameworks (). Backward simulations reconstruct genealogical histories by tracing sampled individuals back to their most recent common ancestors (; ; ; ). They are often the most efficient choice when the goal is to simulate genealogies or genetic variation under demographic models that can be reasonably represented within a coalescent framework (; ). However, when evolutionary outcomes depend on explicitly modeling individual-level processes (e.g., complex fitness effects and life-history variation) and when researchers need to track individuals and genotypes through time, forward-time simulation provides a more natural framework (; ; ).

Within this forward-time modeling landscape, SLiM (Simulating Evolution with Selection and Linkage) supports a broad range of evolutionary models (; ). SLiM enables simulations of whole genomes with recombination, complex demographic histories, and user-defined selective and mutational processes. SLiM provides extensive documentation (; ), together with SLiM Community website (https://github.com/slim-community). In addition, have provided step-by-step scripting tutorials based on representative evolutionary models to help beginners become familiar with SLiM scripting.

Building on these resources, this manuscript focuses on helping beginners translate biological hypotheses into SLiM models by introducing a conceptual framework for understanding scripts, a practical workflow for modifying existing models, and recommendations for the responsible use of AI as a supplementary learning aid. Therefore, this review is designed for new SLiM users to develop a conceptual understanding of SLiM’s scripting and its underlying principles.

2 A mental model of SLiM

A useful way to think about a SLiM script is as the protocol for a virtual evolution experiment. Instead of performing the experiment in a laboratory or in nature, the experiment is carried out inside a computer. Running the script is analogous to performing the experiment. In this virtual world, individuals carry one or more genomes, depending on the model, and mutations accumulate within those genomes over successive generations. The combined effects of these mutations influence each individual’s fitness (the probability of surviving and reproducing).

Every experiment begins by defining the world in which evolution takes place (Figure 1). For example, users can define the properties of the genome, such as its length, mutation rate, recombination rate, and the fitness effects of mutations. In SLiM, these rules are specified in the initialize() block. A block is a set of instructions enclosed in curly brackets ({}) that SLiM executes together.

Figure 1

Once the evolutionary world has been established, the simulation proceeds one generation (simulation cycle) at a time. Each generation can be viewed as a scene in an evolutionary movie. Generations simply follow the biological rules defined during initialization, but users can also schedule additional events (e.g., environmental change and migration event) to occur at specific times using callback blocks, early() and late(). These callbacks execute at the start and end of each generation, respectively, allowing new events to be introduced at precise points in the simulation cycle. By combining many evolutionary events, SLiM can simulate complex evolutionary histories.

Just as a laboratory experiment produces measurements that are analyzed to answer a biological question, a SLiM simulation can produce records of the evolving population, e.g., population size and allele frequencies. SLiM also records the complete evolutionary history of the simulated population using “tree-sequence” recording. It preserves genealogical relationships and mutations throughout the simulation, which can be analyzed using Python packages such as tskit and pyslim. They allow researchers to compare alternative evolutionary hypotheses, examine how populations changed through time, and evaluate whether the simulated behavior matches expectations.

3 Speaking the language of SLiM

A SLiM script is a collection of instructions that describes an evolutionary experiment. These instructions are written in Eidos, a general-purpose scripting language designed specifically for use with SLiM to represent evolutionary processes (). Eidos has its own vocabulary and grammar, like any other language (Table 1).

Table 1

ComponentDescription
ObjectRepresents a biological entity (e.g., population, individual, and mutation)
AttributeDescribes a property of an object (e.g., selection coefficient)
FunctionPerforms an evolutionary action
ParameterSpecifies the details of a function
VariableStores a value that can be used or updated later
Curly bracket, {}Groups instructions that belong to the same event
Comment,//Provides notes for readers

Building blocks in SLiM script.

In Eidos, the evolutionary world is described in much the same way as telling a story. Every story has characters, actions, and descriptions. The characters are biological entities such as populations, individuals, and mutations. These are represented as “objects”. Each object carries information about itself, called “attributes”. For example, a mutation remembers where it occurs in the genome and its selection coefficient.

The story unfolds through evolutionary events. Eidos provides many predefined “functions” that perform common evolutionary actions, such as creating a population and changing selection. Like a verb in a sentence, a function often needs additional information to describe exactly what should happen. This information is supplied through “parameters”. For example, changing population size requires specifying the new population size as a parameter.

Curly brackets ({}) group together all the instructions that belong to the same event. As the story progresses, some information needs to be remembered from one generation to the next. “Variables” act like notes that store values for later use. Finally, comments (//) are notes written for human readers to explain the script and are ignored by SLiM when the simulation runs.

4 A minimal SLiM script

The following example represents a simple neutral Wright-Fisher population that uses the building blocks introduced above (Table 1). It simulates a single population of constant size accumulating neutral mutations over 2,000 generations.

initialize() {

    initializeMutationRate(1e-7);

    initializeMutationType(“m1”, 0.5, “f”, 0.0);

    initializeGenomicElementType(“g1”, m1, 1.0);

    initializeGenomicElement(g1, 0, 9999);

    initializeRecombinationRate(1e-8);

}

1 early() {

    sim.addSubpop(“p1”, 500);

}

2000 late() {

    sim.outputFull();

}

This script can be run in SLiMgui by opening the script file and pressing “Run”. The script begins with an initialize() block, which defines the basic rules of the evolutionary experiment. initializeMutationRate() sets the rate at which new mutations arise. initializeMutationType() defines a mutation type named “m1”; here, the mutation is neutral because its selection coefficient is 0.0.

initializeGenomicElementType() defines a genomic element type named “g1” that contains the “m1” mutations. initializeGenomicElement() defines the genomic region to which the “g1” genomic element applies. In this example, the region spans positions 0 – 9,999. initializeRecombinationRate() defines the rate of recombination during inheritance.

The next block, 1 early(), is an event scheduled at the beginning of generation 1. It creates a subpopulation named “p1” with 500 individuals. The final block, 2000 late(), is an event scheduled at the end of generation 2,000. It uses sim.outputFull() to output the full simulation state, including information about the population and genetic variation present at that time.

Together, these three blocks illustrate the basic logic of a SLiM experiment: define the evolutionary rules, create a population, allow the population to evolve through time, and output the simulation state for interpretation.

5 Translating evolution experiment protocol into SLiM scripts

Once a biological model has been designed, the next task is to express it in a language that SLiM can understand. Writing a SLiM script is fundamentally the process of translating the protocol of a virtual evolutionary experiment into Eidos. Rather than memorizing Eidos commands, beginners should focus on understanding how biological ideas are represented by different components of a SLiM script. We suggest the following four-step workflow (Figure 2).

Figure 2

Step 1: Identify an existing evolutionary scenario to modify.

Most biological questions do not require constructing an entirely new evolutionary model. Instead, they can often be addressed by modifying an existing simulation that captures the same fundamental biological processes. Therefore, an effective way to begin a new SLiM project is to identify an example script that shares the same biological foundation, even if the details differ.

SLiMgui provides over 100 example scripts (recipes) covering a wide range of evolutionary scenarios (, ), making them an excellent starting point. When no recipe closely matches the target model, one should start from the simplest working example that contains the most important shared mechanism.

Step 2: Understand the biological meaning of the existing script.

Before modifying a script, users should understand what each component represents biologically. Although the SLiM manual, SLiMgui documentation, the Eidos manual (; ) provide detailed explanations of functions and options, these resources are technical references and may be difficult for first-time users to interpret. AI tools, such as ChatGPT (), can be used as supplementary learning aids to help explain unfamiliar code in plain language. For example, a beginner may ask:

“This is a line from a SLiM script: initialize(). I am not familiar with SLiM. Explain the function of the line in simple language.”

Providing biological context and indicating that the code is from a SLiM script helps AI tools generate more relevant explanations. However, AI-generated explanations should not be considered authoritative. Because AI tools may produce incomplete or incorrect interpretations, users should verify their understanding by consulting the official SLiM manual and documentation (; ).

Step 3: Modify the model according to the evolutionary scenario.

Once the structure of the existing model is understood, the script can be modified to represent the new evolutionary scenario. For example, modifying the selection coefficient changes the strength of natural selection. Rather than making many changes simultaneously, beginners are encouraged to modify one biological process at a time, verify that the resulting behavior matches expectations, and then proceed to the next modification. This approach makes simulations easier to debug, that is, to identify, understand, and correct errors in the script or unexpected simulation behavior.

Adding a new biological process may require identifying an appropriate SLiM function. In these cases, AI tools can help users identify candidate functions that can then be verified using the SLiM manual (; ). The purpose of AI assistance in this workflow is not to generate a complete simulation independently, but to help beginners navigate existing documentation (; ) and understand how biological concepts are represented in SLiM.

Step 4: Verify code behavior and validate the biological model.

A SLiM script should not be considered reliable simply because it runs without errors. A successful simulation requires addressing two different questions: (1) does the script correctly implement the intended computational process? and (2) does the model represent biologically meaningful evolutionary behavior?

The first question is addressed through code verification. Code verification confirms that the script behaves according to the written instructions. For example, users can check whether population size changes occur at the expected generation or compare a selected step of the simulation with hand calculation. It is important to remember that computer simulations do not replace the logic of the model; they execute that logic faster and across more individuals, generations, and replicates.

The second question is addressed through biological validation. Biological validation evaluates whether the simulated evolutionary outcomes are consistent with biological expectations. This may involve comparing simulation results with analytical predictions from population genetics theory or empirical observations.

6 Case study

To illustrate the workflow described above, we consider a simple evolutionary model of a bacterial population adapting to antibiotic treatment (Figure 3).

Figure 3

To develop a script, we first selected an example SLiM script, “16.3: Modeling Clonal Haploid Bacteria with Horizontal Gene Transfer” (), because it represents a bacterial population and therefore provides a suitable starting point. We next translated this example script into a conceptual diagram showing the biological role of each part of the script (Figures 4A, B). This allowed the model to be viewed as a collection of biological processes rather than programming statements. The diagram identified which components should be retained, modified, removed, or added to represent the target evolutionary scenario (Figure 4C).

Figure 4

For example, the first biological assumption to modify is the population size. The original recipe assumes a carrying capacity of 100,000 individuals:

defineConstant(“K”, 1e5);//carrying capacity

Because our model assumes a maximum population size of 1,000 individuals, this parameter was changed to:

defineConstant(“K”, 1000);//carrying capacity

This modification illustrates an important principle: many biological questions can be addressed by changing existing parameters rather than introducing new code.

We next demonstrate how to code the antibiotic treatment that begins at generation 50 (Figures 3, 4C). Unlike the carrying capacity, this process did not exist in the original script and therefore required adding a new evolutionary event. For beginners, identifying an appropriate SLiM function for a given biological process can be challenging because the SLiM manual () contains hundreds of functions and options (). AI tools can be used to suggest candidate functions or code patterns. For example, to find out how to change the fitness effect of a resistance mutation during a simulation, we asked:

“I am using SLiM version 5. In the initialize() section, I defined the treatment generation using defineConstant(“Treatment”, 50); and the post-treatment selection coefficient using defineConstant(“newfitness”, 0.1);. Write the lines needed in the late() section to change the selection coefficient to newfitness at generation Treatment.”

AI suggested using setSelectionCoeff():

if (sim.generation == Treatment) {m1.setSelectionCoeff(newfitness)};

The manual () confirmed that setSelectionCoeff() is the appropriate function for changing selection coefficients but also revealed two important issues. First, recent versions of SLiM (version 5) use sim.cycle instead of sim.generation (). Second, the selection coefficient cannot be modified directly through the mutation type; the mutation objects must first be obtained (e.g., using sim.mutationsOfType()) before applying setSelectionCoeff(). Thus, the AI-generated code required correction before it could be incorporated into the SLiM script.

During this process, we also observed that follow-up prompts based on error messages often did not resolve mixed syntax from different SLiM versions. This limitation is likely due to frequent changes across SLiM versions and the comparatively small amount of publicly available information for AI training. Overall, we emphasize that AI should be regarded as a tool for identifying relevant functions rather than as an authoritative source of executable code.

Lastly, we evaluated whether the modified script behaved according to the intended evolutionary model. Example expected outcomes are: (1) the bacterial population should initially increase and then stabilize at the carrying capacity of 1,000 individuals and (2) resistant bacteria should increase in frequency after treatment while susceptible bacteria decline. To demonstrate an example code verification, we edited the script (Figure 4C) and had it output the total population size together with the numbers of resistant and susceptible individuals at each generation (Supplementary File). The outputs provided a direct means of determining whether the modified script behaved as intended (Figure 5). Also, the expected number of individuals at each generation (NT × 2, where NT is the population size in the previous generation) agreed with the simulation results until the population reached the carrying capacity. Note that biological validation would require comparison with analytical predictions or empirical observations, which was beyond the scope of this case study.

Figure 5

7 Discussion

In this review, we present a workflow that emphasizes viewing SLiM scripts as descriptions of evolutionary experiments rather than collections of programming commands. By translating scripts into conceptual representations of biological processes, our approach may help beginners develop transferable skills for designing and interpreting evolutionary simulations.

Beyond learning how to implement a model, researchers must also carefully consider how to design appropriate evolutionary simulations. For example, simulation outcomes are inherently dependent on model assumptions. Therefore, the rationale for each assumption should be clearly articulated and biologically justified. Also, it is important to note that not all details of evolutionary history can-or should-be explicitly simulated. Effective models aim to capture the essential processes driving the system, rather than reproducing every mechanistic detail. Overly complex models may obscure interpretation.

In conclusion, we presented a beginner-friendly introduction to SLiM, and the workflow presented here provides a foundation for connecting biological questions and computational implementation.

Statements

Author contributions

MR: Visualization, Formal analysis, Data curation, Methodology, Investigation, Writing – review & editing, Writing – original draft. BP: Data curation, Methodology, Writing – original draft, Investigation, Writing – review & editing. SN: Data curation, Methodology, Writing – original draft, Visualization, Investigation, Formal analysis, Writing – review & editing. NN: Writing – review & editing. SM: Project administration, Writing – original draft, Formal analysis, Methodology, Visualization, Validation, Investigation, Conceptualization, Writing – review & editing, Funding acquisition, Supervision, Resources. AN: Data curation, Formal analysis, Writing – review & editing, Validation, Methodology, Writing – original draft, Visualization, Investigation, Resources, Conceptualization. PD: Conceptualization, Investigation, Writing – review & editing, Resources, Writing – original draft, Data curation, Visualization, Methodology, Formal analysis.

Funding

The author(s) declared that financial support was received for this work and/or its publication. The authors acknowledge financial support from the Cockerham Scholarship (PD), McRight Scholarship (PD, MR, NN), Georgia St. Amand Laboratory Teaching Scholarship (BP), Graduate school Summer Research Assistantship (SN), and Wong-Bridges Scholarship (SN).

Acknowledgments

The authors acknowledge the Bioinfo Research Club and the Department of Biology at the University of Mississippi for promoting an environment that encouraged discussion and collaboration during the development of this work. The authors also acknowledge Dr. Peter C. Zee for his valuable constructive feedback during the club meetings. The authors also appreciate all participants of the Club meetings since fall 2025, whose engagement and feedback contributed to the success of this project. Some figures were created using BioRender.com.

Conflict of interest

The author(s) declared that this work was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.

Generative AI statement

The author(s) declared that generative AI was used in the creation of this manuscript. The authors used ChatGPT (OpenAI) to assist with grammar and language editing, to obtain preliminary plain-language explanations of selected code blocks, and to generate candidate code suggestions for tutorial examples, during manuscript preparation. All AI-suggested revisions and code were carefully reviewed, edited, checked, and validated against the SLiM manual by the authors, who take full responsibility for the final content of the manuscript.

Any alternative text (alt text) provided alongside figures in this article has been generated by Frontiers with the support of artificial intelligence and reasonable efforts have been made to ensure accuracy, including review by the authors wherever possible. If you identify any issues, please contact us.

Publisher’s note

All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article, or claim that may be made by its manufacturer, is not guaranteed or endorsed by the publisher.

Supplementary material

The Supplementary Material for this article can be found online at: https://www.frontiersin.org/articles/10.3389/fevo.2026.1870197/full#supplementary-material

References

Summary

Keywords

beginners, evolution, forward-time simulation, mutation, SLiM

Citation

Roy M, Pokharel B, Nepal S, Nighswander N, Miura S, Naeem A and Dawadi P (2026) Simulating evolution for everyone: a practical introduction to SLiM. Front. Ecol. Evol. 14:1870197. doi: 10.3389/fevo.2026.1870197

Received

01 May 2026

Revised

02 September 2026

Accepted

03 September 2026

Published

23 September 2026

Volume

14 - 2026

Edited by

István Scheuring, Centre for Ecological Research, Hungary

Reviewed by

Martyna Lukaszewicz, University of Idaho, United States

Jonathan Bartlett, The Blyth Institute, United States

Updates

Copyright

*Correspondence: Prabin Dawadi, ; Afifa Naeem,

†These authors have contributed equally to this work

Disclaimer

All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article or claim that may be made by its manufacturer is not guaranteed or endorsed by the publisher.

Outline

Figures

Cite article

Copy to clipboard


Export citation file


Share article

Article metrics