|
1 | 1 | from pymatgen.io.vasp import Wavecar
|
2 | 2 | from pymatgen.io.vasp import Poscar
|
3 | 3 | from pymatgen.io.wannier90 import Unk
|
| 4 | +from itertools import product |
4 | 5 | import numpy as np
|
5 | 6 |
|
6 | 7 |
|
| 8 | +def get_partial_charge_density(wavecar: Wavecar, structure: Poscar, kpoints: list[int], bands: list[int], spins: list[int], spinors: list[int], phases: list[int], scale: float): |
| 9 | + '''Returns the partial charge densities for given kpoints, bands, spins, spinors, phases, and scale.''' |
| 10 | + wave = Wavecar(wavecar) |
| 11 | + poscar = Poscar.from_file(structure) |
| 12 | + |
| 13 | + combinations = list(product(kpoints, bands, spins, spinors, phases)) |
| 14 | + |
| 15 | + #initialize the first chgcar |
| 16 | + parchg = wave.get_parchg(poscar, *combinations[0], scale=scale) |
| 17 | + |
| 18 | + #add the rest of the chgcar |
| 19 | + for kpoint, band, spin, spinor, phase in combinations[1:]: |
| 20 | + parchg += wave.get_parchg(poscar, kpoint, band, spin, spinor, phase, scale) |
| 21 | + |
| 22 | + return parchg |
| 23 | + |
| 24 | +def handle_string_inputs(args, wavecar): |
| 25 | + '''Checks if all is passed as an input and returns a list of all possible values.''' |
| 26 | + args_mapping = { |
| 27 | + 'kpoints': (wavecar.nk, list(range(wavecar.nk))), |
| 28 | + 'bands': (wavecar.nb, list(range(wavecar.nb))), |
| 29 | + 'spins': (wavecar.spin, list(range(wavecar.spin))), |
| 30 | + 'spinors': (2, list(range(2))), |
| 31 | + 'phases': (2, list(range(2))) |
| 32 | + } |
| 33 | + |
| 34 | + for arg, (max_value, default_value) in args_mapping.items(): |
| 35 | + try: |
| 36 | + if args.__dict__[arg] == 'all': |
| 37 | + args.__dict__[arg] = default_value |
| 38 | + elif ':' in args.__dict__[arg]: |
| 39 | + start, end = map(int, args.__dict__[arg].split(':')) |
| 40 | + args.__dict__[arg] = list(range(start, end+1)) |
| 41 | + else: |
| 42 | + args.__dict__[arg] = [int(args.__dict__[arg])] |
| 43 | + except (ValueError, TypeError): |
| 44 | + print(f"Invalid input for {arg}. Please provide a valid input.") |
| 45 | + |
| 46 | + return args |
| 47 | + |
| 48 | + |
7 | 49 | def generate_parchg(args):
|
8 | 50 | '''Generates a PARCHG file from a WAVECAR file. '''
|
9 | 51 | wave = Wavecar(args.input)
|
10 | 52 | poscar = Poscar.from_file(args.structure)
|
11 |
| - |
12 |
| - chgcar = wave.get_parchg(poscar, args.kpoint, args.band, args.spin, args.spinor, args.phase, args.scale) |
| 53 | + args = handle_string_inputs(args, wave) |
| 54 | + parchg = get_partial_charge_density(wave, poscar, args.kpoints, args.bands, args.spins, args.spinors, args.phases, args.scale) |
13 | 55 |
|
14 | 56 | if args.output:
|
15 | 57 | if args.cube:
|
16 |
| - chgcar.to_cube(args.output) |
| 58 | + parchg.to_cube(args.output) |
17 | 59 | else:
|
18 |
| - chgcar.write_file(args.output) |
| 60 | + parchg.write_file(args.output) |
19 | 61 | else:
|
20 |
| - print(chgcar.__str__()) |
| 62 | + print(parchg.__str__()) |
21 | 63 |
|
22 |
| -def generate_fft_mesh(args): |
23 |
| - '''Generates a COEFFS file from a WAVECAR file. ''' |
24 |
| - mesh = Wavecar(args.input).fft_mesh(args.kpoint, args.band, args.spin, args.spinor, args.shift) |
25 |
| - evals = np.fft.ifftn(mesh) |
26 |
| - if args.output: |
27 |
| - np.save(args.output, evals) |
28 |
| - else: |
29 |
| - print(evals) |
| 64 | +# def generate_fft_mesh(args): |
| 65 | +# '''Generates a COEFFS file from a WAVECAR file. ''' |
| 66 | +# mesh = Wavecar(args.input).fft_mesh(args.kpoints, args.bands, args.spins, args.spinors) |
| 67 | +# evals = np.fft.ifftn(mesh) |
| 68 | +# if args.output: |
| 69 | +# np.save(args.output, evals) |
| 70 | +# else: |
| 71 | +# print(evals) |
30 | 72 |
|
31 | 73 | def generate_unk(args):
|
32 | 74 | """
|
|
0 commit comments