Esempio n. 1
0
temperatures[-len(t):] = t
print temperatures

# How many steps at each temperature
nsteps_total = 100000
nsteps = nsteps_total // len(temperatures)

# Interval between plots
plotinterval = 2000

# Make the Langevin dynamics module
dyn = Langevin(atoms, 5*units.fs, units.kB*temperatures[0], 0.002)

# The PTM analyser is called every plotinterval timesteps.
ptm = PTMobserver(atoms, rmsd_max=0.16)
dyn.attach(ptm.analyze, interval=plotinterval)

# 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))
Esempio n. 2
0
i = 0
while atoms.get_temperature() < temperature:
    i = i + 1
    dyn.run(10)
    info.write("Energy per atom (step %d): Epot = %.3f eV   Ekin = %.3f eV\n" %
               (i, atoms.get_potential_energy() / nAtoms,
                atoms.get_kinetic_energy() / nAtoms))
info.write("Temperature has reached %d K: %s\n" %
           (atoms.get_temperature(), time.ctime()))

# Run the real dynamics
dyn = Langevin(atoms, timestep * units.fs, temperature * units.kB, lgvfrict)

# PTM analysis
ptm = PTMobserver(atoms, rmsd_max=0.2, cutoff=5.0)
dyn.attach(ptm.analyze, interval=n_output)

# Output trajectory
writer = Trajectory(outfile, "w", atoms)
ptm.attach(writer)
writer.write()  # Write the initial configuration


# On-the-fly-plotting
def invisible_atoms(a):
    """Return True for atoms that should be invisible."""
    r = atoms.get_positions()
    c = atoms.get_tags()
    cell = atoms.get_cell()
    return (c == 2) | (r[:, 1] < 5.0) | (r[:, 1] > cell[1, 1] - 5)
Esempio n. 3
0
atoms.set_calculator(EMT())

# Make an object doing Langevin dynamics at a temperature of 800 K
dyn = Langevin(atoms,
               timestep=5 * units.fs,
               temperature=800 * units.kB,
               friction=0.005)

# Set the momenta corresponding to T=1600K.  The temperature will
# quickly drop to half of that as the energy is distributed evenly
# among the kinetic and potential energy.
MaxwellBoltzmannDistribution(atoms, 1600 * units.kB)

# Make a trajectory
traj = PickleTrajectory('MD_Cluster.traj', "w", atoms)
dyn.attach(traj,
           interval=500)  # Automatically writes the initial configuration


# Print the energies
def printenergy(a, step=[
    0,
]):
    n = len(a)
    ekin = a.get_kinetic_energy() / n
    epot = a.get_potential_energy() / n
    print("%4d: E_kin = %-9.5f  E_pot = %-9.5f  E_tot = %-9.5f  T = %.1f K" %
          (step[0], ekin, epot, ekin + epot, 2.0 / 3.0 * ekin / units.kB))
    step[0] += 1


printenergy(atoms)
Esempio n. 4
0
# Now the standard EMT Calculator is attached
atoms.set_calculator(EMT())

# Make an object doing Langevin dynamics at a temperature of 800 K
dyn = Langevin(atoms, timestep=5*units.fs, temperature=800*units.kB,
               friction=0.005)

# Set the momenta corresponding to T=1600K.  The temperature will
# quickly drop to half of that as the energy is distributed evenly
# among the kinetic and potential energy.
MaxwellBoltzmannDistribution(atoms, 1600*units.kB)

# Make a trajectory
traj = PickleTrajectory('MD_Cluster.traj', "w", atoms)
dyn.attach(traj, interval=500) # Automatically writes the initial configuration

# Print the energies
def printenergy(a, step=[0,]):
    n = len(a)
    ekin = a.get_kinetic_energy() / n
    epot = a.get_potential_energy() / n
    print ("%4d: E_kin = %-9.5f  E_pot = %-9.5f  E_tot = %-9.5f  T = %.1f K" %
           (step[0], ekin, epot, ekin+epot, 2.0/3.0*ekin/units.kB))
    step[0] += 1
          
printenergy(atoms)
view(atoms)  #If computer is busy, the plot will appear with some delay.

# Now do the dynamics, doing 5000 timesteps, writing energies every 50 steps
dyn.attach(printenergy, 50, atoms)
Esempio n. 5
0
temperatures = (250, 500, 750, 1000, 1250, 1500, 1750)

# How many steps at each temperature
nsteps = 5000

# Interval between plots
plotinterval = 500

# 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())
plotter.set_rotation((10.0, 5.0, 0))
dyn.attach(plotter.plot, interval=plotinterval)

# Some functions for calculating the actual temperature, energy, ...

def temperature(a):
    return 2.0/3.0 * a.get_kinetic_energy() / (len(a) * units.kB)

def etotal(a):
    return (a.get_kinetic_energy() + a.get_potential_energy()) / len(a)

# The main loop

for t in temperatures:
    dyn.set_temperature(units.kB*t)
    for i in range(nsteps/100):
        dyn.run(100)
Esempio n. 6
0
            except OverflowError:
                print "leastSquaresFit failed (this is OK)."
                a = b = c = 0.0
            print "%.6f  T_inf = %.6f (goal: %f)  k = %.6f" % \
                  (ekin, c, temp, b)
    tequil = time.time() - tstart
    print "This took %.1f minutes." % (tequil / 60)
    print "Taking data - this takes", repeats*nsteps/nequil, "times longer!"

monitor = TemperatureMonitor(nprint)

atoms = Atoms(initial)
atoms.set_calculator(EMT())
dyn = Langevin(atoms, timestep*femtosecond, temp*kB, 0.001)
equilibrate(atoms, dyn, kB*temp)
dyn.attach(monitor.Update, 5)
for i in range(repeats):
    monitor.New("Free boundaries, fixcm=True", atoms, temp, i)
    dyn.run(nsteps)
    monitor.Check()

atoms = Atoms(initial)
atoms.set_calculator(EMT())
dyn = Langevin(atoms, timestep*femtosecond, temp*kB, 0.001, fixcm=False)
equilibrate(atoms, dyn, kB*temp)
dyn.attach(monitor.Update, 5)
for i in range(repeats):
    monitor.New("Free boundaries, fixcm=False", atoms, temp, i)
    dyn.run(nsteps)
    monitor.Check()
Esempio n. 7
0
def main(element, T_up, T_low, T_expect, bulkmodulus, makepot):
    def set_temp_fric(dyn, atoms):
        z = atoms.get_positions()[:,2]
        zmax = atoms.get_cell()[2,2]
        zmin = 0
        T = T_low + (T_up - T_low) * (z - zmin) / (zmax - zmin)
        dyn.set_temperature(T * units.kB)

    rnd = world.sum(random.randint(0,2**32)) # Insures the same number on all nodes.
    prefix = "melt-%s-%s" % (element, hex(rnd)[2:])
    if master:
        print "Using output directory", prefix
        os.mkdir(prefix)
    else:
        while not os.path.exists(prefix):
            time.sleep(1)
    if master:
        atoms = FaceCenteredCubic(symbol=element, size=size, pbc=(True, True, False))
        atoms.center(vacuum=10.0, axis=2)
    else:
        atoms = None
    atoms = MakeParallelAtoms(atoms, cpulayout1)
    print world.rank, '-', len(atoms), atoms.get_number_of_atoms()
    atoms.set_calculator(makepot())
    #view(atoms)
    
    dyn = Langevin(atoms, 5*units.fs, 0.0, friction)
    logger = MDLogger(dyn, atoms, prefix+'/Melt-phase1.log', stress=True, peratom=True)
    dyn.attach(logger, interval=100)
    set_temp_fric(dyn, atoms)
    unstress = Inhomogeneous_NPTBerendsen(atoms, 50*units.fs, 0, taup=500*units.fs,
                                          compressibility=1/bulkmodulus)
    dyn.attach(unstress.scale_positions_and_cell, interval=10)
    #traj = PickleTrajectory("melting-phase1.traj", "w", atoms)
    fn1 = prefix + "/Melt-phase1.bundle" 
    if master:
        print "Opening file", fn1
    traj = BundleTrajectory(fn1, "w", atoms, split=True)
    dyn.attach(traj, interval=500)
    
    therm = Thermometer(atoms, prefix+"/TempProfile-phase1.dat")
    dyn.attach(therm.update, interval=500)
    
    for i in range(steps1 / 100):
        dyn.run(100)
        set_temp_fric(dyn, atoms)
    if master:
        print "Closing file", fn1
    traj.close()
    del traj, atoms
    
    # Reread the bundle
    atoms = BundleTrajectory(fn1).get_atoms(-1, cpulayout2)
    atoms.set_calculator(makepot())
    dyn = VelocityVerlet(atoms, 5*units.fs)
    logger = MDLogger(dyn, atoms, prefix+'/PtMelt-phase2.log', stress=True, peratom=True)
    dyn.attach(logger, interval=1000)
    unstress = Inhomogeneous_NPTBerendsen(atoms, 50*units.fs, 0,
                                          taup=5000*units.fs,
                                          compressibility=1/bulkmodulus)
    dyn.attach(unstress.scale_positions_and_cell, interval=10)
    fn2 = prefix + "/Melt-phase2.bundle" 
    if master:
        print "Opening file", fn2
    traj = BundleTrajectory(fn2, "w", atoms)
    dyn.attach(traj, interval=steps2/100)
    
    therm = Thermometer(atoms, prefix+"/TempProfile-phase2.dat")
    dyn.attach(therm.update, interval=steps2/10)
    
    dyn.run(steps2 - takedata)
    therm2 = AveragingThermometer(atoms)
    dyn.attach(therm2.update, interval=100)
    dyn.run(takedata)  # Run the last part
    T = therm2.get_temp()
    if master:
        print "Melting temperature:", T
    ReportTest("Melting temperature", T, T_expect, 3)
    if cleanup:
        world.barrier()
        # Cleanup may fail due to the directory not being updated from
        # writes on the other nodes.  Wait for NFS file system.
        time.sleep(60)
        if master:
            shutil.rmtree(prefix)
    world.barrier()
    ReportTest.Summary()