Parallel Finite Element - General geometry Ewald-like Method
Part of Continuum-particle Simulation Suite under MICCOM
polymer_chain.h
Go to the documentation of this file.
1 // Parallel Finite Element-General Geometry Ewald-like Method.
2 // Copyright (C) 2015-2016 Xujun Zhao, Jiyuan Li, Xikai Jiang
3 
4 // This code is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 
10 // This code is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 
15 
16 // You should have received a copy of the GNU General Public
17 // License along with this code; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20 
21 
22 #pragma once
23 
24 #include <stdio.h>
25 #include "math.h"
26 #include "libmesh/reference_counted_object.h"
27 #include "libmesh/parallel_object.h"
28 
29 
30 #include "point_particle.h"
31 #include "pm_toolbox.h"
32 
33 
34 
35 
36 namespace libMesh
37 {
38 
39 /*
40  * This class defines a polymer chain for bead-spring model,
41  * Note that this is only used for a single chain.
42  */
43 
44  class PMPeriodicBoundary;
45 
46 
47 class PolymerChain : public ReferenceCountedObject<PolymerChain>
48 // public ParallelObject
49 {
50 public:
51 
52  // Constructor
53  PolymerChain(const std::size_t chain_id);
54 
55 
56  // Constructor with periodic boundary
57  PolymerChain(const std::size_t chain_id,
58  PMPeriodicBoundary& pm_pb);
59 
60 
61  // Destructor
62  ~PolymerChain();
63 
64 
65  /*
66  * Read the data of chain from local file, whose data structure is:
67  * Nb
68  * global# local# bead_type x0 y0 z0 a0 b0 c0
69  * global# local# bead_type x1 y1 z1 a1 b1 c1
70  * ......
71  * Generated by Pizza.py chain tool.
72  * Note this is only used to read one chain data.
73  */
74  void read_data(const std::string& filename); // particle xyz file);
75 
76 
77  /*
78  * Read the data of chain from local file
79  * Generated by Pizza.py chain tool.
80  */
81  void read_data_pizza(const std::string& filename);
82 
83 
84  /*
85  * Read the data of chain from local file with vtk format.
86  * This will be useful to restart the simulation
87  */
88  void read_data_vtk(const std::string& filename);
89 
90  /*
91  * Read the data of chain from local file with csv format.
92  * This will be useful to restart the simulation
93  */
94  void read_data_csv(const std::string& filename);
95 
96 
97  /*
98  * Read the data of PBC counter from local file.
99  * This is useful to restart the simulation
100  */
101  void read_pbc_count();
102 
103 
104  /*
105  * Add a bead to the polymer chain, bonded with \bond_bead
106  */
107  void add_bead(const Point& pt,
108  const PointType point_type,
109  const int parent_id,
110  const std::vector<Real>& rot_vec);
111 
112 
113 /* generate multiple polymer_chains for simulation
114 
115  =========================================================================================================
116  * !n_chains ---> number of polymer chains you want to generate
117  * !n_beads_perChain ---> number of beads per chain (all chains have the same number of beads)
118  * !LS ---> the maximum bond length
119  * !init_bbox_min ---> min of the box you want to generate your initial polymers in.
120  * !init_bbox_max ---> mat of the box you wnat to generate your initial polymers in.
121  * !filename ---> where you want to output the polymer data you generated.
122  */
123  void generate_polymer_chains(const unsigned int n_beads,
124  const unsigned int n_chains,
125  const Real init_bondLength,
126  const Point init_bbox_min,
127  const Point init_bbox_max,
128  const std::string& filename,
129  unsigned int comm_in_rank);
130 
131 
132 
133 
134  /************ NOT ready for use right now!
135  *
136  * Generate a polymer chain within the bounding box with random walk.
137  * pt0 defines the location of the first bead;
138  * Number of beads Nb, and number of spring Ns = Nb - 1;
139  * Equilibrium Length of spring is Ls.
140  */
141  void generate_polymer_chain(const Point pt0,
142  const std::size_t Nb, const Real Ls,
143  const Point& bbox_min,
144  const Point& bbox_max,
145  const std::string& filename);
146 
147 
148 
149  /*
150  * Print out the polymer info
151  */
152  void print_info() const;
153 
154 
155  /*
156  * Write out the polymer chain to a local file
157  */
158  void write_polymer_chain(const unsigned int& step_id,
159  const unsigned int& o_step,
160  const Real& real_time,
161  const std::vector<Point>& center0,
162  const std::vector<Real>& lvec,
163  std::vector<std::string>& output_file,
164  unsigned int comm_in_rank) const;
165  /*
166  * Write out trajectories of all polymers (in vtk format)
167  * "output_polymer_o_step.vtk"
168  */
169  void write_polymer_trajectory (const unsigned int& o_step,
170  unsigned int comm_in_rank) const;
171 
172  /*
173  * Write out center of mass of each chain (in vtk format)
174  * "out.center_of_mass"
175  */
176  void write_polymer_com(const unsigned int& step_id,
177  const unsigned int& o_step,
178  const std::vector<Real>& lvec,
179  unsigned int comm_in_rank) const;
180  /*
181  * Write out stretch of each polymer chain
182  * "out.stretch"
183  */
184  void write_polymer_stretch(const unsigned int& step_id,
185  const unsigned int& o_step,
186  const std::vector<Real>& lvec,
187  unsigned int comm_in_rank) const;
188  /*
189  * Write out radius of gyration of each polymer chain
190  * "out.radius_of_gyration"
191  */
192  void write_polymer_rog(const unsigned int& step_id,
193  const unsigned int& o_step,
194  const std::vector<Real>& lvec,
195  unsigned int comm_in_rank) const;
196 
197  /*
198  * Write out mean square displacement
199  * Average over all chains
200  * "out.mean_square_displacement"
201  */
202  void write_polymer_msd(const unsigned int& step_id,
203  const unsigned int& o_step,
204  const std::vector<Point>& center0,
205  const std::vector<Real>& lvec,
206  unsigned int comm_in_rank) const;
207 
208  /*
209  * Write out the bead to a local file
210  */
211  void write_bead(const unsigned int& step_id,
212  const unsigned int& o_step,
213  const Real& real_time,
214  const std::vector<Point>& center0,
215  const std::vector<Real>& lvec,
216  const std::vector<std::string>& output_file,
217  unsigned int comm_in_rank) const;
218 
219  /*
220  * Write out bead trajectories && forces && velocity to csv files
221  * "output_bead_o_step.csv"
222  */
223  void write_bead_trajectory(const unsigned int& o_step,
224  unsigned int comm_in_rank) const;
225 
226  /*
227  * Write out center of mass
228  * average over all beads, output is a point
229  * this center of mass usually is of no use, but I implemented it just in case
230  * "out.center_of_mass"
231  */
232  void write_bead_com(const unsigned int& step_id,
233  const unsigned int& o_step,
234  const std::vector<Real>& lvec,
235  unsigned int comm_in_rank) const;
236 
237  /*
238  * Write out mean square displacement of all beads
239  * Average over all beads
240  * "out.center_of_mass"
241  */
242  void write_bead_msd(const unsigned int& step_id,
243  const unsigned int& o_step,
244  const std::vector<Point>& center0,
245  const std::vector<Real>& lvec,
246  unsigned int comm_in_rank) const;
247  /*
248  * write out step and real time
249  */
250  void write_time(const unsigned int& step_id,
251  const unsigned int& o_step,
252  const Real& real_time,
253  unsigned int comm_in_rank) const;
254 
255  /*
256  * Write out the unfolded polymer chain to a local file in .xyz format
257  */
258  void write_unfolded_polymer_chain(const std::string& filename) const;
259 
260 
261  /*
262  * Write out the center of mass of unfolded polymer chain
263  * to a local file in .xyz format
264  */
265  void write_unfolded_com(const std::string& filename) const;
266 
267 
268  /*
269  * Return the chain id
270  */
271  std::size_t chain_id() const { return _chain_id; }
272 
273 
274  std::size_t n_chains() const { return _n_chains;}
275 
276  /*
277  * Return the total number of beads
278  */
279  std::size_t n_beads() const { return _beads.size(); }
280 
281 
282  /*
283  * Return the total number of bonds
284  */
285  std::size_t n_bonds() const { return _n_bonds; }
286 
287 
288  /*
289  * Return the total number of springs
290  */
291  std::size_t n_springs() const { return _beads.size()-1; }
292 
293 
294  /*
295  * The beads vector for both const Ref and non-const Ref
296  */
297  const std::vector<PointParticle*>& beads() { return _beads; };
298 
299 
300  /*
301  * The bonds vector for both const Ref and non-const Ref
302  */
303  const std::vector<std::vector<std::size_t> >& bonds() { return _bonds; };
304 
305 
306  /*
307  * The i-th spring vector of coarse grained polymer chain
308  * R(i+1) - R(i), where R is position vector of the bead
309  */
310  Point spring_vector(const unsigned int i) const;
311 
312 
313  /*
314  * Return the end-to-end vector of a polymer chain
315  * sum[n=1:N]r(n), where r(n) is the n-th bond vector
316  */
317  Point end_to_end_vector() const;
318 
319 
320  /*
321  * Return the average square end-to-end vector of a polymer chain
322  * sum[m=1:N]sum[n=1:N]r(m)r(n)
323  * for an ideal chain, <R2> = N*b^2
324  */
325  Point end_to_end_vector_square() const;
326 
327 
328  /*
329  * Compute the current length of the chain
330  * Note the chain length is NOT the contour length of the chain
331  */
332  Real compute_chain_length();
333 
334 
335  /*
336  * Contour length of the chain
337  */
338  //const Real contour_length() const;
339 
340  /*
341  * Compute center_of_mass of each chain
342  */
343  void compute_center_of_mass(const std::vector<Real>& lvec,
344  std::vector<Point>& center) const;
345 
346  /*
347  * Compute center of mass at step 0: center0, for beads
348  */
349  void initial_bead_center_of_mass(std::vector<Point>& center0) const;
350 
351  /*
352  * Compute center of mass at step 0: center0, for chains
353  */
354  void initial_chain_center_of_mass(std::vector<Point>& center0) const;
355 
356  /*
357  * Compute chain_stretch of each chain
358  */
359  void compute_chain_stretch(const std::vector<Real>& lvec,
360  std::vector<Point>& stretch) const;
361 
362  /*
363  * Compute radius_of_gyration of each chain
364  */
365  void compute_radius_of_gyration(const std::vector<Real>& lvec,
366  const std::vector<Point>& center,
367  std::vector<Real>& RgSqrt) const;
368 
369 
370  void compute_mean_square_displacement(const std::vector<Point>& R0,
371  const std::vector<Point>& Rt,
372  Point& msd) const;
373  /*
374  * Check if the chain is broken. If so, repair it.
375  * It loops over every bond, so the created chain MUST
376  * have bond information.
377  */
378  bool check_chain(const Real& Ls); // Maxium length of the spring.
379 
380 
381  /*
382  * Return the direction vector of two beads
383  */
384  Point bead_vector(const Point& bead0,
385  const Point& bead1) const;
386 
387 
388 private:
389 
390  // -------------------- New data structure -------------------
391 
392  // number of atoms(beads),
393  std::size_t _n_beads;
394 
395  // number of bonds(springs)
396  std::size_t _n_bonds;
397 
398  // number of chains
399  int _n_chains;
400 
401  // number of atom types
402  std::size_t _n_bead_types;
403 
404  // number of bond types
405  std::size_t _n_bond_types;
406 
407  // number of beads on each chain
408  std::vector<size_t> _n_beads_per_chain;
409 
410  // mass values of atoms(beads)
411  std::vector<Real> _mass;
412 
413  // atom id, chain id and atom types are stored in PointParticle
414 
415  // atoms(beads) info
416  std::vector<PointParticle*> _beads;
417 
418  // bonds info
419  std::vector<std::vector<std::size_t> > _bonds;
420  // -----------------------------------------------------------
421 
422 
423  // the identity of the chain
424  std::size_t _chain_id;
425 
426  // dimension of the system
427  const unsigned int _dim = 3;
428 
429  // Bead list: two neighboring beads are connected by a spring.
430  //std::vector<PointParticle*> _beads;
431 
432  // Pointer to the Periodic boundary condition
433  PMPeriodicBoundary* _periodic_boundary;
434 
435  // precision of output
436  const int o_precision = 6;
437 }; // end of class
438 
439 } // end of namespace
440 
void add_bead(const Point &pt, const PointType point_type, const int parent_id, const std::vector< Real > &rot_vec)
Definition: polymer_chain.C:417
void compute_center_of_mass(const std::vector< Real > &lvec, std::vector< Point > &center) const
Definition: polymer_chain.C:1263
void generate_polymer_chains(const unsigned int n_beads, const unsigned int n_chains, const Real init_bondLength, const Point init_bbox_min, const Point init_bbox_max, const std::string &filename, unsigned int comm_in_rank)
Definition: polymer_chain.C:444
void write_bead_trajectory(const unsigned int &o_step, unsigned int comm_in_rank) const
Definition: polymer_chain.C:947
void write_unfolded_com(const std::string &filename) const
Definition: polymer_chain.C:1113
void read_data(const std::string &filename)
Definition: polymer_chain.C:70
void write_unfolded_polymer_chain(const std::string &filename) const
Definition: polymer_chain.C:1076
void generate_polymer_chain(const Point pt0, const std::size_t Nb, const Real Ls, const Point &bbox_min, const Point &bbox_max, const std::string &filename)
Definition: polymer_chain.C:571
const std::vector< std::vector< std::size_t > > & bonds()
Definition: polymer_chain.h:303
void read_data_vtk(const std::string &filename)
Definition: polymer_chain.C:228
Real compute_chain_length()
Definition: polymer_chain.C:1238
std::size_t chain_id() const
Definition: polymer_chain.h:271
Definition: brownian_system.h:58
Definition: pm_periodic_boundary.h:46
const std::vector< PointParticle * > & beads()
Definition: polymer_chain.h:297
void compute_chain_stretch(const std::vector< Real > &lvec, std::vector< Point > &stretch) const
Definition: polymer_chain.C:1310
void write_polymer_rog(const unsigned int &step_id, const unsigned int &o_step, const std::vector< Real > &lvec, unsigned int comm_in_rank) const
Definition: polymer_chain.C:855
void read_data_pizza(const std::string &filename)
Definition: polymer_chain.C:123
void write_bead(const unsigned int &step_id, const unsigned int &o_step, const Real &real_time, const std::vector< Point > &center0, const std::vector< Real > &lvec, const std::vector< std::string > &output_file, unsigned int comm_in_rank) const
Definition: polymer_chain.C:921
void read_pbc_count()
Definition: polymer_chain.C:382
Point end_to_end_vector() const
Definition: polymer_chain.C:1181
Definition: polymer_chain.h:47
Point bead_vector(const Point &bead0, const Point &bead1) const
Definition: polymer_chain.C:1446
void write_polymer_stretch(const unsigned int &step_id, const unsigned int &o_step, const std::vector< Real > &lvec, unsigned int comm_in_rank) const
Definition: polymer_chain.C:824
std::size_t n_chains() const
Definition: polymer_chain.h:274
std::size_t n_bonds() const
Definition: polymer_chain.h:285
~PolymerChain()
Definition: polymer_chain.C:56
void read_data_csv(const std::string &filename)
Definition: polymer_chain.C:320
void write_polymer_com(const unsigned int &step_id, const unsigned int &o_step, const std::vector< Real > &lvec, unsigned int comm_in_rank) const
Definition: polymer_chain.C:793
void write_polymer_chain(const unsigned int &step_id, const unsigned int &o_step, const Real &real_time, const std::vector< Point > &center0, const std::vector< Real > &lvec, std::vector< std::string > &output_file, unsigned int comm_in_rank) const
Definition: polymer_chain.C:711
void initial_chain_center_of_mass(std::vector< Point > &center0) const
Definition: polymer_chain.C:1294
void print_info() const
Definition: polymer_chain.C:661
std::size_t n_springs() const
Definition: polymer_chain.h:291
void write_polymer_msd(const unsigned int &step_id, const unsigned int &o_step, const std::vector< Point > &center0, const std::vector< Real > &lvec, unsigned int comm_in_rank) const
Definition: polymer_chain.C:887
void compute_radius_of_gyration(const std::vector< Real > &lvec, const std::vector< Point > &center, std::vector< Real > &RgSqrt) const
Definition: polymer_chain.C:1355
void write_bead_com(const unsigned int &step_id, const unsigned int &o_step, const std::vector< Real > &lvec, unsigned int comm_in_rank) const
Definition: polymer_chain.C:983
Point spring_vector(const unsigned int i) const
Definition: polymer_chain.C:1160
PointType
Definition: point_particle.h:39
void initial_bead_center_of_mass(std::vector< Point > &center0) const
Definition: polymer_chain.C:1283
void write_bead_msd(const unsigned int &step_id, const unsigned int &o_step, const std::vector< Point > &center0, const std::vector< Real > &lvec, unsigned int comm_in_rank) const
Definition: polymer_chain.C:1015
void write_time(const unsigned int &step_id, const unsigned int &o_step, const Real &real_time, unsigned int comm_in_rank) const
Definition: polymer_chain.C:1054
PolymerChain(const std::size_t chain_id)
Definition: polymer_chain.C:37
void write_polymer_trajectory(const unsigned int &o_step, unsigned int comm_in_rank) const
Definition: polymer_chain.C:739
void compute_mean_square_displacement(const std::vector< Point > &R0, const std::vector< Point > &Rt, Point &msd) const
Definition: polymer_chain.C:1378
Point end_to_end_vector_square() const
Definition: polymer_chain.C:1205
bool check_chain(const Real &Ls)
Definition: polymer_chain.C:1401
std::size_t n_beads() const
Definition: polymer_chain.h:279