def nanoTubeTest(): print "\nLoading configuration with sp2 bonded carbon (nanotube)" a = NetCDFTrajectory("sp2carbon-nanotube.nc").GetListOfAtoms() a.SetCartesianMomenta(zeros((len(a), 3), Float)) potential = BrennerPotential() a.SetCalculator(potential) print "Calculating forces" f = a.GetCartesianForces() print "Loading correct forces" target = load(open("sp2carbon-nanotube-forces.pickle")) print "Comparing forces" for i in range(len(a)): for j in (0, 1, 2): ReportTest("Force[%d,%d]" % (i, j), f[i, j], target[i, j], 1e-3, silent=True) print "Testing energy conservation" #dyn = PredictorCorrector(a, 0.2) #bad result for energy conservation dyn = VelocityVerlet(a, 0.2 * femtosecond) dyn.Run(100) step = 100 etot = a.GetPotentialEnergy() + a.GetKineticEnergy() print "Total energy after %4.d steps: %.8f" % ( step, a.GetPotentialEnergy() + a.GetKineticEnergy()) for i in range(10): dyn.Run(100) step += 100 print "Total energy after %4.d steps: %.8f" % ( step, a.GetPotentialEnergy() + a.GetKineticEnergy()) ReportTest("Approximate energy conservation", a.GetPotentialEnergy() + a.GetKineticEnergy(), etot, 0.3, silent=True)
from Asap.Utilities import BrennerImport # read the coordinates and the types of atoms from a # brenner dot d file: brenner = BrennerImport.BrennerImport() brenner.initCoord("coord.d") a=brenner.GetListOfAtoms() # initialize the Brenner Potential with automatically adapting cube size potential = BrennerPotential(True) # set accuracy potential.SetRll(2.5) #define the cube size (You can only set the cube size, if you created the potential using BrennerPotential(False)) #potential.SetCubeSize(brenner.GetCubeSize()) a.SetCalculator(potential) #step size 0.2 femtoseconds dyn = VelocityVerlet(a, 0.2*femtosecond) step = 0; etot = a.GetPotentialEnergy() + a.GetKineticEnergy() for i in range(6): dyn.Run(100) step+=100 print "Total energy after %4.d steps: %.8f"%(step,a.GetPotentialEnergy()+a.GetKineticEnergy()) #write xmol.d log file potential.WriteXmol(step, 0.2*femtosecond);
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 (free boundaries)." atoms = ListOfAtoms(initial, periodic=(0,0,0)) atoms.SetCalculator(EMT()) dynamics = VelocityVerlet(atoms, 5*femtosecond) print "Running Verlet dynamics." startcpu, startwall = time.clock(), time.time() dynamics.Run(timesteps) vfcpu, vfwall = time.clock() - startcpu, time.time() - startwall vffraction = vfcpu/vfwall sys.stderr.write("\n") print "Verlet dynamics done." del dynamics, atoms print "Preparing to run Verlet dynamics (periodic boundaries)." atoms = ListOfAtoms(initial, periodic=(1,1,1)) atoms.SetCalculator(EMT()) dynamics = VelocityVerlet(atoms, 5*femtosecond)
from cPickle import * from Numeric import * from Asap.testtools import ReportTest PrintVersion(1) data = load(file("testVerlet.pickle")) init_pos = array(data["initial"]) init_pos.shape = (-1, 3) init_box = array(data["box"]) init_box.shape = (3, 3) atoms = ListOfAtoms(positions=init_pos, cell=init_box) atoms.SetAtomicNumbers(47) atoms.SetCalculator(MonteCarloEMT()) dyn = VelocityVerlet(atoms, 2 * femtosecond) for i in range(20): dyn.Run(10) epot = atoms.GetPotentialEnergy() / len(atoms) ekin = atoms.GetKineticEnergy() / len(atoms) print "E_pot = %-12.5f E_kin = %-12.5f E_tot = %-12.5f" % (epot, ekin, epot + ekin) final_pos = array(data["final"]) diff = max(abs(atoms.GetCartesianPositions().flat - final_pos)) print "Maximal deviation of positions:", diff ReportTest("Maximal deviation of positions", diff, 0, 1e-9) diff = max(abs(atoms.GetStresses().flat - array(data["stress"]))) print "Maximal deviation of stresses:", diff