<commit_before>// movetypes.h

#ifndef MOVETYPES_H
#define MOVETYPES_H

#include <iostream>
#include <set>

#include <memory>

#include "random_gens.h"
#include "origami_system.h"
#include "ideal_random_walk.h"

using std::cout;
using std::unique_ptr;
using std::set;

using namespace Origami;
using namespace RandomGen;
using namespace IdealRandomWalk;

namespace Movetypes {

    // Movetype classes

    class MCMovetype {
        public:
            MCMovetype(
                    OrigamiSystem& origami_system,
                    RandomGens& random_gens,
                    IdealRandomWalks& ideal_random_walks) :
                    m_origami_system {origami_system},
                    m_random_gens {random_gens},
                    m_ideal_random_walks {ideal_random_walks} {};
            virtual ~MCMovetype() {};

            virtual bool attempt_move() = 0;
            void reset_origami();

            virtual string m_label() {return "MCMovetype";};

        protected:
            OrigamiSystem& m_origami_system;
            RandomGens& m_random_gens;
            IdealRandomWalks& m_ideal_random_walks;
            bool m_rejected {false};

            // Lists of modified domains for move reversal
            vector<pair<int, int>> m_modified_domains {};
            vector<pair<int, int>> m_assigned_domains {};
            vector<int> m_added_chains {};

            // Domains mapped to previous configs
            unordered_map<pair<int, int>, VectorThree> m_prev_pos {};
            unordered_map<pair<int, int>, VectorThree> m_prev_ore {};

            // Modifier to correct for excluded volume and overcounting
            double m_modifier {1};

            // Shared methods
            Domain* select_random_domain();
            int select_random_staple_identity();
            int select_random_staple_of_identity(int c_i_ident);
            VectorThree select_random_position(VectorThree p_prev);
            VectorThree select_random_orientation();
            bool test_acceptance(double p_ratio);
            bool staple_is_connector(vector<Domain*> staple);
            bool scan_for_scaffold_domain(Domain*, set<int>& participating_chains);
    };

    class IdentityMCMovetype: public MCMovetype {
        public:
            using MCMovetype::MCMovetype;
            bool attempt_move() {return true;};

            string m_label() {return "IdentityMCMovetype";};
    };

    class OrientationRotationMCMovetype: public MCMovetype {
        public:
            using MCMovetype::MCMovetype;
            bool attempt_move();

            string m_label() {return "OrientationRotationMCMovetype";};
    };

    class RegrowthMCMovetype: public MCMovetype {
        public:
            using MCMovetype::MCMovetype;

            string m_label() {return "RegrowthMCMovetype";};
        protected:
            double set_growth_point(Domain& growth_domain_new, Domain& growth_domain_old);
            void grow_staple(int d_i_index, vector<Domain*> selected_chain);
            virtual void grow_chain(vector<Domain*> domains) = 0;
            pair<Domain*, Domain*> select_new_growthpoint(vector<Domain*> selected_chain);
    };

    class MetMCMovetype: public RegrowthMCMovetype {
        public:
            using RegrowthMCMovetype::RegrowthMCMovetype;

            string m_label() {return "MetMCMovetype";};
        protected:
            double m_delta_e {0};

            void grow_chain(vector<Domain*> domains);
            void unassign_domains(vector<Domain*> domains);
    };

    class MetStapleExchangeMCMovetype: public MetMCMovetype {
        public:
            using MetMCMovetype::MetMCMovetype;
            bool attempt_move();

            string m_label() {return "MetStapleExchangeMCMovetype";}
        protected:

            // These can be overidden for a derived class the excludes misbinding
            int preconstrained_df {0};
            //DEBUG
            //int m_insertion_sites {m_origami_system.num_domains() -
            //        m_origami_system.num_bound_domain_pairs()};
            int m_insertion_sites {m_origami_system.num_domains()};

        private:
            bool staple_insertion_accepted(int c_i_ident);
            bool staple_deletion_accepted(int c_i_ident);
            bool insert_staple();
            bool delete_staple();
    };

    class MetStapleRegrowthMCMovetype: public MetMCMovetype {
        public:
            using MetMCMovetype::MetMCMovetype;
            bool attempt_move();

            string m_label() {return "MetStapleRegrowthMCMovetype";}
    };

    class CBMCMovetype: public RegrowthMCMovetype {
        public:
            using RegrowthMCMovetype::RegrowthMCMovetype;

            string m_label() {return "CBMCMovetype";};
        protected:
            double m_bias {1};
            double m_new_bias {1};
            double m_new_modifier {1};
            bool m_regrow_old {false};
            unordered_map<pair<int, int>, VectorThree> m_old_pos {};
            unordered_map<pair<int, int>, VectorThree> m_old_ore {};

