# from ase.lattice.hexagonal import HexagonalClosedPacked # atoms = HexagonalClosedPacked(symbol=el1,latticeconstant=(lp,c),size=(5,5,5)) atoms = HCPO(symbol=el1, latticeconstant=(a, b, c), size=(8, 4, 4)) else: raise RuntimeError, 'unknown structure "' + str + '"' atoms.set_calculator(calc) print "el:", el1, "str:", str, "lp:", lp if str == "hcp": print "catoi:", catoi v1 = atoms.get_volume() print "v1:", v1 n1 = atoms.get_number_of_atoms() print "n1:", n1 v1pa = v1 / n1 print "v1pa:", v1pa # initial ene0 = atoms.get_potential_energy() print "ene0:", ene0 print "ene0pa:", ene0 / atoms.get_number_of_atoms() ene0pa = ene0 / atoms.get_number_of_atoms() # vacancy atoms.pop(0) nm1 = n1 - 1 ene1nm = atoms.get_potential_energy() print "ene1nm:", ene1nm
cpulayout = [1,3,1] elif world.size == 4: cpulayout = [1,2,2] print_version(1) if ismaster: 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
elif ncpu == 8: layout = (2,2,2) else: raise ValueError("Cannot run on %i CPUs." % ncpu) if cmd == "M": if world.rank == 0: atoms = FaceCenteredCubic(size=size*layout, symbol='Cu') else: atoms = None atoms = MakeParallelAtoms(atoms, layout) else: atoms = FaceCenteredCubic(size=size*layout, symbol='Cu') atoms.set_calculator(EMT()) natoms = atoms.get_number_of_atoms() print "Number of atoms:", natoms assert natoms == ncpu * 500000 print "Potential energy:", atoms.get_potential_energy() start = time.time() d = 0.1 for i in range(nsteps): atoms.arrays['positions'][50][0] += d d = -d f = atoms.get_forces() wall = time.time() - start if cmd in "SM": master = world.rank == 0
from numpy import * symbol = 'Ar' cells = 15 ar = FaceCenteredCubic(symbol, pbc=[(1, 1, 1)], directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], size=[cells, cells, 1]) for m in listmodels(): if symbol in m: try: print "Try model: ", m calc1 = KIMCalculator(m) ar.set_calculator(calc1) N = ar.get_number_of_atoms() ar.set_pbc([(1, 1, 1)]) bulk_energy = ar.get_potential_energy() / N ar.set_pbc([(1, 1, 0)]) surf_energy = ar.get_potential_energy() / N print "\tsurface = ", surf_energy - bulk_energy #virial = ar.get_stresses() #print "\tvirial = ", virial print except SupportError, e: print "\tskipping ", m, "\n\t", e, " ...\n" continue
else: raise RuntimeError("Cannot run on %i CPUs" % (world.size,)) if ismaster: print_version(1) 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()
else: raise RuntimeError("Cannot run on %i CPUs" % (world.size, )) if ismaster: print_version(1) 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!"
# from ase.lattice.hexagonal import HexagonalClosedPacked # atoms = HexagonalClosedPacked(symbol=el1,latticeconstant=(lp,c),size=(5,5,5)) atoms = HCPO(symbol=el1, latticeconstant=(a, b, c), size=(8, 4, 4)) else: raise RuntimeError, "unknown structure \"" + str + "\"" atoms.set_calculator(calc) print "el:", el1, "str:", str, "lp:", lp if str == "hcp": print "catoi:", catoi v1 = atoms.get_volume() print "v1:", v1 n1 = atoms.get_number_of_atoms() print "n1:", n1 v1pa = v1 / n1 print "v1pa:", v1pa # initial ene0 = atoms.get_potential_energy() print "ene0:", ene0 print "ene0pa:", ene0 / atoms.get_number_of_atoms() ene0pa = ene0 / atoms.get_number_of_atoms() # vacancy atoms.pop(0) nm1 = n1 - 1 ene1nm = atoms.get_potential_energy() print "ene1nm:", ene1nm
uc = atoms.get_cell() x = r[:, 0] - 0.5 * uc[0, 0] y = r[:, 1] - 0.5 * uc[1, 1] z = r[:, 2] zprime = z - 0.01 * (x * x + y * y) n = np.argmax(zprime) #a = atoms[n] #dp = np.sqrt(2 * a.mass * 1000.0) #a.momentum = np.array([0, 0, dp]) t = np.zeros(len(atoms), int) t[n] = 1 atoms.set_tags(t) else: atoms = None atoms = MakeParallelAtoms(atoms, cpulayout) print len(atoms), atoms.get_number_of_atoms() atoms.set_calculator(EMT()) traj = PickleTrajectory("UnBalance.traj", "w", atoms) if fast: atoms.get_forces() traj.write() for i in range(50): print "\n\n\n\n*** STEP %i ***\n\n\n\n\n" % (i, ) r = atoms.get_positions() r += atoms.get_tags().reshape((-1, 1)) * np.array([ [0, 0, 20.0], ]) atoms.set_positions(r) atoms.get_forces() traj.write()
from ase.visualize import view from kimcalculator import * from numpy import * symbol = 'Ar' cells = 15 ar = FaceCenteredCubic(symbol, pbc=[(1,1,1)], directions=[[1,0,0],[0,1,0],[0,0,1]], size=[cells,cells,1]) for m in listmodels(): if symbol in m: try: print "Try model: ", m calc1 = KIMCalculator(m) ar.set_calculator(calc1) N = ar.get_number_of_atoms() ar.set_pbc([(1,1,1)]) bulk_energy = ar.get_potential_energy() / N ar.set_pbc([(1,1,0)]) surf_energy = ar.get_potential_energy() / N print "\tsurface = ", surf_energy - bulk_energy #virial = ar.get_stresses() #print "\tvirial = ", virial print except SupportError, e: print "\tskipping ", m, "\n\t", e, " ...\n" continue
#set_verbose(1) master = world.rank == 0 if master: atoms0 = FaceCenteredCubic(symbol='Pt', size=(15, 15, 30)) else: atoms0 = None atoms0 = MakeParallelAtoms(atoms0, (1, 1, 2)) atoms0.set_calculator(pot()) print >> sys.stderr, "*********** FIRST FORCE CALCULATION ************" print >> sys.stderr, "len(atoms) =", len( atoms0), " no. atoms =", atoms0.get_number_of_atoms() f0 = atoms0.get_forces() perturbation = 0.01 * np.random.standard_normal(atoms0.get_positions().shape) r = atoms0.get_positions() + perturbation atoms0.set_positions(r) print >> sys.stderr, "*********** SECOND FORCE CALCULATION ************" f1 = atoms0.get_forces() print >> sys.stderr, "*********** COPYING ATOMS **************" atoms2 = ParallelAtoms((1, 1, 2), atoms0.comm, atoms0, distribute=False) atoms2.set_calculator(pot()) print >> sys.stderr, "*********** THIRD FORCE CALCULATION ************" f2 = atoms2.get_forces() #maxdev = abs(f2 - f1).max()
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()
uc = atoms.get_cell() x = r[:,0] - 0.5 * uc[0,0] y = r[:,1] - 0.5 * uc[1,1] z = r[:,2] zprime = z - 0.01 * (x * x + y * y) n = np.argmax(zprime) #a = atoms[n] #dp = np.sqrt(2 * a.mass * 1000.0) #a.momentum = np.array([0, 0, dp]) t = np.zeros(len(atoms), int) t[n] = 1 atoms.set_tags(t) else: atoms = None atoms = MakeParallelAtoms(atoms, cpulayout) print len(atoms), atoms.get_number_of_atoms() atoms.set_calculator(EMT()) traj = PickleTrajectory("UnBalance.traj", "w", atoms) if fast: atoms.get_forces() traj.write() for i in range(50): print "\n\n\n\n*** STEP %i ***\n\n\n\n\n" % (i,) r = atoms.get_positions() r += atoms.get_tags().reshape((-1,1)) * np.array([[0, 0, 20.0],]) atoms.set_positions(r) atoms.get_forces() traj.write() else: dyn = VelocityVerlet(atoms, 5*units.fs)