def test_full_relativistic(self): """Parsing the full-relativistic output file produced by ONCVPSPS.""" p = OncvOutputParser(filepath("08_O_r.out")) p.scan(verbose=1) repr(p) str(p) assert p.run_completed assert p.fully_relativistic assert p.calc_type == "fully-relativistic" assert p.version == "2.1.1" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.nc == 1 assert p.nv == 2 assert p.lmax == 1 # TODO: Wavefunctions # Build the plotter plotter = p.make_plotter() repr(plotter) str(plotter) self._call_plotter_methods(plotter)
def test_nonrelativistica(self): """Parsing the non-relativistic output file produced by ONCVPSPS.""" # Non-relativistic results p = OncvOutputParser(filepath("08_O_nr.out")) p.scan(verbose=1) assert p.run_completed print(p) assert p.calc_type == "non-relativistic" assert not p.fully_relativistic assert p.version == "2.1.1" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.lmax == 1 assert p.nc == 1 assert p.nv == 2 assert p.lmax == 1 rhov, rhoc, rhom = p.densities["rhoV"], p.densities["rhoC"], p.densities["rhoM"] assert rhov.rmesh[0] == 0.0100642 assert rhov.rmesh[-1] == 3.9647436 assert rhoc.values[0] == 53.3293576 assert all(rhom.values == 0.0) # Conversion to JSON format. p.to_dict # Build the plotter plotter = p.make_plotter()
def test_full_relativistic(self): """Parsing the full-relativistic output file produced by ONCVPSPS.""" p = OncvOutputParser(filepath("08_O_r.out")) p.scan(verbose=1) repr(p); str(p) assert p.run_completed assert p.fully_relativistic assert p.calc_type == "fully-relativistic" assert p.version == "2.1.1" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.nc == 1 assert p.nv == 2 assert p.lmax == 1 # TODO: Wavefunctions # Build the plotter plotter = p.make_plotter() repr(plotter); str(plotter) self._call_plotter_methods(plotter)
def oncv_plot(options): """Plot data with matplotlib. Requires oncvpsp output file.""" out_path = find_oncv_output(options.filename) # Parse output file. onc_parser = OncvOutputParser(out_path) onc_parser.scan() if not onc_parser.run_completed: cprint("oncvpsp output is not complete. Exiting", "red") return 1 # Build the plotter plotter = onc_parser.make_plotter() # Plot data plotter.plot_radial_wfs() plotter.plot_atanlogder_econv() plotter.plot_projectors() plotter.plot_potentials() #plotter.plot_der_potentials() #for order in [1,2,3,4]: # plotter.plot_der_densities(order=order) plotter.plot_densities() #plotter.plot_densities(timesr2=True) plotter.plot_den_formfact() return 0 # Table of methods callables = collections.OrderedDict([ ("wp", plotter.plot_waves_and_projs), ("dp", plotter.plot_dens_and_pots), ("lc", plotter.plot_atanlogder_econv), ("df", plotter.plot_den_formfact), ]) # Call function depending on options.plot_mode if options.plot_mode == "slide": for func in callables.values(): func() else: func = callables.get(options.plot_mode, None) if func is not None: func() else: plotter.plot_key(key=options.plot_mode)
def test_nonrelativistica(self): """Parsing the non-relativistic output file produced by ONCVPSPS.""" # Non-relativistic results p = OncvOutputParser(filepath("08_O_nr.out")) repr(p) str(p) p.scan(verbose=1) repr(p) str(p) assert p.run_completed assert p.calc_type == "non-relativistic" assert not p.fully_relativistic assert p.version == "2.1.1" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.lmax == 1 assert p.nc == 1 assert p.nv == 2 assert p.lmax == 1 rhov, rhoc, rhom = p.densities["rhoV"], p.densities[ "rhoC"], p.densities["rhoM"] assert rhov.rmesh[0] == 0.0100642 assert rhov.rmesh[-1] == 3.9647436 assert rhoc.values[0] == 53.3293576 assert all(rhom.values == 0.0) # Conversion to JSON format. p.to_dict # Build the plotter plotter = p.make_plotter() repr(plotter) str(plotter) self._call_plotter_methods(plotter)
def test_scalar_relativistic(self): """Parsing the scalar-relativistic output file produced by ONCVPSPS.""" # Scalar relativistic output p = OncvOutputParser(filepath("08_O_sr.out")) p.scan(verbose=1) repr(p) str(p) assert p.run_completed assert not p.fully_relativistic assert p.calc_type == "scalar-relativistic" assert p.version == "2.1.1" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.nc == 1 assert p.nv == 2 assert p.lmax == 1 # Test potentials vloc = p.potentials[-1] pl0 = {0: -7.4449470, 1: -14.6551019, -1: -9.5661177} for l, pot in p.potentials.items(): assert pot.rmesh[0], pot.rmesh[-1] == (0.0099448, 3.9647436) str(l) assert pot.values[0] == pl0[l] assert all(pot.rmesh == vloc.rmesh) # Test wavefunctions ae_wfs, ps_wfs = p.radial_wfs.ae, p.radial_wfs.ps nlk = (1, 0, None) ae10, ps10 = ae_wfs[nlk], ps_wfs[nlk] assert ae10[0] == (0.009945, -0.092997) assert ps10[0] == (0.009945, 0.015273) assert ae10[-1] == (3.964744, 0.037697) assert ps10[-1] == (3.964744, 0.037694) nlk = (2, 1, None) ae21, ps21 = ae_wfs[nlk], ps_wfs[nlk] assert ae21[0] == (0.009945, 0.001463) assert ps21[0] == (0.009945, 0.000396) # Test projectors prjs = p.projectors assert prjs[(1, 0, None)][0] == (0.009945, 0.015274) assert prjs[(2, 0, None)][0] == (0.009945, -0.009284) assert prjs[(1, 0, None)][-1] == (3.964744, 0.037697) assert prjs[(2, 0, None)][-1] == (3.964744, 0.330625) assert prjs[(1, 1, None)][0] == (0.009945, 0.000395) assert prjs[(2, 1, None)][0] == (0.009945, -0.000282) # Test convergence data c = p.ene_vs_ecut assert c[0].energies[0] == 5.019345 assert c[0].values[0] == 0.010000 assert c[0].energies[-1] == 25.317286 assert c[0].values[-1] == 0.000010 assert c[1].energies[0] == 19.469226 assert c[1].values[0] == 0.010000 # Test log derivatives ae0, ps0 = p.atan_logders.ae[0], p.atan_logders.ps[0] assert ae0.energies[0], ae0.values[0] == (2.000000, 0.706765) assert ps0.energies[0], ps0.values[0] == (2.000000, 0.703758) assert ae0.energies[-1], ae0.energies[-1] == (-2.000000, 3.906687) assert ps0.energies[-1], ps0.energies[-1] == (-2.000000, 3.906357) ae1, ps1 = p.atan_logders.ae[1], p.atan_logders.ps[1] assert ae1.energies[0], ae1.values[0] == (2.000000, -2.523018) assert ps1.values[0] == -2.521334 # Build the plotter plotter = p.make_plotter() repr(plotter) str(plotter) self._call_plotter_methods(plotter)
def test_scalar_relativistic(self): """Parsing the scalar-relativistic output file produced by ONCVPSPS.""" # Scalar relativistic output p = OncvOutputParser(filepath("08_O_sr.out")) p.scan(verbose=1) repr(p); str(p) assert p.run_completed assert not p.fully_relativistic assert p.calc_type == "scalar-relativistic" assert p.version == "2.1.1" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.nc == 1 assert p.nv == 2 assert p.lmax == 1 # Test potentials vloc = p.potentials[-1] pl0 = {0: -7.4449470, 1: -14.6551019, -1: -9.5661177} for l, pot in p.potentials.items(): assert pot.rmesh[0], pot.rmesh[-1] == (0.0099448, 3.9647436) str(l) assert pot.values[0] == pl0[l] assert all(pot.rmesh == vloc.rmesh) # Test wavefunctions ae_wfs, ps_wfs = p.radial_wfs.ae, p.radial_wfs.ps nlk = (1, 0, None) ae10, ps10 = ae_wfs[nlk], ps_wfs[nlk] assert ae10[0] == (0.009945, -0.092997) assert ps10[0] == (0.009945, 0.015273) assert ae10[-1] == (3.964744, 0.037697) assert ps10[-1] == (3.964744, 0.037694) nlk = (2, 1, None) ae21, ps21 = ae_wfs[nlk], ps_wfs[nlk] assert ae21[0] == (0.009945, 0.001463) assert ps21[0] == (0.009945, 0.000396) # Test projectors prjs = p.projectors assert prjs[(1, 0, None)][0] == (0.009945, 0.015274) assert prjs[(2, 0, None)][0] == (0.009945, -0.009284) assert prjs[(1, 0, None)][-1] == (3.964744, 0.037697) assert prjs[(2, 0, None)][-1] == (3.964744, 0.330625) assert prjs[(1, 1, None)][0] == (0.009945, 0.000395) assert prjs[(2, 1, None)][0] == (0.009945, -0.000282) # Test convergence data c = p.ene_vs_ecut assert c[0].energies[0] == 5.019345 assert c[0].values[0] == 0.010000 assert c[0].energies[-1] == 25.317286 assert c[0].values[-1] == 0.000010 assert c[1].energies[0] == 19.469226 assert c[1].values[0] == 0.010000 # Test log derivatives ae0, ps0 = p.atan_logders.ae[0], p.atan_logders.ps[0] assert ae0.energies[0], ae0.values[0] == (2.000000, 0.706765) assert ps0.energies[0], ps0.values[0] == (2.000000, 0.703758) assert ae0.energies[-1], ae0.energies[-1] == (-2.000000, 3.906687) assert ps0.energies[-1], ps0.energies[-1] == (-2.000000, 3.906357) ae1, ps1 = p.atan_logders.ae[1], p.atan_logders.ps[1] assert ae1.energies[0], ae1.values[0] == (2.000000, -2.523018) assert ps1.values[0] == -2.521334 # Build the plotter plotter = p.make_plotter() repr(plotter); str(plotter) self._call_plotter_methods(plotter)
def main(): parser = argparse.ArgumentParser() #formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('filename', default="", help="Path to the output file") parser.add_argument("-p", "--plot-mode", default="slide", help=("Quantity to plot. Possible values: %s" % str(["slide", "wp, dp, lc"] + PseudoGenDataPlotter.all_keys) + "\n" "wp --> wavefunctions and projectors\n" + "dp --> densities and potentials\n" + "lc --> atan(logder) and convergence wrt ecut")) parser.add_argument("-j", "--json", action="store_true", default=False, help="Produce a string with the results in a JSON dictionary and exit") parser.add_argument("-8", "--psp8", action="store_true", default=False, help="produce a .psp8 file with initial dojo report and exit") options = parser.parse_args() onc_parser = OncvOutputParser(options.filename) onc_parser.scan() if options.json: import json print(json.dumps(onc_parser.to_dict, indent=4)) return 0 if options.psp8: print(onc_parser.get_pseudo_str()) return 0 # Build the plotter plotter = onc_parser.make_plotter() # Table of methods callables = collections.OrderedDict([ ("wp", plotter.plot_waves_and_projs), ("dp", plotter.plot_dens_and_pots), ("lc", plotter.plot_atanlogder_econv), ]) #plotter.plot_radial_wfs() #plotter.plot_projectors() #plotter.plot_potentials() #plotter.plot_der_potentials() #plotter.plot_densities() #plotter.plot_der_densities(order=1) #plotter.plot_der_densities(order=2) plotter.plot_der_densities(order=4) return # Call function depending on options.plot_mode if options.plot_mode == "slide": for func in callables.values(): func() else: func = callables.get(options.plot_mode, None) if func is not None: func() else: plotter.plot_key(key=options.plot_mode) return 0
def test_oncvoutput_parser(): """Test the parsing of the output file produced by ONCVPSPS.""" # TODO: Full-relativistic case not yet supported. with pytest.raises(OncvOutputParser.Error): OncvOutputParser(filepath("08_O_r.out")) # Non-relativistic results p = OncvOutputParser(filepath("08_O_nr.out")) print(p) assert not p.fully_relativistic assert p.calc_type == "non-relativistic" assert p.atsym == "O" assert p.z == "8.00" assert p.iexc == "3" assert p.lmax == 1 rhov, rhoc, rhom = p.densities["rhoV"], p.densities["rhoC"], p.densities["rhoM"] assert rhov.rmesh[0] == 0.0100642 assert rhov.rmesh[-1] == 3.9647436 assert rhoc.values[0] == 53.3293576 assert all(rhom.values == 0.0) # Conversion to JSON format. p.to_dict # Build the plotter plotter = p.make_plotter() # Scalar relativistic output p = OncvOutputParser(filepath("08_O_sr.out")) assert not p.fully_relativistic assert p.calc_type == "scalar-relativistic" assert p.lmax == 1 # Test potentials vloc = p.potentials[-1] pl0 = {0: -7.4449470, 1: -14.6551019, -1: -9.5661177} for l, pot in p.potentials.items(): assert pot.rmesh[0], pot.rmesh[-1] == (0.0099448, 3.9647436) print(l) assert pot.values[0] == pl0[l] assert all(pot.rmesh == vloc.rmesh) # Test wavefunctions ae_wfs, ps_wfs = p.radial_wfs.ae, p.radial_wfs.ps ae10, ps10 = ae_wfs[(1, 0)], ps_wfs[(1, 0)] assert ae10[0] == (0.009945, -0.092997) assert ps10[0] == (0.009945, 0.015273) assert ae10[-1] == (3.964744, 0.037697) assert ps10[-1] == (3.964744, 0.037694) ae21, ps21 = ae_wfs[(2, 1)], ps_wfs[(2, 1)] assert ae21[0] == (0.009945, 0.001463) assert ps21[0] == (0.009945, 0.000396) # Test projectors prjs = p.projectors assert prjs[(1, 0)][0] == (0.009945, 0.015274) assert prjs[(2, 0)][0] == (0.009945, -0.009284) assert prjs[(1, 0)][-1] == (3.964744, 0.037697) assert prjs[(2, 0)][-1] == (3.964744, 0.330625) assert prjs[(1, 1)][0] == (0.009945, 0.000395) assert prjs[(2, 1)][0] == (0.009945, -0.000282) # Test convergence data c = p.ene_vs_ecut assert c[0].energies[0] == 5.019345 assert c[0].values[0] == 0.010000 assert c[0].energies[-1] == 25.317286 assert c[0].values[-1] == 0.000010 assert c[1].energies[0] == 19.469226 assert c[1].values[0] == 0.010000 # Test log derivatives ae0, ps0 = p.atan_logders.ae[0], p.atan_logders.ps[0] assert ae0.energies[0], ae0.values[0] == (2.000000, 0.706765) assert ps0.energies[0], ps0.values[0] == (2.000000, 0.703758) assert ae0.energies[-1], ae0.energies[-1] == (-2.000000, 3.906687) assert ps0.energies[-1], ps0.energies[-1] == (-2.000000, 3.906357) ae1, ps1 = p.atan_logders.ae[1], p.atan_logders.ps[1] assert ae1.energies[0], ae1.values[0] == (2.000000, -2.523018) assert ps1.values[0] == -2.521334