コード例 #1
0
ファイル: Force1D.py プロジェクト: auag92/n2dm
def main():
    positions = np.zeros((N, 3))
    positions[:,0] = d * np.arange(N)
    if ismaster:
        atoms = Atoms("Cu%i" % (N,), positions=positions, cell=(N*d, w, w),
                      pbc=False)
        atoms.center()
    else:
        atoms = None
    if isparallel:
        atoms = MakeParallelAtoms(atoms, cpulayout)
        id = atoms.get_ids()
    else:
        id = np.arange(N)
    #view(atoms)
    
    atoms.set_calculator(EMT())
    f = atoms.get_forces()
    x = atoms.get_positions()[:,0]
    # time.sleep(world.rank)
    for i in range(len(atoms)):
        print world.rank, x[i], f[i]
        
    # Now running actual tests - these are different on the two processors, but that should
    # not be a problem
    for i in range(len(f)):
        if id[i] > 1 and id[i] < N - 2:
            ftot = (f[i] * f[i]).sum()
            ReportTest("Force on atom %i" % (id[i],), ftot, 0.0, 1e-13)
    world.barrier()        
    ReportTest.Summary()
コード例 #2
0
ファイル: Force1D.py プロジェクト: AKrishnachand/n2dm
def main():
    positions = np.zeros((N, 3))
    positions[:, 0] = d * np.arange(N)
    if ismaster:
        atoms = Atoms("Cu%i" % (N, ),
                      positions=positions,
                      cell=(N * d, w, w),
                      pbc=False)
        atoms.center()
    else:
        atoms = None
    if isparallel:
        atoms = MakeParallelAtoms(atoms, cpulayout)
        id = atoms.get_ids()
    else:
        id = np.arange(N)
    #view(atoms)

    atoms.set_calculator(EMT())
    f = atoms.get_forces()
    x = atoms.get_positions()[:, 0]
    # time.sleep(world.rank)
    for i in range(len(atoms)):
        print world.rank, x[i], f[i]

    # Now running actual tests - these are different on the two processors, but that should
    # not be a problem
    for i in range(len(f)):
        if id[i] > 1 and id[i] < N - 2:
            ftot = (f[i] * f[i]).sum()
            ReportTest("Force on atom %i" % (id[i], ), ftot, 0.0, 1e-13)
    world.barrier()
    ReportTest.Summary()
コード例 #3
0
 def report():
     for i in range(world.size):
         if i == world.rank:
             print "Data on processor", i
             for key in atoms.arrays.keys():
                 print "  ", key, atoms.arrays[key].shape
             r = atoms.get_positions()
             if len(r):
                 print "Limits to the positions:"
                 print ("[%.4f, %.4f]  [%.4f, %.4f]  [%.4f, %.4f]" %
                        (min(r[:,0]), max(r[:,0]), min(r[:,1]), max(r[:,1]),
                         min(r[:,2]), max(r[:,2])))
             if world.size > 1:
                 print "Ghost data on processor", i
                 for key in atoms.ghosts.keys():
                     print "  ", key, atoms.ghosts[key].shape
                 r = atoms.ghosts['positions']
                 if len(r):
                     print "Limits to the ghost positions:"
                     print ("[%.4f, %.4f]  [%.4f, %.4f]  [%.4f, %.4f]" %
                            (min(r[:,0]), max(r[:,0]), min(r[:,1]), max(r[:,1]),
                             min(r[:,2]), max(r[:,2])))
         world.barrier()
コード例 #4
0
    def _make_bundledir(self, filename):
        """Make the main bundle directory.

        Since all MPI tasks might write to it, all tasks must wait for
        the directory to appear.

        For performance reasons, the first frame directory is created immediately.
        """
        assert not os.path.isdir(filename)
        world.barrier()
        if self.master:
            self.log("Making directory "+filename)
            os.mkdir(filename)
            framedir = os.path.join(filename, "F0")
            self.log("Making directory "+ framedir)    
            os.mkdir(framedir)
        else:
            i = 0
            while not os.path.isdir(filename):
                time.sleep(1)
                i += 1
            if i > 10:
                self.log("Waiting %d seconds for %s to appear!"
                         % (i, filename))
コード例 #5
0
ファイル: makeparallel.py プロジェクト: AKrishnachand/n2dm
    natoms = atoms.get_number_of_atoms()
else:
    natoms = len(atoms)

report()

print
print

if world.size > 1:
    atoms.distribute()

report()

print
print
print "Calculating total energy."
#if world.rank == 0:
#    set_verbose(1)

atoms.set_calculator(EMT())
e = atoms.get_potential_energy()

report()

ReportTest("Potential energy", e, -2.40461833565e-3 * natoms / 4, 1e-5)

print "Exiting."
world.barrier()
#ReportTest.Summary()
コード例 #6
0
ファイル: simplempi.py プロジェクト: auag92/n2dm
import asap3
from asap3.mpi import world
from asap3.testtools import ReportTest
import numpy as np

if world.size == 1:
    raise RuntimeError("Cannot test MPI communication on a single processor.")

if world.rank == 0:
    asap3.print_version(1)

world.barrier()

outdata = np.array([world.rank * 2], int)
indata = np.zeros(1, int)

to = world.rank + 1
if to >= world.size:
    to = 0
fr = world.rank - 1
if fr < 0:
    fr += world.size

print "%d: to=%d from=%d" % (world.rank, to, fr)

rq = world.send(outdata, to, block=False)
world.receive(indata, fr)
world.wait(rq)

ReportTest("Data received by %s from %s" % (world.rank, fr), indata[0], 2*fr, 0)
コード例 #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()