FEDIT scripting examples

Set bandplot points

The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/fedit_use/setbandplot where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

setbandplot.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env python
# ===================================================================
# file:   bandplot.py
# author: k.koepernik@ifw-dresden.de
# date:   19 Apr 2017
from __future__ import print_function
import sys
import pyfplo.fedit as fedit
# ===================================================================
# 
# ===================================================================
def work():


    points=[
        ['$~G',[0,0,0]],
        ['X',[1,0,0]],
        ['M',[1,1,0]],
        ['$~G',[0,0,0]],
        ['Z',[0,0,1]],
        ]

    # IMPORTANT:
    # We only want to change bandplot settings in an existing/new =.in.
    # Hence, we set recreate=False, which DOES NOT resets non-symmetry input.
    fed=fedit.Fedit(recreate=False)
    fed.bandplot(active=True,points=points,weights=True,
                 interval=[2000,-1,1])
    fed.pipeFedit()
    
    
    return

# ===================================================================
# 
# ===================================================================

if __name__ == '__main__':

    work()
    
    sys.exit(0)




Simple fedit example

This example runs fplo for pre-prepared input until convergence, then switches on the bandplot option and re-runs to calculate the band structure. The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/fedit_use/simple where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

README

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Read the script to understand what it is doing.
It just demonstrates how one could use python to run things.
The fedit part is actually very minimal.

run simple.py as

  simple.py

then have a look what was created.


If pyfplo path needs to be set use wrapp.sh. First edit pyfplopath
in wrapp.sh and then just put it in front as in any of the following.

wrapp.sh simple.py

A wrapper to setup paths wrapp.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#! /usr/bin/env sh
#
# Example wrapper script for path setting.
#
########################################################################



# set your path here

pyfplopath=$HOME/FPLO/FPLO22.00-62/PYTHON/

export PYTHONPATH=$pyfplopath:$PYTHONPATH


$*

The python script simple.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env python
# ===================================================================
# file:   simple.py
# author: k.koepernik@ifw-dresden.de
# date:   06 Jun 2017
from __future__ import print_function
import sys
import os
import pyfplo.fedit as fedit

print( '\npyfplo version=: {0}\nfrom: {1}\n'.format(fedit.version,fedit.__file__))
# protect against wrong version
#if fedit.version!='22.00': raise RuntimeError('pyfplo version is incorrect.')

# ===================================================================
# 
# ===================================================================
def work():

    # rm old files
    os.system('rm +dos* +band +bweigh*')

    # get a Fedit instance
    fed=fedit.Fedit(recreate=False)
    # set  some stuff for the SCF run
    fed.bzintegration(nxyz=[6,6,6])

    # switch off bandplot (if already set) so that we do not
    # calculate unnecessary stuff during self consistency
    fed.bandplot(active=False)
    # write  input file
    fed.pipeFedit()

    # run fplo (SCF)
    os.system(fedit.fploExecutable()+"|tee outscf")


    # now we re-run for bandplot.
    # Note that we use the Fedit() from before
    fed.bandplot(active=True)
    fed.pipeFedit()
    os.system(fedit.fploExecutable()+"|tee outb")

    
    return

# ===================================================================
# 
# ===================================================================

if __name__ == '__main__':

    work()
    
    sys.exit(0)




BCC Iron

This example prepares fplo input and optionally runs the calculations. The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/fedit_use/bccFe where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

README

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Read the script to understand what it is doing.
It just demonstrates how one could use python to do things.
The fedit part is actually very small.

run simple.py as

  simple.py

then have a look what was created.
Now run

  simple.py -r -c

to do the calculations and collect the results.

Or just

  simple.py  -c

to only collect results (if there are any yet).

If pyfplo path needs to be set use wrapp.sh. First edit pyfplopath
in wrapp.sh and then just put it in front as in any of the following.

wrapp.sh simple.py
wrapp.sh simple.py  -r -c
wrapp.sh simple.py  -c

