+PottsHamiltonian::PottsHamiltonian(const std::string &couplingsFile, const std::string &seq2stateFile) : bh(1.0), bJ(1.0)
+{
+ getCouplings(couplingsFile);
+ getSeq2State(seq2stateFile);
+}
+
+
// Read correlations and number of sites in from a file
+// Code adapted from John Barton.
-PottsHamiltonian::PottsHamiltonian(std::string &FILENAME) {
+void PottsHamiltonian::getCouplings(const std::string &FILENAME)
+{
FILE *input = fopen(FILENAME.c_str(),"r"); // <paramfile>.j
if (input == NULL) { perror((std::string("ERROR: ") + FILENAME).c_str()); exit(1); }
}
+void PottsHamiltonian::getSeq2State(const std::string &FILENAME)
+{
+}
+
// Set energies based on an initial configuration
+// Code adapted from John Barton.
// Note: config[i] = 0 denotes the 2nd most common state,
-// whereas config[i] = J[i].size() is the top state
-// Also, "gauge fixing" sets field and couplings between
+// whereas config[i] = J[i].size() is the top state.
+// Also, "gauge fixing" sets field at and couplings between
// the commonest states to zero.
-double PottsHamiltonian::get_energy(const std::vector<unsigned> &config) const {
+double PottsHamiltonian::get_energy(const PottsState &config) const
+{
// Compute energy of the input configuration
- double E = 0;
+ double Efield = 0;
+ double Ecoupling = 0;
for (unsigned i=0;i<config.size();i++) {
if (config[i]!=J[i].size()) {
- E -= J[i][config[i]];
+ Efield -= J[i][config[i]];
for (unsigned j=i+1;j<config.size();j++) {
if (config[j]!=J[i].size())
- E -= J[index(i,j,config.size())][sindex(config[i],config[j],J[i].size(),J[j].size())];
+ Ecoupling -= J[index(i,j,config.size())][sindex(config[i],config[j],J[i].size(),J[j].size())];
}
}
+ double E = bh*Efield + bJ*Ecoupling;
return E;
}
typedef std::set<unsigned int> MutatedSiteSequence;
+typedef std::vector<unsigned> PottsState;
+
class Virus;
double bJ; // couplings "inverse temperature" multiplier
Coupling J;
- PottsHamiltonian(std::string &FILENAME);
+ PottsHamiltonian(const std::string &couplingsfile, const std::string &seq2stateFile);
PottsHamiltonian() : bh(1.0), bJ(1.0) { }
- double get_energy(const std::vector<unsigned> &config) const;
+ double get_energy(const PottsState &config) const;
void set_temp(double x) { bh=x; bJ=x; }
void set_temp(double x, double y) { bh=x; bJ=y; }
+ void getCouplings(const std::string &FILENAME);
+ void getSeq2State(const std::string &FILENAME);
+
};
#endif // HAM_SS_H
int main(int argc, char *argv[]) {
+ std::string fname = argv[1];
+ PottsHamiltonian H(fname,"");
+ for (unsigned i=0; i<H.J.size(); i++) {
+ for (unsigned j=0; j<H.J[i].size(); j++) {
+ std::cout << H.J[i][j] << ' ';
+ }
+ std::cout << '\n';
+ }
+ return 0;
+
RunParameters_SS r;
unsigned seed = sim_random_seed();