forked from gfrd/egfrd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEGFRDSimulatorFactory.hpp
96 lines (79 loc) · 3.45 KB
/
EGFRDSimulatorFactory.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef EGFRD_SIMULATOR_FACTORY_HPP
#define EGFRD_SIMULATOR_FACTORY_HPP
#include "ParticleSimulatorFactory.hpp"
#include "EGFRDSimulator.hpp"
#include "CuboidalRegion.hpp"
#include "linear_algebra.hpp"
template<typename Ttraits_>
class EGFRDSimulatorFactory: public ParticleSimulatorFactory<Ttraits_>
{
public:
typedef ParticleSimulatorFactory<Ttraits_> base_type;
typedef Ttraits_ traits_type;
typedef typename traits_type::world_type world_type;
typedef typename world_type::traits_type world_traits_type;
// shorthand typedefs
typedef typename world_traits_type::length_type length_type;
typedef typename world_traits_type::size_type size_type;
typedef typename world_traits_type::position_type position_type;
typedef typename world_traits_type::rng_type rng_type;
typedef typename traits_type::network_rules_type network_rules_type;
typedef CuboidalRegion<world_traits_type> cuboidal_region_type;
public:
EGFRDSimulatorFactory(rng_type& rng): rng_(rng) {}
virtual ~EGFRDSimulatorFactory() {}
virtual EGFRDSimulator<traits_type>* operator()(ParticleModel const& model) const
{
length_type const world_size(boost::lexical_cast<length_type>(model["size"]));
size_type matrix_size(3);
int dissociation_retry_moves(3);
try
{
matrix_size = boost::lexical_cast<length_type>(model["matrix_size"]);
}
catch (not_found const&) {}
try
{
dissociation_retry_moves = boost::lexical_cast<length_type>(model["dissociation_retry_moves"]);
}
catch (not_found const&) {}
position_type const x(divide(position_type(world_size, world_size, world_size), 2));
boost::shared_ptr<world_type> world(
new world_type(world_size, matrix_size));
world->add_structure(
boost::shared_ptr<cuboidal_region_type>(
new cuboidal_region_type(
"world", model.get_def_structure_type_id(),
typename cuboidal_region_type::shape_type(x, x))));
BOOST_FOREACH (boost::shared_ptr<StructureType> st,
model.get_structure_types())
{
std::string const& type((*st)["type"]);
// TODO: add surfaces to world
}
// Making sure that all the species have a structure_type defined?
BOOST_FOREACH (boost::shared_ptr<SpeciesType> st,
model.get_species_types())
{
structure_type_id_type const& structure_type_id((*st)["structure_type"]);
world->add_species(
typename world_traits_type::species_type(
st->id(),
boost::lexical_cast<typename world_traits_type::D_type>(
(*st)["D"]),
boost::lexical_cast<length_type>((*st)["radius"]),
boost::lexical_cast<typename world_traits_type::structure_type_id_type>(
structure_type_id.empty() ? model.get_def_structure_type_id(): structure_type_id)
));
}
return new EGFRDSimulator<traits_type>(
world,
boost::shared_ptr<network_rules_type>(
new network_rules_type(model.network_rules())),
rng_, dissociation_retry_moves);
}
///// Member variables
protected:
rng_type& rng_;
};
#endif /* EGFRD_SIMULATION_HPP */