Exemplo n.º 1
0
def maketraj(atoms, t, nstep):
    e = [atoms.get_potential_energy()]
    dyn = VelocityVerlet(atoms, 5*units.fs)
    for i in range(nstep):
        dyn.run(10)
        e.append(atoms.get_potential_energy())
        if t is not None:
            t.write()
    return e
Exemplo n.º 2
0
def maketraj(atoms, t, nstep):
    e = [atoms.get_potential_energy()]
    dyn = VelocityVerlet(atoms, 5 * units.fs)
    for i in range(nstep):
        dyn.run(10)
        e.append(atoms.get_potential_energy())
        if t is not None:
            t.write()
    return e
Exemplo n.º 3
0
def twoAtomForce():
  print "\nRunning LJ twoAtomForce"
  elements = [29]
  epsilon  = [0.15]
  sigma    = [2.7]

  atoms=Atoms(positions=[(0.0, 0.0, 0.0),(0.0, 0.0, 2.0)],
              symbols="Cu2")

  atoms.set_calculator(LennardJones(elements, epsilon, sigma, -1.0, False))


  result = atoms.get_potential_energy()

  r = atoms.get_positions()
  r.flat[:] += 0.06 * np.sin(np.arange(3*len(atoms)))
  atoms.set_positions(r)
  resA, resB = atoms.get_forces() ;
  storedForces = [ -1.15732425,   13.10743025, -258.04517252 ]

  for a in range(1,3):
    ReportTest(("  Simple force test dimension %d" % a), resA[a],
               storedForces[a], 1e-8, silent=Silent)


  print "  Running Verlet dynamics (%s)" % ("Cu",)
  dyn = VelocityVerlet(atoms, 2*units.fs)
  dyn.run(100)

  etot1 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
  dyn.run(1000)
  etot2 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
  ReportTest(("  Energy conservation (%s)" % ("Cu",)), etot1, etot2, 1.0, silent=Silent)

  epot = atoms.get_potential_energies()
  stress = atoms.get_stresses()

  e = []
  s = []
  j = 0
  for i in range(0, len(atoms), 100):
      e.append(epot[i])
      s.append(stress[i,j])
      j = (j + 1) % 6
  print "  e"+"Cu"+" =", repr(e)
  print "  s"+"Cu"+" =", repr(s)
Exemplo n.º 4
0
def dotest(atoms, nsteps, ampl, name):
    print "Potential energy", atoms.get_potential_energy() / len(atoms)
    r = atoms.get_positions()
    r.flat[:] += ampl * sin(arange(3*len(atoms)))
    atoms.set_positions(r)
    print "Potential energy", atoms.get_potential_energy() / len(atoms)

    print "Running Verlet dynamics (%s)" % (name,)
    dyn = VelocityVerlet(atoms, 2*femtosecond)
    etot1 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    dyn.run(nsteps)
    etot2 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    ReportTest(("Energy conservation (%s)" % (name,)), etot1, etot2, 1.0)
    print etot1, etot2

    epot = atoms.get_potential_energies()
    stress = atoms.get_stresses()
    if firsttime:
        print "Reporting energies and stresses"
        e = []
        s = []
        j = 0
        for i in range(0, len(atoms), 100):
            e.append(epot[i])
            s.append(stress[i,j])
            j = (j + 1) % 6
        print >> out, "e"+name+" =", repr(e)
        print >> out, "s"+name+" =", repr(s)
    else:
        print "Testing energies and stresses"
        j = 0
        eres=getattr(potResults, "e"+name)
        sres=getattr(potResults, "s"+name)
        for i in range(len(atoms)/100):
            ReportTest(("%s energy %d" % (name, i*100)),
                       epot[i*100], eres[i], 1e-8, silent=True)
            ReportTest(("%s stress %d" % (name, i*100)),
                       stress[i*100, j], sres[i], 1e-8, silent=True)
            j = (j + 1) % 6
