MEDYAN  3.1
Software for simulating active matter dynamics
Cylinder.cpp
Go to the documentation of this file.
1 
2 //------------------------------------------------------------------
3 // **MEDYAN** - Simulation Package for the Mechanochemical
4 // Dynamics of Active Networks, v3.1
5 //
6 // Copyright (2015-2016) Papoian Lab, University of Maryland
7 //
8 // ALL RIGHTS RESERVED
9 //
10 // See the MEDYAN web page for more information:
11 // http://www.medyan.org
12 //------------------------------------------------------------------
13 
14 #include "Cylinder.h"
15 
16 #include "SubSystem.h"
17 #include "CController.h"
18 #include "ChemManager.h"
19 #include "ChemRNode.h"
20 
21 #include "Filament.h"
22 #include "Bead.h"
23 
24 #include "GController.h"
25 #include "MathFunctions.h"
26 
27 using namespace mathfunc;
28 
30 
31  coordinate = midPointCoordinate(_b1->coordinate, _b2->coordinate, 0.5);
32 }
33 
34 
35 Cylinder::Cylinder(Composite* parent, Bead* b1, Bead* b2, short type, int position,
36  bool extensionFront, bool extensionBack, bool initialization)
37 
38  : Trackable(true, true, true, false),
39  _b1(b1), _b2(b2), _type(type), _position(position), _ID(_cylinders.getID()) {
40 
41  parent->addChild(unique_ptr<Component>(this));
42 
43  //Set coordinate
45 
47  catch (exception& e) {
48  cout << e.what() << endl;
49 
50  printSelf();
51 
52  exit(EXIT_FAILURE);
53  }
54 
55  //add to compartment
57 
58 #ifdef CHEMISTRY
59  _cCylinder = unique_ptr<CCylinder>(new CCylinder(_compartment, this));
60  _cCylinder->setCylinder(this);
61 
62  //init using chem manager
63  _chemManager->initializeCCylinder(_cCylinder.get(), extensionFront,
64  extensionBack, initialization);
65 #endif
66 
67 #ifdef MECHANICS
68  //set eqLength according to cylinder size
69  double eqLength = twoPointDistance(b1->coordinate, b2->coordinate);
70 
71  _mCylinder = unique_ptr<MCylinder>(new MCylinder(_type, eqLength));
72  _mCylinder->setCylinder(this);
73 #endif
74 
75 }
76 
77 Cylinder::~Cylinder() noexcept {
78 
79  //remove from compartment
81 
82 }
83 
85 int Cylinder::getType() {return _type;}
86 
88 
89  //check if were still in same compartment, set new position
91 
92  Compartment* c;
93 
95  catch (exception& e) {
96  cout << e.what();
97 
98  printSelf();
99 
100  exit(EXIT_FAILURE);
101  }
102 
103  if(c != _compartment) {
104 
105 #ifdef CHEMISTRY
106  auto oldCompartment = _compartment;
107  auto newCompartment = c;
108 #endif
109 
110  //remove from old compartment, add to new
112  _compartment = c;
113  _compartment->addCylinder(this);
114 
115 #ifdef CHEMISTRY
116  auto oldCCylinder = _cCylinder.get();
117 
118  //Remove old ccylinder from binding managers
119  for(auto &manager : oldCompartment->getFilamentBindingManagers())
120  manager->removePossibleBindings(oldCCylinder);
121 
122  //clone and set new ccylinder
123  CCylinder* clone = _cCylinder->clone(c);
124  setCCylinder(clone);
125 
126  auto newCCylinder = _cCylinder.get();
127 
128  //Add new ccylinder to binding managers
129  for(auto &manager : newCompartment->getFilamentBindingManagers())
130  manager->addPossibleBindings(newCCylinder);
131  }
132 #endif
133 
134 #ifdef MECHANICS
135  //update length
137  _b2->coordinate));
138 #endif
139 
140 }
141 
144 
146 
147  double force;
148 
149  //if no rate changer was defined, skip
150  if(_polyChanger.empty()) return;
151 
152  //load force from front (affects plus end polymerization)
153  if(_plusEnd) {
154 
155  //get force of front bead
156  force = _b2->getLoadForcesP();
157 
158  //change all plus end polymerization rates
159  for(auto &r : _cCylinder->getInternalReactions()) {
160 
161  if(r->getReactionType() == ReactionType::POLYMERIZATIONPLUSEND) {
162 
163  float newRate = _polyChanger[_type]->changeRate(r->getBareRate(), force);
164 
165  r->setRate(newRate);
166  r->updatePropensity();
167  }
168  }
169  }
170 
171  //load force from back (affects minus end polymerization)
172  if(_minusEnd) {
173 
174  //get force of front bead
175  force = _b1->getLoadForcesM();
176 
177  //change all plus end polymerization rates
178  for(auto &r : _cCylinder->getInternalReactions()) {
179 
180  if(r->getReactionType() == ReactionType::POLYMERIZATIONMINUSEND) {
181 
182  float newRate = _polyChanger[_type]->changeRate(r->getBareRate(), force);
183 
184  r->setRate(newRate);
185  r->updatePropensity();
186  }
187  }
188  }
189 }
190 
191 bool Cylinder::isFullLength() {
192 
193 #ifdef MECHANICS
194  return areEqual(_mCylinder->getEqLength(), SysParams::Geometry().cylinderSize[_type]);
195 #else
196  return true;
197 #endif
198 }
199 
200 void Cylinder::printSelf() {
201 
202  cout << endl;
203 
204  cout << "Cylinder: ptr = " << this << endl;
205  cout << "Cylinder ID = " << _ID << endl;
206  cout << "Parent ptr = " << getParent() << endl;
207  cout << "Coordinates = " << coordinate[0] << ", " << coordinate[1] << ", " << coordinate[2] << endl;
208 
209  if(_plusEnd) cout << "Is a plus end." << endl;
210  if(_minusEnd) cout << "Is a minus end." << endl;
211 
212  if(_branchingCylinder != nullptr) cout << "Has a branching cylinder." << endl;
213 
214  cout << "Position = " << _position << endl;
215 
216  cout << endl;
217 
218 #ifdef CHEMISTRY
219  cout << "Chemical composition of cylinder:" << endl;
220  _cCylinder->printCCylinder();
221 #endif
222 
223  cout << endl;
224 
225  cout << "Bead information..." << endl;
226 
227  _b1->printSelf();
228  _b2->printSelf();
229 
230  cout << endl;
231 }
232 
233 bool Cylinder::within(Cylinder* other, double dist) {
234 
235  //check midpoints
236  if(twoPointDistance(coordinate, other->coordinate) <= dist)
237  return true;
238 
239  //briefly check endpoints of other
240  if(twoPointDistance(coordinate, other->_b1->coordinate) <= dist ||
241  twoPointDistance(coordinate, other->_b2->coordinate) <= dist)
242  return true;
243 
244  return false;
245 }
246 
247 vector<FilamentRateChanger*> Cylinder::_polyChanger;
249 
unique_ptr< CCylinder > _cCylinder
Pointer to chem cylinder.
Definition: Cylinder.h:61
bool _plusEnd
If the cylinder is at the plus end.
Definition: Cylinder.h:65
void updateCoordinate()
Helper to get coordinate.
Definition: Cylinder.cpp:29
virtual void printSelf()
Prints information about this node. Useful for debugging.
static ChemManager * _chemManager
A pointer to the ChemManager, intiailized by CController.
Definition: Cylinder.h:81
A container or holding Species and Reactions.
Definition: Compartment.h:49
For initailizing chemical reactions based on a specific system.
Definition: ChemManager.h:39
bool areEqual(double d1, double d2)
Check equaility of doubles.
Definition: utility.h:34
short _type
Type of cylinder, either corresponding to Filament or other.
Definition: Cylinder.h:68
static Compartment * getCompartment(const vector< size_t > &indices)
Get a compartment based on coordinates or indices.
Definition: GController.cpp:27
A collection class to hold instances of a given class.
Definition: Database.h:38
An abstract base class for a trackable object in the SubSystem.
Definition: Trackable.h:33
Cylinder(Composite *parent, Bead *b1, Bead *b2, short type, int position, bool extensionFront=false, bool extensionBack=false, bool initialization=false)
Constructor, initializes a cylinder.
Definition: Cylinder.cpp:35
virtual void updateReactionRates()
Update the reaction rates, inherited from Reactable.
virtual void updatePosition()
Update the position, inherited from Movable.
Definition: Cylinder.cpp:87
A container to store a MCylinder and CCylinder.
Definition: Cylinder.h:50
is used for the mathematics module for the entire codebase mathfunc includes functions to calculate d...
unique_ptr< MCylinder > _mCylinder
Pointer to mech cylinder.
Definition: Cylinder.h:60
Composite * getParent()
Returns the pointer to the parent node.
Definition: Component.h:78
bool isFullLength()
Check if this cylinder is grown to full length.
vector< double > coordinate
Coordinates of the bead.
Definition: Bead.h:54
double getLoadForcesP()
Helper functions for load forces.
Definition: Bead.cpp:100
void setCCylinder(CCylinder *c)
set chem cylinder
Definition: Cylinder.h:106
vector< double > coordinate
Coordinates of midpoint, updated with updatePosition()
Definition: Cylinder.h:88
virtual void addChild(unique_ptr< Component > &&child)
Adds a Component child to this Composite node.
Definition: Composite.h:81
Used to hold mechanical properties of a Cylinder.
Definition: MCylinder.h:29
virtual void initializeCCylinder(CCylinder *cc, bool extensionFront, bool extensionBack, bool initialization)
Initializer for chem cylinders, based on the given simulation.
static const GeoParams & Geometry()
Const getter.
Definition: SysParams.h:264
virtual bool within(Cylinder *other, double dist)
Returns whether a cylinder is within a certain distance from another Uses the closest point between t...
double twoPointDistance(const vector< double > &v1, const vector< double > &v2)
Compute distance between two points with coordinates: (x1,y1,z1) and (x2,y2,z3)
Definition: MathFunctions.h:54
Holds all CMonomers and Reactions associated with it.
Definition: CCylinder.h:44
static vector< FilamentRateChanger * > _polyChanger
For dynamic polymerization rate.
Definition: Cylinder.h:79
The aggregating class for the Composite pattern.
Definition: Composite.h:42
vector< double > midPointCoordinate(const vector< double > &v1, const vector< double > &v2, double alpha)
Returns coordinates of a point v located on a line between v1 and v2.
Bead * _b2
Pointer to the end bead.
Definition: Cylinder.h:58
int _position
Position on structure.
Definition: Cylinder.h:63
bool _minusEnd
If the cylinder is at the minus end.
Definition: Cylinder.h:66
int _ID
Unique ID of cylinder, managed by Database.
Definition: Cylinder.h:70
virtual ~Cylinder() noexcept
Definition: Cylinder.cpp:77
void removeCylinder(Cylinder *c)
Remove a cylinder from this compartment.
Definition: Compartment.h:490
vector< double > cylinderSize
Geometry parameter.
Definition: SysParams.h:187
double getLoadForcesM()
Definition: Bead.cpp:111
Compartment * _compartment
Where this cylinder is.
Definition: Cylinder.h:72
virtual int getType()
Get cylinder type.
Definition: Cylinder.cpp:85
virtual void printSelf()
Prints information about this node. Useful for debugging.
Definition: Bead.cpp:83
void addCylinder(Cylinder *c)
Add a cylinder to this compartment.
Definition: Compartment.h:486
Cylinder * _branchingCylinder
ptr to a branching cylinder
Definition: Cylinder.h:74
static Database< Cylinder * > _cylinders
Collection in SubSystem.
Definition: Cylinder.h:76
Bead * _b1
Pointer to the first bead.
Definition: Cylinder.h:57
Represents a single coordinate between Cylinders, and holds forces needed for mechanical equilibratio...
Definition: Bead.h:49