def setUp(self): np.random.seed(0) self.npar = 1 self.system = SamplerSystem() self.nreplicas = 500 replicas = [Replica(x, energy) for energy, x in [self.system.sample_configuration(10.) for i in range(self.nreplicas)]] mc_walker = self.system ns = NestedSampling(replicas, mc_walker=mc_walker, nproc=1, verbose=False, iprint=100) run_nested_sampling(ns, label="test") self.energies = np.array(ns.max_energies) self.T = np.linspace(0.1, 1.0, 10) # compute the heat capacity and internal energy from the results of the NS run self.cvNS = compute_heat_capacity(self.energies, self.nreplicas, npar=self.npar, ndof=self.system.ndof, Tmin=min(self.T), Tmax=max(self.T), nT=len(self.T), live_replicas=False) # compute the same directly from the HSA self.cvHSA = minima_to_cv(self.system.database.minima(), kT=self.T, k=self.system.ndof)
def _compute_cv(self): Tlist = self._get_T_range() lZ, U, U2, Cv = minima_to_cv(self.minima, Tlist, self._get_ndof()) self.Tlist = Tlist self.Cv = Cv
minima = db.minima() else: dbfname = args.fname db = Database(dbfname, createdb=False) minima = [m for m in db.minima() if m.fvib is not None and m.pgorder is not None] if len(minima) == 0: print "There are not minima with the necessary thermodynamic information in the database. Have you computed the normal mode"\ " frequencies and point group order for all the minima? See pele.thermodynamics "\ " for more information" exit(1) print "computing heat capacity from", len(minima), "minima" Tmin = args.Tmin Tmax = args.Tmax nT = args.Tcount dT = (Tmax-Tmin) / nT T = np.array([Tmin + dT*i for i in range(nT)]) Z, U, U2, Cv = minima_to_cv(minima, T, k) with open(args.o, "w") as fout: fout.write("#T Cv <E> <E**2>\n") for vals in zip(T, Cv, U, U2): fout.write("%g %g %g %g\n" % vals) plt.plot(T, Cv, '-') plt.xlabel("T") plt.ylabel("Cv") plt.savefig(args.o + ".pdf")