Exemplo n.º 5
0
def twoAtomForce():
    print "\nRunning LJ twoAtomForce"
    elements = [29]
    epsilon = [0.15]
    sigma = [2.7]

    atoms = Atoms(positions=[(0.0, 0.0, 0.0), (0.0, 0.0, 2.0)], symbols="Cu2")

    atoms.set_calculator(LennardJones(elements, epsilon, sigma, -1.0, False))

    result = atoms.get_potential_energy()

    r = atoms.get_positions()
    r.flat[:] += 0.06 * np.sin(np.arange(3 * len(atoms)))
    atoms.set_positions(r)
    resA, resB = atoms.get_forces()
    storedForces = [-1.15732425, 13.10743025, -258.04517252]

    for a in range(1, 3):
        ReportTest(("  Simple force test dimension %d" % a),
                   resA[a],
                   storedForces[a],
                   1e-8,
                   silent=Silent)

    print "  Running Verlet dynamics (%s)" % ("Cu", )
    dyn = VelocityVerlet(atoms, 2 * units.fs)
    dyn.run(100)

    etot1 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    dyn.run(1000)
    etot2 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    ReportTest(("  Energy conservation (%s)" % ("Cu", )),
               etot1,
               etot2,
               1.0,
               silent=Silent)

    epot = atoms.get_potential_energies()
    stress = atoms.get_stresses()

    e = []
    s = []
    j = 0
    for i in range(0, len(atoms), 100):
        e.append(epot[i])
        s.append(stress[i, j])
        j = (j + 1) % 6
    print "  e" + "Cu" + " =", repr(e)
    print "  s" + "Cu" + " =", repr(s)
Exemplo n.º 6
0
def Compare(name, atoms, observer, ref, interval=4):
    dyn = VelocityVerlet(atoms, 5*units.fs)
    dyn.attach(observer, interval=interval)
    r = []
    for i in range(50):
        dyn.run(5)
        epot = atoms.get_potential_energy() / len(atoms)
        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)
Exemplo n.º 7
0
    z = init.get_positions()[:,2]
    fixedatoms = np.less(z, 0.501*z.max())
    print len(init), sum(fixedatoms)
    MaxwellBoltzmannDistribution(init, 6000*units.kB)
    init.set_tags(fixedatoms)
else:
    init = None

print
print "Running simulation with Filter"
atoms1 = MakeParallelAtoms(init, cpulayout)
atoms1.arrays['r_init'] = atoms1.get_positions()
atoms1.set_calculator(EMT())
atoms1a = Filter(atoms1, mask=np.logical_not(atoms1.get_tags()))

dyn = VelocityVerlet(atoms1a, 3*units.fs)
dyn.run(100)

print
print "Running simulation with Asap's FixAtoms"
atoms2 = MakeParallelAtoms(init, cpulayout)
atoms2.arrays['r_init'] = atoms2.get_positions()
atoms2.set_calculator(EMT())
atoms2.set_constraint(FixAtoms(mask=atoms2.get_tags()))

dyn = VelocityVerlet(atoms2, 3*units.fs)
dyn.run(100)

print
print "Running Langevin simulation with Asap's FixAtoms"
atoms4 = MakeParallelAtoms(init, cpulayout)
Exemplo n.º 8
0
from numpy import *
from asap3 import Atoms, EMT, units
from ase.visualize.primiplotter import *
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.verlet import VelocityVerlet

# Create the atoms
atoms = FaceCenteredCubic(size=(3,3,3), symbol="Cu", pbc=False)

# Give the first atom a non-zero momentum
atoms[0].set_momentum(array([0, -11.3, 0]))

# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Now do molecular dynamics, printing kinetic, potential and total
# energy every ten timesteps.
dyn = VelocityVerlet(atoms, 5.0*units.fs)

# Set up a plotter
plotter = PrimiPlotter(atoms)
plotter.set_output(X11Window())

# Attach it to the dynamics, so it is informed every 25'th time a
# timestep is made.
dyn.attach(plotter.plot, interval=25)

# Now do 1000 timesteps.
dyn.run(1000)
print "The output is in the NetCDF file TrajectoryMD-output.traj"
Exemplo n.º 9
0
        if line[:7] == "cpu MHz":
            cpumhz = line
            break
except:
    print "Cannot get CPU info from /proc/cpuinfo"

