Example #1
0
# The plotter
def invisible_atoms(a):
    """Return True for atoms that should be invisible."""
    r = atoms.get_positions()
    centerofmass = r.sum(axis=0) / len(atoms)
    return (r[:,2] < centerofmass[2])

plotter = PrimiPlotter(atoms)
plotter.set_invisibility_function(invisible_atoms)
plotter.set_colors(mycolors) # Map tags to colors
# plotter.set_output(X11Window())   # Plot in a window on the screen
plotter.set_output(JpegFile("ptm"))  # Save plots in files plt0000.gif ...
plotter.set_rotation((10.0, 5.0, 0))

# Attach the plotter to the PTMobserver object.  That guarantees
# that the plotter is called AFTER the PTM analysis has been done.
# Similarly, a Trajectory should be attached to the PTMobserver
# object.  By using interval=1 (the default), the plotter is called
# every time PTMobserver is called, i.e. every plotinterval
# timesteps.
ptm.attach(plotter.plot)

# The main loop
for t in temperatures:
    dyn.set_temperature(units.kB*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)
        
Example #2
0
 print "Timing with %i atoms (%i threads)" % (natoms, nthreads)
 blocksize = int(np.ceil((natoms/4)**(1./3.)))
 atoms = FaceCenteredCubic(symbol='Cu', size=(blocksize,blocksize,blocksize), pbc=False)
 print "Creating block with %i atoms, cutting to %i atoms" % (len(atoms), natoms)
 atoms = atoms[:natoms]
 assert len(atoms) == natoms
 atoms.set_calculator(EMT())
 MaxwellBoltzmannDistribution(atoms, 2 * T * units.kB)
 dyn = VelocityVerlet(atoms, 5*units.fs)
 ptsteps = int(laststeps * (0.1 * targettime / lasttime) * lastsize / natoms)
 if ptsteps < 100:
     ptsteps = 100
 print "Running pre-timing (%i steps)..." % (ptsteps,)
 t1 = time.time()
 dyn.run(ptsteps - 50)
 MaxwellBoltzmannDistribution(atoms, (2 * T - atoms.get_temperature()) * units.kB)
 dyn.run(50)
 t1 = time.time() - t1
 steps = int(ptsteps * targettime / t1)
 if steps < 200:
     steps = 200 
 print "Temperature is %.1f K" % (atoms.get_temperature(),)
 print "Running main timing (%i steps)" % (steps,)
 MaxwellBoltzmannDistribution(atoms, T * units.kB)
 t1 = time.time()
 dyn.run(steps)
 t1 = time.time() - t1
 lasttime = t1
 print "... done in %.1f s  (T = %.1f K)." % (t1, atoms.get_temperature())
 t1 *= 1e6 / (natoms * steps)
 print "RESULT: %.3f us/atom/step  (%i atoms, %i threads)" % (t1, natoms, nthreads)
Example #3
0
# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Temperature profile
temperatures = (250, 500, 750, 1000, 1250, 1500, 1750)

# How many steps at each temperature
nsteps = 10000

# Interval between plots
plotinterval = 2000

# Make the Langevin dynamics module
dyn = Langevin(atoms, 5 * units.fs, units.kB * temperatures[0], 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(units.kB * 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))