def energy(lamb): ############################################################# # He created from H2 and external potential # ############################################################# d = 0.74 a = 6.0 atoms_external = Atoms('H2', positions=[(0, 0, 0), (0, 0, d)], cell=(a, a, a)) atoms_external.center() pc = PointChargePotential([lamb, -lamb], [[3.0, 3.0, 2.63], [3.0, 3.0, 3.37]]) output = 'output/result' + str(lamb).replace('.', '_') + '.txt' calc = GPAW(xc='PBE', txt=output, external=pc) atoms_external.set_calculator(calc) pot_en = atoms_external.get_potential_energy() density = calc.get_all_electron_density(gridrefinement=4) write('output/density_' + str(lamb).replace('.', '_') + '.cube', atoms_external, data=density) return (pot_en)
atom_conf.set_calculator(calc) pot_en = atom_conf.get_potential_energy() #density = calc.get_all_electron_density(gridrefinement=4) #return( pot_en, density ) return(pot_en) d = 0.74 a = 6.0 rc_list=[-1, -0.1, -1e-2, 1e-2, 1e-1, 1] for rc_item in rc_list: output_He_expot_H2 = 'output/par_pc/'+'rc_'+str(rc_item).replace('.','_')+'.txt' atom_conf_He_expot_H2=Atoms('H2', positions=[(0, 0, 0),(0, 0, d)], cell=(a,a,a) ) atom_conf_He_expot_H2.center() pos=atom_conf_He_expot_H2.get_positions() print('Position H2 = ' + str(pos)) pc_He_expot_H2 = PointChargePotential( [1.0, -1.0], [ pos[0], pos[1] ], rc=rc_item ) calc = GPAW(xc='PBE', txt=output_He_expot_H2, external=pc_He_expot_H2) atom_conf_He_expot_H2.set_calculator(calc) energy_He_expot_H2 = atom_conf_He_expot_H2.get_potential_energy() #energy_He_expot_H2 = energy_calc_with_expot(atom_conf_He_expot_H2, output_He_expot_H2, pc_He_expot_H2) print('Energy He calculated from H2 + external potential = ' + str(energy_He_expot_H2) ) density = calc.get_all_electron_density(gridrefinement=4) write('output/par_pc/'+'dens_rc_'+str(rc_item).replace('.','_')+'.cube', atom_conf_He_expot_H2, data=density)
#print('Energy CO = ' + str(energy_N2) ) d = 0.74 a = 6 gs = 0.04 atom_conf_He_expot_H2 = Atoms('H2', positions=[(0, 0, 0), (0, 0, d)], cell=(a, a, a)) atom_conf_He_expot_H2.center() pos = atom_conf_He_expot_H2.get_positions() print('Position=' + str(pos)) output_He_expot_H2 = '/home/misa/APDFT/prototyping/gpaw/h2_he/output/alch_vs_normal/He_expot_H2.txt' pc_H = PointChargePotential([1.0, -1.0], [pos[0], pos[1]], rc=1e-3, width=20) calc = GPAW(xc='PBE', txt=output_He_expot_H2, external=pc_H, h=gs) atom_conf_He_expot_H2.set_calculator(calc) energy_He_expot_H2 = atom_conf_He_expot_H2.get_potential_energy() #energy_He = energy_calc_with_expot(atom_conf_He, output_He, pc_He) print('Energy He_expot_H2 = ' + str(energy_He_expot_H2)) #density = calc.get_all_electron_density(gridrefinement=4) #write('output/density_He_expot_H2.cube', atom_conf_He_expot_H2, data=density) atom_conf_He = Atoms('He', positions=[(0, 0, d)], cell=(a, a, a)) atom_conf_He.center() output_He = 'output/alch_vs_normal/He.txt'
R_pv[0, v] += eps ep = f(rc) R_pv[0, v] -= 2 * eps em = f(rc) R_pv[0, v] += eps F = -(ep - em) / (2 * eps) * h**3 equal(F, -F_pv[0, v], 1e-9) # High-level test: lih = Atoms('LiH') lih[1].y += 1.64 lih.center(vacuum=3) pos = lih.cell.sum(axis=0) print(pos) pc = PointChargePotential([-1.0], [pos]) lih.calc = GPAW(external=pc, txt='lih-pc.txt') f1 = lih.get_forces() fpc1 = pc.get_forces(lih.calc) print(fpc1) print(fpc1 + f1.sum(0)) f2 = [[numeric_force(lih, a, v) for v in range(3)] for a in range(2)] print(f1) print(f1 - f2) assert abs(f1 - f2).max() < 2e-3 x = 0.0001 for v in range(3): pos[v] += x pc.set_positions([pos])
def embed(self, q_p, rc=0.2, rc2=np.inf, width=1.0): """Embed QM region in point-charges.""" pc = PointChargePotential(q_p, rc=rc, rc2=rc2, width=width) self.set(external=pc) return pc
""" import numpy as np from ase import Atoms from ase.units import Bohr, Hartree from gpaw import GPAW from gpaw.external import PointChargePotential a = 4.5 H = Atoms('H', [(a / 2, a / 2, a / 2)], pbc=0, cell=(a, a, a)) calc = GPAW(nbands=1, h=0.2, charge=1, txt='H.txt') H.set_calculator(calc) e0 = H.get_potential_energy() assert abs(e0 + calc.get_reference_energy()) < 0.014 # Test the point charge potential with a smooth cutoff: pcp = PointChargePotential([-1], rc2=5.5, width=1.5) calc.set(external=pcp) E = [] F = [] D = np.linspace(2, 6, 30) for d in D: pcp.set_positions([[a / 2, a / 2, a / 2 + d]]) e = H.get_potential_energy() - e0 f1 = H.get_forces() f2 = pcp.get_forces(calc) eref = -1 / d * Bohr * Hartree print(d, e, eref, abs(f1 + f2).max()) if d < 4.0: error = e + 1 / d * Bohr * Hartree assert abs(error) < 0.01, error assert abs(f1 + f2).max() < 0.01