Skip to content

Commit

Permalink
add deviatePositions() method to Subpopulation
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Jan 19, 2024
1 parent 8a9997a commit 132ba44
Show file tree
Hide file tree
Showing 14 changed files with 594 additions and 133 deletions.
14 changes: 8 additions & 6 deletions QtSLiM/help/SLiMHelpClasses.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ early() {
sim.killIndividuals(c(inds4[death4], inds5[death5], inds6));

// disperse prior to density-dependence
inds = p1.individuals;
pos = inds.spatialPosition;
pos = p1.pointDeviated(inds.size(), pos, "reprising", INF, "n", 0.02);
inds.setSpatialPosition(pos);
p1.deviatePositions(NULL, "reprising", INF, "n", 0.02);

// spatial competition provides density-dependent selection
i1.evaluate(p1);
inds = p1.individuals;
competition = i1.localPopulationDensity(inds);
inds.fitnessScaling = K / competition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ initialize() {
}
1: late() {
// Dispersal and boundary enforcement
inds = p1.individuals;
pos = inds.spatialPosition;
pos = p1.pointDeviated(inds.size(), pos, "reprising", INF, "n", 0.02);
inds.setSpatialPosition(pos);
p1.deviatePositions(NULL, "reprising", INF, "n", 0.02);

// Evaluate for competition
i1.evaluate(p1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ early() {
sim.killIndividuals(c(inds4[death4], inds5[death5], inds6));

// disperse prior to density-dependence
inds = p1.individuals;
pos = inds.spatialPosition;
pos = p1.pointDeviated(inds.size(), pos, "reprising", INF, "n", 0.02);
inds.setSpatialPosition(pos);
p1.deviatePositions(NULL, "reprising", INF, "n", 0.02);

// spatial competition provides density-dependent selection
i1.evaluate(p1);
inds = p1.individuals;
competition = i1.localPopulationDensity(inds);
inds.fitnessScaling = K / competition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ initialize() {
}
1: late() {
// Dispersal and boundary enforcement
inds = p1.individuals;
pos = inds.spatialPosition;
pos = p1.pointDeviated(inds.size(), pos, "reprising", INF, "n", 0.02);
inds.setSpatialPosition(pos);
p1.deviatePositions(NULL, "reprising", INF, "n", 0.02);

// Evaluate for competition
i1.evaluate(p1);
Expand Down
68 changes: 65 additions & 3 deletions SLiMgui/SLiMHelpClasses.rtf
Original file line number Diff line number Diff line change
Expand Up @@ -8451,6 +8451,8 @@ Also beginning in SLiM 4.1, in spatial models the spatial position of the offspr
\f4\fs20 property in 2D/3D models, and the
\f3\fs18 z
\f4\fs20 property in 3D models. Properties not inherited will be left uninitialized, as they were prior to SLiM 4.1. The parent\'92s spatial position is probably not desirable in itself; the intention here is to make it easy to model the natal dispersal of all the new offspring for a given tick with a single vectorized call to
\f3\fs18 deviatePositions()
\f4\fs20 /
\f3\fs18 pointDeviated()
\f4\fs20 .\
Note that this method is only for use in nonWF models. See
Expand Down Expand Up @@ -8590,6 +8592,8 @@ Also beginning in SLiM 4.1, in spatial models the spatial position of the offspr
\f4\fs20 property in 2D/3D models, and the
\f3\fs18 z
\f4\fs20 property in 3D models. Properties not inherited will be left uninitialized, as they were prior to SLiM 4.1. The parent\'92s spatial position is probably not desirable in itself; the intention here is to make it easy to model the natal dispersal of all the new offspring for a given tick with a single vectorized call to
\f3\fs18 deviatePositions()
\f4\fs20 /
\f3\fs18 pointDeviated()
\f4\fs20 .\
Note that this method is only for use in nonWF models, in which offspring generation is managed manually by the model script; in such models,
Expand Down Expand Up @@ -8927,6 +8931,8 @@ Also beginning in SLiM 4.1, in spatial models the spatial position of the offspr
\f4\fs20 property in 2D/3D models, and the
\f3\fs18 z
\f4\fs20 property in 3D models. Properties not inherited will be left uninitialized, as they were prior to SLiM 4.1. The parent\'92s spatial position is probably not desirable in itself; the intention here is to make it easy to model the natal dispersal of all the new offspring for a given tick with a single vectorized call to
\f3\fs18 deviatePositions()
\f4\fs20 /
\f3\fs18 pointDeviated()
\f4\fs20 . If
\f3\fs18 parent1
Expand Down Expand Up @@ -9002,6 +9008,8 @@ Also beginning in SLiM 4.1, in spatial models the spatial position of the offspr
\f4\fs20 property in 2D/3D models, and the
\f3\fs18 z
\f4\fs20 property in 3D models. Properties not inherited will be left uninitialized, as they were prior to SLiM 4.1. The parent\'92s spatial position is probably not desirable in itself; the intention here is to make it easy to model the natal dispersal of all the new offspring for a given tick with a single vectorized call to
\f3\fs18 deviatePositions()
\f4\fs20 /
\f3\fs18 pointDeviated()
\f4\fs20 .\
Note that this method is only for use in nonWF models. See
Expand Down Expand Up @@ -9260,6 +9268,56 @@ Note that at present, SLiMgui will only display spatial maps of spatiality
\f4\fs20 method will return translated color strings for any spatial map, however, even if SLiMgui is unable to display the spatial map. If there are multiple spatial maps that SLiMgui is capable of displaying, it choose one for display by default, but other maps may be selected from the action menu on the individuals view (by clicking on the button with the gear icon).\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf2 \'96\'a0(void)deviatePositions(No<Individual>\'a0individuals, string$\'a0boundary, numeric$\'a0maxDistance, string$\'a0functionType, ...)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\f4\fs20 \cf2 Deviates the spatial positions of the individuals supplied in
\f3\fs18 individuals
\f4\fs20 , using the provided boundary condition and dispersal kernel. If
\f3\fs18 individuals
\f4\fs20 is
\f3\fs18 NULL
\f4\fs20 , the positions of all individuals in the target subpopulation are deviated. This method is essentially a more efficient shorthand for getting the spatial positions of
\f3\fs18 individuals
\f4\fs20 from the
\f3\fs18 spatialPosition
\f4\fs20 property, deviating those positions with
\f3\fs18 pointDeviated()
\f4\fs20 , and setting the deviated positions back into
\f3\fs18 individuals
\f4\fs20 with the
\f3\fs18 setSpatialPosition()
\f4\fs20 method. The boundary condition
\f3\fs18 boundary
\f4\fs20 must be one of
\f3\fs18 "none"
\f4\fs20 ,
\f3\fs18 "periodic"
\f4\fs20 ,
\f3\fs18 "reflecting"
\f4\fs20 ,
\f3\fs18 "stopping"
\f4\fs20 , or
\f3\fs18 "reprising"
\f4\fs20 , and the spatial kernel type
\f3\fs18 functionType
\f4\fs20 must be one of
\f3\fs18 "f"
\f4\fs20 ,
\f3\fs18 "l"
\f4\fs20 ,
\f3\fs18 "e"
\f4\fs20 ,
\f3\fs18 "n"
\f4\fs20 , or
\f3\fs18 "t"
\f4\fs20 , with the ellipsis parameters
\f3\fs18 ...
\f4\fs20 supplying kernel configuration parameters appropriate for that kernel type; see
\f3\fs18 pointDeviated()
\f4\fs20 for further details.\
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf0 \'96\'a0(void)outputMSSample(integer$\'a0sampleSize, [logical$\'a0replace\'a0=\'a0T], [string$\'a0requestedSex\'a0=\'a0"*"], [Ns$\'a0filePath\'a0=\'a0NULL], [logical$\'a0append\'a0=\'a0F]\cf2 \expnd0\expndtw0\kerning0
, [logical$\'a0filterMonomorphic\'a0=\'a0F]\cf0 \kerning1\expnd0\expndtw0 )
\f5 \
Expand Down Expand Up @@ -9443,7 +9501,9 @@ The parameters
\f3\fs18 ...
\f4\fs20 , as detailed below) and then applying a boundary condition specified by
\f3\fs18 boundary
\f4\fs20 . This method therefore performs the steps of a simple dispersal algorithm in a single vectorized call.\
\f4\fs20 . This method therefore performs the steps of a simple dispersal algorithm in a single vectorized call. See
\f3\fs18 deviatePositions()
\f4\fs20 for an even more efficient approach.\
The parameter
\f3\fs18 point
\f4\fs20 may contain a single point which is deviated and bounded
Expand Down Expand Up @@ -9598,13 +9658,15 @@ The boundary condition must be one of
\f4\fs20 methods; see their documentation for further details. For
\f3\fs18 "reprising"
\f4\fs20 , if the deviated point is out of bounds a new deviated point will be chosen, based upon the same original point, until a point inside bounds is obtained. Note that absorbing boundaries (for which being out-of-bounds is lethal) would be implemented in script; this method cannot enforce them.\
In the typical usage case,
Note that for the typical usage case, in which
\f3\fs18 point
\f4\fs20 comes from the
\f3\fs18 spatialPosition
\f4\fs20 property for a vector of individuals, and the result is then set back onto the same vector of individuals using the
\f3\fs18 setSpatialPosition()
\f4\fs20 method; however, this method might be useful in other situations too.\
\f4\fs20 method, the
\f3\fs18 deviatePositions()
\f4\fs20 method provides an even more efficient alternative.\
\pard\pardeftab720\li720\fi-446\ri720\sb180\sa60\partightenfactor0
\f3\fs18 \cf0 \'96\'a0(logical)pointInBounds(float\'a0point)
Expand Down
1 change: 1 addition & 0 deletions VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ development head (in the master branch):
as a side effect, for loop index variables are now constants until the loop has finished
to demonstrate the new syntax, recipes 10.5 and 19.7 have been modified to use it
fix #422: readFromPopulationFile() for .trees files in SLiM 4.1 hits a MUCH higher peak memory usage in some cases, due to over-copying of mutation runs
add deviatePositions() method to Subpopulation for even faster offspring positioning than with pointDeviated(); revise recipes 16.3 and 16.8 to use it


version 4.1 (Eidos version 3.1):
Expand Down
18 changes: 9 additions & 9 deletions core/population.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
species_.RecordNewGenome(nullptr, &child_genome_2, &parent_genome_2, nullptr);
}

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

DoClonalMutation(&source_subpop, child_genome_1, parent_genome_1, child_sex, mutation_callbacks);
Expand Down Expand Up @@ -1547,7 +1547,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
if (recording_tree_sequence)
species_.SetCurrentNewIndividual(new_child);

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

// recombination, gene-conversion, mutation
Expand Down Expand Up @@ -1637,7 +1637,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
if (recording_tree_sequence)
species_.SetCurrentNewIndividual(new_child);

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

// recombination, gene-conversion, mutation
Expand Down Expand Up @@ -1932,7 +1932,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
species_.RecordNewGenome(nullptr, &child_genome_2, &parent_genome_2, nullptr);
}

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop->parent_individuals_[parent1]);

DoClonalMutation(source_subpop, child_genome_1, parent_genome_1, child_sex, mutation_callbacks);
Expand Down Expand Up @@ -2005,7 +2005,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
if (recording_tree_sequence)
species_.SetCurrentNewIndividual(new_child);

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop->parent_individuals_[parent1]);

// recombination, gene-conversion, mutation
Expand Down Expand Up @@ -2205,7 +2205,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
//if (recording_tree_sequence)
// species_.SetCurrentNewIndividual(new_child); // this is disabled because it is not thread-safe, and we have no callbacks so we will not retract this child

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

// recombination, gene-conversion, mutation
Expand Down Expand Up @@ -2246,7 +2246,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
//if (recording_tree_sequence)
// species_.SetCurrentNewIndividual(new_child); // this is disabled because it is not thread-safe, and we have no callbacks so we will not retract this child

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

// recombination, gene-conversion, mutation
Expand Down Expand Up @@ -2306,7 +2306,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
}
}

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