logger.write(cpumhz)
logger.write(modelname)
logger.write(asapversion + "\n")
logger.write("Number of threads: " + str(nthreads) + "\n")

atoms300 = MakeCu()

atoms = Atoms(atoms300)
atoms.set_calculator(EMT())
dyn = VelocityVerlet(atoms, 5 * units.fs)
Timing("Ver300", dyn.run, 50, len(atoms))

atoms = MakeCu(1000)
dyn = VelocityVerlet(atoms, 5 * units.fs)
Timing("Ver1000", dyn.run, 50, len(atoms))

atoms = Atoms(atoms300)
atoms.set_calculator(EMT())
dyn = Langevin(atoms, 5 * units.fs, 300 * units.kB, 0.001)
Timing("Langevin", dyn.run, 50, len(atoms))

atoms = Atoms(atoms300)
atoms.set_calculator(EMT())
dyn = NPT(atoms, 5 * units.fs, 300 * units.kB, 0, 25 * units.fs,
          (75 * units.fs)**2 * 140 * units.GPa)
Exemplo n.º 10
0
    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)

print "Testing RestrictedCNA"
atoms = Atoms(iniatoms)
atoms.set_calculator(EMT())
cna = RestrictedCNA(atoms)
Compare("RestrictedCNA", atoms, cna.analyze, ref)
Exemplo n.º 11
0
from asap3 import Atoms, EMT, units
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.verlet import VelocityVerlet

# Create the atoms
atoms = FaceCenteredCubic(size=(3,3,3), symbol="Cu", pbc=False)

# Give the first atom a non-zero momentum
atoms[0].set_momentum(array([0, -11.3, 0]))
print "Kinetic energies of all atoms:"
p = atoms.get_momenta()
kinenergies = 0.5 * (p * p).sum(1) / atoms.get_masses()
print kinenergies

# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Now do molecular dynamics, printing kinetic, potential and total
# energy every ten timesteps.
dyn = VelocityVerlet(atoms, 5.0*units.fs)
print ""
print "Energy per atom:"
print "  %15s %15s %15s" % ("Pot. energy", "Kin. energy", "Total energy")

for i in range(25):
    dyn.run(10)
    epot = atoms.get_potential_energy()/len(atoms)
    ekin = atoms.get_kinetic_energy()/len(atoms)
    print "%15.5f %15.5f %15.5f" % (epot, ekin, epot+ekin)

Exemplo n.º 12
0
    atoms = FaceCenteredCubic(size=(2,10,10), symbol="Cu", pbc=False,
                              latticeconstant = 3.5)
else:
    atoms = None

if isparallel:
    atoms = MakeParallelAtoms(atoms, cpulayout)
atoms.set_calculator(asap3.EMT())
natoms = atoms.get_number_of_atoms()
    
ReportTest("Number of atoms", natoms, 800, 0)

# Make a small perturbation of the momenta
atoms.set_momenta(1e-6 * random.random([len(atoms), 3]))
print "Initializing ..."
predyn = VelocityVerlet(atoms, 0.5)
try:
    predyn.run(2500)
except:
    print atoms.arrays['positions']
    print atoms.arrays['momenta']
    print atoms.arrays['momenta'].shape
    print atoms.get_masses()
    print atoms.get_masses().shape
    
    raise

initr = atoms.get_positions()
initp = atoms.get_momenta()

Exemplo n.º 13
0
for nthreads in threads:
    try:
        AsapThreads(nthreads)
    except ValueError:
        break
    maxthread = nthreads
    for natoms in sizes:
        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)
Exemplo n.º 14
0
from numpy import *
from asap3 import Atoms, EMT, units
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.verlet import VelocityVerlet

# Create the atoms
atoms = FaceCenteredCubic(size=(3, 3, 3), symbol="Cu", pbc=False)

# Give the first atom a non-zero momentum
atoms[0].set_momentum(array([0, -11.3, 0]))
print "Kinetic energies of all atoms:"
p = atoms.get_momenta()
kinenergies = 0.5 * (p * p).sum(1) / atoms.get_masses()
print kinenergies

# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Now do molecular dynamics, printing kinetic, potential and total
# energy every ten timesteps.
dyn = VelocityVerlet(atoms, 5.0 * units.fs)
print ""
print "Energy per atom:"
print "  %15s %15s %15s" % ("Pot. energy", "Kin. energy", "Total energy")

for i in range(25):
    dyn.run(10)
    epot = atoms.get_potential_energy() / len(atoms)
    ekin = atoms.get_kinetic_energy() / len(atoms)
    print "%15.5f %15.5f %15.5f" % (epot, ekin, epot + ekin)
Exemplo n.º 15
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.
Exemplo n.º 16
0
    df = max(fabs(f.flat[:] - oldf.flat[:]))
    print "Maximal deviation:  Energy", de, "  Force", df
    ReportTest("Max force error", df, 0.0, 1e-11)
    ReportTest("Max energy error", de, 0.0, 1e-11)
    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 Verlet dynamics."
atoms = Atoms(initial)
atoms.set_calculator(EMT())
dynamics = VelocityVerlet(atoms, 5*units.fs)

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

vcpu, vwall = time.clock() - startcpu, time.time() - startwall
vfraction = vcpu/vwall
sys.stderr.write("\n")
print "Verlet dynamics done."
del dynamics, atoms

print "Preparing to run Langevin dynamics."
atoms = Atoms(initial)
atoms.set_calculator(EMT())
dynamics = Langevin(atoms, 5*units.fs, 400*units.kB, 0.001)
Exemplo n.º 17
0
def dynamicsTest(size, before, steps, v0, rCut, nonSense):
    print "\n\nStarting LJ dynamicsTest with "
    print "  cube of size                  %d" % size
    print "  time before measurement start %d*1*femtoseconds" % before
    print "  measuring time                %d*femtoseconds" % steps
    print "  add v0                        %d" % (v0 == 1)
    print "  rCut                          %d" % rCut
    print "  3 kinds of atoms              %s" % (nonSense == 1)

    start = time()

    nsteps = steps
    #Warning: numbers and constants are not supposed to make sense or to be correct!!
    #         they're only here to assure that the program handles the input correctly
    if nonSense:
        elements = [29, 79, 39]
        epsilon = [0.15, 0.00, 0.00, 0.10, 0.25, 0.00, 0.31, 0.60, 0.15]
        sigma = [2.7, 0.00, 0.00, 1.90, 2.7, 0.00, 2.20, 1.50, 2.7]
        atoms = L1_2([[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                     size=(size, size, size),
                     element=("Cu", "Au"),
                     periodic=(1, 0, 1),
                     debug=0,
                     latticeconstant=3.95)
        atoms.set_calculator(LennardJones(elements, epsilon, sigma, rCut, v0))
    else:
        elements = [29]
        epsilon = [0.15]
        sigma = [2.7]
        atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
                                  size=(size, size, size),
                                  symbol="Cu",
                                  pbc=(1, 0, 1),
                                  debug=0,
                                  latticeconstant=1.09 * sigma[0] * 1.41)
        atoms.set_calculator(LennardJones(elements, epsilon, sigma, rCut, v0))

    r = atoms.get_positions()
    r.flat[:] += 0.06 * np.sin(np.arange(3 * len(atoms)))
    atoms.set_positions(r)

    print "  Running Verlet dynamics (%s)" % ("Cu", )
    dyn = VelocityVerlet(atoms, 1 * units.fs)
    dyn.run(before)

    etot1 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    for i in range(nsteps / 10):
        dyn.run(10)
        #print atoms.get_potential_energy()/len(atoms), atoms.get_kinetic_energy()/len(atoms), (atoms.get_potential_energy() + atoms.get_kinetic_energy())/len(atoms)
    etot2 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    ReportTest(("  Energy conservation (%s)" % ("Cu", )),
               etot1,
               etot2,
               2,
               silent=Silent)
    print "Before: ", etot1, " now: ", etot2, " diff= ", (etot1 - etot2)
    epot = atoms.get_potential_energies()
    stress = atoms.get_stresses()
    print "  Reporting energies and stresses"

    e = []
    s = []
    j = 0
    for i in range(0, len(atoms), 100):
        e.append(epot[i])
        s.append(stress[i, j])
        j = (j + 1) % 6
    print "  e" + "Cu" + " =", repr(e)
    print "  s" + "Cu" + " =", repr(s)
    end = time()
    print "  ++++ Test runtime of the LJ dynamicsTest was %d seconds ++++\n\n" % (
        end - start)
    if 1:
        sumstress = np.zeros(6, np.float)
        for s in stress:
            sumstress += s
        totalstress = atoms.get_stress()
        for i in range(6):
            ReportTest("Sum of stresses (%d)" % (i, ),
                       sumstress[i] / len(atoms), totalstress[i],
                       abs(0.01 * totalstress[i]))
Exemplo n.º 18
0
from ase.visualize.primiplotter import *
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.verlet import VelocityVerlet

# Create the atoms
atoms = FaceCenteredCubic(size=(3,3,3), symbol="Cu", pbc=False)

# Give the first atom a non-zero momentum
atoms[0].momentum = array([0, -11.3, 0])

# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Now do molecular dynamics, printing kinetic, potential and total
# energy every ten timesteps.
dyn = VelocityVerlet(atoms, 5.0*units.fs)

# Set up a plotter
plotter = PrimiPlotter(atoms)
plotter.set_output(X11Window())   # Plot in X11 window on the user's screen
plotter.set_output(JpegFile("a"))  # Save as GIF files
# plotter.set_output(PostScriptFile("a"))  # Save as PS files

# Attach it to the dynamics, so it is informed every 25'th time a
# timestep is made.
dyn.attach(plotter.plot, interval=25)

# Now do 1000 timesteps.
dyn.run(1000)
print "The output is in the NetCDF file TrajectoryMD-output.traj"
Exemplo n.º 19
0
from numpy import *
from asap3 import Atoms, EMT, units, PickleTrajectory
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.verlet import VelocityVerlet

# Create the atoms
atoms = FaceCenteredCubic(size=(3,3,3), symbol="Cu", pbc=False)

# Give the first atom a non-zero momentum
atoms[0].set_momentum(array([0, -11.3, 0]))

# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Now do molecular dynamics, printing kinetic, potential and total
# energy every ten timesteps.
dyn = VelocityVerlet(atoms, 5.0*units.fs)


# Make a trajectory writing output
trajectory = PickleTrajectory("TrajectoryMD-output.traj", "w", atoms)

# Attach it to the dynamics, so it is informed every fifth time a
# timestep is made.
dyn.attach(trajectory, interval=5)

# Now do 1000 timesteps.
dyn.run(1000)
print "The output is in the NetCDF file TrajectoryMD-output.traj"
Exemplo n.º 20
0
frict = 0.001
temp = 100 # K
repeats = 5

# Set up atoms in a regular simple-cubic lattice.
initial = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]],
                            size = (1,5,5), symbol="Cu", latticeconstant=3.5,
                            pbc=False, debug=0)
