def read_results(self): self.results = {} assert os.path.exists(self.outfile), "%s missing" % self.outfile st = io.read_pw_scf(self.outfile) self.results['energy'] = st.etot self.results['forces'] = st.forces self.results['stress'] = stress_pwtools2ase(st.stress)
def read_results(self): self.results = {} assert os.path.exists(self.outfile), "%s missing" %self.outfile st = io.read_pw_scf(self.outfile) self.results['energy'] = st.etot self.results['forces'] = st.forces self.results['stress'] = stress_pwtools2ase(st.stress)
def test_scf_cell(): filename = 'files/pw.vc_relax_coords_fixed.out' common.system('gunzip %s.gz' %filename) pp = parse.PwSCFOutputFile(filename, use_alat=False) cell_2d_red = pp.get_cell() assert np.allclose(cell_2d_red, cell_2d_red_ref, atol=1e-15, rtol=0) pp = parse.PwSCFOutputFile(filename, use_alat=True) assert np.allclose(pp.get_cell(), cell_2d_red*pp.get_alat(), atol=1e-15, rtol=0) st = io.read_pw_scf(filename) tr = io.read_pw_md(filename) # tr is from a vc-relax w/ fixed fractional coords, check that assert np.allclose(np.zeros((tr.nstep,tr.natoms,3)), tr.coords_frac - tr.coords_frac[0,...].copy(), rtol=0, atol=1e-15) # check if scf parser gets the same coords_frac as the trajectory parser # Note: this and the next test have the same max error of # 4.33868466709e-08 (b/c of limited accuracy in printed numbers in # pwscf output) assert np.allclose(st.coords_frac,tr.coords_frac[0,...], atol=1e-7, rtol=0) # same test, plus test of concatenate() works trcat = crys.concatenate((st,tr)) assert np.allclose(np.zeros((trcat.nstep,trcat.natoms,3)), trcat.coords_frac - trcat.coords_frac[0,...].copy(), rtol=0, atol=1e-7)
def test_pw_scf_no_forces_stress(): fn = unpack_compressed('files/pw.scf_no_forces_stress.out.gz') pp = PwSCFOutputFile(fn) assert pp.get_forces() is None assert pp.get_stress() is None st = io.read_pw_scf(fn) assert st.stress is None assert st.forces is None
def get_atoms_with_calc_lammps(): st_start = io.read_pw_scf('files/ase/pw.scf.out.start.wz-AlN') at = st_start.get_ase_atoms(pbc=True) label = pj(testdir, prefix, 'calc_dir', 'lmp') calc = Lammps(label=label, pair_style='tersoff', pair_coeff='* * AlN.tersoff Al N', command='lammps < lmp.in > lmp.out 2>&1', backup=True, ) at.set_calculator(calc) return at
def get_atoms_with_calc_pwscf(pseudo_dir): st_start = io.read_pw_scf('files/ase/pw.scf.out.start.rs-AlN') at = st_start.get_ase_atoms(pbc=True) label = pj(testdir, prefix, 'calc_dir', 'pw') calc = Pwscf(label=label, kpts=1/0.9, ecutwfc=30, conv_thr=1e-5, pp='pbe-n-kjpaw_psl.0.1.UPF', pseudo_dir=pseudo_dir, calc_name='my_calc', outdir=pj(testdir, prefix, 'scratch'), command='pw.x < pw.in > pw.out 2>&1', backup=True, ) at.set_calculator(calc) return at
def test_pwscf_calculator(): if not have_ase(): skip("no ASE found, skipping test") elif not have_pwx(): skip("no pw.x found, skipping test") else: pseudo_dir = pj(testdir, prefix, 'pseudo') print(common.backtick("mkdir -pv {p}; cp files/qe_pseudos/*.gz {p}/; \ gunzip {p}/*".format(p=pseudo_dir))) at = get_atoms_with_calc_pwscf(pseudo_dir) print("scf") # trigger calculation here forces = at.get_forces() etot = at.get_potential_energy() stress = at.get_stress(voigt=False) # 3x3 st = io.read_pw_scf(at.calc.label + '.out') assert np.allclose(forces, st.forces) assert np.allclose(etot, st.etot) assert np.allclose(st.stress, -stress * constants.eV_by_Ang3_to_GPa) # files/ase/pw.scf.out.start is a norm-conserving LDA struct, # calculated with pz-vbc.UPF, so the PBE vc-relax will make the cell # a bit bigger print("vc-relax") from ase.optimize import BFGS from ase.constraints import UnitCellFilter opt = BFGS(UnitCellFilter(at)) cell = parse.arr2d_from_txt(""" -1.97281509 0. 1.97281509 0. 1.97281509 1.97281509 -1.97281509 1.97281509 0.""") assert np.allclose(cell, at.get_cell()) opt.run(fmax=0.05) # run only 2 steps cell = parse.arr2d_from_txt(""" -2.01837531 0. 2.01837531 0. 2.01837531 2.01837531 -2.01837531 2.01837531 0""") assert np.allclose(cell, at.get_cell()) # at least 1 backup files must exist: pw.*.0 is the SCF run, backed up # in the first iter of the vc-relax assert os.path.exists(at.calc.infile + '.0')
def test_pwscf_calculator(): if not have_ase(): skip("no ASE found, skipping test") elif not have_pwx(): skip("no pw.x found, skipping test") else: pseudo_dir = pj(testdir, prefix, 'pseudo') print common.backtick("mkdir -pv {p}; cp files/qe_pseudos/*.gz {p}/; \ gunzip {p}/*".format(p=pseudo_dir)) at = get_atoms_with_calc_pwscf(pseudo_dir) print "scf" # trigger calculation here forces = at.get_forces() etot = at.get_potential_energy() stress = at.get_stress(voigt=False) # 3x3 st = io.read_pw_scf(at.calc.label + '.out') assert np.allclose(forces, st.forces) assert np.allclose(etot, st.etot) assert np.allclose(st.stress, -stress * constants.eV_by_Ang3_to_GPa) # files/ase/pw.scf.out.start is a norm-conserving LDA struct, # calculated with pz-vbc.UPF, so the PBE vc-relax will make the cell # a bit bigger print "vc-relax" from ase.optimize import BFGS from ase.constraints import UnitCellFilter opt = BFGS(UnitCellFilter(at)) cell = parse.arr2d_from_txt(""" -1.97281509 0. 1.97281509 0. 1.97281509 1.97281509 -1.97281509 1.97281509 0.""") assert np.allclose(cell, at.get_cell()) opt.run(fmax=0.05) # run only 2 steps cell = parse.arr2d_from_txt(""" -2.01837531 0. 2.01837531 0. 2.01837531 2.01837531 -2.01837531 2.01837531 0""") assert np.allclose(cell, at.get_cell()) # at least 1 backup files must exist: pw.*.0 is the SCF run, backed up # in the first iter of the vc-relax assert os.path.exists(at.calc.infile + '.0')
def test_scf_cell(): filename = 'files/pw.vc_relax_coords_fixed.out' common.system('gunzip %s.gz' % filename) pp = parse.PwSCFOutputFile(filename, use_alat=False) cell_2d_red = pp.get_cell() assert np.allclose(cell_2d_red, cell_2d_red_ref, atol=1e-15, rtol=0) pp = parse.PwSCFOutputFile(filename, use_alat=True) assert np.allclose(pp.get_cell(), cell_2d_red * pp.get_alat(), atol=1e-15, rtol=0) st = io.read_pw_scf(filename) tr = io.read_pw_md(filename) # tr is from a vc-relax w/ fixed fractional coords, check that assert np.allclose(np.zeros((tr.nstep, tr.natoms, 3)), tr.coords_frac - tr.coords_frac[0, ...].copy(), rtol=0, atol=1e-15) # check if scf parser gets the same coords_frac as the trajectory parser # Note: this and the next test have the same max error of # 4.33868466709e-08 (b/c of limited accuracy in printed numbers in # pwscf output) assert np.allclose(st.coords_frac, tr.coords_frac[0, ...], atol=1e-7, rtol=0) # same test, plus test of concatenate() works trcat = crys.concatenate((st, tr)) assert np.allclose(np.zeros((trcat.nstep, trcat.natoms, 3)), trcat.coords_frac - trcat.coords_frac[0, ...].copy(), rtol=0, atol=1e-7)
sp_points_frac = np.array([\ [0,0,0], [.5,0,0], [1/2., 1/2., 0], [0,0.5,0], [0,0,0], [0,0,.5], [0.5,0,.5], [0.5,0.5,.5], [0.0,0.5,.5], [0,0,.5], ]) # recip. cell in 2*pi/alat units, need this to make QE happy, q-points in # matdyn.in and matdyn.freq output file are cartesian in 2*pi/alat st = io.read_pw_scf('pw.out') rcell_reduced = crys.recip_cell(st.cell) / 2.0 / np.pi * st.cryst_const[0] sp_points = np.dot(sp_points_frac, rcell_reduced) # fine path: use N=500 for nice LO-TO split jumps [see below for more comments # on that] ks_path = kpath.kpath(sp_points, N=50) # call matdyn.x templ_txt = """ &input asr='crystal', XXXMASS flfrc='q2r.fc', flfrq='XXXFNFREQ' /
#!/usr/bin/python # Parse each pw.out and write results/idx/struct.pk from pwtools import sql, io db = sql.SQLiteDB('calc.db', table='calc') for idx in db.get_list1d("select idx from calc"): print(idx) st = io.read_pw_scf('calc/%i/pw.out' % idx) st.dump('results/%i/struct.pk' % idx)