| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | #include <filesystem> | |||
| 2 | #include "types.hpp" | |||
| 3 | #include "measurement.hpp" | |||
| 4 | #include "geometry.hpp" | |||
| 5 | #include "system.hpp" | |||
| 6 | #include "linalg.hpp" | |||
| 7 | ||||
| 8 | ✗ | std::ostream& operator<<(std::ostream& o, const Measurement m) | ||
| 9 | { | |||
| 10 | // set precession to 4 decimal digits | |||
| 11 | ✗ | o.setf(std::ios::fixed, std::ios::floatfield); | ||
| 12 | o.precision(4); | |||
| 13 | ||||
| 14 | // write output data in file | |||
| 15 | ✗ | return o << m.time << "\t" << m.number_of_m_ts << "\t" << m.average_length << "\t" << m.length_density << "\t" | ||
| 16 | ✗ | << m.optical_density << "\t" << m.order.r << "\t" << m.order.rdirector[0] << "\t" << m.order.rdirector[1] | ||
| 17 | ✗ | << "\t" << m.order.rdirector[2] << "\r\n"; | ||
| 18 | } | |||
| 19 | ||||
| 20 | ✗ | void write_measurement_descriptors(std::ostream& o) | ||
| 21 | { | |||
| 22 | // write header of the output file | |||
| 23 | ✗ | o << "time\t\t" << " #MT\t" << " <l>\t" << " rho\t" << "rho_opt\t" << " R\t" << "R_x\t" << "R_y\t" << "R_z\r\n"; | ||
| 24 | ✗ | return; | ||
| 25 | } | |||
| 26 | ||||
| 27 | ✗ | void System::initialize_output(void) | ||
| 28 | { | |||
| 29 | ||||
| 30 | // if create sub-directory in enabled | |||
| 31 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (p.create_subdir) | |
| 32 | { | |||
| 33 | std::string identifier; | |||
| 34 | time_t time_raw; | |||
| 35 | struct tm* time_struct; | |||
| 36 | char time_name[100]; | |||
| 37 | ||||
| 38 | ✗ | time(&time_raw); | ||
| 39 | ✗ | time_struct = localtime(&time_raw); | ||
| 40 | ✗ | strftime(time_name, 100, "%c", time_struct); | ||
| 41 | ||||
| 42 | // create subdirectory with a time Tag, to isolate each data folder | |||
| 43 | ✗ | p.output_dir += "/" + p.geometry + "/outputData" + std::string(time_name); | ||
| 44 | ✗ | int i = std::filesystem::create_directories(p.output_dir.c_str()); | ||
| 45 | ||||
| 46 | // if the sub-directory path is invalid | |||
| 47 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (i) | |
| 48 | { | |||
| 49 | ✗ | std::cerr << "ERROR: creating output directory " << p.output_dir << " ; " << strerror(i) << "\n"; | ||
| 50 | ✗ | exit(-1); | ||
| 51 | } | |||
| 52 | } | |||
| 53 | ||||
| 54 | // open output parameter file | |||
| 55 | std::string file_name | |||
| 56 | ✗ | = std::string(p.output_dir + "/" + p.geometry + "/outputData" + std::string("/parameters.txt")); | ||
| 57 | ✗ | parameter_file.open(file_name.c_str()); | ||
| 58 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (!parameter_file) | |
| 59 | { | |||
| 60 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | std::cout << "ERROR: cannot open file for output (parameters)\n"; | |
| 61 | ✗ | exit(-1); | ||
| 62 | } | |||
| 63 | ||||
| 64 | // open output measurements file | |||
| 65 | ✗ | file_name = std::string(p.output_dir + "/" + p.geometry + "/outputData" + std::string("/measurements.txt")); | ||
| 66 | ✗ | measurement_file.open(file_name.c_str()); | ||
| 67 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (!measurement_file.is_open()) | |
| 68 | { | |||
| 69 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | std::cout << "ERROR: cannot open file for output (measurements)\n"; | |
| 70 | ✗ | exit(-1); | ||
| 71 | } | |||
| 72 | ||||
| 73 | // write in measurement file | |||
| 74 | ✗ | write_measurement_descriptors(measurement_file); | ||
| 75 | ||||
| 76 | // open output Draw_MT_segments file | |||
| 77 | ✗ | file_name = std::string(p.output_dir + "/" + p.geometry + "/outputData" + std::string("/Draw_MT_segments.txt")); | ||
| 78 | ✗ | movie_file.open(file_name.c_str()); | ||
| 79 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (!movie_file.is_open()) | |
| 80 | { | |||
| 81 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | std::cout << "ERROR: cannot open file for output (Draw_MT_segments.txt)\n"; | |
| 82 | ✗ | exit(-1); | ||
| 83 | } | |||
| 84 | ||||
| 85 | // open output heatMapOrder file | |||
| 86 | ✗ | file_name = std::string(p.output_dir + "/" + p.geometry + "/outputData" + std::string("/heatMapOrder.txt")); | ||
| 87 | ✗ | heat_map_file.open(file_name.c_str()); | ||
| 88 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (!heat_map_file.is_open()) | |
| 89 | { | |||
| 90 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | std::cout << "ERROR: cannot open file for output (heatMapOrder.txt)\n"; | |
| 91 | ✗ | exit(-1); | ||
| 92 | } | |||
| 93 | ||||
| 94 | ✗ | return; | ||
| 95 | } | |||
| 96 | ||||
| 97 | ✗ | void System::close_files() | ||
| 98 | { | |||
| 99 | /// close the output files before the program terminates | |||
| 100 | ✗ | parameter_file.close(); | ||
| 101 | ✗ | movie_file.close(); | ||
| 102 | ✗ | measurement_file.close(); | ||
| 103 | ||||
| 104 | ✗ | return; | ||
| 105 | } | |||
| 106 | ||||
| 107 | ✗ | void System::perform_measurement(void) | ||
| 108 | { | |||
| 109 | Measurement m; | |||
| 110 | ||||
| 111 | // measurementHistory reach at MAX_HISTORY_SIZE, archive only upto last MIN_HISTORY_SIZE arrays, and write down the | |||
| 112 | // rest on output file (immediately !) | |||
| 113 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (measurement_history.size() == MAX_HISTORY_SIZE) | |
| 114 | { | |||
| 115 | ✗ | write_measurements_to_file(MIN_HISTORY_SIZE - 1); | ||
| 116 | } | |||
| 117 | ||||
| 118 | ✗ | m.time = system_time + system_time_offset; | ||
| 119 | ||||
| 120 | // length densities (per area) | |||
| 121 | ✗ | m.length_density = total_length / geometry->area; | ||
| 122 | ✗ | m.optical_density = geometry->optical_length() / geometry->area; | ||
| 123 | ||||
| 124 | // total number of microtubules | |||
| 125 | ✗ | m.number_of_m_ts = growing_mts.size() + shrinking_mts.size(); | ||
| 126 | ✗ | m.growing_number = growing_mts.size(); | ||
| 127 | ✗ | m.shrinking_number = shrinking_mts.size(); | ||
| 128 | ||||
| 129 | int segment_count = 0; | |||
| 130 | Microtubule* mt; | |||
| 131 | ||||
| 132 | mt = growing_mts.first(); | |||
| 133 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (mt != nullptr) | |
| 134 | { | |||
| 135 | ✗ | segment_count += mt->segments.size(); | ||
| 136 | mt = mt->next(); | |||
| 137 | } | |||
| 138 | mt = shrinking_mts.first(); | |||
| 139 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | while (mt != nullptr) | |
| 140 | { | |||
| 141 | ✗ | segment_count += mt->segments.size(); | ||
| 142 | mt = mt->next(); | |||
| 143 | } | |||
| 144 | ||||
| 145 | // total number of segments | |||
| 146 | ✗ | m.segments = segment_count - boundary_crossing_count; | ||
| 147 | ||||
| 148 | // total number of trajectories (both active and inactive) | |||
| 149 | ✗ | m.trajectories = geometry->trajectory_count(); | ||
| 150 | ||||
| 151 | // average length of microtubules | |||
| 152 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (m.number_of_m_ts) | |
| 153 | { | |||
| 154 | ✗ | m.average_length = total_length / m.number_of_m_ts; | ||
| 155 | ✗ | m.segments_per_mt = static_cast<double>(m.segments) / m.number_of_m_ts; | ||
| 156 | } | |||
| 157 | else | |||
| 158 | { | |||
| 159 | ✗ | m.average_length = 0.; | ||
| 160 | ✗ | m.segments_per_mt = 1.; | ||
| 161 | } | |||
| 162 | ||||
| 163 | // order parameter | |||
| 164 | ✗ | geometry->get_order_parameters(m.order); | ||
| 165 | ||||
| 166 | // total number zippering | |||
| 167 | ✗ | m.zipper_count = total_zipper_count; | ||
| 168 | ||||
| 169 | // total number of cross-overs | |||
| 170 | ✗ | m.crossover_count = total_crossover_count; | ||
| 171 | ||||
| 172 | // total number of induced catastrophes | |||
| 173 | ✗ | m.induced_catastrophe_count = total_induced_catastrophe_count; | ||
| 174 | ||||
| 175 | // total number of valid events | |||
| 176 | ✗ | m.valid_d_event_count = total_valid_d_event_count; | ||
| 177 | ||||
| 178 | // total number of invalid events | |||
| 179 | ✗ | m.invalid_d_event_count = total_invalid_d_event_count; | ||
| 180 | ||||
| 181 | // total number of severing event | |||
| 182 | ✗ | m.s_event_count = total_s_event_count; | ||
| 183 | ✗ | m.length_severing_count = total_length_severing_count; | ||
| 184 | ✗ | m.intersection_severing_count = total_intersection_severing_count; | ||
| 185 | ||||
| 186 | // total number of occupied intersections | |||
| 187 | #ifdef CROSS_SEV | |||
| 188 | ✗ | m.occupied_intersection_count = occupied_intersection_list.size(); | ||
| 189 | #else | |||
| 190 | m.occupiedIntersectionCount = 0; | |||
| 191 | #endif | |||
| 192 | ||||
| 193 | // G-effective at difference faces | |||
| 194 | // for(int dTag =0;dTag <=p.faceNumber; dTag++) | |||
| 195 | // m.G_effAdjust.push_back = (p.kRes/(-p.vMin+p.vTM) - p.RegionKcatMultiplier[dTag]*p.kCat/(realVplus - | |||
| 196 | // p.vTM))*std::pow((2.0*(-p.vMin+p.vTM)*(realVplus-p.vTM)*(realVplus - p.vTM))/ | |||
| 197 | // (p.kNuc*(-p.vMin+realVplus)*realVplus), 1./3.); | |||
| 198 | ||||
| 199 | // archive (store) measurement | |||
| 200 | ✗ | measurement_history.push_back(m); | ||
| 201 | ||||
| 202 | // show output | |||
| 203 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (p.show_output == 1) | |
| 204 | { | |||
| 205 | ✗ | std::cout << "[t=" << std::setprecision(9) << m.time << std::setprecision(6) << "\t\t" << m.trajectories | ||
| 206 | ✗ | << " trajectories \t" << m.segments << " segments]\n" | ||
| 207 | ✗ | << "density [real]: " << m.length_density << "\t\t [optical]: " << m.optical_density << "\n" | ||
| 208 | ✗ | << "length/MT : " << m.average_length << "\tMT#: " << m.number_of_m_ts | ||
| 209 | ✗ | << "\tsegments/MT: " << m.segments_per_mt << "\n" | ||
| 210 | ✗ | << "R [real] : " << m.order.r << "[" << m.order.rdirector[0] << ", " << m.order.rdirector[1] | ||
| 211 | ✗ | << ", " << m.order.rdirector[2] << "]" << "\n" | ||
| 212 | ✗ | << "C [real] : " << m.order.c << "\n\n"; | ||
| 213 | //<< "G_eff_adjust : " << m.G_effAdjust[0] << " [on regular surfaces]\n\n"; | |||
| 214 | } | |||
| 215 | ||||
| 216 | ✗ | return; | ||
| 217 | } | |||
| 218 | ||||
| 219 | ✗ | void System::write_measurements_to_file(int number_to_keep) | ||
| 220 | { | |||
| 221 | int i, i_max; | |||
| 222 | ||||
| 223 | ✗ | i_max = measurement_history.size() - number_to_keep; | ||
| 224 | ||||
| 225 | // write output on files | |||
| 226 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (i = 0; i < i_max; i++) | |
| 227 | { | |||
| 228 | ✗ | measurement_file << measurement_history[0]; | ||
| 229 | ✗ | measurement_history.pop_front(); | ||
| 230 | } | |||
| 231 | ||||
| 232 | ✗ | return; | ||
| 233 | } | |||
| 234 |