From: Dariusz Murakowski Date: Thu, 16 Jul 2015 03:30:09 +0000 (-0400) Subject: Optionally track relative contribution to energy from fields and couplings during... X-Git-Url: http://src.murakowski.org/?a=commitdiff_plain;h=ed0c1445b46e274362c9a811b37c92b6e4f5e5df;p=VirEvoDyn.git Optionally track relative contribution to energy from fields and couplings during MC sampling. --- diff --git a/mainQEE.cpp b/mainQEE.cpp index 6b67dbe..3cd263b 100755 --- a/mainQEE.cpp +++ b/mainQEE.cpp @@ -132,6 +132,8 @@ int main(int argc, char *argv[]) { else if (strcmp(argv[i],"-p3")==0) { r.saveP3=true; } else if (strcmp(argv[i],"-pk")==0) { r.savePk=true; } else if (strcmp(argv[i],"-v")==0) { r.useVerbose=true; } + + else if (strcmp(argv[i],"-trackE")==0) { r.trackE=true; } else printf("Unrecognized command! '%s'\n",argv[i]); diff --git a/monteCarlo.cpp b/monteCarlo.cpp index 9b34b80..c8b1d86 100644 --- a/monteCarlo.cpp +++ b/monteCarlo.cpp @@ -474,7 +474,15 @@ void getSample(const Vector &expJ, const IntVector &neighbor, MT::MersenneTwist // Get Monte Carlo sample with some sites fixed -void getFixedSample(const Vector &expJ, const IntVector &neighbor, const std::vector &fixedSites, MT::MersenneTwist &mt, int N, int numSteps, int stepSize, std::vector &lattice, std::vector &nonzero, Vector &p, Vector &expH, std::vector &sumExpH) { +void getFixedSample(const Vector &expJ, const IntVector &neighbor, const std::vector &fixedSites, MT::MersenneTwist &mt, int N, int numSteps, int stepSize, std::vector &lattice, std::vector &nonzero, Vector &p, Vector &expH, std::vector &sumExpH, const Vector &J, bool trackEnergy, FILE *EOut) { + + double Efield = 0.0; + double Ecoupling = 0.0; + double Etotal = 0.0; + if (trackEnergy) { + Etotal = calculateEnergy(J, lattice, Efield, Ecoupling); + fprintf(EOut,"%.6e\t%.6e\t%.6e\n",Etotal,Efield,Ecoupling); + } for (int n=0;n &config, double &Efield, double &Ecoupling) +{ + Efield = 0; + Ecoupling = 0; + + for (unsigned i=0;i > &epitopeStates, const std::vector &epitopeStartSite, int numSteps, int numRuns, Vector &p, std::vector &latticeStart) { +void getEpitopeCorrelations(const Vector &J, const Vector &expJ, const std::vector > &epitopeStates, const std::vector &epitopeStartSite, int numSteps, int numRuns, Vector &p, std::vector &latticeStart, bool trackEnergy, const std::string &energyOutFileName) { // Create and initialize Monte Carlo variables @@ -844,6 +888,8 @@ void getEpitopeCorrelations(const Vector &J, const Vector &expJ, const std::vect // MC variables int stepSize = 4*N; + //if (trackEnergy) + // stepSize = N; // Set variables for parallel @@ -855,6 +901,13 @@ void getEpitopeCorrelations(const Vector &J, const Vector &expJ, const std::vect MT::MersenneTwist mt; mt.init_genrand(seed[0]); + + // possibly track energy + FILE *EOut = NULL; + if (trackEnergy) { + EOut = fopen(energyOutFileName.c_str(),"w"); + if (EOut == NULL) { perror("File error"); exit(1); } + } // Thermalize and get initial error @@ -883,7 +936,7 @@ void getEpitopeCorrelations(const Vector &J, const Vector &expJ, const std::vect } } setEnergies(expJ, neighbor, lattice, nonzero, expH, sumExpH); - getFixedSample(expJ, neighbor, fixedSites, mt, N, numSteps, stepSize, lattice, nonzero, p, expH, sumExpH); + getFixedSample(expJ, neighbor, fixedSites, mt, N, numSteps, stepSize, lattice, nonzero, p, expH, sumExpH, J, trackEnergy, EOut); } @@ -891,6 +944,9 @@ void getEpitopeCorrelations(const Vector &J, const Vector &expJ, const std::vect for (int i=0;i void updateCorrelations(const std::vector &, const std::vector &, Vector &); void updateCorrelationsP3(const std::vector &, const std::vector &, Vector &, std::vector > > > &); void getSample(const Vector &, const IntVector &, MT::MersenneTwist &, int, int, int, std::vector &, std::vector &, Vector &, Vector &, std::vector &); -void getFixedSample(const Vector &, const IntVector &, const std::vector &, MT::MersenneTwist &, int, int, int, std::vector &, std::vector &, Vector &, Vector &, std::vector &); +void getFixedSample(const Vector &, const IntVector &, const std::vector &, MT::MersenneTwist &, int, int, int, std::vector &, std::vector &, Vector &, Vector &, std::vector &, const Vector &, bool, FILE *); void getFixedSampleP3Pk(const Vector &, const IntVector &, const std::vector &, MT::MersenneTwist &, int, int, int, std::vector &, std::vector &, Vector &, std::vector > > > &, std::vector &, Vector &, std::vector &); void writeFixedSample(FILE *, const Vector &, const IntVector &, const std::vector &, MT::MersenneTwist &, int, int, int, std::vector &, std::vector &, Vector &, Vector &, std::vector &); @@ -33,9 +33,10 @@ void getNeighbors(const Vector &, int, double, IntVector &); // Control functions void getError(const Vector &, const Vector &, int, double, int, int, double, double, std::vector &); void getErrorMCLearn(const Vector &, const Vector &, Vector &, double, int, int, double, double, Vector &, std::vector &, std::vector &); -void getEpitopeCorrelations(const Vector &, const Vector &, const std::vector > &, const std::vector &, int, int, Vector &, std::vector &); +void getEpitopeCorrelations(const Vector &, const Vector &, const std::vector > &, const std::vector &, int, int, Vector &, std::vector &, bool, const std::string &); void getEpitopeCorrelationsP3Pk(const Vector &, const Vector &, const std::vector > &, const std::vector &, int, int, Vector &, std::vector > > > &, std::vector &, std::vector &); void getEpitopeStates(FILE *, const Vector &, const Vector &, const std::vector > &, const std::vector &, int, int, Vector &, std::vector &); +double calculateEnergy(const Vector &, const std::vector &, double &, double &); #endif diff --git a/qEpitopeEval.cpp b/qEpitopeEval.cpp index c1472dd..4807def 100755 --- a/qEpitopeEval.cpp +++ b/qEpitopeEval.cpp @@ -92,7 +92,7 @@ void runEpitopeEval(RunParameters &r, std::vector > &eStates, s // Run MC and get error if (r.saveP3) getEpitopeCorrelationsP3Pk(J, expJ, eStates, eStartSite, r.b, r.runs, p, p3, pk, lattice); - else getEpitopeCorrelations(J, expJ, eStates, eStartSite, r.b, r.runs, p, lattice); + else getEpitopeCorrelations(J, expJ, eStates, eStartSite, r.b, r.runs, p, lattice, r.trackE, r.getEnergyOutFile()); // Write out correlations diff --git a/qEpitopeEval.h b/qEpitopeEval.h index fcc4c67..a4d3e24 100755 --- a/qEpitopeEval.h +++ b/qEpitopeEval.h @@ -34,6 +34,8 @@ public: bool saveP2; // If true, record pair correlations in additions to one-point correlations bool saveP3; // If true, record three-point correlations bool savePk; // If true, record P(k) mutations curve + + bool trackE; // if true, save relative contribution to energy from fields and couplings RunParameters() { @@ -49,6 +51,8 @@ public: saveP2=false; saveP3=false; savePk=false; + + trackE = false; } std::string getInfile() { return (directory+"/"+infile+".j"); } @@ -59,6 +63,7 @@ public: std::string getPkOutfile() { return (directory+"/"+outfile+".pk"); } std::string getPkOutfile(int i) { return (directory+"/"+outfile+"-"+tostring(i)+".pk"); } std::string getStartInfile() { return (directory+"/"+startfile+".dat"); } + std::string getEnergyOutFile() { return (directory+"/"+outfile+".E"); } ~RunParameters() {} };