From 7c2948e69397acd295df3c8b868b13d42dada4a7 Mon Sep 17 00:00:00 2001 From: Dariusz Murakowski Date: Tue, 21 Apr 2015 15:02:50 -0400 Subject: [PATCH] Formatting: retab, clean whitespace. --- ham_ss.cpp | 118 +++++++++++++++++++++++++++++------------------------------ ham_ss.h | 2 +- pop_ss.cpp | 32 ++++++---------- pop_ss.h | 10 ++--- reaction.cpp | 4 +- ss.cpp | 58 ++++++++++++++--------------- ss.h | 33 +++++++++-------- 7 files changed, 125 insertions(+), 132 deletions(-) diff --git a/ham_ss.cpp b/ham_ss.cpp index 536d72a..817dca2 100644 --- a/ham_ss.cpp +++ b/ham_ss.cpp @@ -10,44 +10,44 @@ //Constructor for loading couplings from John Barton's Ising Inversion code -//Code for this function derived from John Barton's code +//Code for this function derived from John Barton's code Hamiltonian::Hamiltonian(std::string &FILENAME) { - + this->bh=1.0; this->bJ=1.0; - FILE* input; - input = fopen(FILENAME.c_str(),"r"); // .j + FILE* input; + input = fopen(FILENAME.c_str(),"r"); // .j if (input == NULL) { perror((std::string("ERROR: ") + FILENAME).c_str()); exit(1); } - - typedef std::vector Key; - std::map JIndex; + + typedef std::vector Key; + std::map JIndex; char o; - int site=0; + int site=0; + + fscanf(input,"%d",&size); - fscanf(input,"%d",&size); - - while (fscanf(input,"%d",&site)==1) { + while (fscanf(input,"%d",&site)==1) { Key inputKey(2,site); - while (fscanf(input,"%c",&o)==1) { - - if (o==';') break; - - else { - - int neighborSite=0; - double neighborJ=0; - fscanf(input,"%d %c %lf",&neighborSite,&o,&neighborJ); - - if (neighborSite==site) { + while (fscanf(input,"%c",&o)==1) { + + if (o==';') break; + + else { + + int neighborSite=0; + double neighborJ=0; + fscanf(input,"%d %c %lf",&neighborSite,&o,&neighborJ); + + if (neighborSite==site) { - inputKey[1]=site; + inputKey[1]=site; JIndex[inputKey]=neighborJ; - - } - else { + + } + else { inputKey[1]=neighborSite; JIndex[inputKey]=neighborJ; @@ -55,46 +55,46 @@ Hamiltonian::Hamiltonian(std::string &FILENAME) { } //std::cout << site << " " << neighborSite << " " << neighborJ << "\n"; - } + } - } + } + + } - } - - fclose(input); - Key inputKey(2,0); - J.resize(size); + fclose(input); + Key inputKey(2,0); + J.resize(size); - for(int i=0;i &mutated_sites) const { - + double efield = 0.0; double ecoupling = 0.0; - std::set::iterator iter1; - std::set::iterator iter2; + std::set::iterator iter1; + std::set::iterator iter2; - for (iter1=mutated_sites.begin();iter1!=mutated_sites.end();++iter1) { + for (iter1=mutated_sites.begin();iter1!=mutated_sites.end();++iter1) { - efield -= J[*iter1][*iter1]; - + efield -= J[*iter1][*iter1]; + iter2 = iter1; ++iter2; - + for (;iter2!=mutated_sites.end();iter2++) ecoupling -= J[*iter1][*iter2]; - + } return ((efield * bh) + (ecoupling * bJ)); diff --git a/ham_ss.h b/ham_ss.h index 0e30271..2c87010 100644 --- a/ham_ss.h +++ b/ham_ss.h @@ -33,7 +33,7 @@ public: Hamiltonian(std::string &FILENAME); Hamiltonian() { } virtual ~Hamiltonian() { } - + virtual double get_energy(const std::set &mutated_sites) const; void set_temp(double x) { bh=x; bJ=x; } diff --git a/pop_ss.cpp b/pop_ss.cpp index 8e43690..0a3d5b0 100644 --- a/pop_ss.cpp +++ b/pop_ss.cpp @@ -13,34 +13,28 @@ //Constuct a virus object of wildtype Virus::Virus(const Hamiltonian &H, double mu) { - - this->mutated_sites.clear(); - this->mu=mu; - L=H.size; - energy=0; - + this->mutated_sites.clear(); + this->mu=mu; + L=H.size; + energy=0; } //Construct a virus and compute its energy. Virus::Virus(const Hamiltonian &H, double mu, const std::set &mutated_sites) { - - this->mutated_sites=mutated_sites; - this->mu=mu; - L=H.size; - update_energy(H); - -} + this->mutated_sites=mutated_sites; + this->mu=mu; + L=H.size; + update_energy(H); +} //Print key numerical parameters of the object to the terminal for diagnostics. void Virus::print_parameters() { - - std::cout << "mu = " << mu << std::endl; - std::cout << "energy = " << energy << std::endl; - + std::cout << "mu = " << mu << std::endl; + std::cout << "energy = " << energy << std::endl; } @@ -48,16 +42,12 @@ void Virus::print_parameters() { //Hamiltonian that determines the energy void Virus::update_energy(const Hamiltonian &H) { - energy=H.get_energy(mutated_sites); - } bool operator<(const Virus& lhs, const Virus& rhs) { - return lhs.mutated_sites < rhs.mutated_sites; - } diff --git a/pop_ss.h b/pop_ss.h index 22ec9a5..8f35f16 100644 --- a/pop_ss.h +++ b/pop_ss.h @@ -14,12 +14,11 @@ class Hamiltonian; class Virus { - public: double energy; std::set mutated_sites; - + Virus(const Hamiltonian &H, double mu); Virus(const Hamiltonian &H, double mu, const std::set &mutated_sites); @@ -29,12 +28,13 @@ public: double mu; unsigned int L; - + void update_energy(const Hamiltonian &H); }; +// needed for STL map bool operator<(const Virus& lhs, const Virus& rhs); @@ -89,10 +89,10 @@ public: std::vector epitopes; std::vector affinity; size_t num_ep; - + double recognized(const Virus &v) const; double recognized(const MutatedSiteSequence &mutated_sites) const; }; - + #endif // POP_SS_H diff --git a/reaction.cpp b/reaction.cpp index 9d3ad2a..191fce1 100644 --- a/reaction.cpp +++ b/reaction.cpp @@ -5,7 +5,7 @@ #include "reaction.h" -extern gsl_rng *rnd; //pointer to random number generator state +extern gsl_rng *rnd; //pointer to random number generator state //static long factorial[] = {1, 1, 2, 6, 24, 120, 720}; @@ -95,7 +95,7 @@ void VirusReaction::fire() if (rand <= a_sum * rate_constant) break; } - + // pick how many sites to mutate in the new virus // adapted from WF Virus::mutate() //double mu = iter->first.mu; diff --git a/ss.cpp b/ss.cpp index 739a1d5..f13069e 100644 --- a/ss.cpp +++ b/ss.cpp @@ -15,7 +15,7 @@ #include "ss.h" #include "reaction.h" -gsl_rng *rnd; //pointer to random number generator state +gsl_rng *rnd; //pointer to random number generator state // generate a random number generator seed from /dev/urandom // borrowed from SSC src/runtime/ssc_rts.c @@ -44,8 +44,8 @@ void run(RunParameters_SS &r, unsigned seed) { // Initialize RNG and set initial state, if importing from file - //static gsl_rng *rnd = gsl_rng_alloc(gsl_rng_taus2); //pointer to random number generator state - rnd = gsl_rng_alloc(gsl_rng_taus2); //pointer to random number generator state + //static gsl_rng *rnd = gsl_rng_alloc(gsl_rng_taus2); //pointer to random number generator state + rnd = gsl_rng_alloc(gsl_rng_taus2); //pointer to random number generator state //srand((unsigned)time(0)); //gsl_rng_set(rnd,rand()); @@ -200,7 +200,7 @@ void simulate(Rxn_parray &reactions, Species_parray &species, double t_end, long break; } } - + // TODO: better handle case with total propensity == 0.0 if (rxn == end) @@ -236,11 +236,11 @@ void importState(RunParameters_SS &r) { char o; double frac; - unsigned int site; + unsigned int site; // Import initial state of the population - while (fscanf(input,"%le",&frac)==1) { + while (fscanf(input,"%le",&frac)==1) { std::cout << frac; // XXX @@ -248,27 +248,27 @@ void importState(RunParameters_SS &r) { std::set tempSet; - while (fscanf(input,"%c",&o)==1) { + while (fscanf(input,"%c",&o)==1) { std::cout << o; // XXX - - if (o=='\n' || o==';') break; - - else { - - fscanf(input,"%u",&site); + + if (o=='\n' || o==';') break; + + else { + + fscanf(input,"%u",&site); std::cout << site; // XXX tempSet.insert(site); } - - } + + } r.initPop.push_back(tempSet); if (o==';') break; - } + } std::cout << "\n"; // XXX @@ -478,15 +478,15 @@ void usage() */ int main(int argc, char *argv[]) { - + RunParameters_SS r; unsigned seed = sim_random_seed(); - + // Process command line input - + for (int i=1;i Species_parray; // Converts generic to string template - inline std::string tostring (const T& t) { std::stringstream ss; @@ -118,13 +117,13 @@ public: bool runUntilEscape; // If true, run the simulation until the population escapes bool runUntilEscape_all; // If true, run the simulation until the population escapes *all* immune pressure bool importState; // If true, import state from a state file - bool useEpitope; // Include selective pressure on an epitope + bool useEpitope; // Include selective pressure on an epitope bool useVerbose; // If true, print extra information while program is running - + std::vector > initPop; // Initial population sequences std::vector initFrac; // Initial population fraction - + std::string couplingsInfile; std::string trajectoryOutfile; std::string supplementaryOutfile; @@ -158,16 +157,17 @@ public: double rate_h; + // constructor sets default parameters RunParameters_SS() { directory=""; - + n = 100000; num_runs = 1000; mu = 6.0e-5; bh = 1.0; bJ = 1.0; - + importState=false; useVerbose=false; @@ -194,10 +194,11 @@ public: } + void setFiles() { - + if (strcmp(directory.c_str(),"")!=0) { - + couplingsInfile=directory+"/"+infile+".j"; trajectoryOutfile=directory+"/"+outfile+".dat"; supplementaryOutfile=directory+"/"+outfile+".sum"; @@ -207,11 +208,11 @@ public: for (size_t i = 0; i != epitopefiles.size(); ++i) { epitopefiles[i] = directory+"/"+epitopefiles[i]+".ep"; } - + } - + else { - + couplingsInfile=infile+".j"; trajectoryOutfile=outfile+".dat"; supplementaryOutfile=outfile+".sum"; @@ -221,14 +222,16 @@ public: for (size_t i = 0; i != epitopefiles.size(); ++i) { epitopefiles[i] = epitopefiles[i]+".ep"; } - + } - + //printf("%s\n%s\n%s\n",couplingsInfile.c_str(),trajectoryOutfile.c_str(),stateInfile.c_str()); - + } + + ~RunParameters_SS() {} - + }; -- 2.7.4