initial.set_calculator(EMT())
    
ReportTest("Number of atoms", len(initial), 100, 0)

# Make a small perturbation of the momenta
initial.set_momenta(1e-6 * np.random.normal(size=[len(initial), 3]))
print "Initializing (1) ..."
predyn = VelocityVerlet(initial, 0.5)
predyn.run(2500)

initial2 = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]],
                             size = (4,4,4), symbol="Cu", debug=0)
initial2.set_calculator(EMT())
# Make a small perturbation of the momenta
initial2.set_momenta(1e-6 * np.random.normal(size=[len(initial2), 3]))
print "Initializing (2) ..."
predyn = VelocityVerlet(initial2, 0.5)
predyn.run(2500)


class TemperatureMonitor:
    def __init__(self, report):
        self.report = report
Exemplo n.º 21
0
from asap3.testtools import ReportTest
import numpy as np

init = FaceCenteredCubic(size=(10,10,10), symbol='Cu', pbc=False)
z = init.get_positions()[:,2]
fixedatoms = np.less(z, 0.501*z.max())
print len(init), sum(fixedatoms)
MaxwellBoltzmannDistribution(init, 2000*units.kB)

print
print "Running simulation with Filter"
atoms1 = Atoms(init)
atoms1.set_calculator(EMT())
atoms1a = Filter(atoms1, mask=np.logical_not(fixedatoms))