A wrapper to setup paths wrapp.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#! /usr/bin/env sh
#
# Example wrapper script for path setting.
#
########################################################################



# set your path here

pyfplopath=$HOME/FPLO/FPLO22.00-62/PYTHON/

export PYTHONPATH=$pyfplopath:$PYTHONPATH


$*

The python script simple.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#! /usr/bin/env python
#
# Example script to create a series of calculations for varying lattice
# constant for bcc Fe. 
# 
# 
########################################################################
from __future__ import print_function
import sys

# If your pyfplo is not found you could als
# explicitly specify the pyfplo version path:
#sys.path.insert(0,"/home/magru/FPLO/FPLO22.00-62/PYTHON/doc");

import os
from optparse import OptionParser
import numpy as np
import pyfplo.fedit as fedit


print( '\npyfplo version=: {0}\nfrom: {1}\n'.format(fedit.version,fedit.__file__))
# protect against wrong version
#if fedit.version!='22.00': raise RuntimeError('pyfplo version is incorrect.')

# ===================================================================
# 
# ===================================================================

def INPUT(n):
    if sys.version_info[0] == 3:
        return input(n)
    else:
        return raw_input(n)

# ===================================================================
# 
# ===================================================================

def work(fplo,runit=False):

    # sanity check
    if runit:
        if INPUT("Shall I run the jobs: [y/n]")!='y':
            print( "\nOK no running then.\n")
            sys.exit(0)
    else:
        if INPUT("Shall I (re)create the input: [y/n]")!='y':
            print( "\nOK, aborting.\n")
            sys.exit(0)
    

    # Give all directories a name prefixed with the name of the parameter,
    # which is running, followed by the parameter itself
    prefix='a0='

    # Remember the current directory.
    ROOT=os.getcwd()

    # loop over the running parameter, in our case the lattice constant

    for x in np.arange(4.4,6.01,0.4):
        # make sure we are in the root directory of our data directory tree
        os.chdir(ROOT)

        # create the directory name as described above (example 'a0=6.00')
        # Use explicit format for x to ensure 2 digits after the comma.
        
        dir='{0}{1}'.format(prefix,'{0:12.2f}'.format(x).strip())


        # input creation branch

        # if the directory does not yet exist, create it
        if not os.path.exists(dir):
            os.mkdir(dir)
            print( 'directory '+dir+' created')
        else:
            print( 'directory {0} exists allready'.format(dir))

        # change into the directory of paramter $xx
        os.chdir(dir)
        

        # do the fedit magic
        fed=fedit.Fedit()
        fed.resetPipeInput(recreate=True) # important
        fed.symmetry(compound="Fe, a0-variation",
                     spacegroup=229,
                     type='cry',
                     units='bohr',
                     latcon=[x,x,x],
                     angles=['90.']*3,
                     atoms=[['fe',[0,0,0]]],
        )
        fed.bzintegration([16,16,16])
        fed.vxc(version='5') # gga
        fed.relativistic('scalar')
        fed.spin(spin=2,initialspinsplit=1,initialspin=[[1,2.5]])
        fed.pipeFedit()

        # do we run the job?
        if runit: 

            print( fplo+" running in  "+dir+" ...")

            # now execute, whatever is nessecary to launch job in the current 
            # directory (dir)

            # START Example
            # We just run the jobs sequentially on a single machine
            # and redirect stdout to file 'out' and stderr to /dev/null.
            # (In this way there will be no dangling output and the job could
            # run savely in the background, which is not done in our example
            # here.)

            # Furthermore, we use the +yes-file mechanism to avoid a crash
            # due to repeated inital polarization (spin split).
            # The "y" below enforces fplo to continue in such situation 
            # without a repeated split and  does nothing otherwise. See manual.
            with open('+yes','w') as f:
                f.write('y')

            os.system('cat +yes | {0} 2>/dev/null > out'.format(fplo))
            # END Example

        # just in case
        os.chdir(ROOT)        
    # and of x-loop

    os.chdir(ROOT)

    # 
    # After the run we should have a directory structure like
    #
    # ./a0=4.40/
    # ./a0=4.80/
    # ./a0=5.20/
    # ./a0=5.60/
    # ./a0=6.00/
    # ./simple.py
    #
    # where every directory contains the same setup, except for the
    # lattice constant.
    # We may now perform converged calculations (option -r) in all directories.
    # If we want to change, say, the number of k-points, we edit this number
    # in the pipe-section above, re-run that script to change the input and 
    # re-converge the calculations (option -r).
    #


