示例#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)
        
示例#2
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))