Ramping up the temperature
In this example, a small cubic nanoparticle is melted by increasing the temperature stepwise. Five plots are generated at each temperature using PrimiPlotter.
"Melting a copper cluster."
from asap3 import EMT, units
from asap3.visualize.primiplotter import PrimiPlotter, PngFile
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.langevin import Langevin
from asap3.constraints import FixCom
# Create the atoms
atoms = FaceCenteredCubic(size=(5,5,5), symbol="Cu", pbc=False)
# Associate the EMT potential with the atoms
atoms.calc = EMT()
# Temperature profile
temperatures = (250, 500, 750, 1000, 1250, 1500, 1750)
# How many steps at each temperature
nsteps = 10000
# Interval between plots
plotinterval = 2000
# Keep the center of mass fixed (do this before making the dynamics)
atoms.set_constraint(FixCom())
# Make the Langevin dynamics module
dyn = Langevin(atoms, 5*units.fs, temperature_K=temperatures[0], friction=0.002)
# The plotter
plotter = PrimiPlotter(atoms)
# plotter.set_output(X11Window()) # Plot in a window on the screen
plotter.set_output(PngFile("plt")) # Save plots in files plt0000.gif ...
plotter.set_rotation((10.0, 5.0, 0))
dyn.attach(plotter.plot, interval=plotinterval)
# The main loop
for t in temperatures:
dyn.set_temperature(temperature_K=t)
for i in range(nsteps//100):
dyn.run(100)
print("E_total = %-10.5f T = %.0f K (goal: %.0f K, step %d of %d)" %\
(atoms.get_total_energy()/len(atoms), atoms.get_temperature(),
t, i, nsteps//100))