# ===================================================================
# 
# ===================================================================

def collect():

    # collect the results
    os.system("grepfplo -p 'a0=' -m EE | tee e")
    os.system("grepfplo -p 'a0=' -m SS | tee s")
    os.system("xfbp pic.cmd")
    
    
# ===================================================================
# 
# ===================================================================
if __name__ == "__main__":

    # Set an FPLO version, you need to set this according to your
    # needs, including possibly a path. Or you use option -p.
    # A guess for the default name:
    FPLO=fedit.fploExecutable()

    # scan command line options
    usage = "usage: %prog [-c] [-r] [-h] [-p fploexecname]"
    parser = OptionParser(usage)
    parser.add_option('-r','',action='store_true',dest='run',default=False,
                      help='force fplo run')
    parser.add_option('-c','',action='store_true',dest='collect',default=False,
                      help='collect results')
    parser.add_option('-p','',type='str',dest='fplo',default=FPLO,
                      help='optional: the name of an FPLO executable\n'+
                      'possibly with explicit path')
    (options, args) = parser.parse_args()

    # do the work
    if not options.collect or options.run:
        work(options.fplo,options.run)

    if options.collect:
        collect()

BCC and FCC Iron

A more complex example, preparing input and running fplo is shown here. Note, that we run sequentially. If you have a job queueing system you need to modify the script accordingly. The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/fedit_use/Fe where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

README

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Read the script to understand what it is doing.
It just demonstrates how one could use python to do things.
The fedit part is actually very small.

run notsosimple.py as

  notsosimple.py

then have a look what was created.
Now run

  notsosimple.py -r -c

to do the calculations and collect the results.

Or just

  notsosimple.py  -c

to only collect results (if there are any yet).

If pyfplo path needs to be set use wrapp.sh. First edit pyfplopath
in wrapp.sh and then just put it in front as in any of the following.

wrapp.sh notsosimple.py
wrapp.sh notsosimple.py  -r -c
wrapp.sh notsosimple.py  -c

A wrapper to setup paths wrapp.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#! /usr/bin/env sh
#
# Example wrapper script for path setting.
#
########################################################################



# set your path here


pyfplopath=$HOME/FPLO/FPLO22.00-62/PYTHON

export PYTHONPATH=$PYTHONPATH:$pyfplopath


$*

The python script notsosimple.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#! /usr/bin/env python
#
# Example script to create a series of calculations for varying lattice
# constant for bcc and fcc Fe. 
# 
# 
########################################################################
from __future__ import print_function
import sys
# If your pyfplo is not found you could als
# explicitly specify the pyfplo version path:
#sys.path.insert(0,"/home/magru/FPLO/FPLO22.00-62/PYTHON/doc");

import os
from optparse import OptionParser
import numpy as np
import pyfplo.fedit as fedit
import pyfplo.fploio as fploio

print( '\npyfplo version=: {0}\nfrom: {1}\n'.format(fedit.version,fedit.__file__))
# protect against wrong version
#if fedit.version!='22.00': raise RuntimeError('pyfplo version is incorrect.')


# ===================================================================
# 
# ===================================================================

def makeInput(a0,structure,vxc,spin):

    if structure=='bcc':
        group=229
    elif structure=='fcc':
        group=225

    if vxc=='lda':
        xc='4'
    elif vxc=='gga':
        xc='5'
        
    fed=fedit.Fedit()
    fed.resetPipeInput(recreate=True) # important
    fed.symmetry(compound="Fe, a0-variation",
                 spacegroup=group,
                 type='cry',
                 units='bohr',
                 latcon=[a0]*3,
                 angles=['90.']*3,
                 atoms=[['fe',[0,0,0]]],
    )
    fed.bzintegration([12,12,12])
    fed.vxc(version=xc)
    fed.relativistic('scalar')
    fed.spin(spin=spin,initialspinsplit=1,initialspin=[[1,2.5]])
    fed.pipeFedit()
    


