I have a 3D simple cubic lattice, which I call Grid
in my code, with periodic boundary conditions of size 20x20x20 (number are arbitrary). What I want to do is plant multiple polymer chains with a degree of polymerization N (graphs with N nodes) that do no overlap, are self-avoiding.
At the moment, I can plant one polymer recursively. This is my code
const std::vector <int> ex{1,0,0}, nex{-1,0,0}, ey{0,1,0}, ney{0,-1,0}, ez{0,0,1}, nez{0,0,-1}; // unit directions
const std::vector <std::vector <int>> drns = {ex, nex, ey, ney, ez, nez}; // vector of unit directions
void Grid::plant_polymer(int DoP, std::vector <std::vector <int>>* loc_list){
// loc_list is the list of places the polymer has been
// for this function, I provide a starting point
if (DoP == 0){
Polymer p (loc_list);
this->polymer_chains.push_back(p); // polymer_chains is the attribute which holds all polymer chains in the grid
return; // once the degree of polymerization hits zero, you are done
};
// until then
// increment final vector in loc_list in a unit direction
std::vector <int> next(3,0);
for (auto v: drns){
next = add_vectors(&((*loc_list).at((*loc_list).size()-1)), &v);
impose_pbc(&next, this->x_len, this->y_len, this->z_len);
if (this->occupied[next]==0){ // occupied is a map which takes in a location, and spits out if it is occupied (1) or not (0)
// occupied is an attribute of the class Grid
dop--; // decrease dop now that a monomer unit has been added
(*loc_list).push_back(next); // add monomer to list
this->occupied[next] == 1;
return plant_polymer(DoP, loc_list);
}
}
std::cout << "no solution found for the self-avoiding random walk...";
return;
This is not a general solution. I am providing a seed for the polymer, and also, I am only planting one polymer. I want to make it such that I can plant multiple polymers, without specifying a seed. Is it possible to recursively hunt for a starting position, every time I want to add a polymer, and then build a polymer while making sure it is not overlapping with other polymers already in the system? Any advice you have would be appreciated.