<commit_before>/*******************************************************************************
GPU OPTIMIZED MONTE CARLO (GOMC) 2.40
Copyright (C) 2018  GOMC Group
A copy of the GNU General Public License can be found in the COPYRIGHT.txt
along with this program, also can be found at <http://www.gnu.org/licenses/>.
********************************************************************************/
/*
 * This source code follows the replica exchange design pattern of 
 * GROMACS molecular simulation package, and there is source code within this file
 * that was directly taken and adapted to fit our purposes.
 * citation: GROMACS Abraham, et al. (2015) SoftwareX 1-2 19-25
 */
#ifndef PARALLELTEMPERING_H
#define PARALLELTEMPERING_H

#include "MoveBase.h"
#include "System.h"
#include "StaticVals.h"
#include <cmath>
#include <mpi.h>
#include "ParallelTemperingMPIMethods.h"



class ParallelTempering : public MoveBase
{
public:
  ParallelTempering(System &sys, StaticVals const& statV, MultiSim *& multisim, ulong & stepRef);

  virtual uint Prep(const double subDraw, const double movPerc);
  virtual void CalcEn();
  virtual uint Transform();
  virtual void Accept(const uint rejectState, const uint step);
  virtual void PrintAcceptKind();
  //void PrepCFCMC(const uint box);

private:
  void InitRecordKeeper();
  void DestroyRecordKeeper();

  void print_ind(FILE *fplog, const char *leg, int n, int *ind, const bool *bEx);
  void print_prob(FILE *fplog, const char *leg, int n, double *prob);
  double calc_delta(FILE * fplog, bool bPrint, int i, int j, int ip, int jp);
  void print_transition_matrix(FILE * fplog, int n, int **nmoves, int *nattempt);
  void print_count(FILE *fplog, const char *leg, int n, int *count);
  void print_replica_exchange_statistics(FILE * fplog);

  void cyclic_decomposition(const int *destinations, int **cyclic, bool *incycle, const int nrepl, int *nswap);
  void compute_exchange_order(int **cyclic, int **order, const int nrepl, const int maxswap);
  void prepare_to_do_exchange(const int replica_id, int *maxswap, bool *bThisReplicaExchanged);
  void exchange_state(int b);

  // This will require a custom mpi sender
  SystemPotential sysPotNew;
  // These both will need an xyz over mpi sender
  Coordinates newMolsPos;
  COM newCOMs;

  FILE * fplog;

  ulong & step;

  //! Helps cut off probability values.
  const int c_probabilityCutoff = 100;

  const MoleculeLookup& molLookupRef;

  //! Replica ID
  int       repl;
  //! Total number of replica
  int       nrepl;<commit_msg>Fixed building on the grid errors<commit_after>/*******************************************************************************
GPU OPTIMIZED MONTE CARLO (GOMC) 2.40
Copyright (C) 2018  GOMC Group
A copy of the GNU General Public License can be found in the COPYRIGHT.txt
along with this program, also can be found at <http://www.gnu.org/licenses/>.
********************************************************************************/
/*
 * This source code follows the replica exchange design pattern of 
 * GROMACS molecular simulation package, and there is source code within this file
 * that was directly taken and adapted to fit our purposes.
 * citation: GROMACS Abraham, et al. (2015) SoftwareX 1-2 19-25
 */
#ifndef PARALLELTEMPERING_H
#define PARALLELTEMPERING_H

#include "MoveBase.h"
#include "System.h"
#include "StaticVals.h"
#include <cmath>
#include <mpi.h>
#include "ParallelTemperingMPIMethods.h"

//! Helps cut off probability values.
#define c_probabilityCutoff 100;

class ParallelTempering : public MoveBase
{
public:
  ParallelTempering(System &sys, StaticVals const& statV, MultiSim *& multisim, ulong & stepRef);

  virtual uint Prep(const double subDraw, const double movPerc);
  virtual void CalcEn();
  virtual uint Transform();
  virtual void Accept(const uint rejectState, const uint step);
  virtual void PrintAcceptKind();
  //void PrepCFCMC(const uint box);

private:
  void InitRecordKeeper();
  void DestroyRecordKeeper();

  void print_ind(FILE *fplog, const char *leg, int n, int *ind, const bool *bEx);
  void print_prob(FILE *fplog, const char *leg, int n, double *prob);
  double calc_delta(FILE * fplog, bool bPrint, int i, int j, int ip, int jp);
  void print_transition_matrix(FILE * fplog, int n, int **nmoves, int *nattempt);
  void print_count(FILE *fplog, const char *leg, int n, int *count);
  void print_replica_exchange_statistics(FILE * fplog);

  void cyclic_decomposition(const int *destinations, int **cyclic, bool *incycle, const int nrepl, int *nswap);
  void compute_exchange_order(int **cyclic, int **order, const int nrepl, const int maxswap);
  void prepare_to_do_exchange(const int replica_id, int *maxswap, bool *bThisReplicaExchanged);
  void exchange_state(int b);

  // This will require a custom mpi sender
  SystemPotential sysPotNew;
  // These both will need an xyz over mpi sender
  Coordinates newMolsPos;
  COM newCOMs;

  FILE * fplog;

  ulong & step;

  const MoleculeLookup& molLookupRef;

  //! Replica ID
  int       repl;
  //! Total number of replica
  int       nrepl;
{'fraction_non_alphanumeric': 0.1483667847304211, 'fraction_numerical': 0.007870916961826053, 'mean_word_length': 4.829128440366972, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2949544', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1522, 'n_words': 567}