Exemplo n.º 1
0
def eosPrepare(directory=None, evname='EOS'):
    if directory is None:
        directory = os.getcwd()
    currentdir = os.getcwd()
    os.chdir(directory)

    if not os.path.isfile('./1.0/POSCAR'):
        return False

    poscar = open('./1.0/POSCAR', 'r')
    lines = poscar.readlines()

    numberofatoms = lines[6][:-1].lstrip()
    numberofatoms = " ".join(numberofatoms.split())
    numberofatoms = sum(map(int, numberofatoms.split(' ')))

    #Setup e-v.dat
    eos = {}
    with open(evname, 'w') as eosfile:
        for i in sorted(os.listdir()):
            if os.path.isdir(i) and i.replace('.', '', 1).isdigit():
                E = execute(
                    'grep \'energy  without entropy\'  ' + i +
                    '/OUTCAR | tail -1 | awk \'{ print $7 }\'').strip()
                V = execute(
                    'grep vol ' + i +
                    '/OUTCAR | tail -n 1 | awk \'{print $5}\'').strip()
                eos[i] = (float(E) / numberofatoms, V)
                eosfile.write(V + ' ' + str(E) + '\n')

    os.chdir(currentdir)
    return eos
Exemplo n.º 2
0
def initialize(settings, hard=''):
    #print 'write incar kpoints potcar, make directory?'
    #inherit()
    writeSettings(settings)
    poscar = open('./POSCAR', 'r')
    lines = poscar.readlines()
    elements = lines[5][:-1].strip()
    execute('POTgen' + str(hard) + ' ' + str(elements))
    return 0
Exemplo n.º 3
0
def decompress():
    nodes = getNodeInfo()
    ncore = min(nodes.values())
    if os.path.isfile('CHGCAR.gz'):
        print('Decompressing CHGCAR.gz in ' + os.getcwd() + '.')
        execute('pigz -f -d -6 -p' + str(ncore) + ' CHGCAR.gz')

    if os.path.isfile('WAVECAR.gz'):
        print('Decompressing WAVECAR.gz in ' + os.getcwd() + '.')
        execute('pigz -f -d -6 -p' + str(ncore) + ' WAVECAR.gz')
Exemplo n.º 4
0
def readSettings(settings):
    settings['INCAR'] = readINCAR()
    settings['KPOINTS'] = readKPOINTS()
    POTCAR_version = execute('grep -a \'TITEL\' POTCAR | awk \'{ print $4 }\'')
    settings['POTCAR'] = POTCAR_version.strip().replace('\n', ', ')
    #read/writePOTCAR would be useful
    return settings
Exemplo n.º 5
0
def eosPrepare(directory = None, evname = 'EOS'):
    if directory == None:
        directory = os.getcwd()
    currentdir = os.getcwd()
    os.chdir(directory)
    os.chdir('../')
    
    #Setup e-v.dat
    eos = {}
    with open(evname,'w') as eosfile:
        for i in os.listdir():
            if os.path.isdir(i) and i.replace('.','',1).isdigit():
                E = execute('grep \'energy  without entropy\'  ' + i + '/OUTCAR | tail -1 | awk \'{ print $7 }\'').strip()
                V = execute('grep vol ' + i + '/OUTCAR | tail -n 1 | awk \'{print $5}\'').strip()
                eos[i] = (E,V)
                eosfile.write(V + ' ' + E + '\n')
    
    os.chdir(currentdir)
    return eos
Exemplo n.º 6
0
def run(ratio = 1,cwd = None):
    global vasp
    #could move hybrid to parallel setup
    if cwd == None:
        cwd = os.getcwd();
    nodes = getNodeInfo()

    #cores = mysql_query('SELECT `cores` FROM `clusters` WHERE `name` = ' + str(os.getenv('VSC_INSTITUTE_CLUSTER')))
    hybrid = str(int(min(nodes.values())/int(ratio)))
    return execute('mympirun -h ' + hybrid + ' --output ' + cwd + '/tempout ' + vasp)
