コード例 #1
0
    print(
        "\n** ERROR: CHGCAR data block error, total of %s data blocks was found."
        % len(vasp_charge.chg))
    sys.exit(0)

del vasp_charge

# Exctract data
#------------------------
if spin == 3:  # SOC
    chg_total = VaspChargeDensity(filename=None)
    chg_total.atoms = [
        atoms,
    ]
    chg_total.chg = [
        potl_total,
    ]

    chg_x = VaspChargeDensity(filename=None)
    chg_x.atoms = [
        atoms,
    ]
    chg_x.chg = [
        potl_x,
    ]

    chg_y = VaspChargeDensity(filename=None)
    chg_y.atoms = [
        atoms,
    ]
    chg_y.chg = [
コード例 #2
0
ファイル: chgdiff.py プロジェクト: MsKriS/ase_tools
        print "\n**ERROR: Two sets of data are not on the same grid."
        print "Data from file %s on %dx%dx%d grid." % (CHGCARfile1, chg1.shape[0], chg1.shape[1], chg1.shape[2])
        print "Data from file %s on %dx%dx%d grid.\n" % (CHGCARfile2, chg2.shape[0], chg2.shape[1], chg2.shape[2])
        sys.exit(0)
    else:
        print "Subtracting data from file %s ..." % CHGCARfile2,
        sys.stdout.flush()

    # Take difference
    # -----------------
    chgdiff = chgdiff - chg2
    print "done."

vasp_charge_diff = VaspChargeDensity(filename=None)
vasp_charge_diff.atoms = [atoms1]
vasp_charge_diff.chg = [chgdiff]

# Print out charge density
# --------------------------
# Check whether CHGDIFF exists
if os.path.isfile("./CHGDIFF"):
    print "\n**WARNING: A file called CHGDIFF already exists in this directory."
    yesno = raw_input("Type y to continue and overwrite it, any other key to stop\n")
    if yesno != "y":
        sys.exit(0)


print "Writing density difference data to file CHGDIFF ...",
sys.stdout.flush()
vasp_charge_diff.write(filename="CHGDIFF", format="chgcar")
print "done."
コード例 #3
0
    wcell = int(options.wcell)
    if wcell == 0:
        chga = chg1
    elif wcell == 1:
        chga = chg2
    else:
        print 'Error, invalid argument to -w option'
        sys.exit(1)
else:
    chga = chg1

if len(chg1.chg) != len(chg2.chg):
    print 'Number of images in charge density files not equal. Using just \
the final images in both files.'

    chg1.chg = [chg1.chg[-1]]
    chg1.atoms = [chg1.atoms[-1]]
    if chg1.is_spin_polarized():
        chg1.chgdiff = [chg1.chgdiff[-1]]
        chg2.chgdiff = [chg2.chgdiff[-1]]
    chg2.chg = [chg2.chg[-1]]
    chg2.atoms = [chg2.atoms[-1]]

newchg = VaspChargeDensity(None)

print 'Start charge manipul'

for i, atchg in enumerate(chg1.chg):
    c1 = atchg
    c2 = chg2.chg[i]
    newchg.atoms.append(chga.atoms[i].copy())
コード例 #4
0
ファイル: chgadd.py プロジェクト: zhenming-xu/ase_tools
        sys.stdout.flush()

    # Add charge density
    #-----------------
    chgadd += chg2
    print "done."

zero = raw_input(
    "Set negative values of the added charge density to zero (Yes/No): ")

vasp_charge_add = VaspChargeDensity(filename=None)
vasp_charge_add.atoms = [
    atoms1,
]
vasp_charge_add.chg = [
    chgadd,
]

# Print out charge density
#--------------------------
# Check whether CHGADD exists
if os.path.isfile("./CHGADD"):
    print "\n**WARNING: A file called CHGADD already exists in this directory."
    yesno = raw_input(
        "Type y to continue and overwrite it, any other key to stop\n")
    if yesno != "y":
        sys.exit(0)

print "Writing added density data to file CHGADD ...",
sys.stdout.flush()
vasp_charge_add.write(filename="CHGADD", format="chgcar")
コード例 #5
0
# Calculate up spin density (sum+diff)/2
#----------------------------------------
parchg_up = (parchg_sum+parchg_diff)/2.

# Calculate down spin density (sum-diff)/2
#----------------------------------------
parchg_down = (parchg_sum-parchg_diff)/2.

# Write out parchg files
#------------------------
parchgfile = PARCHGfile + ".UP"
print "Writing up spin data to file %s..." % parchgfile,
sys.stdout.flush()
output_charge_data = VaspChargeDensity(filename=None)
output_charge_data.atoms=[geomdata,]
output_charge_data.chg=[parchg_up,]
output_charge_data.write(filename=parchgfile,format="chgcar")
print "done."

parchgfile = PARCHGfile + ".DOWN"
print "Writing down spin data to file %s..." % parchgfile,
sys.stdout.flush()
output_charge_data = VaspChargeDensity(filename=None)
output_charge_data.atoms=[geomdata,]
output_charge_data.chg=[parchg_down,]
output_charge_data.write(filename=parchgfile,format="chgcar")
print "done."

parchgfile = PARCHGfile + ".DIFF"
print "Writing up-down spin data to file %s..." % parchgfile,
sys.stdout.flush()
コード例 #6
0
def chgarith(chgf1, chgf2, op, filename, wcell):

    # chgf1 = args[0]
    # chgf2 = args[2]
    # op = args[1]

    chg1 = VaspChargeDensity(chgf1)
    chg2 = VaspChargeDensity(chgf2)

    # if options.wcell:
    #     wcell = int(options.wcell)
    if wcell == 0:
        chga = chg1
    elif wcell == 1:
        chga = chg2
    #     else:
    #         print ('Error, invalid argument to -w option')
    #         sys.exit(1)
    # else:
    # chga = chg1

    if len(chg1.chg) != len(chg2.chg):
        print(
            'Number of images in charge density files not equal. Using just   the final images in both files.'
        )
        print('len(chg.chg)', len(chg1.chg), len(chg2.chg))
        chg1.chg = [chg1.chg[-1]]
        chg1.atoms = [chg1.atoms[-1]]
        if chg1.is_spin_polarized():
            chg1.chgdiff = [chg1.chgdiff[-1]]
            chg2.chgdiff = [chg2.chgdiff[-1]]
        chg2.chg = [chg2.chg[-1]]
        chg2.atoms = [chg2.atoms[-1]]

    newchg = VaspChargeDensity(None)

    print('Start charge manipul')

    for i, atchg in enumerate(chg1.chg):
        c1 = atchg
        c2 = chg2.chg[i]
        newchg.atoms.append(chga.atoms[i].copy())
        if op == '+':
            nc = c1 + c2
            oplong = '_add_'
        elif op == '-':
            nc = c1 - c2
            oplong = '_sub_'
        elif op == '*':
            nc = c1 * c2
            oplong = '_mult_'
        elif op == '/':
            nc = c1 / c2
            oplong = '_div_'
        elif op == 'avg':
            nc = (c1 + c2) / 2
            oplong = '_avg_'
        newchg.chg.append(nc)

    if chg1.is_spin_polarized():
        print('Spin polarized')

        for i, cd in enumerate(chg1.chgdiff):
            cd2 = chg2.chgdiff[i]
            if op == '+':
                nd = cd + cd2
            elif op == '-':
                nd = cd - cd2
            elif op == '*':
                nd = cd * cd2
            elif op == '/':
                nd = cd / cd2
            elif op == 'avg':
                nd = (cd + cd2) / 2
            newchg.chgdiff.append(nd)

    # Screw doing anything fancy with the augmentation charges
    # Just take them from the same file as the embedded atoms object.
    newchg.aug = chga.aug
    newchg.augdiff = chga.augdiff

    # if options.outfile:
    #     fname = options.outfile
    # else:
    #     from os.path import basename
    #     fname = basename(chgf1) + oplong + basename(chgf2)

    newchg.write(filename)

    return filename
コード例 #7
0
        sys.exit(0)
    else:
        print "Subtracting data from file %s ..." % CHGCARfile2,
        sys.stdout.flush()

    # Take difference
    #-----------------
    chgdiff = chgdiff - chg2
    print "done."

vasp_charge_diff = VaspChargeDensity(filename=None)
vasp_charge_diff.atoms = [
    atoms1,
]
vasp_charge_diff.chg = [
    chgdiff,
]

# Print out charge density
#--------------------------
# Check whether CHGDIFF exists
if os.path.isfile("./CHGDIFF"):
    print "\n**WARNING: A file called CHGDIFF already exists in this directory."
    yesno = raw_input(
        "Type y to continue and overwrite it, any other key to stop\n")
    if yesno != "y":
        sys.exit(0)

print "Writing density difference data to file CHGDIFF ...",
sys.stdout.flush()
vasp_charge_diff.write(filename="CHGDIFF", format="chgcar")
コード例 #8
0
ファイル: chgadd.py プロジェクト: MsKriS/ase_tools
       print "Data from file %s on %dx%dx%d grid.\n" % (CHGCARfile2,chg2.shape[0],chg2.shape[1],chg2.shape[2])
       sys.exit(0)
    else:
       print "Adding data from file %s ..." % CHGCARfile2,
       sys.stdout.flush()

    # Add charge density
    #-----------------
    chgadd += chg2
    print "done." 

zero = raw_input("Set negative values of the added charge density to zero (Yes/No): ")

vasp_charge_add = VaspChargeDensity(filename=None)
vasp_charge_add.atoms=[atoms1,]
vasp_charge_add.chg=[chgadd,] 

# Print out charge density
#--------------------------
# Check whether CHGADD exists
if os.path.isfile("./CHGADD"):
   print "\n**WARNING: A file called CHGADD already exists in this directory."
   yesno=raw_input("Type y to continue and overwrite it, any other key to stop\n")
   if yesno!="y":
      sys.exit(0)


print "Writing added density data to file CHGADD ...", 
sys.stdout.flush()
vasp_charge_add.write(filename="CHGADD",format="chgcar")
print "done."
コード例 #9
0
ファイル: ase.field.manipulator.py プロジェクト: gitkusiu/bin
        field *= x

    if (options.plus != None):
        plus = options.plus
        field += plus
        print plus, min(field), max(field)
#        for i,x in enumerate(field):
#            for j,y in enumerate(x):
#                for k,z in enumerate(y):
#                    field[i][j][k] += plus
#        print field.shape
#        field = field +

####### WRITEING THE FILE #############
    if (oformat == "xsf"):
        #        write_xsf(sys.stdout,field[1],field[0])
        write_xsf(sys.stdout, atoms, field)
    elif (oformat == "cube"):
        #        print "Warrning: Third line should contain number of atoms together with position of the origin of the volumetric data."
        #        print "Warrning: Make sure it contain corrrect data."
        write_cube(sys.stdout, atoms, field)
    elif (oformat == "locpot"):
        locpot_out = VaspChargeDensity(filename=None)
        locpot_out.atoms = [
            atoms,
        ]
        locpot_out.chg = [
            field,
        ]
        locpot_out.write(filename=sys.argv[num - 1] + ".out", format="chgcar")