# ===================================================================
# 
# ===================================================================

def work(fplo,structure,vxc,spin,runit=False):


    # Give all directories a name prefixed with the name of the parameter,
    # which is running, followed by the parameter itself
    prefix='V='

    # Remember the current directory.
    ROOT=os.getcwd()

    # loop over the running parameter, in our case the lattice constant (volume)

    vvs=np.arange(60.,90.001,3)
    if structure=='bcc':
        nsite=2
    else:
        nsite=4

    spdir='NSP' if spin==1 else 'SP'
    basedir=vxc+'/'+structure+'/'+spdir
        
    for v in vvs:

        x=(v*nsite)**(1./3)
        
        # make sure we are in the root directory of our data directory tree
        os.chdir(ROOT)

        # create the directory name as described above (example 'V=60.00')
        # Use explicit format for x to ensure 2 digits after the comma.
        # This of course depends on the actual values.

        dir='{2}/{0}{1}'.format(prefix,'{0:12.2f}'.format(v).strip(),
                                        basedir)


        # input creation branch

        # if the directory does not yet exist, create it
        if not os.path.exists(dir):
            os.makedirs(dir);
            print( 'directory '+dir+' created')

        # change into the directory of paramter v
        os.chdir(dir)
        

        # make input
        makeInput(x,structure,vxc,spin)

        # do we run the job?
        if runit: 

            print( fplo+" running in  "+dir+" ...")

            # now execute, whatever is nessecary to launch job in the current 
            # directory (dir)

            # START Example
            # We just run the jobs sequentially on a single machine
            # and redirect stdout to file 'out' and stderr to /dev/null.
            # (In this way there will be no dangling output and the job could
            # run savely in the background, which is not done in our example
            # here.)

            # Furthermore, we use the +yes-file mechanism to avoid a crash
            # due to repeated inital polarization (spin split).
            # The "y" below enforces fplo to continue in such situation 
            # without a repeated split and  does nothing otherwise. See manual.
            with open('+yes','w') as f:
                f.write('y')

            os.system('cat +yes | {0} 2>/dev/null > out'.format(fplo))
            # END Example



        # just in case
        os.chdir(ROOT)        
    # and of x-loop

    os.chdir(ROOT)

    if runit:
        os.chdir(basedir)
        os.system("grepfplo -p 'V=' -m EE | tee e".format(prefix))
        os.system("grepfplo -p 'V=' -m SS | tee s".format(prefix))
        os.chdir(ROOT)



# ===================================================================
# 
# ===================================================================

def collect():

    # collect the results
    os.system("xfbp pic.cmd")


# ===================================================================
# 
# ===================================================================

def INPUT(n):
    if sys.version_info[0] == 3:
        return input(n)
    else:
        return raw_input(n)
    
