Ok I found my mistake!!
When defining my msprime.Demography object(), I used add_population to add an ancestral population called "pop_anc".
Apparently this was wrong, because that population did not exist in the initial tree from SLiM, which is why it appeared nowhere in the tree metadata leading to the error message.
ts = pyslim.load("test.trees")
Ne_demo = 500
t_split = 4*Ne_demo
demography = msprime.Demography.from_tree_sequence(ts)
for pop in demography.populations:
pop.initial_size = Ne_demo
# demography.add_population(name="pop_anc", initial_size= int(Ne_demo*2)) # This is the line to be removed.
demography.add_population_split(time=t_split, derived=["p1", "p2"], ancestral="pop_0") # Use pop_0 instead, it already exists in the tree.
demography.set_symmetric_migration_rate(populations=["p1", "p2"], rate=0.05)
rts = pyslim.recapitate(ts, demography=demography, recombination_rate=rate_map, random_seed=1) # Now works!
So this is great, and I guess it is actually possible to add a new, unexisting population to the tree, but then we have to set its metadata manually?
Sorry for the confusion!
Thank you so much again for all the help you provide to us users, with the endless SLiM/pyslim possibilities!!
Best regards,
Chrystelle