dyn = VelocityVerlet(atoms1a, 0.5*units.fs)
dyn.run(50)
r1 = atoms1.get_positions()

print
print "Running simulation with Asap's FixAtoms"
atoms2 = Atoms(init)
atoms2.set_calculator(EMT())
atoms2.set_constraint(FixAtoms(mask=fixedatoms))

dyn = VelocityVerlet(atoms2, 0.5*units.fs)
dyn.run(50)
r2 = atoms2.get_positions()

print
print "Running simulation with ASE's FixAtoms"
Exemplo n.º 22
0
"""

from numpy import *
from asap3 import Atoms, EMT, units, Trajectory
from ase.lattice.cubic import FaceCenteredCubic
from asap3.md.verlet import VelocityVerlet

# Create the atoms
atoms = FaceCenteredCubic(size=(3, 3, 3), symbol="Cu", pbc=False)

# Give the first atom a non-zero momentum
atoms[0].momentum = array([0, -11.3, 0])

# Associate the EMT potential with the atoms
atoms.set_calculator(EMT())

# Now do molecular dynamics, printing kinetic, potential and total
# energy every ten timesteps.
dyn = VelocityVerlet(atoms, 5.0 * units.fs)

# Make a trajectory writing output
trajectory = Trajectory("TrajectoryMD-output.traj", "w", atoms)

# Attach it to the dynamics, so it is informed every fifth time a
# timestep is made.
dyn.attach(trajectory, interval=5)

# Now do 1000 timesteps.
dyn.run(1000)
print "The output is in the ASE Trajectory file TrajectoryMD-output.traj"
Exemplo n.º 23
0
    ReportTest("Max force error", df, 0.0, 1e-11)
    ReportTest("Max energy error", de, 0.0, 1e-11)
    print e[:20]
    print olde[:20]
    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 Verlet dynamics."
atoms = Atoms(initial)
atoms.set_calculator(EMT())
dynamics = VelocityVerlet(atoms, 5*units.fs)

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

vcpu, vwall = time.clock() - startcpu, time.time() - startwall
vfraction = vcpu/vwall
sys.stderr.write("\n")
print "Verlet dynamics done."
del dynamics, atoms

print "Preparing to run Langevin dynamics."
atoms = Atoms(initial)
atoms.set_calculator(EMT())
dynamics = Langevin(atoms, 5*units.fs, 400*units.kB, 0.001)
    else:
        atoms = None
        out = file("/dev/null", "w")

    if isparallel:
        atoms = MakeParallelAtoms(atoms, cpulayout)
        nTotalAtoms = atoms.get_number_of_atoms()
    else:
        nTotalAtoms = len(atoms)

    #report()

    print "Setting potential"
    atoms.set_calculator(OpenKIMcalculator(openkimmodel, allowed='MI_OPBC_F'))

    dyn = VelocityVerlet(atoms, 2 * femtosecond)
    # if isparallel:
    #     traj = ParallelNetCDFTrajectory("ptraj.nc", atoms, interval=20)
    # else:
    #     traj = NetCDFTrajectory("ptraj.nc", atoms, interval=20)
    # dyn.Attach(traj)
    # traj.Update()

    print "Number of atoms:", nTotalAtoms

    epot = atoms.get_potential_energy() / nTotalAtoms
    ekin = atoms.get_kinetic_energy() / nTotalAtoms
    etotallist = [epot+ekin]
    ekinlist = [ekin]

    #report()
Exemplo n.º 25
0
from asap3.testtools import ReportTest
import numpy as np

init = FaceCenteredCubic(size=(10, 10, 10), symbol='Cu', pbc=False)
z = init.get_positions()[:, 2]
fixedatoms = np.less(z, 0.501 * z.max())
print len(init), sum(fixedatoms)
MaxwellBoltzmannDistribution(init, 2000 * units.kB)

print
print "Running simulation with Filter"
atoms1 = Atoms(init)
atoms1.set_calculator(EMT())
atoms1a = Filter(atoms1, mask=np.logical_not(fixedatoms))

dyn = VelocityVerlet(atoms1a, 0.5 * units.fs)
dyn.run(50)
r1 = atoms1.get_positions()

print
print "Running simulation with Asap's FixAtoms"
atoms2 = Atoms(init)
atoms2.set_calculator(EMT())
atoms2.set_constraint(FixAtoms(mask=fixedatoms))

dyn = VelocityVerlet(atoms2, 0.5 * units.fs)
dyn.run(50)
r2 = atoms2.get_positions()

print
print "Running simulation with ASE's FixAtoms"
Exemplo n.º 26
0
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.

Exemplo n.º 27
0
def dynamicsTest(size, before, steps, v0, rCut, nonSense):
    print "\n\nStarting LJ dynamicsTest with "
    print "  cube of size                  %d"%size
    print "  time before measurement start %d*1*femtoseconds"%before
    print "  measuring time                %d*femtoseconds"%steps
    print "  add v0                        %d"%(v0==1)
    print "  rCut                          %d"%rCut
    print "  3 kinds of atoms              %s"%(nonSense==1)

    start = time();

    nsteps = steps;
    #Warning: numbers and constants are not supposed to make sense or to be correct!!
    #         they're only here to assure that the program handles the input correctly
    if nonSense:
      elements = [29, 79, 39]
      epsilon  = [0.15, 0.00, 0.00,
                  0.10, 0.25, 0.00,
                  0.31, 0.60, 0.15]
      sigma    = [2.7 , 0.00, 0.00,
                  1.90, 2.7 , 0.00,
                  2.20, 1.50, 2.7 ]
      atoms = L1_2([[1,0,0],[0,1,0],[0,0,1]], size=(size,size,size),
                              element=("Cu", "Au"), periodic=(1,0,1), debug=0,
                              latticeconstant=3.95)
      atoms.set_calculator(LennardJones(elements, epsilon, sigma, rCut, v0))
    else:
      elements = [29]
      epsilon  = [0.15]
      sigma    = [2.7]
      atoms = FaceCenteredCubic(directions=[[1,0,0],[0,1,0],[0,0,1]],
                                size=(size,size,size),
                                symbol="Cu", pbc=(1,0,1), debug=0,
                                latticeconstant=1.09*sigma[0]*1.41)
      atoms.set_calculator(LennardJones(elements, epsilon, sigma, rCut, v0))

    r = atoms.get_positions()
    r.flat[:] += 0.06 * np.sin(np.arange(3*len(atoms)))
    atoms.set_positions(r)

    print "  Running Verlet dynamics (%s)" % ("Cu",)
    dyn = VelocityVerlet(atoms, 1*units.fs)
    dyn.run(before)
    
    etot1 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    for i in range(nsteps/10):
        dyn.run(10)
        #print atoms.get_potential_energy()/len(atoms), atoms.get_kinetic_energy()/len(atoms), (atoms.get_potential_energy() + atoms.get_kinetic_energy())/len(atoms)
    etot2 = (atoms.get_potential_energy() + atoms.get_kinetic_energy())
    ReportTest(("  Energy conservation (%s)" % ("Cu",)), etot1, etot2, 2, silent=Silent)
    print "Before: ", etot1, " now: ", etot2, " diff= ", (etot1-etot2)
    epot = atoms.get_potential_energies()
    stress = atoms.get_stresses()
    print "  Reporting energies and stresses"
    
    e = []
    s = []
    j = 0
    for i in range(0, len(atoms), 100):
        e.append(epot[i])
        s.append(stress[i,j])
        j = (j + 1) % 6
    print "  e"+"Cu"+" =", repr(e)
    print "  s"+"Cu"+" =", repr(s)
    end = time();
    print "  ++++ Test runtime of the LJ dynamicsTest was %d seconds ++++\n\n" %(end-start)
    if 1:
        sumstress = np.zeros(6, np.float)
        for s in stress:
            sumstress += s
        totalstress = atoms.get_stress()
        for i in range(6):
            ReportTest("Sum of stresses (%d)" % (i,), sumstress[i]/len(atoms),
                       totalstress[i], abs(0.01*totalstress[i]))