            void calc_biases(
                    Domain& domain,
                    VectorThree p_prev,
                    vector<pair<VectorThree, VectorThree>>& configs,
                    vector<double>& bfactors);
            virtual vector<double> calc_bias(vector<double> bfactors,
                    Domain*, vector<pair<VectorThree, VectorThree>>&, VectorThree,
                    vector<Domain*>) = 0;
            void select_and_set_config(vector<Domain*> domains, int i);
            void select_and_set_new_config(
                    Domain& domain,
                    vector<double> weights,
                    vector<pair<VectorThree, VectorThree>> configs);
            void select_and_set_old_config(Domain& domain);
            double set_old_growth_point(Domain& growth_domain_new, Domain& growth_domain_old);
            bool test_cb_acceptance();
            void unassign_domains(vector<Domain*>);
            void setup_for_regrow_old();
            vector<pair<Domain*, Domain*>> find_bound_domains(
                    vector<Domain*> selected_chain);
            pair<Domain*, Domain*> select_old_growthpoint(
                    vector<pair<Domain*, Domain*>> bound_domains);
    };

    class CBStapleExchangeMCMovetype: public CBMCMovetype {
        public:
            using CBMCMovetype::CBMCMovetype;
            CBStapleExchangeMCMovetype(
                    OrigamiSystem& origami_system,
                    RandomGens& random_gens,
                    IdealRandomWalks& ideal_random_walks) :
                    CBMCMovetype(
                            origami_system,
                            random_gens,
                            ideal_random_walks) {}
            bool attempt_move();

            string m_label() {return "CBStapleExchangeMCMovetype";};
        protected:

            // These can be overidden for a derived class the excludes misbinding
            int preconstrained_df {0};
            int m_insertion_sites {m_origami_system.num_domains() -
                    m_origami_system.num_bound_domain_pairs()};

        private:
            double calc_staple_insertion_acc_ratio(int c_i_ident);
            double calc_staple_deletion_acc_ratio(int c_i_ident);
            vector<double> calc_bias(vector<double> bfactors,
                    Domain*, vector<pair<VectorThree, VectorThree>>&, VectorThree,
                    vector<Domain*>);
            bool insert_staple();
            bool delete_staple();
            void unassign_and_delete_staple(int c_i,vector<Domain*> staple);
            void grow_chain(vector<Domain*> domains);
            void unassign_for_regrowth(vector<Domain*>);

    };
<commit_msg>Corrected num insertions for CB<commit_after>// movetypes.h

#ifndef MOVETYPES_H
#define MOVETYPES_H

#include <iostream>
#include <set>

#include <memory>

#include "random_gens.h"
#include "origami_system.h"
#include "ideal_random_walk.h"

using std::cout;
using std::unique_ptr;
using std::set;

using namespace Origami;
using namespace RandomGen;
using namespace IdealRandomWalk;

namespace Movetypes {

    // Movetype classes

    class MCMovetype {
        public:
            MCMovetype(
                    OrigamiSystem& origami_system,
                    RandomGens& random_gens,
                    IdealRandomWalks& ideal_random_walks) :
                    m_origami_system {origami_system},
                    m_random_gens {random_gens},
                    m_ideal_random_walks {ideal_random_walks} {};
            virtual ~MCMovetype() {};

            virtual bool attempt_move() = 0;
            void reset_origami();

            virtual string m_label() {return "MCMovetype";};

        protected:
            OrigamiSystem& m_origami_system;
            RandomGens& m_random_gens;
            IdealRandomWalks& m_ideal_random_walks;
            bool m_rejected {false};

            // Lists of modified domains for move reversal
            vector<pair<int, int>> m_modified_domains {};
            vector<pair<int, int>> m_assigned_domains {};
            vector<int> m_added_chains {};

            // Domains mapped to previous configs
            unordered_map<pair<int, int>, VectorThree> m_prev_pos {};
            unordered_map<pair<int, int>, VectorThree> m_prev_ore {};

            // Modifier to correct for excluded volume and overcounting
            double m_modifier {1};

            // Shared methods
            Domain* select_random_domain();
            int select_random_staple_identity();
            int select_random_staple_of_identity(int c_i_ident);
            VectorThree select_random_position(VectorThree p_prev);
            VectorThree select_random_orientation();
            bool test_acceptance(double p_ratio);
            bool staple_is_connector(vector<Domain*> staple);
            bool scan_for_scaffold_domain(Domain*, set<int>& participating_chains);
    };

    class IdentityMCMovetype: public MCMovetype {
        public:
            using MCMovetype::MCMovetype;
            bool attempt_move() {return true;};

            string m_label() {return "IdentityMCMovetype";};
    };

    class OrientationRotationMCMovetype: public MCMovetype {
        public:
            using MCMovetype::MCMovetype;
            bool attempt_move();

            string m_label() {return "OrientationRotationMCMovetype";};
    };

