periodic=(0, 0, 1)) basis = atoms.GetUnitCell() center = 0.5 * array([basis[0, 0], basis[1, 1], basis[2, 2]]) + array( [0.1, 0.1, 0.1]) disl = Dislocation(center, atoms.MillerToDirection((1, 1, 0)), atoms.MillerToDirection((1, 1, 0)) / 2.0) #atoms = ListOfAtoms(slab) disl.ApplyTo(atoms) atoms.SetCalculator(EMT(EMTRasmussenParameters())) # Constant temperatur dynamics dyn = Langevin(atoms, 5 * femtosecond, 300 * kB, 0.002) # Run Common Neighbor Analysis on each n_output timestep, using the # positions averaged over the last n_avg timesteps, and writing the # result to the output file. avg = TimeAveragedPositions(atoms, n_avg, n_output) dyn.Attach(avg) cna = RestrictedCNA(avg, verbose=1) avg.Attach(cna) # We output and plot the instantaneous positions. Replace atoms with # avg to output and plot the averaged positions instead. plotlog = open("plot.log", "w") plotter = PrimiPlotter(atoms, verbose=1) plotter.SetOutput(PostScriptFile("cna_plot")) plotter.SetOutput(GifFile("cna_plot"))
dynamics = VelocityVerlet(atoms, 5*femtosecond) print "Running Verlet dynamics." startcpu, startwall = time.clock(), time.time() dynamics.Run(timesteps) vpcpu, vpwall = time.clock() - startcpu, time.time() - startwall vpfraction = vpcpu/vpwall sys.stderr.write("\n") print "Verlet dynamics done." del dynamics, atoms print "Preparing to run Langevin dynamics (periodic boundaries)." atoms = ListOfAtoms(initial, periodic=(1,1,1)) atoms.SetCalculator(EMT()) dynamics = Langevin(atoms, 5*femtosecond, 400*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." del dynamics, atoms print "" print "" print "TIMING RESULTS:" print "Verlet (free): CPU time %.2fs Wall clock time %.2fs (%.0f%%)" % (vfcpu, vfwall, vffraction * 100)
min(rs) >= 0.0, silent=True) ReportTest.BoolTest("Overflow (%d)" % (self.n, ), max(rs) <= 1.0, silent=True) print "Ekin =", atoms.GetKineticEnergy() / len(atoms), min(rs), max(rs) PrintVersion(1) atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], size=(20, 10, 4), element='Cu', periodic=(1, 1, 1)) atoms.SetCalculator(EMT()) dyn = Langevin(atoms, 5 * femtosecond, 3000 * kB, 0.05) dyn.Attach(Check(atoms)) dyn.Run(100) r = matrixmultiply(atoms.GetCartesianPositions(), inverse(atoms.GetUnitCell())).flat print min(r), max(r) atoms2 = ListOfAtoms(atoms) atoms2.SetCartesianPositions(2 * atoms2.GetCartesianPositions() - 4.0) atoms2.SetCalculator(EMT()) r = matrixmultiply(atoms2.GetCartesianPositions(), inverse(atoms2.GetUnitCell())).flat print min(r), max(r) Check(atoms2).Update() ReportTest.Summary()
for j in range(N): for k in range(N): pos.append((i, j, k)) pos.append((i, j + 0.5, k + 0.5)) pos.append((i + 0.5, j, k + 0.5)) pos.append((i + 0.5, j + 0.5, k)) pos = array(pos) * latconst supercell = [N * latconst, N * latconst, N * latconst] # Create the atoms object atoms = ListOfAtoms(positions=pos, cell=supercell) atoms.SetAtomicNumbers(Z) # The dynamics atoms.SetCalculator(EMT()) # Use the EMT potential dyn = Langevin(atoms, 5 * femtosecond, 800 * kB, 0.002) # Output to NetCDF file trajectory = NetCDFTrajectory("output.nc", atoms, interval=2000) dyn.Attach(trajectory) # Do the dynamics for i in range(100): if i == 50: dyn.SetTemperature(2000 * kB) print "Setting temperature to 2000K" dyn.Run(100) print "Ekin = %.5f Epot = %.5f Etot = %.5f" % \ (atoms.GetKineticEnergy()/len(atoms), atoms.GetPotentialEnergy()/len(atoms), (atoms.GetKineticEnergy()+atoms.GetPotentialEnergy())/len(atoms))
# Now the atoms are created from the positions and a sufficiently # large unit cell. The unit cell is uncritical as there are no # periodic boundaries, and the atoms are able to move outside the unit # cell, so in principle it should work with the default # 1-Angstrom-cube unit cell. atoms = ListOfAtoms(positions=positions, cell=[max(positions[:,0]), max(positions[:,1]), max(positions[:,2])]) atoms.SetAtomicNumbers(element) # Now the standard EMT Calculator is attached atoms.SetCalculator(EMT()) # Make an object doing Langevin dynamics at a temperature of 800 K dyn = Langevin(atoms, dt=5*femtosecond, temperature=800*kB, friction=0.005) # Make a trajectory traj = NetCDFTrajectory('MD_Cluster.nc', atoms, interval=500) dyn.Attach(traj) # Write the initial configuration traj.Update() # Print the energies def printenergy(a, step=[0,]): n = len(a) ekin = a.GetKineticEnergy() / n epot = a.GetPotentialEnergy() / 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/kB))