38 namespace Clustering {
41 compute_wtd(std::list<std::size_t> streaks) {
43 if (streaks.size() > 0) {
44 streaks.sort(std::greater<std::size_t>());
45 std::size_t max_streak = streaks.front();
46 for (std::size_t i=0; i <= max_streak; ++i) {
48 for (
auto s: streaks) {
54 wtd[i] = n_steps / ((float) streaks.size());
61 main(boost::program_options::variables_map args) {
62 using namespace Clustering::Tools;
63 namespace b_po = boost::program_options;
66 std::set<std::size_t> state_names(states.begin(), states.end());
67 std::size_t n_frames = states.size();
68 if (args.count(
"output") || args.count(
"distribution") || args.count(
"cores")) {
71 std::vector<std::size_t> concat_limits;
72 if (args.count(
"concat-limits")) {
73 concat_limits = Clustering::Tools::read_single_column<std::size_t>(args[
"concat-limits"].as<std::string>());
74 }
else if (args.count(
"concat-nframes")) {
75 std::size_t n_frames_per_subtraj = args[
"concat-nframes"].as<std::size_t>();
76 for (std::size_t i=n_frames_per_subtraj; i <= n_frames; i += n_frames_per_subtraj) {
77 concat_limits.push_back(i);
80 concat_limits = {n_frames};
83 std::map<std::size_t, std::size_t> coring_windows;
85 std::ifstream ifs(args[
"windows"].as<std::string>());
86 std::string buf1, buf2;
87 std::size_t size_for_all = 1;
93 size_for_all = string_to_num<std::size_t>(buf2);
95 coring_windows[string_to_num<std::size_t>(buf1)] = string_to_num<std::size_t>(buf2);
100 for (std::size_t name: state_names) {
101 if ( ! coring_windows.count(name)){
102 coring_windows[name] = size_for_all;
107 std::vector<std::size_t> cored_traj(n_frames);
108 std::size_t current_core = states[0];
109 std::vector<long> cores(n_frames);
111 std::size_t last_limit = 0;
112 for (std::size_t next_limit: concat_limits) {
113 for (std::size_t i=last_limit; i < next_limit; ++i) {
115 std::size_t w = std::min(i+coring_windows[states[i]], next_limit);
116 bool is_in_core =
true;
117 for (std::size_t j=i+1; j < w; ++j) {
118 if (states[j] != states[i]) {
124 current_core = states[i];
125 cores[i] = current_core;
129 cored_traj[i] = current_core;
131 last_limit = next_limit;
134 if (args.count(
"output")) {
138 if (args.count(
"cores")) {
139 Clustering::Tools::write_single_column<long>(args[
"cores"].as<std::string>(), cores,
false);
142 if (args.count(
"distribution")) {
143 std::map<std::size_t, std::list<std::size_t>> streaks;
144 std::size_t current_state = cored_traj[0];
146 for (std::size_t state: cored_traj) {
147 if (state == current_state) {
150 streaks[current_state].push_back(n_counts);
151 current_state = state;
155 streaks[current_state].push_back(n_counts);
157 std::map<std::size_t, WTDMap> etds;
158 for (std::size_t state: state_names) {
159 etds[state] = compute_wtd(streaks[state]);
162 for (
auto state_etd: etds) {
164 Clustering::Tools::write_map<std::size_t, float>(fname, state_etd.second);
168 std::cerr <<
"\n" <<
"error (coring): nothing to do! please define '--output', '--distribution' or both!" <<
"\n\n";