<commit_before>#include "core.h"
#include "move.h"
#include "speciation.h"
#include "clustermove.h"
#include "chainmove.h"
#include "aux/iteratorsupport.h"
#include "aux/eigensupport.h"
#include "spdlog/spdlog.h"

namespace Faunus {
namespace Move {

Random Movebase::slump; // static instance of Random (shared for all moves)

void Movebase::from_json(const json &j) {
    auto it = j.find("repeat");
    if (it != j.end()) {
        if (it->is_number())
            repeat = it->get<double>();
        else if (it->is_string())
            if (it->get<std::string>() == "N")
                repeat = -1;
    }
    _from_json(j);
    if (repeat < 0)
        repeat = 0;
}

void Movebase::to_json(json &j) const {
    _to_json(j);
    if (timer_move.result() > 0.01) // only print if more than 1% of the time
        j["relative time (without energy calc)"] = timer_move.result();
    if (timer.result() > 0.01) // only print if more than 1% of the time
        j["relative time"] = timer.result();
    j["acceptance"] = double(accepted) / cnt;
    j["repeat"] = repeat;
    j["moves"] = cnt;
    if (!cite.empty())
        j["cite"] = cite;
    _roundjson(j, 3);
}

void Movebase::move(Change &change) {
    timer.start();
    timer_move.start();
    cnt++;
    change.clear();
    _move(change);
    if (change.empty())
        timer.stop();
    timer_move.stop();
}

void Movebase::accept(Change &c) {
    accepted++;
    _accept(c);
    timer.stop();
}

void Movebase::reject(Change &c) {
    rejected++;
    _reject(c);
    timer.stop();
}

double Movebase::bias(Change &, double, double) {
    return 0; // du
}

void Movebase::_accept(Change &) {}

void Movebase::_reject(Change &) {}

void from_json(const json &j, Movebase &m) { m.from_json(j); }

void to_json(json &j, const Movebase &m) {
    assert(!m.name.empty());
    m.to_json(j[m.name]);
}

void AtomicTranslateRotate::_to_json(json &j) const {
    j = {{"dir", dir},
         {"molid", molid},
         {u8::rootof + u8::bracket("r" + u8::squared), std::sqrt(msqd.avg())},
         {"molecule", molname}};
    _roundjson(j, 3);
}
void AtomicTranslateRotate::_from_json(const json &j) {
    assert(!molecules.empty());
    try {
        assertKeys(j, {"molecule", "dir", "repeat"});
        molname = j.at("molecule");
        auto it = findName(molecules, molname);
        if (it == molecules.end())
            throw std::runtime_error("unknown molecule '" + molname + "'");
        molid = it->id();<commit_msg>Warn if atomic move is applied on rigid molecule<commit_after>#include "core.h"
#include "move.h"
#include "speciation.h"
#include "clustermove.h"
#include "chainmove.h"
#include "aux/iteratorsupport.h"
#include "aux/eigensupport.h"
#include "spdlog/spdlog.h"

namespace Faunus {
namespace Move {

Random Movebase::slump; // static instance of Random (shared for all moves)

void Movebase::from_json(const json &j) {
    auto it = j.find("repeat");
    if (it != j.end()) {
        if (it->is_number())
            repeat = it->get<double>();
        else if (it->is_string())
            if (it->get<std::string>() == "N")
                repeat = -1;
    }
    _from_json(j);
    if (repeat < 0)
        repeat = 0;
}

void Movebase::to_json(json &j) const {
    _to_json(j);
    if (timer_move.result() > 0.01) // only print if more than 1% of the time
        j["relative time (without energy calc)"] = timer_move.result();
    if (timer.result() > 0.01) // only print if more than 1% of the time
        j["relative time"] = timer.result();
    j["acceptance"] = double(accepted) / cnt;
    j["repeat"] = repeat;
    j["moves"] = cnt;
    if (!cite.empty())
        j["cite"] = cite;
    _roundjson(j, 3);
}

void Movebase::move(Change &change) {
    timer.start();
    timer_move.start();
    cnt++;
    change.clear();
    _move(change);
    if (change.empty())
        timer.stop();
    timer_move.stop();
}

void Movebase::accept(Change &c) {
    accepted++;
    _accept(c);
    timer.stop();
}

void Movebase::reject(Change &c) {
    rejected++;
    _reject(c);
    timer.stop();
}

double Movebase::bias(Change &, double, double) {
    return 0; // du
}

void Movebase::_accept(Change &) {}

void Movebase::_reject(Change &) {}

void from_json(const json &j, Movebase &m) { m.from_json(j); }

void to_json(json &j, const Movebase &m) {
    assert(!m.name.empty());
    m.to_json(j[m.name]);
}

void AtomicTranslateRotate::_to_json(json &j) const {
    j = {{"dir", dir},
         {"molid", molid},
         {u8::rootof + u8::bracket("r" + u8::squared), std::sqrt(msqd.avg())},
         {"molecule", molname}};
    _roundjson(j, 3);
}
void AtomicTranslateRotate::_from_json(const json &j) {
    assert(!molecules.empty());
    try {
        assertKeys(j, {"molecule", "dir", "repeat"});
        molname = j.at("molecule");
        auto it = findName(molecules, molname);
        if (it == molecules.end())
            throw std::runtime_error("unknown molecule '" + molname + "'");
        molid = it->id();
        if (Faunus::molecules[molid].rigid) {
            faunus_logger->warn("structure of rigid molecule {} may be disturbed by {}", molname, name);
        }
{'fraction_non_alphanumeric': 0.18023255813953487, 'fraction_numerical': 0.006589147286821705, 'mean_word_length': 2.9128127369219103, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 22, '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': '2676354', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1805, 'n_words': 421}