def test_maxwellboltzmann(): from ase.md.velocitydistribution import MaxwellBoltzmannDistribution from ase.lattice.cubic import FaceCenteredCubic atoms = FaceCenteredCubic(size=(50, 50, 50), symbol="Cu", pbc=False) print("Number of atoms:", len(atoms)) MaxwellBoltzmannDistribution(atoms, temperature_K=0.1 / kB) temp = atoms.get_kinetic_energy() / (1.5 * len(atoms)) print("Temperature", temp, " (should be 0.1)") assert abs(temp - 0.1) < 1e-3
from asap3 import Atoms, EMT, units from ase.lattice.cubic import FaceCenteredCubic from asap3.md.verlet import VelocityVerlet # Create the atoms atoms = FaceCenteredCubic(size=(3,3,3), symbol="Cu", pbc=False) # Give the first atom a non-zero momentum atoms[0].set_momentum(array([0, -11.3, 0])) print "Kinetic energies of all atoms:" p = atoms.get_momenta() kinenergies = 0.5 * (p * p).sum(1) / atoms.get_masses() print kinenergies # Associate the EMT potential with the atoms atoms.set_calculator(EMT()) # Now do molecular dynamics, printing kinetic, potential and total # energy every ten timesteps. dyn = VelocityVerlet(atoms, 5.0*units.fs) print "" print "Energy per atom:" print " %15s %15s %15s" % ("Pot. energy", "Kin. energy", "Total energy") for i in range(25): dyn.run(10) epot = atoms.get_potential_energy()/len(atoms) ekin = atoms.get_kinetic_energy()/len(atoms) print "%15.5f %15.5f %15.5f" % (epot, ekin, epot+ekin)
raise initr = atoms.get_positions() initp = atoms.get_momenta() def targetfunc(params, x): return params[0] * exp(-params[1] * x) + params[2] output = file("Langevin.dat", "w") for temp, frict in ((0.01, 0.001),): dyn = Langevin(atoms, timestep, temp, frict) print "" print "Testing Langevin dynamics with T = %f eV and lambda = %f" % (temp, frict) ekin = atoms.get_kinetic_energy()/natoms print ekin output.write("%.8f\n" % ekin) temperatures = [(0, 2.0 / 3.0 * ekin)] a = 0.1 b = frict c = temp print "Equilibrating ..." tstart = time.time() for i in xrange(1,nequil+1): dyn.run(nminor) ekin = atoms.get_kinetic_energy() / natoms if i % nequilprint == 0: print "%.6f T = %.6f (goal: %f)" % \ (ekin, 2./3. * ekin, temp) output.write("%.8f\n" % ekin)
if not hasattr(NPT, '_npt_version'): print "Skipping test: NP dynamics does not work in parallel with this old version of ASE." else: if ismaster: atoms = FaceCenteredCubic(size=(30,15,15), symbol="Cu", pbc=True) else: atoms = None atoms = MakeParallelAtoms(atoms, cpulayout) atoms.set_calculator(EMT()) print "Number of atoms:", atoms.get_number_of_atoms() print "Heating to %d K using Langevin" % T_goal lgv = Langevin(atoms, 5 * units.fs, temperature=2*T_goal*units.kB, friction=0.05) while atoms.get_kinetic_energy() < 1.5 * atoms.get_number_of_atoms() * T_goal * units.kB: lgv.run(5) T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() * units.kB) print "Temperature is now %.2f K" % (T,) print "Desired temperature reached!" lgv.set_temperature(T_goal*units.kB) for i in range(2): lgv.run(20) s = atoms.get_stress() p = -(s[0] + s[1] + s[2])/3.0 / units.GPa T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() * units.kB) print "Pressure is %f GPa, desired pressure is %f GPa (T = %.2f K)" % (p, p_goal, T) dv = (p - p_goal) / bulk print "Adjusting volume by", dv
def targetfunc(params, x): return params[0] * exp(-params[1] * x) + params[2] output = file("Langevin.dat", "w") for temp, frict, fixcm in ( (0.01, 0.001, True), (0.0025, 0.001, False), ): dyn = Langevin(atoms, timestep, temp, frict, fixcm=fixcm) print "" print "Testing Langevin dynamics with T = %f eV and lambda = %f" % (temp, frict) ekin = atoms.get_kinetic_energy() / len(atoms) print ekin output.write("%.8f\n" % ekin) temperatures = [(0, 2.0 / 3.0 * ekin)] a = 0.1 b = frict c = temp print "Equilibrating ..." tstart = time.time() for i in xrange(1, nequil + 1): dyn.run(nminor) ekin = atoms.get_kinetic_energy() / len(atoms) if i % nequilprint == 0: print "%.6f T = %.6f (goal: %f)" % \ (ekin, 2.0/3.0 * ekin, temp)
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution from ase.lattice.cubic import FaceCenteredCubic atoms = FaceCenteredCubic(size=(50,50,50), symbol="Cu", pbc=False) print "Number of atoms:", len(atoms) MaxwellBoltzmannDistribution(atoms, 0.1) temp = atoms.get_kinetic_energy() / (1.5 * len(atoms)) print "Temperature", temp, " (should be 0.1)" assert abs(temp - 0.1) < 1e-3
e_start_pot = e_start_dict[boundary] except KeyError: e_start_pot = e_start_dict[boundary] = e_st_pot else: ReportTest("Initial energy ", e_st_pot, e_start_pot, 1e-4, silent=True) dyn = VelocityVerlet(atoms, logfile="-", dt=3 * units.fs, loginterval=1) dyn.run(50) e_start = (atoms.get_potential_energy() + atoms.get_kinetic_energy()) / natoms if ismaster: print "Running" dyn = VelocityVerlet(atoms, dt=5 * units.fs) logger = MDLogger(dyn, atoms, '-', peratom=True) logger() dyn.attach(logger, interval=25) if writetraj: if cpulayout is None: tname = "longVerlet-serial-%d-%d-%d.traj" % tuple(boundary) else: tname = ("longVerlet-%d-%d-%d--%d-%d-%d.traj" % (tuple(cpulayout) + tuple(boundary))) traj = PickleTrajectory(tname, "w", atoms) traj.write() dyn.attach(traj, interval=1000)
else: if ismaster: atoms = FaceCenteredCubic(size=(30, 15, 15), symbol="Cu", pbc=True) else: atoms = None atoms = MakeParallelAtoms(atoms, cpulayout) atoms.set_calculator(EMT()) print "Number of atoms:", atoms.get_number_of_atoms() print "Heating to %d K using Langevin" % T_goal lgv = Langevin(atoms, 5 * units.fs, temperature=2 * T_goal * units.kB, friction=0.05) while atoms.get_kinetic_energy( ) < 1.5 * atoms.get_number_of_atoms() * T_goal * units.kB: lgv.run(5) T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() * units.kB) print "Temperature is now %.2f K" % (T, ) print "Desired temperature reached!" lgv.set_temperature(T_goal * units.kB) for i in range(2): lgv.run(20) s = atoms.get_stress() p = -(s[0] + s[1] + s[2]) / 3.0 / units.GPa T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() * units.kB) print "Pressure is %f GPa, desired pressure is %f GPa (T = %.2f K)" % (
atoms.set_calculator(EMT()) MaxwellBoltzmannDistribution(atoms, 3000*units.kB) if ismaster: print "Initializing" e_st_pot = atoms.get_potential_energy()/natoms try: e_start_pot = e_start_dict[boundary] except KeyError: e_start_pot = e_start_dict[boundary] = e_st_pot else: ReportTest("Initial energy ", e_st_pot, e_start_pot, 1e-4, silent=True) dyn = VelocityVerlet(atoms, logfile="-", dt=3*units.fs, loginterval=1) dyn.run(50) e_start = (atoms.get_potential_energy() + atoms.get_kinetic_energy())/natoms if ismaster: print "Running" dyn = VelocityVerlet(atoms, dt=5*units.fs) logger = MDLogger(dyn, atoms, '-', peratom=True) logger() dyn.attach(logger, interval=25) if writetraj: if cpulayout is None: tname = "longVerlet-serial-%d-%d-%d.traj" % tuple(boundary) else: tname = ("longVerlet-%d-%d-%d--%d-%d-%d.traj" % (tuple(cpulayout) + tuple(boundary))) traj = PickleTrajectory(tname, "w", atoms) traj.write() dyn.attach(traj, interval=1000)
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution from ase.lattice.cubic import FaceCenteredCubic atoms = FaceCenteredCubic(size=(50, 50, 50), symbol="Cu", pbc=False) print("Number of atoms:", len(atoms)) MaxwellBoltzmannDistribution(atoms, 0.1) temp = atoms.get_kinetic_energy() / (1.5 * len(atoms)) print("Temperature", temp, " (should be 0.1)") assert abs(temp - 0.1) < 1e-3
size = 5 import ase.io from ase.io.trajectory import Trajectory atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], symbol='Pd', size=(size, size, size), pbc=True) traj = ase.io.Trajectory('traj_1.traj','w') atoms.set_calculator(EMT()) MaxwellBoltzmannDistribution(atoms, 300 * units.kB) traj.write(atoms) dyn = VelocityVerlet(atoms, dt=1 * units.fs) for step in range(10): pot = atoms.get_potential_energy() kin = atoms.get_kinetic_energy() with open('traj_1.txt','w') as f: f.write("{}: Total Energy={}, POT={}, KIN={}\n".format(step, pot+kin, pot, kin)) dyn.run(5) ase.io.write('traj_1.xyz',ase.io.read('traj_1.traj'), append=True) traj.write(atoms)
else: raise RuntimeError, "Expected zero or two parameter to the script!" #ReportTest.Verbose() atoms = FaceCenteredCubic(directions=((1,0,0), (0,1,0), (0,0,1)), size=(15,15,15), symbol="Cu", pbc=True) atoms.set_calculator(EMT()) print "Number of atoms:", len(atoms) print "Heating to %d K using Langevin" % T_goal lgv = Langevin(atoms, 5 * units.fs, temperature=2*T_goal*units.kB, friction=0.01) MaxwellBoltzmannDistribution(atoms, 0.9*T_goal*units.kB) while atoms.get_kinetic_energy() < 1.5 * len(atoms) * T_goal * units.kB: lgv.run(10) T = atoms.get_kinetic_energy() / (1.5 * len(atoms) * units.kB) print "Temperature is now %.2f K" % (T,) print "Desired temperature reached!" lgv.set_temperature(T_goal*units.kB) for i in range(4): lgv.run(100) s = atoms.get_stress() p = -(s[0] + s[1] + s[2])/3.0 / units.GPa T = atoms.get_kinetic_energy() / (1.5 * len(atoms) * units.kB) print "Pressure is %f GPa, desired pressure is %f GPa (T = %.2f K)" % (p, p_goal, T) dv = (p - p_goal) / bulk print "Adjusting volume by", dv