def converge(calc):
    presults = getResults(calc['parent'])
    if 'settingsmod' not in presults.keys():
        presults['settingsmod'] = {}
        
    for propset in presults['convergence']:
        total = len(propset)
        prop = propset[0]
        for i in range(1,total):
            (crit,cond,current,converged) = propset[i]
            if converged == 1:
                continue;
            elif crit == 'K':
                if 'KPOINTS' not in presults['settingsmod'].keys():
                    presults['settingsmod']['KPOINTS'] = {}
                if 'K' not in presults['settingsmod']['KPOINTS'].keys():
                    presults['settingsmod']['KPOINTS']['K'] = '2 2 2'
                else:
                    presults['settingsmod']['KPOINTS']['K'] = ' '.join([str(int(x) + 2) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')])
            #curkp = [int(x) for x in calc['settings']['KPOINTS']['K'].split(' ')]
           #curmod = [int(x) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')]
             #   calc['settings']['KPOINTS']['K'] = ' '.join([str(curkp[x] + curmod[x]) for x in range(3)])
                break;
            elif crit == 'ENCUT':
                if 'INCAR' not in presults['settingsmod'].keys():
                    presults['settingsmod']['INCAR'] = {}
                if 'ENCUT' not in presults['settingsmod']['INCAR']:
                    presults['settingsmod']['INCAR']['ENCUT'] = 100
                else:
                    presults['settingsmod']['INCAR']['ENCUT'] += 100
              #  calc['settings']['INCAR']['ENCUT'] = int(calc['settings']['INCAR']['ENCUT']) + presults['settingsmod']['INCAR']['ENCUT']
                break;
    updateResults(presults,calc['parent'])
    return True
Esempio n. 2
0
def toggleISYM(calc):
    presults = getResults(calc['parent'])
    if 'ISYM' not in calc['settings']['INCAR'].keys():
        calc['settings']['INCAR']['ISYM'] = 1

    calc['settings']['INCAR']['ISYM'] = (
        int(calc['settings']['INCAR']['ISYM']) + 1) % 2
    return True
Esempio n. 3
0
def halveSigmaInherit(calc):
    presults = getResults(calc['parent'])
    if 'settingsmod' not in presults.keys():
        presults['settingsmod'] = {"INCAR": {}}
    if 'INCAR' not in presults['settingsmod'].keys():
        presults['settingsmod']['INCAR'] = {}
    elif presults['settingsmod'].get('INCAR').get('SIGMA') != None:
        presults['settingsmod']['INCAR']['SIGMA'] = float(
            presults['settingsmod']['INCAR']['SIGMA']) / 2
    else:
        presults['settingsmod']['INCAR']['SIGMA'] = float(
            calc['settings']['INCAR']['SIGMA']) / 2
    updateResults(presults, calc['parent'])
    return True
def cont(calc):
    import HighThroughput.manage.calculation as manage
    baks = 0
    bako = 0
    bakx = 0
    bakt = 0

    for file in os.listdir(os.curdir):
        if os.path.isfile(file) and file[0:10] == 'POSCAR.bak':
            baks += 1
        if os.path.isfile(file) and file[0:10] == 'OUTCAR.bak':
            bako += 1
        if os.path.isfile(file) and file[0:11] == 'XDATCAR.bak':
            bakx += 1
        if os.path.isfile(file) and file[0:11] == 'tempout.bak':
            bakt += 1

    if os.path.isfile('CONTCAR') and os.stat('CONTCAR').st_size > 0:
        os.rename('POSCAR','POSCAR.bak' + str(baks))
        os.rename('CONTCAR','POSCAR')
    if os.path.isfile('OUTCAR') and os.stat('OUTCAR').st_size > 0:
        os.rename('OUTCAR','OUTCAR.bak' + str(bako))
    if os.path.isfile('XDATCAR') and os.stat('XDATCAR').st_size > 0:
        os.rename('XDATCAR','XDATCAR.bak' + str(bakx))
    if os.path.isfile('tempout') and os.stat('tempout').st_size > 0:
        os.rename('tempout','tempout.bak' + str(bakt))
        
    psettings = manage.getSettings(calc['parent'])
    presults = manage.getResults(calc['parent'])
    
    if 'continued' not in psettings.keys():
        psettings['continued'] = 1
    else:
        psettings['continued'] += 1


    if presults.get('settingsmod') != None:
        if presults['settingsmod'].get('KPOINTS').get('K') != None and calc['settings']['KPOINTS'].get('K') != None:
            curkp = [int(x) for x in calc['settings']['KPOINTS']['K'].split(' ')]
            curmod = [int(x) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')]
            calc['settings']['KPOINTS']['K'] = ' '.join([str(curkp[x] + curmod[x]) for x in range(3)])
    
        if 'ENCUT' in presults['settingsmod'].keys():
            calc['settings']['INCAR']['ENCUT'] = int(calc['settings']['INCAR']['ENCUT']) + presults['settingsmod']['INCAR']['ENCUT']
    
    manage.updateSettings(psettings, calc['parent'])
    manage.updateResults(presults, calc['parent'])

    return calc
Esempio n. 5
0
def changeSpinInherit(calc):
    presults = getResults(calc['parent'])
    if 'settingsmod' not in presults.keys():
        presults['settingsmod'] = {"INCAR": {}}
    if 'INCAR' not in presults['settingsmod'].keys():
        presults['settingsmod']['INCAR'] = {}
    if presults['settingsmod'].get('INCAR').get('ISPIN') != None:
        presults['settingsmod']['INCAR']['ISPIN'] = (
            int(presults['settingsmod']['INCAR']['ISPIN']) - 2) % 2 + 1
    else:
        presults['settingsmod']['INCAR']['ISPIN'] = (
            int(calc['settings']['INCAR']['ISPIN']) - 2) % 2 + 1
    print('Setting spin to ' + str(presults['settingsmod']['INCAR']['ISPIN']))
    updateResults(presults, calc['parent'])
    return True
Esempio n. 6
0
def raiseSYMPREC(calc):
    presults = getResults(calc['parent'])
    if 'settingsmod' not in presults.keys():
        presults['settingsmod'] = {}

    if 'SYMPREC' not in calc['settings']['INCAR'].keys():
        calc['settings']['INCAR']['SYMPREC'] = 1e-5
    if 'INCAR' not in presults['settingsmod'].keys():
        presults['settingsmod']['INCAR'] = {}
    if 'ENCUT' not in presults['settingsmod']['INCAR']:
        presults['settingsmod']['INCAR']['SYMPREC'] = np.float32(
            calc['settings']['INCAR']['SYMPREC']) * 10.
    else:
        presults['settingsmod']['INCAR']['SYMPREC'] = np.float32(
            calc['settings']['INCAR']['SYMPREC']) * 10.
    return True
def notConverged(calc):
    presults = getResults(calc['parent'])
    error = False
    if 'convergence' not in presults.keys():
        return False
    else:
        #"convergence": [["Ehull", ["K", 0.01, [], 0]]] format, could add more than two els to each tuple to determine how to increase the settings and so on
        new = []
        for propset in presults['convergence']:
            total = len(propset)
            prop = propset[0]
            pnew = (prop,)
            for i in range(1,total):
                (crit,cond,current,converged) = propset[i]
                if converged == 1:
                    propset[i][-1] = 1
                    pnew += (tuple(propset[i]),)
                    continue;
                print('Checking ' + prop + ' convergence ' + ' with respect to ' + crit + '.')


                newval = gather({ prop  : ''})[prop]
                
                current.append(newval)
                
                if len(current) == 1:
                    error = True
                else:

                    delta = np.abs(current[-1] - current[-2])

                    if delta > cond:
                        print('Not converged. Remaining error of ' + str(delta) + ' on ' + prop + '.')
                        error = True
                    else:
                        print('Property ' + prop + ' is converged up to ' + str(delta) + '.')
                        if crit == 'K':
                            presults['settingsmod']['KPOINTS']['K'] = ' '.join([str(int(x) - 2) for x in presults['settingsmod']['KPOINTS']['K'].split(' ')])
                        elif crit == 'ENCUT':
                            presults['settingsmod']['INCAR']['ENCUT'] -= 100
                        converged = 1
                pnew += ((crit,cond,current,converged),)
            new.append(pnew)
   # presults['convergence'] = json.dumps(new).translate(str.maketrans({"'":  r"\'"}))
    updateResults(presults,calc['parent'])               
    return error
Esempio n. 8
0
def changeSmearInherit(calc):
    presults = getResults(calc['parent'])
    if 'settingsmod' not in presults.keys():
        presults['settingsmod'] = {"INCAR": {}}
    if 'INCAR' not in presults['settingsmod'].keys():
        presults['settingsmod']['INCAR'] = {}

    if presults['settingsmod'].get('INCAR').get('ISMEAR') != None:
        if presults['settingsmod'].get('INCAR').get('ISMEAR') == 0:
            presults['settingsmod']['INCAR']['ISMEAR'] = 1
            presults['settingsmod']['INCAR']['SIGMA'] = 0.2
        elif presults['settingsmod'].get('INCAR').get('ISMEAR') == 1:
            presults['settingsmod']['INCAR']['ISMEAR'] = 0
            presults['settingsmod']['INCAR']['SIGMA'] = 0.05
    else:
        if calc['settings']['INCAR']['ISMEAR'] == 0:
            presults['settingsmod']['INCAR']['ISMEAR'] = 1
            presults['settingsmod']['INCAR']['SIGMA'] = 0.2
        elif calc['settings']['INCAR']['ISMEAR'] == 1:
            presults['settingsmod']['INCAR']['ISMEAR'] = 0
            presults['settingsmod']['INCAR']['SIGMA'] = 0.05
    updateResults(presults, calc['parent'])
    return True
Esempio n. 9
0
step = int(np.ceil(float(cinfo['stat']) / 2))

# Configure settings per step
# By default always inherit
inheritcontcar = True
inheritchgcar = True
inheritwavecar = True
# Can define this by default, though I've added an if statement for each step anyways
inheritstep = step - 1
parent = HT.get(cinfo['parent'])
inheritmod = None
inheritgrid = False
rescale = 1.0

if parent['parent'] != '0':
    pparent = HT.getResults(parent['parent'])
    inheritmod = pparent.get('settingsmod')
    print('The following settingsmod will be inherited: ')
    print(inheritmod)

#==============================================================================
# In this section you can also make manual changes to the settings, for example:
# if int(qid) == 167 or int(qid) == 171:
#     cinfo['settings']['KPOINTS']['K'] = '12 12 12'
#     cinfo['settings']['INCAR']['NKRED'] = '2'
# cinfo['settings']['INCAR']['LSUBROT'] = '.TRUE.'
# if int(cfile) == 10025486:
#     cinfo['settings']['INCAR']['ALGO'] = 'A'
#     cinfo['settings']['INCAR']['NELM'] = 30
#     cinfo['settings']['INCAR']['TIME'] = 1.95
# if int(cfile) == 10031153:
Esempio 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
Esempio n. 11
0
def cont(calc):
    print('DEBUG: continue')
    baks = 0
    bako = 0
    bakx = 0
    bakt = 0
    bakv = 0

    for file in os.listdir(os.curdir):
        if os.path.isfile(file) and file[0:10] == 'POSCAR.bak':
            baks += 1
        if os.path.isfile(file) and file[0:10] == 'OUTCAR.bak':
            bako += 1
        if os.path.isfile(file) and file[0:11] == 'XDATCAR.bak':
            bakx += 1
        if os.path.isfile(file) and file[0:11] == 'tempout.bak':
            bakt += 1
        if os.path.isfile(file) and file[0:11] == 'vasprun.bak':
            bakv += 1

    if os.path.isfile('CONTCAR') and os.stat('CONTCAR').st_size > 0:
        os.rename('POSCAR', 'POSCAR.bak' + str(baks))
        os.rename('CONTCAR', 'POSCAR')
    if os.path.isfile('OUTCAR') and os.stat('OUTCAR').st_size > 0:
        os.rename('OUTCAR', 'OUTCAR.bak' + str(bako))
    if os.path.isfile('XDATCAR') and os.stat('XDATCAR').st_size > 0:
        os.rename('XDATCAR', 'XDATCAR.bak' + str(bakx))
    if os.path.isfile('tempout') and os.stat('tempout').st_size > 0:
        os.rename('tempout', 'tempout.bak' + str(bakt))
    if os.path.isfile('vasprun.xml') and os.stat('vasprun.xml').st_size > 0:
        os.rename('vasprun.xml', 'vasprun.bak' + str(bakv))

    psettings = manage.getSettings(calc['parent'])
    presults = manage.getResults(calc['parent'])

    if 'continued' not in psettings.keys():
        psettings['continued'] = 1
    else:
        psettings['continued'] += 1

    if presults.get('settingsmod') is not None:
        if presults['settingsmod'].get('KPOINTS') is not None and calc[
                'settings'].get('KPOINTS') is not None:
            if presults['settingsmod'].get('KPOINTS').get(
                    'K') is not None and calc['settings']['KPOINTS'].get(
                        'K') is not None:
                curkp = [
                    int(x) for x in calc['settings']['KPOINTS']['K'].split(' ')
                ]
                curmod = [
                    int(x)
                    for x in presults['settingsmod']['KPOINTS']['K'].split(' ')
                ]
                calc['settings']['KPOINTS']['K'] = ' '.join(
                    [str(curkp[x] + curmod[x]) for x in range(3)])

        if presults.get('settingsmod').get('INCAR') is not None:
            if presults.get('settingsmod').get('INCAR').get(
                    'ENCUT') is not None:
                calc['settings']['INCAR']['ENCUT'] = int(calc['settings']['INCAR']['ENCUT']) + \
                                                     presults['settingsmod']['INCAR']['ENCUT']
            if presults.get('settingsmod').get('INCAR').get(
                    'SIGMA') is not None:
                calc['settings']['INCAR']['SIGMA'] = presults['settingsmod'][
                    'INCAR']['SIGMA']

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

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

    manage.updateSettings(psettings, calc['parent'])
    manage.updateResults(presults, calc['parent'])

    return calc
Esempio n. 12
0
    while (ended == 0 and tries < 10):
        ended = HT.end(cid)
        tries = tries + 1
        print tries
        time.sleep(random.randint(10, 100))
    if (ended == 0):
        print('ERROR: I tried to end calculation ' + str(cid) + str(tries) +
              ' times, but no succes.')  #tries should always be 10
        HT.updateResults({'error': 'Ending calculation failed'}, cid)

    else:
        if status < 15:
            #os.remove('CHGCAR')
            os.remove('CHG')

        results = HT.getResults(cid)

        #could leave this out when working with QZP's

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

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

        energy = float(energy)

        Eatom = energy / numberofatoms
        results['Eatom'] = Eatom
Esempio n. 13
0
if 'error' in locals():
    HT.updateResults({'error':error}, cid)
elif energy=='' or not 'energy' in locals():
    HT.updateResults({'error':'Energy missing'}, cid)
    print('Energy missing! Error...')
elif not os.path.isfile('CHGCAR') and not os.path.isfile('CHG'):
    HT.updateResults({'error':'CHGCAR and CHG missing. VASP Error?'}, cid)
    print('CHGCAR/CHG missing. VASP Error?')
else:
    print('Energy OK. Ending calculation, deleting junk files and fetching results.')
    HT.end(cid)

    if status<19:
        os.remove('CHG')

    results = HT.getResults(cid)

    #could leave this out when working with QZP's

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

    energy = float(energy)

    if step == 1:
        results['E0PBE'] = energy
    else:
        results['E0HSE06'] = energy
        results['E0PBE'] = float(execute('grep \'energy  without entropy\'  ../STEP1/OUTCAR | tail -1 | awk \'{ print $4 }\''))
    cinfo['settings']['INCAR']['NKRED'] = '2'
cinfo['settings']['INCAR']['LSUBROT'] = '.TRUE.'
if int(cfile) == 10025486:
    cinfo['settings']['INCAR']['ALGO'] = 'A'
    cinfo['settings']['INCAR']['NELM'] = 30
    cinfo['settings']['INCAR']['TIME'] = 1.95
if int(cfile) == 10031153:
    cinfo['settings']['INCAR']['MAGMOM'] = '2*1.0000 2*-1.0000'

if int(cfile) == 10031210:
    cinfo['settings']['INCAR']['MAGMOM'] = '1. 1. -1. -1.'

parallelSetup(cinfo['settings'])
if os.getenv('VSC_INSTITUTE_CLUSTER') == 'muk':
    cinfo['settings']['INCAR']['NCORE'] = '16'
perror = HT.getResults(cinfo['parent'])
if perror.get('errors') != None:
    fixerrors(cinfo)
writeSettings(cinfo['settings'])
run()
finderrors(cinfo)
if os.path.isfile('STOPCAR'):
    os.remove('STOPCAR')

print('END STATUS ' + cinfo['stat'])

#UPDATE POTCAR INFO

POTCAR_version = execute('grep -a \'TITEL\' POTCAR | awk \'{ print $4 }\'')
cinfo['settings']['POTCAR'] = POTCAR_version.strip().replace('\n', ', ')