Working example - parameters for the simulation of a trait#

import fwdpy11

N = 1000
rho = 1000.0
mu_neutral = 0.0
mu_selected = 1e-3

GSSmo = fwdpy11.GaussianStabilizingSelection.single_trait(
    [
        fwdpy11.Optimum(when=0, optimum=0.0, VS=1.0),
        fwdpy11.Optimum(when=10 * N - 200, optimum=1.0, VS=1.0),
    ]
)

p = {
    "nregions": [],
    "gvalue": fwdpy11.Additive(2.0, GSSmo),
    "sregions": [fwdpy11.GaussianS(0, 1., 1, 0.1)],
    "recregions": [fwdpy11.PoissonInterval(0, 1., rho / float(4 * N))],
    "rates": (mu_neutral, mu_selected, None),
    # Keep mutations at frequency 1 in the pop if they affect fitness.
    "prune_selected": False,
    "demography": None,
    "simlen": 10 * N,
}
params = fwdpy11.ModelParams(**p)
print(params.asblack())
fwdpy11.ModelParams(
    nregions=[],
    sregions=[
        fwdpy11.GaussianS(
            beg=0,
            end=1.0,
            weight=1.0,
            sd=0.1,
            h=1.0,
            coupled=True,
            label=0,
            scaling=1.0,
        )
    ],
    recregions=[fwdpy11.PoissonInterval(beg=0, end=1.0, mean=0.25, discrete=False)],
    rates=fwdpy11.MutationAndRecombinationRates(
        neutral_mutation_rate=0.0, selected_mutation_rate=0.001, recombination_rate=None
    ),
    gvalue=fwdpy11.Additive(
        scaling=2.0,
        gvalue_to_fitness=fwdpy11.GaussianStabilizingSelection(
            is_single_trait=True,
            optima=[
                fwdpy11.Optimum(optimum=0.0, VS=1.0, when=0),
                fwdpy11.Optimum(optimum=1.0, VS=1.0, when=9800),
            ],
        ),
        noise=None,
        ndemes=1,
    ),
    demography=None,
    simlen=10000,
    prune_selected=False,
    allow_residual_selfing=True,
)

Modifying model parameters#

Instances of fwdpy11.ModelParams are immutable. To change them, either:

  • Modify the original dict

  • Or, do a round trip through a temporary dict.

The first option is straightforward. Let’s see the second in action. We’ll change the simulation length.

temp_dict = params.asdict()
temp_dict["simlen"] *= 2
params = fwdpy11.ModelParams(**temp_dict)
print(params.simlen)
20000