    class RegrowthMCMovetype: public MCMovetype {
        public:
            using MCMovetype::MCMovetype;

            string m_label() {return "RegrowthMCMovetype";};
        protected:
            double set_growth_point(Domain& growth_domain_new, Domain& growth_domain_old);
            void grow_staple(int d_i_index, vector<Domain*> selected_chain);
            virtual void grow_chain(vector<Domain*> domains) = 0;
            pair<Domain*, Domain*> select_new_growthpoint(vector<Domain*> selected_chain);
    };

    class MetMCMovetype: public RegrowthMCMovetype {
        public:
            using RegrowthMCMovetype::RegrowthMCMovetype;

            string m_label() {return "MetMCMovetype";};
        protected:
            double m_delta_e {0};

            void grow_chain(vector<Domain*> domains);
            void unassign_domains(vector<Domain*> domains);
    };

    class MetStapleExchangeMCMovetype: public MetMCMovetype {
        public:
            using MetMCMovetype::MetMCMovetype;
            bool attempt_move();

            string m_label() {return "MetStapleExchangeMCMovetype";}
        protected:

            // These can be overidden for a derived class the excludes misbinding
            int preconstrained_df {0};

            // I select by domains not by sites, so this is consistent
            int m_insertion_sites {m_origami_system.num_domains()};

        private:
            bool staple_insertion_accepted(int c_i_ident);
            bool staple_deletion_accepted(int c_i_ident);
            bool insert_staple();
            bool delete_staple();
    };

    class MetStapleRegrowthMCMovetype: public MetMCMovetype {
        public:
            using MetMCMovetype::MetMCMovetype;
            bool attempt_move();

            string m_label() {return "MetStapleRegrowthMCMovetype";}
    };

    class CBMCMovetype: public RegrowthMCMovetype {
        public:
            using RegrowthMCMovetype::RegrowthMCMovetype;

            string m_label() {return "CBMCMovetype";};
        protected:
            double m_bias {1};
            double m_new_bias {1};
            double m_new_modifier {1};
            bool m_regrow_old {false};
            unordered_map<pair<int, int>, VectorThree> m_old_pos {};
            unordered_map<pair<int, int>, VectorThree> m_old_ore {};

            void calc_biases(
                    Domain& domain,
                    VectorThree p_prev,
                    vector<pair<VectorThree, VectorThree>>& configs,
                    vector<double>& bfactors);
            virtual vector<double> calc_bias(vector<double> bfactors,
                    Domain*, vector<pair<VectorThree, VectorThree>>&, VectorThree,
                    vector<Domain*>) = 0;
            void select_and_set_config(vector<Domain*> domains, int i);
            void select_and_set_new_config(
                    Domain& domain,
                    vector<double> weights,
                    vector<pair<VectorThree, VectorThree>> configs);
            void select_and_set_old_config(Domain& domain);
            double set_old_growth_point(Domain& growth_domain_new, Domain& growth_domain_old);
            bool test_cb_acceptance();
            void unassign_domains(vector<Domain*>);
            void setup_for_regrow_old();
            vector<pair<Domain*, Domain*>> find_bound_domains(
                    vector<Domain*> selected_chain);
            pair<Domain*, Domain*> select_old_growthpoint(
                    vector<pair<Domain*, Domain*>> bound_domains);
    };

    class CBStapleExchangeMCMovetype: public CBMCMovetype {
        public:
            using CBMCMovetype::CBMCMovetype;
            CBStapleExchangeMCMovetype(
                    OrigamiSystem& origami_system,
                    RandomGens& random_gens,
                    IdealRandomWalks& ideal_random_walks) :
                    CBMCMovetype(
                            origami_system,
                            random_gens,
                            ideal_random_walks) {}
            bool attempt_move();

            string m_label() {return "CBStapleExchangeMCMovetype";};
        protected:

            // These can be overidden for a derived class the excludes misbinding
            int preconstrained_df {0};

            // I select by domains not by sites, so this is consistent
            int m_insertion_sites {m_origami_system.num_domains()};

        private:
            double calc_staple_insertion_acc_ratio(int c_i_ident);
            double calc_staple_deletion_acc_ratio(int c_i_ident);
            vector<double> calc_bias(vector<double> bfactors,
                    Domain*, vector<pair<VectorThree, VectorThree>>&, VectorThree,
                    vector<Domain*>);
            bool insert_staple();
            bool delete_staple();
            void unassign_and_delete_staple(int c_i,vector<Domain*> staple);
            void grow_chain(vector<Domain*> domains);
            void unassign_for_regrowth(vector<Domain*>);

    };

{'fraction_non_alphanumeric': 0.08139233954451346, 'fraction_numerical': 0.0012939958592132505, 'mean_word_length': 2.1455026455026456, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178093', 'n_tokens_mistral': 4574, 'n_tokens_neox': 4162, 'n_words': 904}