# ===================================================================
# 
# ===================================================================
if __name__ == "__main__":

    # Set an FPLO version, you need to set this according to your
    # needs, including possibly a path. Or you use option -p.
    # A guess for the default name:
    FPLO=fploio.fploExecutable()

    # scan command line options
    usage = "usage: %prog [-c] [-r] [-h] [-p fploexecname]"
    parser = OptionParser(usage)
    parser.add_option('-r','',action='store_true',dest='run',default=False,
                      help='force fplo run')
    parser.add_option('-c','',action='store_true',dest='collect',default=False,
                      help='collect results')
    parser.add_option('-p','',type='str',dest='fplo',default=FPLO,
                      help='optional: the name of an FPLO executable\n'+
                      'possibly with explicit path')
    (options, args) = parser.parse_args()

    # sanity check
    if (not options.collect) and options.run:
        if INPUT("Shall I run the jobs: [y/n]")!='y':
            print( "\nOK no running then.\n")
            sys.exit(0)
    elif (not options.collect) and  (not options.run):
        if INPUT("Shall I (re)create the input: [y/n]")!='y':
            print( "\nOK, aborting.\n")
            sys.exit(0)
    

    # do the work
    if not options.collect or options.run:
        for structure in ['bcc','fcc']:
            for vxc in ['lda','gga']:
                for spin in [1,2]:
                    if structure=='fcc' and spin==2: continue
                    work(options.fplo,structure,vxc,spin,options.run)
                    
    if (not options.collect) and options.run:
        print( '\nTo show results rerun with option -c.')
        print( 'To rerun (shorter output files) rerun -r or -r -c.\n')

    if (not options.collect) and  (not options.run):
        print( '\nTo calculate run with option -r or -r -c\n')
        
    if options.collect:
        collect()

Set Extended basis

To simply switch on an extended basis (as was used in some fplo publications) use the following example as orientation (the actual code is three lines) The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/set_extended_basis where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

README

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
Read the script to understand what it is doing.
It just demonstrates how one can set an extended basis  
in an existing =.in.

run extended_basis.py as

  extended_basis.py

then have a look at =.in via fedit.


If pyfplo path needs to be set use wrapp.sh. First edit pyfplopath
in wrapp.sh and then just put it in front as in any of the following.

wrapp.sh extended_basis.py

A wrapper to setup paths wrapp.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#! /usr/bin/env sh
#
# Example wrapper script for path setting.
#
########################################################################



# set your path here

pyfplopath=$HOME/FPLO/FPLO22.00-62/PYTHON/

export PYTHONPATH=$pyfplopath:$PYTHONPATH


$*

The python script extended_basis.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#! /usr/bin/env python
# ===================================================================
# file:   extended_basis.py
# author: k.koepernik@ifw-dresden.de
# date:   06 Jun 2017
from __future__ import print_function
import sys
import os
import pyfplo.fedit as fedit

print( '\npyfplo version=: {0}\nfrom: {1}\n'.format(fedit.version,fedit.__file__))
# protect against wrong version
#if fedit.version!='22.00': raise RuntimeError('pyfplo version is incorrect.')

# ===================================================================
# 
# ===================================================================
def work():
    # Get an Fedit instance:
    # We eant to change the basis in an existing =.in so recreate=False !!
    fed=fedit.Fedit(recreate=False)
    # Set extensionlevel=2 and add H-3d and f-orbital if needed and
    # leave the rest as it is:
    fed.basis(extensionlevel=2,add3d=True,addf=True)
    # If the rest of the basis menu should be reset to default use:
    fed.basis(extensionlevel=2,add3d=True,addf=True,
              multicore=[],multisemicore=[],
              core4f=[],core4fNoValenceF=[])
    
    fed.pipeFedit(prot=True)
    return

# ===================================================================
# 
# ===================================================================

if __name__ == '__main__':

    work()
    
    sys.exit(0)




BCC Iron, extended basis

This example prepares fplo input and optionally runs the calculations to show the influence of an extended basis. The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/fedit_use/bccFe_extended_basis where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

README

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Read the script to understand what it is doing.
It just demonstrates how to use pyfplo.fedit to
choose the basis.

run extbasis.py as

  extbasis.py

then have a look what was created.
Now run

  extbasis.py -r -c

to do the calculations and collect the results.

Or just

  extbasis.py  -c

to only collect results (if there are any yet).

If pyfplo path needs to be set use wrapp.sh. First edit pyfplopath
in wrapp.sh and then just put it in front as in any of the following.

wrapp.sh extbasis.py
wrapp.sh extbasis.py  -r -c
wrapp.sh extbasis.py  -c

A wrapper to setup paths wrapp.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#! /usr/bin/env sh
#
# Example wrapper script for path setting.
#
########################################################################



# set your path here

