Example #1
0
    def scan(self):
        super(VaspWavefunctionLoader, self).scan()

        from ase.io import read
        # from ...common.misc import vaspwfc
        from VaspBandUnfolding.vaspwfc import vaspwfc

        # Read cell from POSCAR file
        ase_cell = read("POSCAR")
        cell = Cell(ase_cell)

        # Read wfc from WAVECAR file
        self.wavecar = vaspwfc()
        ngrid = self.wavecar._ngrid.copy() * 2
        # ft = FourierTransform(*self.wavecar._ngrid)
        ft = FourierTransform(*ngrid)
        nspin, nkpts, nbands = self.wavecar._occs.shape
        assert nspin == 2 and nkpts == 1

        # Get band indices (starting from 1) witt significant occupations
        iuorbs = np.where(self.wavecar._occs[0, 0] > 0.8)[0] + 1
        idorbs = np.where(self.wavecar._occs[1, 0] > 0.8)[0] + 1

        nuorbs = len(iuorbs)
        ndorbs = len(idorbs)
        norbs = nuorbs + ndorbs

        iorb_sb_map = list(
            ("up", iuorbs[iorb]) if iorb < nuorbs else ("down",
                                                        idorbs[iorb - nuorbs])
            for iorb in range(norbs))

        iorb_fname_map = ["WAVECAR"] * norbs
        self.wfc = Wavefunction(cell=cell,
                                ft=ft,
                                nuorbs=nuorbs,
                                ndorbs=ndorbs,
                                iorb_sb_map=iorb_sb_map,
                                iorb_fname_map=iorb_fname_map)
parser.add_argument("-g2",
                    dest="gamma_2",
                    default=False,
                    action="store_true",
                    help="Second WAVECAR is in gamma-format")
parser.add_argument("--phase",
                    dest="show_phase",
                    default=False,
                    action="store_true",
                    help="Show the difference in phase (degrees)")
args = parser.parse_args()

gammas = [args.gamma_1, args.gamma_2]
wavs = args.wavs

wfc_1 = vaspwfc.vaspwfc(wavs[0], lgamma=gammas[0])
wfc_2 = vaspwfc.vaspwfc(wavs[1], lgamma=gammas[1])

func1 = wfc_1.wfc_r(*args.wfc1)
func2 = wfc_2.wfc_r(*args.wfc2)

similarity = np.sum(np.conjugate(func1) * func2)
angle = np.angle(similarity, deg=True)
power = np.abs(similarity)

similarity = np.abs(np.sum(np.conjugate(func1) * func2))
if args.show_phase:
    print("Wavefunction similarity: {:.3f} {:2f}".format(similarity, angle))
else:
    print("Wavefunction similarity: {:.3f}".format(similarity))
parser.add_argument("-range", dest="ipr_range", default=15, type=int)
parser.add_argument("--gamma", dest="gamma", default=False, action="store_true")
band_group.add_argument("-center", dest="spin_center", default=None, type=int)
band_group.add_argument("-bands", dest="bands", default=None, type=int, nargs="+", help="Manual specification of bands to calculate IPR")

input = parser.parse_args()

#if input.ibzkpt == "":
#    input.ibzkpt = glob.glob("*IBZKPT*")[0]
#if input.outcar == "":
#    input.outcar = glob.glob("*OUTCAR*")[0]
if input.wav == "":
    input.wav = glob.glob("*WAVECAR*")[0]

# read files
wav = vaspwfc(input.wav, lgamma=input.gamma)

if input.spin_center is None and input.bands is None:
	occupation=open(input.occupation,'r')
	spin_1=open(input.spin1,'r')
	spin_2=open(input.spin2,'r')
	# find number of bands
	occupation_lines = occupation.readlines()
	spin_1_lines = spin_1.readlines()
	spin_2_lines = spin_2.readlines()

	bands = int(spin_2_lines[-1].split()[0])

	# find highest occupied band (HOB)
	HOB_1 = 0
	HOB_2 = 0
Example #4
0
if args.cell is None:
    cells = search_for("*CONTCAR*")
    if cells is None:
        cells = search_for("*POSCAR*")
    if cells is None:
        raise ValueError(
            "No valid CONTCAR or POSCAR found! Specify with -cell")
    args.cell = cells

if args.wavecar is None:
    wavs = search_for("*WAVECAR*")
    if wavs is None:
        raise Exception("No valid WAVECAR found! Specify with -wavecar")
    args.wavecar = wavs

print("Calculating orbitals:")
print("Structure file: {}".format(args.cell))
print("Wavefunction file: {}".format(args.wavecar))

wav = vaspwfc(args.wavecar, lgamma=args.gamma, gamma_half=args.gamma_half)
for band in args.bands:
    wavefunc = wav.wfc_r(args.spin, args.k_point, band)
    argument = wavefunc
    if args.calc_density:
        argument = wavefunc.real**2 + wavefunc.imag**2
    wav.save2vesta(argument,
                   lreal=not args.imaginary,
                   poscar=args.cell,
                   prefix="".join(["wav_s" + str(args.spin) + "_",
                                   str(band)]))
k_points = in_args.k_points
#ibzkpt_path = in_args.IBZKPT

# find kpoints
#ibzkpt=open(ibzkpt_path,'r')
#ibzkpt.readline()
#kpoints=int(ibzkpt.readline())
#ibzkpt.close()

# find wavecars
from_wav_path = in_args.from_wav
to_wav_path = in_args.to_wav

# from ground to tag step
from_wav = vaspwfc(from_wav_path, lgamma=in_args.gamma)
to_wav = vaspwfc(to_wav_path, lgamma=in_args.gamma)

# get parchial charge bands
if in_args.bands is not None:
    parchg = in_args.bands
else:
    HOB = from_wav.find_HOB()
    HOB = max(HOB)
    parchg = np.array([HOB - i for i in range(10, -11, -1)])
    parchg = parchg[np.logical_and(parchg >= 1, parchg <= from_wav._nbands)]

# make output array to save dE, overlap and tdm
output = np.empty((2, len(k_points), len(parchg), len(parchg), 5),
                  dtype=np.complex_)