Exemplo n.º 7
0
def gather(results):
    for key in results:
        if key[0:2] == 'E0':
            results[key] = float(execute('grep \'energy  without entropy\'  OUTCAR | tail -1 | awk \'{ print $7 }\''))
            if 'atom' in key:
                poscar = open('POSCAR','r')
                lines = poscar.readlines()
        
                numberofatoms = lines[6][:-1].lstrip()
                numberofatoms = " ".join(numberofatoms.split())
                numberofatoms = sum(map(int, numberofatoms.split(' ')))/numberofatoms
                results[key] /= numberofatoms
        elif key == 'natoms':
            poscar = open('POSCAR','r')
            lines = poscar.readlines()
    
            numberofatoms = lines[6][:-1].lstrip()
            numberofatoms = " ".join(numberofatoms.split())
            numberofatoms = sum(map(int, numberofatoms.split(' ')))/numberofatoms
            results[key] = numberofatoms
        elif key == 'Ehull':
            results[key] = float(execute('HTehull ./'))
        elif key == 'Eatom':
            #to be implemented
            results[key] = float(execute('HTehull ./'))   
        elif key == 'Epure':
            #to be implemented
            results[key] = float(execute('HTehull ./'))
        elif key == 'cellparams':
            crystal = ase.io.read('CONTCAR')
            results[key] = list(crystal.get_cell_lengths_and_angles())
        elif key == 'volume':
            results[key] = float(execute('grep vol OUTCAR | tail -n 1 | awk \'{print $5}\''))
        elif key == 'eos':
            eosPrepare()
            v0, e0, B, BP, residuals = eosFit()
            results[key] = {'V0' : v0, 'E0' : e0, 'B0' : B, 'BP' : BP, 'res' : residuals}
    return results
Exemplo n.º 8
0
    print('Initializing job.')
    inherit(cinfo,
            cdir[inheritstep],
            contcar=inheritcontcar,
            chgcar=inheritchgcar,
            wavecar=inheritwavecar,
            grid=inheritgrid,
            settingsmod=inheritmod,
            rescale=rescale)
    #Verify your potcardir, potgen should possibly just become a python function.
    initialize(cinfo['settings'])

#Post setup modifications.
encutlow = 1.25 * float(
    execute(
        'grep ENMAX POTCAR | awk \'{print $3}\' | cut -d\; -f1 | sort -n | tail -n1'
    ))

if step < 12:
    cinfo['settings']['INCAR']['ENCUT'] = encutlow
else:
    cinfo['settings']['INCAR']['ENCUT'] = 520

if detectSP('POSCAR'):
    # This could be abstracted further, though the magnetic elements chosen in
    # detectSP are not uniquely chosen either.
    cinfo['settings']['INCAR']['ISPIN'] = 2