pyfplopath=$HOME/FPLO/FPLO22.00-62/PYTHON/

export PYTHONPATH=$pyfplopath:$PYTHONPATH


$*

The python script extbasis.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#! /usr/bin/env python
#
# Example script to create a series of calculations for varying lattice
# constant for bcc Fe. 
# 
# 
########################################################################
from __future__ import print_function
import sys

# If your pyfplo is not found you could als
# explicitly specify the pyfplo version path:
#sys.path.insert(0,"/home/magru/FPLO/FPLO22.00-62/PYTHON/doc");

import os
from optparse import OptionParser
import numpy as np
import pyfplo.fedit as fedit


print( '\npyfplo version=: {0}\nfrom: {1}\n'.format(fedit.version,fedit.__file__))
# protect against wrong version
#if fedit.version!='22.00': raise RuntimeError('pyfplo version is incorrect.')

# ===================================================================
# 
# ===================================================================

def INPUT(n):
    if sys.version_info[0] == 3:
        return input(n)
    else:
        return raw_input(n)

# ===================================================================
# 
# ===================================================================

def work(fplo,bases,runit=False):

    # sanity check
    if runit:
        if INPUT("Shall I run the jobs: [y/n]")!='y':
            print( "\nOK no running then.\n")
            sys.exit(0)
    else:
        if INPUT("Shall I (re)create the input: [y/n]")!='y':
            print( "\nOK, aborting.\n")
            sys.exit(0)
    

    # Give all directories a name prefixed with the name of the parameter,
    # which is running, followed by the parameter itself
    prefix='a0='

    # Remember the current directory.
    ROOT=os.getcwd()

    # loop over the running parameter, in our case the lattice constant

    for bas in bases:
        os.chdir(ROOT)

        if not os.path.exists(bas): os.mkdir(bas)
        os.chdir(bas)
        
        for x in np.arange(4.4,6.01,0.4):
            # make sure we are in the root directory of our data directory tree

            # create the directory name as described above (example 'a0=6.00')
            # Use explicit format for x to ensure 2 digits after the comma.

            dir='{0}{1}'.format(prefix,'{0:12.2f}'.format(x).strip())


            # input creation branch

            # if the directory does not yet exist, create it
            if not os.path.exists(dir):
                os.mkdir(dir)
                print( 'directory '+dir+' created')
            else:
                print( 'directory {0} exists allready'.format(dir))

            # change into the directory of paramter $xx
            os.chdir(dir)


            # do the fedit magic
            fed=fedit.Fedit()
            fed.resetPipeInput(recreate=True) # important
            fed.symmetry(compound="Fe, a0-variation",
                         spacegroup=229,
                         type='cry',
                         units='bohr',
                         latcon=[x,x,x],
                         angles=['90.']*3,
                         atoms=[['fe',[0,0,0]]],
            )
            fed.bzintegration([16,16,16])
            fed.vxc(version='5') # gga
            fed.relativistic('scalar')
            if bas=='DT+f':
                fed.basis(extensionlevel=2,addf=True,add3d=True)
            fed.spin(spin=2,initialspinsplit=1,initialspin=[[1,2.5]])
            fed.pipeFedit()

            # do we run the job?
            if runit: 

                print( fplo+" running in  "+dir+" ...")

                # now execute, whatever is nessecary to launch job in the current 
                # directory (dir)

                # START Example
                # We just run the jobs sequentially on a single machine
                # and redirect stdout to file 'out' and stderr to /dev/null.
                # (In this way there will be no dangling output and the job could
                # run savely in the background, which is not done in our example
                # here.)

                # Furthermore, we use the +yes-file mechanism to avoid a crash
                # due to repeated inital polarization (spin split).
                # The "y" below enforces fplo to continue in such situation 
                # without a repeated split and  does nothing otherwise. See manual.
                with open('+yes','w') as f:
                    f.write('y')

                os.system('cat +yes | {0} 2>/dev/null > out'.format(fplo))
                # END Example

            # just in case
            os.chdir(ROOT)
            os.chdir(bas)        
        # and of x-loop
    # and of bas-loop

    os.chdir(ROOT)

    # 
    # After the run we should have a directory structure like
    #
    # ./a0=4.40/
    # ./a0=4.80/
    # ./a0=5.20/
    # ./a0=5.60/
    # ./a0=6.00/
    # ./simple.py
    #
    # where every directory contains the same setup, except for the
    # lattice constant.
    # We may now perform converged calculations (option -r) in all directories.
    # If we want to change, say, the number of k-points, we edit this number
    # in the pipe-section above, re-run that script to change the input and 
    # re-converge the calculations (option -r).
    #


# ===================================================================
# 
# ===================================================================

def collect(bases):

    # collect the results
    ROOT=os.getcwd()
    for bas in bases:
        os.chdir(ROOT)
        os.chdir(bas)
        os.system("grepfplo -p 'a0=' -m EE | tee e")
        os.system("grepfplo -p 'a0=' -m SS | tee s")
        
    os.chdir(ROOT)
    os.system("xfbp pic.xpy")
    
    
# ===================================================================
# 
# ===================================================================
if __name__ == "__main__":

    # Set an FPLO version, you need to set this according to your
    # needs, including possibly a path. Or you use option -p.
    # A guess for the default name:
    FPLO=fedit.fploExecutable()

    # scan command line options
    usage = "usage: %prog [-c] [-r] [-h] [-p fploexecname]"
    parser = OptionParser(usage)
    parser.add_option('-r','',action='store_true',dest='run',default=False,
                      help='force fplo run')
    parser.add_option('-c','',action='store_true',dest='collect',default=False,
                      help='collect results')
    parser.add_option('-p','',type='str',dest='fplo',default=FPLO,
                      help='optional: the name of an FPLO executable\n'+
                      'possibly with explicit path')
    (options, args) = parser.parse_args()


    bases=['def','DT+f']
    # do the work
    if not options.collect or options.run:
        work(options.fplo,bases,options.run)

    if options.collect:
        collect(bases)

mBJ XC-potential

This example prepares fplo input and optionally runs the calculations to show the influence of an extended basis on the gap-results for the mBJ XC-potential. The tutorial files are in FPLO.../DOC/pyfplo/Examples/fploio/fedit_use/mBJ where FPLO... stands for your version’s FPLO directory, e.g. FPLO21.00-61. Here are the files of this directory:

README

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
This example illustrates the use of fedit, mBJ-xc-potential,
an extended basis and pyfplo.fploio.OutGrep. It wi

to only create the input run as

    mbj.py
    
run the calculations serially ( you need to modify to run on batch systems)

    mbj.py -r

if done collect results like so

    mbj.py -c



If pyfplo path needs to be set use wrapp.sh. First edit pyfplopath
in wrapp.sh and then just put it in front as in any of the following.

wrapp.sh mbj.py -r

wrapp.sh mbj.py -c


A wrapper to setup paths wrapp.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#! /usr/bin/env sh
#
# Example wrapper script for path setting.
#
########################################################################



# set your path here

pyfplopath=$HOME/FPLO/FPLO22.00-62/PYTHON/

export PYTHONPATH=$pyfplopath:$PYTHONPATH


$*

The python script mbj.py

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#! /usr/bin/env python3
# ===================================================================
# file:   mbj.py
# author: k.koepernik@ifw-dresden.de
# date:   30 Jun 2022

from __future__ import print_function
import sys,os
import numpy as np
import argparse
import pyfplo.fedit as fedit
import pyfplo.fploio as fploio

ROOT=os.getcwd()
FPLO=fedit.fploExecutable()
# ===================================================================
# 
# ===================================================================
def mkdir(dir):
    if not os.path.exists(dir): os.mkdir(dir)
    return dir

