def testEqualOneModelPTI(self): calculator_pti = self.model_pti[0].ase() calculator = self.model[0].ase() atoms = Diamond(symbol="C", pbc=True) atoms_pti = Diamond(symbol="C", pbc=True) atoms.set_calculator(calculator) atoms_pti.set_calculator(calculator_pti) self.assertEqual(atoms.get_potential_energy(), atoms_pti.get_potential_energy())
def test_pbc(self): a = Diamond('Si', latticeconstant=5.432, size=[2,2,2]) sx, sy, sz = a.get_cell().diagonal() a.set_calculator(Tersoff()) e1 = a.get_potential_energy() a.set_pbc([True,True,False]) e2 = a.get_potential_energy() a.set_pbc(True) a.set_cell([sx,sy,2*sz]) e3 = a.get_potential_energy() self.assertEqual(e2, e3) # This should give the unrelaxed surface energy esurf = (e2-e1)/(2*sx*sy) * Jm2 self.assertTrue(abs(esurf-2.309) < 0.001)
def test_calculator(): """ Take ASE structure, PySCF object, and run through ASE calculator interface. This allows other ASE methods to be used with PySCF; here we try to compute an equation of state. """ ase_atom=Diamond(symbol='C', latticeconstant=3.5668) # Set up a cell; everything except atom; the ASE calculator will # set the atom variable cell = pbcgto.Cell() cell.h=ase_atom.cell cell.basis = 'gth-szv' cell.pseudo = 'gth-pade' cell.gs=np.array([8,8,8]) cell.verbose = 0 # Set up the kind of calculation to be done # Additional variables for mf_class are passed through mf_dict mf_class=pbcdft.RKS mf_dict = { 'xc' : 'lda,vwn' } # Once this is setup, ASE is used for everything from this point on ase_atom.set_calculator(pyscf_ase.PySCF(molcell=cell, mf_class=mf_class, mf_dict=mf_dict)) print "ASE energy", ase_atom.get_potential_energy() print "ASE energy (should avoid re-evaluation)", ase_atom.get_potential_energy() # Compute equation of state ase_cell=ase_atom.cell volumes = [] energies = [] for x in np.linspace(0.95, 1.2, 5): ase_atom.set_cell(ase_cell * x, scale_atoms = True) print "[x: %f, E: %f]" % (x, ase_atom.get_potential_energy()) volumes.append(ase_atom.get_volume()) energies.append(ase_atom.get_potential_energy()) eos = EquationOfState(volumes, energies) v0, e0, B = eos.fit() print(B / kJ * 1.0e24, 'GPa') eos.plot('eos.png')
cell.verbose = 0 # Set up the kind of calculation to be done # Additional variables for mf_class are passed through mf_dict # E.g. gamma-point SCF calculation can be set to mf_class = pbcdft.RKS # SCF with k-point sampling can be set to mf_class = lambda cell: pbcdft.KRKS(cell, kpts=cell.make_kpts([2, 2, 2])) mf_dict = {'xc': 'lda,vwn'} # Once this is setup, ASE is used for everything from this point on ase_atom.set_calculator( pyscf_ase.PySCF(molcell=cell, mf_class=mf_class, mf_dict=mf_dict)) print("ASE energy", ase_atom.get_potential_energy()) print("ASE energy (should avoid re-evaluation)", ase_atom.get_potential_energy()) # Compute equation of state ase_cell = ase_atom.cell volumes = [] energies = [] for x in np.linspace(0.95, 1.2, 5): ase_atom.set_cell(ase_cell * x, scale_atoms=True) print "[x: %f, E: %f]" % (x, ase_atom.get_potential_energy()) volumes.append(ase_atom.get_volume()) energies.append(ase_atom.get_potential_energy()) eos = EquationOfState(volumes, energies) v0, e0, B = eos.fit() print(B / kJ * 1.0e24, 'GPa')
if not hasattr(model, 'bulk_reference_216'): # set up the a bulk = Diamond(symbol='Si', latticeconstant=a0) # specify that we will use model.calculator to compute forces, energies and stresses bulk.set_calculator(model.calculator) # use one of the routines from utilities module to relax the initial # unit cell and atomic positions bulk = relax_config(bulk, relax_pos=True, relax_cell=True, tol=tol, traj_file=None) bulk *= (N, N, N) bulk_energy = bulk.get_potential_energy() else: bulk = model.bulk_reference_216 bulk_energy = bulk.get_potential_energy() def dumbbell_interstitial_energy(bulk): Nat = bulk.get_number_of_atoms() int_struct = bulk.copy() int_struct.set_calculator(bulk.get_calculator()) # add an atom to introduce an interstitial int_struct.append(Atom('Si', (-0.5, 0.5, 5.44 / 2.0 + 1.0))) p = int_struct.get_positions() p[149, 0] -= 1.0 p[149, 1] += 1.0
if not hasattr(model, 'bulk_reference'): # set up the a bulk = Diamond(symbol='Si', latticeconstant=a0) # specify that we will use model.calculator to compute forces, energies and stresses bulk.set_calculator(model.calculator) # use one of the routines from utilities module to relax the initial # unit cell and atomic positions bulk = relax_atoms_cell(bulk, tol=fmax, traj_file=None) else: bulk = model.bulk_reference.copy() bulk.set_calculator(model.bulk_reference.calc) print "BOB doing bulk pot en" e0 = bulk.get_potential_energy()/float(len(bulk)) print "got e0 ", e0 def interface_energy(e0, filename): interface = ase.io.read(os.path.join(os.path.dirname(__file__),filename), format='extxyz') # adjust lattice constant interface.set_calculator(model.calculator) # relax atom positions, holding cell fixed interface.positions += 0.01*np.random.random_sample((len(interface),3)) print "pre relax config" ase.io.write(sys.stdout, interface, format='extxyz') print "BOB doing gb relax"
# use one of the routines from utilities module to relax the initial # unit cell and atomic positions bulk = relax_atoms_cell(bulk, tol=fmax, traj_file=None) else: bulk = model.bulk_reference.copy() bulk.set_calculator(model.calculator) a0 = bulk.cell[0, 0] # get lattice constant from relaxed bulk print "got a0 ", a0 bulk = Diamond(symbol="Si", latticeconstant=a0, directions=[[1, -1, 0], [1, 0, -1], [1, 1, 1]]) bulk.set_calculator(model.calculator) # compute surface formation energy as difference of periodic and curface cell ebulk_per_atom = bulk.get_potential_energy() / bulk.get_number_of_atoms() print 'bulk per atom energy', ebulk_per_atom bulk *= (1, 1, 10) ebulk = bulk.get_potential_energy() print 'bulk 1x1x10 cell energy', ebulk # now calculate the relaxed unreconstructed 111 surface energy bulk.positions[:, 2] += 2.0 # select shuffle plane to be cut bulk.wrap() bulk.cell[2, :] += [0.0, 0.0, 10.0] np.random.seed(75) bulkNat = bulk.get_number_of_atoms() #bulk.positions += (np.random.rand((bulkNat*3))*0.1).reshape([bulkNat,3]) #bulk = relax_atoms(bulk, tol=fmax, traj_file="model-"+model.name+"-surface-energy-111-expanded-bulk-relaxed.opt.xyz") eexp = bulk.get_potential_energy() print 'expanded cell energy', eexp e111 = 0.5 * (eexp - ebulk) / np.linalg.norm(
if not hasattr(model, 'bulk_reference'): # set up the a bulk = Diamond(symbol='Si', latticeconstant=5.43) # specify that we will use model.calculator to compute forces, energies and stresses bulk.set_calculator(model.calculator) # use one of the routines from utilities module to relax the initial # unit cell and atomic positions bulk = relax_atoms_cell(bulk, tol=fmax, traj_file=None) else: bulk = model.bulk_reference.copy() bulk.set_calculator(model.calculator) print "calling bulk.get_potential_energy()" e0_per_atom = bulk.get_potential_energy() / len(bulk) print "got e0_per_atom ", e0_per_atom def traj_energy(e0_per_atom, traj): ats = ase.io.read(os.path.dirname(__file__) + "/" + traj, index=':', format='extxyz') orig_Es = [] model_Es = [] for at in ats: # save reference energy orig_Es.append(at.get_potential_energy() / len(at)) # calc new energy at.set_calculator(model.calculator)
cell.pseudo = 'gth-pade' cell.verbose = 0 # Set up the kind of calculation to be done # Additional variables for mf_class are passed through mf_dict # E.g. gamma-point SCF calculation can be set to mf_class = pbcdft.RKS # SCF with k-point sampling can be set to mf_class = lambda cell: pbcdft.KRKS(cell, kpts=cell.make_kpts([2,2,2])) mf_dict = { 'xc' : 'lda,vwn' } # Once this is setup, ASE is used for everything from this point on ase_atom.set_calculator(pyscf_ase.PySCF(molcell=cell, mf_class=mf_class, mf_dict=mf_dict)) print("ASE energy", ase_atom.get_potential_energy()) print("ASE energy (should avoid re-evaluation)", ase_atom.get_potential_energy()) # Compute equation of state ase_cell=ase_atom.cell volumes = [] energies = [] for x in np.linspace(0.95, 1.2, 5): ase_atom.set_cell(ase_cell * x, scale_atoms = True) print "[x: %f, E: %f]" % (x, ase_atom.get_potential_energy()) volumes.append(ase_atom.get_volume()) energies.append(ase_atom.get_potential_energy()) eos = EquationOfState(volumes, energies) v0, e0, B = eos.fit() print(B / kJ * 1.0e24, 'GPa') eos.plot('eos.png')
print liquid_traj_filename try: liquid_traj = quippy.AtomsList(liquid_traj_filename) if __builtin__.do_io: print "read %s from file" % liquid_traj_filename except: if __builtin__.do_io: print "generating %s" % liquid_traj_filename if 'LIQUID_NO_RUN' in os.environ: sys.exit(1) # specify that we will use model.calculator to compute forces, energies and stresses bulk.set_calculator(model.calculator) print "doing bulk" print bulk.get_potential_energy() print "done" try: model.calculator.print_() except: pass #################################################################################################### # initial heating dyn_heat = quippy.Dynamics(bulk, 0.5 * ase.units.fs, trajectory=None, initialtemperature=T_melt, loginterval=10, logfile="model-" + model.name + "-test-liquid-heat.log")
# set up the a bulk = Diamond(symbol='Si', latticeconstant=a0) # specify that we will use model.calculator to compute forces, energies and stresses bulk.set_calculator(model.calculator) # use one of the routines from utilities module to relax the initial # unit cell and atomic positions bulk = relax_atoms_cell(bulk, tol=fmax, traj_file=None) else: bulk = model.bulk_reference.copy() print("Found bulk_reference, lattice constant", bulk.get_cell()[0,0] ) bulk.set_calculator(model.bulk_reference.calc) a0 = bulk.cell[0,0] # get lattice constant from relaxed bulk e0 = bulk.get_potential_energy()/8.0 print "got a0 ", a0 print "got e0 ", e0 def defect_energy(a0, e0, filename): tmp = ase.io.read(os.path.dirname(__file__)+"/"+filename, index=':', format='extxyz') defect = tmp[0] # adjust lattice constant # defect.set_cell([2*a0, 2*a0, 2*a0], scale_atoms=True) defect.set_calculator(model.calculator) # relax atom positions and cell