DoClonalMutation(&source_subpop, child_genome_1, parent_genome_1, child_sex, nullptr);
Expand Down Expand Up @@ -2363,7 +2363,7 @@ void Population::EvolveSubpopulation(Subpopulation &p_subpop, bool p_mate_choice
//if (recording_tree_sequence)
// species_.SetCurrentNewIndividual(new_child); // this is disabled because it is not thread-safe, and we have no callbacks so we will not retract this child

// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for pointDeviated()
// BCH 9/26/2023: inherit the spatial position of the first parent by default, to set up for deviatePositions()/pointDeviated()
new_child->InheritSpatialPosition(species_.SpatialDimensionality(), source_subpop.parent_individuals_[parent1]);

// recombination, gene-conversion, mutation
Expand Down
1 change: 1 addition & 0 deletions core/slim_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,7 @@ const std::string &gStr_treeSeqSimplify = EidosRegisteredString("treeSeqSimplify
const std::string &gStr_treeSeqRememberIndividuals = EidosRegisteredString("treeSeqRememberIndividuals", gID_treeSeqRememberIndividuals);
const std::string &gStr_treeSeqOutput = EidosRegisteredString("treeSeqOutput", gID_treeSeqOutput);
const std::string &gStr_setMigrationRates = EidosRegisteredString("setMigrationRates", gID_setMigrationRates);
const std::string &gStr_deviatePositions = EidosRegisteredString("deviatePositions", gID_deviatePositions);
const std::string &gStr_pointDeviated = EidosRegisteredString("pointDeviated", gID_pointDeviated);
const std::string &gStr_pointInBounds = EidosRegisteredString("pointInBounds", gID_pointInBounds);
const std::string &gStr_pointReflected = EidosRegisteredString("pointReflected", gID_pointReflected);
Expand Down
2 changes: 2 additions & 0 deletions core/slim_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,7 @@ extern const std::string &gStr_treeSeqSimplify;
extern const std::string &gStr_treeSeqRememberIndividuals;
extern const std::string &gStr_treeSeqOutput;
extern const std::string &gStr_setMigrationRates;
extern const std::string &gStr_deviatePositions;
extern const std::string &gStr_pointDeviated;
extern const std::string &gStr_pointInBounds;
extern const std::string &gStr_pointReflected;
Expand Down Expand Up @@ -1335,6 +1336,7 @@ enum _SLiMGlobalStringID : int {
gID_treeSeqRememberIndividuals,
gID_treeSeqOutput,
gID_setMigrationRates,
gID_deviatePositions,
gID_pointDeviated,
gID_pointInBounds,
gID_pointReflected,
Expand Down
Loading

0 comments on commit 132ba44

Please sign in to comment.