# ===================================================================
# 
# ===================================================================
def work(basis,xcfunctionals,cases,options):

    os.chdir(ROOT)

    
    for case in cases:
        comp=case['compound']
        a0=case['a0']
        b0=case['b0'] if 'b0' in case else a0
        c0=case['c0'] if 'c0' in case else a0
        setting=case['setting'] if 'setting' in case else None
        rel=case['rel'] if 'rel' in case else 'S'
        spin=case['spin'] if 'spin' in case else 1
        initialspin=(case['initialspin'] if 'initialspin' in case
                     else None)
            

        os.chdir(ROOT)
        dir=mkdir(dir='{comp}'.format(comp=comp))
        for bas in basis:
            dir=mkdir('{comp}/{bas}'.format(comp=comp,bas=bas))
            for xc in xcfunctionals:
                dir=mkdir('{comp}/{bas}/{xc}'
                          .format(comp=comp,bas=bas,xc=xc[1]))
                os.chdir(dir)

                if(not options.collect):
                    fed=fedit.Fedit(recreate=True)
                    fed.symmetry(spacegroup=case['spgr'],
                                 setting=setting,
                                 latcon=[a0,b0,c0],
                                 units='ang',
                                 atoms=case['atoms'])
                    fed.spin(spin=spin,initialspinsplit=True,
                             initialspin=initialspin,
                             fsm=[True if spin==2 else False,0])
                    fed.vxc(version=xc[0])
                    fed.relativistic(mode=rel)
                    if bas=='DT+f':
                        fed.basis(extensionlevel=2,
                                  addf=True,add3d=True)
                    fed.pipeFedit()

                if(options.run):
                    print('running {} in {}'.format(FPLO,dir))
                    with open('+yes','w') as fh:
                        fh.write('y\ny\ny\ny\n')
                    os.system('cat +yes | {} > out '.format(FPLO))
                
                if(options.collect):
                    og=fploio.OutGrep('out')
                    try:
                        gap=float(og.grep('gap')[-1])
                    except:
                        gap=-1e6
                    print(('{comp:<12s} {bas:<10s} {xc:<12s} '+
                           '{gap:10.3f} eV    last dev={it}')
                          .format(comp=comp,bas=bas,xc=xc[1],gap=gap,
                                  it=og.grep('it')[-1]))
                os.chdir(ROOT)
    return
# ===================================================================
# 
# ===================================================================
def options():
    parser = argparse.ArgumentParser(description='',
                                     conflict_handler='resolve',
                                     epilog="")
    parser.add_argument('-c', '--collect',dest='collect',
                        action='store_true',
                        help='',default=False)
    parser.add_argument('-r', '--run',dest='run',action='store_true',
                        help='',default=False)
    args = parser.parse_args()
    return args
# ===================================================================
# 
# ===================================================================

if __name__ == '__main__':
    args=options()
    
    work(basis=['def','DT+f'],
         xcfunctionals=[['4','PW92'],['9','mBJLDAc']],
         cases=[{'compound':'C','spgr':'227','a0':3.567,
                 'atoms':[['C',['1/8','1/8','1/8']]],'rel':'S'},
                 {'compound':'CaF2','spgr':'225','a0':5.462,
                  'atoms':[['Ca',['0','0','0']],
                           ['F',['1/4','1/4','1/4']]],'rel':'S'},
                {'compound':'AlAs','spgr':'216','a0':5.6620,
                 'atoms':[['Al',['0','0','0']],
                          ['As',['1/4','1/4','1/4']]],'rel':'F'},
                {'compound':'HfS2','spgr':'164',
                 'a0':3.631,'c0':5.841,
                 'atoms':[['Hf',['0','0','0']],
                          ['S',['1/3','2/3','1/4']]],'rel':'F'},
                {'compound':'NiO','spgr':'166','setting':'E',
                 'a0':np.sqrt(0.5)*4.176,'c0':np.sqrt(12.)*4.176,
                 'atoms':[['Ni',['0','0','0']],
                          ['Ni',['0','0','1/2']],
                          ['O',['0','0','1/4']]],
                 'spin':2,'initialspin':[[1,4],[2,-4],[3,0]]},
         ]
         ,options=args
         )
    sys.exit(0)