#Redivide KP AFTER initializing for settingsmod
setupKP(cinfo['settings'], minkp)
#Setup parallellization settings
Exemplo n.º 9
0
def gather(results):
    if 'Ehull' in results.keys():
        results['Ehullold'] = 0
        results['potcorr'] = 0
        results['path'] = ''
    resultkeys = list(results.keys()).copy()
    results['Edisp'] = 0

    for key in resultkeys:
        print(key)
        if key[0:2] == 'E0' and 'disp' not in key:
            try:
                vdw = float(
                    execute('grep \'Edisp\' OUTCAR | awk \'{print $3}\''))
            except ValueError:
                vdw = 0
            results['Edisp'] = vdw
            results[key + 'disp'] = float(
                execute(
                    'grep \'energy  without entropy\'  OUTCAR | tail -1 | awk \'{ print $7 }\''
                ))
            results[key] = results[key + 'disp'] - vdw
            if 'atom' in key:
                poscar = open('POSCAR', 'r')
                lines = poscar.readlines()

                numberofatoms = lines[6][:-1].lstrip()
                numberofatoms = " ".join(numberofatoms.split())
                numberofatoms = sum(map(int, numberofatoms.split(' ')))
                results[key] /= numberofatoms
                results[key + 'disp'] /= numberofatoms
        elif key == 'natoms':
            poscar = open('POSCAR', 'r')
            lines = poscar.readlines()

            numberofatoms = lines[6][:-1].lstrip()
            numberofatoms = " ".join(numberofatoms.split())
            numberofatoms = sum(map(int, numberofatoms.split(' ')))
            results[key] = numberofatoms
        elif key == 'Ehull':
            results[key + 'old'] = float(getEhull().split(' ')[0])
            ehull, path = tuple(
                [x.strip() for x in getEhull(new='1').split(' ', maxsplit=1)])
            potcorr = getPotCorr(
            )  #float(execute('HTpotcorr ./ 1 | tail -n 1'))
            results[key] = float(ehull) + potcorr
            results['path'] = path
            results['potcorr'] = potcorr
        elif key == 'Eatom':
            #to be implemented
            results[key] = float(
                execute(
                    'grep \'energy  without entropy\'  OUTCAR | tail -1 | awk \'{ print $7 }\''
                ))
            poscar = open('POSCAR', 'r')
            lines = poscar.readlines()

            numberofatoms = lines[6][:-1].lstrip()
            numberofatoms = " ".join(numberofatoms.split())
            numberofatoms = sum(map(int, numberofatoms.split(' ')))
            results[key] /= numberofatoms
            results[key] -= float(execute('HTeatom ./ | tail -n 1'))
        elif key == 'Epure':
            #to be implemented
            results[key] = float(
                execute(
                    'grep \'energy  without entropy\'  OUTCAR | tail -1 | awk \'{ print $7 }\''
                ))
            poscar = open('POSCAR', 'r')
            lines = poscar.readlines()

            numberofatoms = lines[6][:-1].lstrip()
            numberofatoms = " ".join(numberofatoms.split())
            numberofatoms = sum(map(int, numberofatoms.split(' ')))
            results[key] /= numberofatoms
            results[key] -= float(execute('HTepure ./ | tail -n 1'))
        elif key == 'Eelectro':
            results[key] = execute('HTelectro ./')
        elif key == 'cellparams':
            crystal = ase.io.read('CONTCAR')
            results[key] = list(crystal.get_cell_lengths_and_angles())
        elif key == 'volume':
            results[key] = float(
                execute('grep vol OUTCAR | tail -n 1 | awk \'{print $5}\''))
        elif key == 'eos':
            test = eosPrepare(directory='../')
            if not test:
                continue
            v0, e0, B, BP, residuals = eosFit()
            results[key] = {
                'V0': v0,
                'E0': e0,
                'B0': B,
                'BP': BP,
                'res': residuals
            }
        elif key == 'BG':
            vr = Vasprun('vasprun.xml', occu_tol=0.1)
            results[key] = vr.eigenvalue_band_properties[0]
        elif key == 'smearerr':
            s0 = float(
                execute(
                    'grep \'energy  without entropy\'  OUTCAR | tail -1 | awk \'{ print $7 }\''
                ))
            s = float(
                execute(
                    'grep \'energy  without entropy\'  OUTCAR | tail -1 | awk \'{ print $4 }\''
                ))
            results[key] = s0 - s
        elif key == 'magmom':
            magmom = execute(
                'grep number.*magnetization OUTCAR | tail -n 1 | awk \'{print $6}\''
            ).isdigit()
            if isfloat(magmom):
                results[key] = np.abs(float(magmom))
            else:
                results[key] = 0

    return results
