예제 #1
0
def MakeCu(T=300, size=(29,29,30)):
    print "Preparing", T, "K Copper system."
    atoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]],
                              symbol='Cu', size=size)
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 2*T * units.kB)
    #dyn = VelocityVerlet(atoms, 5*units.fs)
    dyn = Langevin(atoms, 5*units.fs, T*units.kB, 0.05)
    dyn.run(50)
    print "Done.  Temperature =", temperature(atoms), \
          "K.  Number of atoms: ", len(atoms)
    return atoms
예제 #2
0
def MakeCu3Ni(T=300):
    print "Preparing", T, "K NiCu3 system."
    atoms = L1_2(directions=[[1,0,0],[0,1,0],[0,0,1]], symbol=('Ni', 'Cu'),
                 latticeconstant=3.61, size=(29,29,30))
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 2*T * units.kB)
    #dyn = VelocityVerlet(atoms, 5*units.fs)
    dyn = Langevin(atoms, 5*units.fs, T*units.kB, 0.05)
    dyn.run(50)
    print "Done.  Temperature =", temperature(atoms), \
          "K.  Number of atoms: ", len(atoms)
    return atoms
예제 #3
0
def MakeCu(T=300, size=(29, 29, 30)):
    print "Preparing", T, "K Copper system."
    atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                              symbol='Cu',
                              size=size)
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 2 * T * units.kB)
    #dyn = VelocityVerlet(atoms, 5*units.fs)
    dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.05)
    dyn.run(50)
    print "Done.  Temperature =", temperature(atoms), \
          "K.  Number of atoms: ", len(atoms)
    return atoms
예제 #4
0
def MakeCu3Ni(T=300):
    print "Preparing", T, "K NiCu3 system."
    atoms = L1_2(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                 symbol=('Ni', 'Cu'),
                 latticeconstant=3.61,
                 size=(29, 29, 30))
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 2 * T * units.kB)
    #dyn = VelocityVerlet(atoms, 5*units.fs)
    dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.05)
    dyn.run(50)
    print "Done.  Temperature =", temperature(atoms), \
          "K.  Number of atoms: ", len(atoms)
    return atoms
예제 #5
0
        ekin = atoms.get_kinetic_energy() / len(atoms)
        r.append([epot, ekin, epot+ekin])
    r = array(r)
    diff = r - ref
    maxdiff = diff.max()
    print "Maximal difference is", maxdiff
    ReportTest(name, maxdiff, 0.0, 1e-6)
    
print_version(1)

print "Making initial system"
iniatoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]],
                             size=(10,5,5), symbol="Cu", pbc=(1,1,0))
iniatoms.set_calculator(EMT())
inidyn = Langevin(iniatoms, 5*units.fs, 450*units.kB, 0.05)
inidyn.run(100)
print "Temperature is now", iniatoms.get_kinetic_energy() / (1.5*units.kB*len(iniatoms)), "K"

print "Making reference simulation"
refatoms = Atoms(iniatoms)
refatoms.set_calculator(EMT())
dyn = VelocityVerlet(refatoms, 5*units.fs)
ref = []
for i in range(50):
    dyn.run(5)
    epot = refatoms.get_potential_energy() / len(refatoms)
    ekin = refatoms.get_kinetic_energy() / len(refatoms)
    ref.append([epot, ekin, epot+ekin])

ref = array(ref)
예제 #6
0
for temp, frict in ((0.01, 0.001),):
    dyn = Langevin(atoms, timestep, temp, frict)
    print ""
    print "Testing Langevin dynamics with T = %f eV and lambda = %f" % (temp, frict)
    ekin = atoms.get_kinetic_energy()/natoms
    print ekin
    output.write("%.8f\n" % ekin)
    temperatures = [(0, 2.0 / 3.0 * ekin)]
    a = 0.1
    b = frict
    c = temp
    print "Equilibrating ..."
    tstart = time.time()
    for i in xrange(1,nequil+1):
        dyn.run(nminor)
        ekin = atoms.get_kinetic_energy() / natoms
        if i % nequilprint == 0:
            print "%.6f  T = %.6f (goal: %f)" % \
                  (ekin, 2./3. * ekin, temp)
        output.write("%.8f\n" % ekin)
    tequil = time.time() - tstart
    print "This took %s minutes." % (tequil / 60)
    output.write("&\n")
    temperatures = []
    print "Taking data - this takes", nsteps/nequil, "times longer!"
    tstart = time.time()
    for i in xrange(1,nsteps+1):
        dyn.run(nminor)
        ekin = atoms.get_kinetic_energy() / natoms
        temperatures.append(2.0/3.0 * ekin)
예제 #7
0
파일: parallelNPT.py 프로젝트: auag92/n2dm
if not hasattr(NPT, '_npt_version'):
    print "Skipping test: NP dynamics does not work in parallel with this old version of ASE."
else:
    if ismaster:
        atoms = FaceCenteredCubic(size=(30,15,15), symbol="Cu", pbc=True)
    else:
        atoms = None
    atoms = MakeParallelAtoms(atoms, cpulayout)
    atoms.set_calculator(EMT())
    print "Number of atoms:", atoms.get_number_of_atoms()

    print "Heating to %d K using Langevin" % T_goal
    lgv = Langevin(atoms, 5 * units.fs, temperature=2*T_goal*units.kB, friction=0.05)

    while atoms.get_kinetic_energy() < 1.5 * atoms.get_number_of_atoms() * T_goal * units.kB:
        lgv.run(5)
        T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() * units.kB)
        print "Temperature is now %.2f K" % (T,)
    print "Desired temperature reached!"

    lgv.set_temperature(T_goal*units.kB)

    for i in range(2):
        lgv.run(20)
        s = atoms.get_stress()
        p = -(s[0] + s[1] + s[2])/3.0 / units.GPa
        T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() * units.kB)
        print "Pressure is %f GPa, desired pressure is %f GPa (T = %.2f K)" % (p, p_goal, T)
        dv = (p - p_goal) / bulk
        print "Adjusting volume by", dv
        cell = atoms.get_cell()
예제 #8
0
# 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)
dyn.run(5000)
view(atoms)

# Now increase the temperature to 2000 K and continue
dyn.set_temperature(2000 * units.kB)
dyn.run(5000)
view(atoms)
예제 #9
0
        atoms = FaceCenteredCubic(size=(30, 15, 15), symbol="Cu", pbc=True)
    else:
        atoms = None
    atoms = MakeParallelAtoms(atoms, cpulayout)
    atoms.set_calculator(EMT())
    print "Number of atoms:", atoms.get_number_of_atoms()

    print "Heating to %d K using Langevin" % T_goal
    lgv = Langevin(atoms,
                   5 * units.fs,
                   temperature=2 * T_goal * units.kB,
                   friction=0.05)

    while atoms.get_kinetic_energy(
    ) < 1.5 * atoms.get_number_of_atoms() * T_goal * units.kB:
        lgv.run(5)
        T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() *
                                          units.kB)
        print "Temperature is now %.2f K" % (T, )
    print "Desired temperature reached!"

    lgv.set_temperature(T_goal * units.kB)

    for i in range(2):
        lgv.run(20)
        s = atoms.get_stress()
        p = -(s[0] + s[1] + s[2]) / 3.0 / units.GPa
        T = atoms.get_kinetic_energy() / (1.5 * atoms.get_number_of_atoms() *
                                          units.kB)
        print "Pressure is %f GPa, desired pressure is %f GPa (T = %.2f K)" % (
            p, p_goal, T)
예제 #10
0
import sys

if len(sys.argv) == 2:
    arg = sys.argv[1]
else:
    arg = 'Wrong number of arguments.'
if arg == 'EMT':
    filename = 'small_EMT.dat'
elif arg == 'EMT2013':
    filename = 'small_EMT2013.dat'
else:
    print __doc__
    sys.exit(1)

T = 450
atoms = FaceCenteredCubic(size=(10, 10, 10), symbol='Cu', pbc=False)
if arg == 'EMT':
    atoms.set_calculator(EMT())
else:
    atoms.set_calculator(EMT2013(EMT2013_parameters))

print "Setting temperature:", T, "K"
MaxwellBoltzmannDistribution(atoms, 2 * T * units.kB)
Stationary(atoms)

dyn1 = Langevin(atoms, 2 * units.fs, temperature=T * units.kB, friction=0.05)
dyn1.run(200)

dyn = VelocityVerlet(atoms, 3 * units.fs, logfile=filename, loginterval=25)
dyn.run(10000000)  # 10^7 timesteps is 3 ns.
예제 #11
0
    del olde, oldf
else:
    print "WARNING: No self-check database found, creating it."
    cPickle.dump((e, f), open(selfcheckfilename, "w"))
del e, f, atoms

ReportTest.Summary(exit=1)

print "Preparing to run Langevin dynamics."
atoms = Atoms(initial)
atoms.set_calculator(EMT())
dynamics = Langevin(atoms, 5 * units.fs, 400 * units.kB, 0.001)

print "Running Langevin dynamics."
startcpu, startwall = time.clock(), time.time()
dynamics.run(timesteps)

lcpu, lwall = time.clock() - startcpu, time.time() - startwall
lfraction = lcpu / lwall
sys.stderr.write("\n")
print "Langevin dynamics done."
print "Temperature:", atoms.get_temperature()
#del dynamics, atoms

print ""
print ""
print "TIMING RESULTS:"
print "Langevin: CPU time %.2fs  Wall clock time %.2fs (%.0f%%)" % (
    lcpu, lwall, lfraction * 100)
print ""
예제 #12
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()

atoms = Atoms(initial2)
atoms.set_calculator(EMT())
dyn = Langevin(atoms, timestep*femtosecond, temp*kB, 0.001)
예제 #13
0
                 latticeconstant=3.61, size=(29,29,30))
    atoms.set_calculator(EMT())
    MaxwellBoltzmannDistribution(atoms, 2*T * units.kB)
    #dyn = VelocityVerlet(atoms, 5*units.fs)
    dyn = Langevin(atoms, 5*units.fs, T*units.kB, 0.05)
    dyn.run(50)
    print "Done.  Temperature =", temperature(atoms), \
          "K.  Number of atoms: ", len(atoms)
    return atoms

# Make sure that CPU speed is revved up.
dummy = L1_2(directions=[[1,0,0],[0,1,0],[0,0,1]], symbol=('Au', 'Cu'),
             latticeconstant=4.08, size=(10,10,10), debug=0)
dummy.set_calculator(EMT())
dyn = Langevin(dummy, 5*units.fs, 300*units.kB, 0.05)
dyn.run(10)
del dummy

logger.write("\n\nRunning on %s %s\n" % (host, when))
modelname = "Unknown CPU model name"
cpumhz = "Unknown CPU speed"
try:
    lines = open("/proc/cpuinfo").readlines()
    for line in lines:
        if line[:10] == "model name":
            modelname = line
            break
    for line in lines:
        if line[:7] == "cpu MHz":
            cpumhz = line
            break
예제 #14
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()    
예제 #15
0
파일: PTMdemo.py 프로젝트: torhans/StudyGit
# 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)
        
예제 #16
0
파일: Melting.py 프로젝트: auag92/n2dm
# 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)
        print "E_total = %-10.5f  T = %.0f K  (goal: %.0f K, step %d of %d)" %\
              (etotal(atoms), temperature(atoms), t, i, nsteps/100)
        
예제 #17
0
atoms = Trajectory(infile).get_atoms(-1, cpulayout)
nAtoms = atoms.get_number_of_atoms()
info.write("Distribution on CPU cores: {0}\n".format(str(atoms.nCells)))
atoms.set_calculator(EMT())

# Rapidly move the temperature to the desired range by running a
# langevin simulation with increased friction at twice the temperature
# until the desired temperature is crossed.

dyn = Langevin(atoms, timestep * units.fs, temperature * 2 * units.kB,
               20 * lgvfrict)

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)
예제 #18
0
파일: MD_Cluster3.py 프로젝트: auag92/n2dm
# 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)
dyn.run(5000)
view(atoms)

# Now increase the temperature to 2000 K and continue
dyn.set_temperature(2000 * units.kB)
dyn.run(5000)
view(atoms)
예제 #19
0
파일: LongEMTsmall.py 프로젝트: auag92/n2dm
if len(sys.argv) == 2:
    arg = sys.argv[1]
else:
    arg = 'Wrong number of arguments.'
if arg == 'EMT':
    filename = 'small_EMT.dat'
elif arg == 'EMT2013':
    filename = 'small_EMT2013.dat'
else:
    print __doc__
    sys.exit(1)

    
T = 450
atoms = FaceCenteredCubic(size=(10,10,10), symbol='Cu', pbc=False)
if arg == 'EMT':
    atoms.set_calculator(EMT())
else:
    atoms.set_calculator(EMT2013(EMT2013_parameters))
    
print "Setting temperature:", T, "K"
MaxwellBoltzmannDistribution(atoms, 2*T*units.kB)
Stationary(atoms)

dyn1 = Langevin(atoms, 2*units.fs, temperature=T*units.kB, friction=0.05)
dyn1.run(200)

dyn = VelocityVerlet(atoms, 3*units.fs, logfile=filename, loginterval=25)
dyn.run(10000000) # 10^7 timesteps is 3 ns.

예제 #20
0
    dyn = Langevin(atoms, 5 * units.fs, T * units.kB, 0.05)
    dyn.run(50)
    print "Done.  Temperature =", temperature(atoms), \
          "K.  Number of atoms: ", len(atoms)
    return atoms


# Make sure that CPU speed is revved up.
dummy = L1_2(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
             symbol=('Au', 'Cu'),
             latticeconstant=4.08,
             size=(10, 10, 10),
             debug=0)
dummy.set_calculator(EMT())
dyn = Langevin(dummy, 5 * units.fs, 300 * units.kB, 0.05)
dyn.run(10)
del dummy

logger.write("\n\nRunning on %s %s\n" % (host, when))
modelname = "Unknown CPU model name"
cpumhz = "Unknown CPU speed"
try:
    lines = open("/proc/cpuinfo").readlines()
    for line in lines:
        if line[:10] == "model name":
            modelname = line
            break
    for line in lines:
        if line[:7] == "cpu MHz":
            cpumhz = line
            break