18.11.2012 Views

ASE Manual Release 3.6.1.2825 CAMd - CampOS Wiki

ASE Manual Release 3.6.1.2825 CAMd - CampOS Wiki

ASE Manual Release 3.6.1.2825 CAMd - CampOS Wiki

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ASE</strong> <strong>Manual</strong>, <strong>Release</strong> 3.6.1.2828<br />

# Now run the dynamics<br />

dyn.attach(printenergy, interval=10)<br />

printenergy()<br />

dyn.run(200)<br />

Constant temperature MD<br />

Often, you want to control the temperature of an MD simulation. This can be done with the Langevin dynamics<br />

module. In the previous examples, replace the line dyn = VelocityVerlet(...) with:<br />

dyn = Langevin(atoms, 5*units.fs, T*units.kB, 0.002)<br />

where T is the desired temperature in Kelvin. You also need to import Langevin, see the class below.<br />

The Langevin dynamics will then slowly adjust the total energy of the system so the temperature approaches the<br />

desired one.<br />

As a slightly less boring example, let us use this to melt a chunck of copper by starting the simulation without any<br />

momentum of the atoms (no kinetic energy), and with a desired temperature above the melting point. We will also<br />

save information about the atoms in a trajectory file called moldyn3.traj.<br />

"Demonstrates molecular dynamics with constant energy."<br />

from ase.calculators.emt import EMT<br />

from ase.lattice.cubic import FaceCenteredCubic<br />

from ase.md.langevin import Langevin<br />

from ase.io.trajectory import PickleTrajectory<br />

from ase import units<br />

from asap3 import EMT # Way too slow with ase.EMT !<br />

size = 10<br />

T = 1500 # Kelvin<br />

# Set up a crystal<br />

atoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]], symbol="Cu",<br />

size=(size,size,size), pbc=False)<br />

# Describe the interatomic interactions with the Effective Medium Theory<br />

atoms.set_calculator(EMT())<br />

# We want to run MD with constant energy using the Langevin algorithm<br />

# with a time step of 5 fs, the temperature T and the friction<br />

# coefficient to 0.02 atomic units.<br />

dyn = Langevin(atoms, 5*units.fs, T*units.kB, 0.002)<br />

#Function to print the potential, kinetic and total energy.<br />

def printenergy(a=atoms): #store a reference to atoms in the definition.<br />

epot = a.get_potential_energy() / len(a)<br />

ekin = a.get_kinetic_energy() / len(a)<br />

print ("Energy per atom: Epot = %.3feV Ekin = %.3feV (T=%3.0fK) Etot = %.3feV" %<br />

(epot, ekin, ekin/(1.5*units.kB), epot+ekin))<br />

dyn.attach(printenergy, interval=50)<br />

#We also want to save the positions of all atoms after every 100th time step.<br />

traj = PickleTrajectory("moldyn3.traj", ’w’, atoms)<br />

dyn.attach(traj.write, interval=50)<br />

# Now run the dynamics<br />

printenergy()<br />

dyn.run(5000)<br />

After running the simulation, you can study the result with the command<br />

40 Chapter 6. Tutorials

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!