World.h
Go to the documentation of this file.
1 //
2 // This file is part of the FFEA simulation package
3 //
4 // Copyright (c) by the Theory and Development FFEA teams,
5 // as they appear in the README.md file.
6 //
7 // FFEA is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // FFEA is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with FFEA. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // To help us fund FFEA development, we humbly ask that you cite
21 // the research papers on the package.
22 //
23 
24 #ifndef WORLD_H_INCLUDED
25 #define WORLD_H_INCLUDED
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <cstring>
30 #include <string>
31 #include <time.h>
32 #include <unistd.h>
33 #include <iostream>
34 #include <fstream>
35 #include <vector>
36 #include <omp.h>
37 #include <ctime>
38 #include <algorithm>
39 
40 #include <boost/algorithm/string.hpp>
41 #include <typeinfo>
42 #include <Eigen/Sparse>
43 #include <Eigen/Eigenvalues>
44 
45 #ifdef FFEA_PARALLEL_FUTURE
46 #include <future>
47 #include <chrono>
48 #endif
49 
50 // #include "MersenneTwister.h"
51 #include "RngStream.h"
53 #include "BEM_Poisson_Boltzmann.h"
54 #include "BiCGSTAB_solver.h"
55 #include "FFEA_user_info.h"
56 #include "FFEA_return_codes.h"
57 #include "FFEA_input_reader.h"
58 #include "mat_vec_types.h"
59 #include "mesh_node.h"
60 #include "tetra_element_linear.h"
61 #include "SimulationParams.h"
62 #include "Solver.h"
64 #include "Face.h"
65 #include "Blob.h"
66 #include "World.h"
67 #include "VdW_solver.h"
68 #include "Steric_solver.h"
69 #include "LJSteric_solver.h"
70 #include "PreComp_solver.h"
71 #include "LJ_matrix.h"
72 #include "BindingSite.h"
73 #include "Spring.h"
75 #include "KineticState.h"
76 
77 #include "dimensions.h"
78 using namespace std;
79 
80 class World {
81 public:
82  World();
83 
84  ~World();
85 
86  /* */
87  int init(string FFEA_script_filename, int frames_to_delete, int mode, bool writeEnergy);
88 
89  /* */
90  int get_smallest_time_constants();
91 
92  /* */
93  int lem(set<int> blob_indices, int num_modes);
94 
95  /* */
96  int dmm(set<int> blob_indices, int num_modes);
97 
98  /* */
99  int dmm_rp(set<int> blob_indices, int num_modes);
100 
101  /* */
102  int run();
103 
104  /* */
105  int read_and_build_system(vector<string> script_vector);
106 
107  /* */
108  int load_kinetic_maps(vector<string> map_fnames, vector<int> map_from, vector<int> map_to, int blob_index);
109 
110  /* */
111  int build_kinetic_identity_maps();
112 
113  /* */
114  int load_kinetic_states(string states_fname, int blob_index);
115 
116  /* */
117  int load_kinetic_rates(string rates_fname, int blob_index);
118 
119  /* */
120  void print_kinetic_rates_to_screen(int type);
121 
122  /* */
123  void get_system_CoM(vector3 *system_CoM);
124 
125  /* */
126  void get_system_centroid(vector3 *centroid);
127 
128  /* */
129  void get_system_dimensions(vector3 *dimenstion_vector);
130 
131  /* */
132  int enm(int *blob_index, int num_modes);
133 
134  /* */
135  int get_num_blobs();
136 
137 
138 private:
139 
142 
145 
149 
151 
156 
159 
162 
165 
168 
171 
174 
176  unsigned long **Seeds;
177 
180 
183 
186 
192 
195 
198 
201 
205 
208 
212 
214 
215  scalar kineticenergy, strainenergy, springenergy, **springfieldenergy, vdwenergy, preCompenergy;
217 
220 
222 
223  vector3 CoM, CoG;
226 
229 
230  /*
231  *
232  */
233  // SurfaceElementLookup surface_element_lookup;
234 
237 
240 
247 
252 
255 
258 
261 
262 
271 
272 
274 
275  long long step_initial;
276 
277  int load_springs(const char *fname);
278 
279  void activate_springs();
280 
281  int apply_springs();
282 
283  scalar get_spring_field_energy(int index0, int index1);
284 
286  int calculate_kinetic_rates();
287 
289  int choose_new_kinetic_state(int blob_index, int *target);
290 
292  int change_kinetic_state(int blob_index, int target_state);
293 
294  int get_next_script_tag(FILE *in, char *buf);
295 
296  void apply_dense_matrix(scalar *y, scalar *M, scalar *x, int N);
297 
298  void do_es();
299 
300  void make_trajectory_from_eigenvector(string traj_out_fname, int blob_index, int mode_index, Eigen_VectorX evec, scalar step);
301 
302  void print_evecs_to_file(string fname, Eigen_MatrixX ev, int num_rows, int num_modes);
303 
304  void print_evals_to_file(string fname, Eigen_VectorX ev, int num_modes, scalar scale);
305 
306  void write_eig_to_files(scalar *evals_ordered, scalar **evecs_ordered, int num_modes, int num_nodes);
307 
308  void write_output_header(FILE *fout, string fname);
309 
310  void print_trajectory_and_measurement_files(int step, scalar wtime);
311  void print_checkpoints();
312  void write_pre_print_to_trajfile(int step);
313  void do_nothing();
314 
315  int prebuild_nearest_neighbour_lookup_wrapper(scalar cell_size);
316 #ifdef FFEA_PARALLEL_FUTURE
317  std::future<void> thread_writingTraj;
318  std::future<int> thread_updatingVdWLL;
319  std::future<int> thread_updatingPCLL;
320  bool updatingVdWLL();
321  bool updatingVdWLL_ready_to_swap();
322  int catch_thread_updatingVdWLL(int step, scalar wtime, int where);
323  bool updatingPCLL();
324  bool updatingPCLL_ready_to_swap();
325  int catch_thread_updatingPCLL(int step, scalar wtime, int where);
326 #endif
327 
328  void make_measurements();
329 
330  void write_measurements_to_file(FILE *fout, int step);
331 
332  void write_detailed_measurements_to_file(FILE *fout);
333 
334  void print_trajectory_conformation_changes(FILE *fout, int step, int *from_index, int *to_index);
335 
336  void print_kinetic_files(int step);
337 
338  void print_static_trajectory(int step, scalar wtime, int blob_index);
339 
341  void calc_blob_corr_matrix(int num_blobs,scalar *blob_corr);
342 
344 
345  int die_with_dignity(int step, scalar wtime);
346 };
347 
348 #endif
KineticState ** kinetic_state
Kinetic State and Rate objects.
Definition: World.h:152
unsigned long ** Seeds
A pointer to an array of arrays, containing the seeds of the different RNGStreams.
Definition: World.h:176
BindingSite_matrix binding_matrix
Binding Interactions matrix.
Definition: World.h:260
Definition: BiCGSTAB_solver.h:34
scalar rmsd
Definition: World.h:224
Definition: Blob.h:94
scalar * blob_corr
Definition: World.h:343
scalar vdwenergy
Definition: World.h:215
scalar * work_vec
Definition: World.h:246
int num_seeds
The number of seeds stored in Seeds.
Definition: World.h:179
long long step_initial
Definition: World.h:275
Definition: World.h:80
vector3 box_dim
Definition: World.h:273
Definition: PreComp_solver.h:49
Eigen::MatrixXd Eigen_MatrixX
Definition: Blob.h:65
FFEA_input_reader * systemreader
Definition: World.h:211
Eigen::VectorXd Eigen_VectorX
Definition: Blob.h:66
STL namespace.
NearestNeighbourLinkedListCube lookup
Data structure keeping track of which `cell&#39; each face lies in (where the world has been discretised ...
Definition: World.h:191
Definition: SimulationParams.h:66
vector3 CoM
Definition: World.h:223
FILE * measurement_out
Output measurement file.
Definition: World.h:200
scalar *** kinetic_rate
Definition: World.h:153
int num_threads
How many threads are available for parallelisation.
Definition: World.h:170
Spring * spring_array
An array of springs which connect nodes if necessary.
Definition: World.h:158
Definition: KineticState.h:38
Definition: Spring.h:27
Definition: SparseMatrixFixedPattern.h:36
scalar * phi_Gamma
Vector of the electrostatic potential on each surface in entire system.
Definition: World.h:244
scalar *** kinetic_base_rate
Definition: World.h:154
SparseMatrixFixedPattern *** kinetic_map
Maps for kinetic switching of conformations.
Definition: World.h:147
Blob ** active_blob_array
Which conformation is active in each blob.
Definition: World.h:144
RngStream * rng
An array of pointers to random number generators (for use in parallel)
Definition: World.h:173
PreComp_solver pc_solver
PreComputed potentials solver.
Definition: World.h:270
SimulationParams params
Parameters being used for this simulation.
Definition: World.h:185
Definition: RngStream.h:43
FILE * kinetics_out
Output kinetics file.
Definition: World.h:197
Definition: BEM_Poisson_Boltzmann.h:42
RngStream * kinetic_rng
An array of pointers to random number generators for use in kinetics.
Definition: World.h:182
FILE * checkpoint_out
Output Checkpoint file
Definition: World.h:228
int total_num_surface_faces
Number of surface faces in entire system.
Definition: World.h:239
Blob ** blob_array
2-D Array of Blob objects (blob i, conformation j)
Definition: World.h:141
Definition: VdW_solver.h:39
Definition: SimulationParams.h:75
FILE * detailed_meas_out
Definition: World.h:204
int num_springs
And how many springs are there?
Definition: World.h:161
FILE * trajectory_out
Output trajectory file.
Definition: World.h:194
SparseMatrixFixedPattern **** kinetic_return_map
Definition: World.h:148
PreComp_params pc_params
stores info within the <precomp> block at the .ffea file.
Definition: World.h:266
FFEA_input_reader * ffeareader
Definition: World.h:210
Definition: FFEA_input_reader.h:38
BiCGSTAB_solver nonsymmetric_solver
Biconjugate gradient stabilised solver for nonsymmetric matrices.
Definition: World.h:251
LJ_matrix lj_matrix
LJ parameters matrix.
Definition: World.h:257
FILE * trajbeads_out
Output file for the trajectory beads. Completely optional.
Definition: World.h:207
vector3 L
Definition: World.h:219
int num_binding_sites
How many kinetic binding sites are there?
Definition: World.h:164
VdW_solver * vdw_solver
Definition: World.h:254
Definition: NearestNeighbourLinkedListCube.h:34
scalar * J_Gamma
Definition: World.h:245
bool mass_in_system
Check whether mass is present anywhere, to determine whether or not to write kinetic energies to file...
Definition: World.h:167
Definition: mat_vec_types.h:90
Definition: LJ_matrix.h:46
double scalar
Definition: mat_vec_types.h:36
bool writeDetailed
Output detailed measurements file. May be unneccesary.
Definition: World.h:203
BEM_Poisson_Boltzmann PB_solver
BEM solver for the exterior electrostatics.
Definition: World.h:236
Definition: BindingSite.h:82