Exemplo n.º 10
0
def inherit(calc,
            path,
            contcar=True,
            chgcar=True,
            wavecar=True,
            settingsmod=None,
            grid=False,
            rescale=1.0):
    #pstep = int(math.ceil(float(stat)/2.)) -1
    if path is None:
        return True
        #inputfile = os.path.join(qdir, 'import', str(cfile) + '.vasp')

        #qdir, 'CALCULATIONS/' + cfile + '/STEP' + str(pstep)
    if contcar:
        contcarnames = [
            'CONTCAR', 'POSCAR' + calc['file'] + '.vasp',
            'POSCAR' + calc['file'], calc['file'], calc['file'] + '.vasp'
        ]
        for name in contcarnames:
            temp = os.path.join(path, name)
            if os.path.isfile(temp):
                inputfile = temp
                print('Inheriting geometry from ' + inputfile + '.')
                shutil.copy(inputfile, './POSCAR')
                rescalePOSCAR('POSCAR', rescale)
                break

    if chgcar:
        chgcarnames = [
            'CHGCAR.gz', 'CHGCAR', 'CHGCAR' + calc['file'] + '.gz',
            'CHGCAR' + calc['file']
        ]
        for name in chgcarnames:
            temp = os.path.join(path, name)
            if os.path.isfile(temp):
                density = temp
                out = 'CHGCAR'
                if density[-3:] == '.gz':
                    out += '.gz'
                print('Inheriting charge density from ' + density + '.')
                shutil.copy(density, out)
                if calc['settings']['INCAR'].get('ICHARG') is None:
                    calc['settings']['INCAR']['ICHARG'] = 1
                break

    if wavecar:
        wavecarnames = [
            'WAVECAR.gz', 'WAVECAR', 'WAVECAR' + calc['file'] + '.gz',
            'WAVECAR' + calc['file']
        ]
        for name in wavecarnames:
            temp = os.path.join(path, name)
            if os.path.isfile(temp):
                wavecar = temp
                out = 'WAVECAR'
                if wavecar[-3:] == '.gz':
                    out += '.gz'
                print('Inheriting wave functions from ' + wavecar + '.')
                shutil.copy(wavecar, out)
                break
    if grid:
        outcar = os.path.join(path, 'OUTCAR')
        ng = execute('grep "dimension x,y,z NGX" ' + outcar +
                     ' | head -n 1').strip().split()
        calc['settings']['INCAR']['NGX'] = int(ng[4])
        calc['settings']['INCAR']['NGY'] = int(ng[7])
        calc['settings']['INCAR']['NGZ'] = int(ng[10])

    if settingsmod:
        presults = manage.getResults(calc['parent'])
        presults['settingsmod'] = settingsmod
        manage.updateResults(presults, calc['parent'])
        print('These setting mods are inherited:')
        print(presults['settingsmod'])
        if settingsmod.get('KPOINTS') is not None and calc['settings'].get(
                'KPOINTS').get('K') is not None:
            curkp = [
                int(x) for x in calc['settings']['KPOINTS']['K'].split(' ')
            ]
            curmod = [int(x) for x in settingsmod['KPOINTS']['K'].split(' ')]
            calc['settings']['KPOINTS']['K'] = ' '.join(
                [str(curkp[x] + curmod[x]) for x in range(3)])
            print(curkp, curmod)
            print('Calibration update to kpoints executed.')
        if settingsmod.get('INCAR') is not None:
            if settingsmod.get('INCAR').get('ENCUT') is not None:
                calc['settings']['INCAR']['ENCUT'] = int(
                    calc['settings']['INCAR']
                    ['ENCUT']) + settingsmod['INCAR']['ENCUT']

            if settingsmod.get('INCAR').get('SIGMA') is not None:
                calc['settings']['INCAR']['SIGMA'] = settingsmod['INCAR'][
                    'SIGMA']

            if settingsmod.get('INCAR').get('ISMEAR') is not None:
                if int(calc['settings']['INCAR']['ISMEAR']) != -5:
                    calc['settings']['INCAR']['ISMEAR'] = settingsmod['INCAR'][
                        'ISMEAR']

            if settingsmod.get('INCAR').get('ISPIN') is not None:
                calc['settings']['INCAR']['ISPIN'] = settingsmod['INCAR'][
                    'ISPIN']

        #if os.path.isfile('CHGCAR'):
        #    os.rename('CHGCAR','CHGCAR.prec')
    return calc
# Error catching

finderrors(cinfo)

# Checkpoint cleanup
if os.path.isfile('STOPCAR'):
    os.remove('STOPCAR')

print('Ending Calculation')

# Checkpoint abortion
if os.path.isfile('aborted'):
    print('Calculation aborted')
    if cinfo['server'] != 'breniac':
        execute(submitscript + ' ' + str(qid) + ' ' + str(submit_arg))
    else:
        execute('ssh login1 "' + submitscript + ' ' + str(qid) + ' ' + str(submit_arg) + '"')
    sys.exit()
    
# Post-processing (run hooks? or extra functions in VASP module)

# Gather results and settings and end calculation

# Nowadays I take the energy with sigma -> 0, while in theory without entropy should be nearly the same, 
# this seems more robust and is also used by the VASP group

# Store detected errors
if 'error' in locals():
    HT.updateResults({'error':error}, cinfo['id'])
else: