@ -18,12 +18,27 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# SOFTWARE.
from argparse import ArgumentParser
from pickle import dump , load
from pickle import dump , load
import numpy as np
import numpy as np
from sisl . io import fdfSileSiesta
default_args = dict (
# list of accepted input parameters
ACCEPTED_INPUTS = [
" infile " ,
" outfile " ,
" scf_xcf_orientation " ,
" ref_xcf_orientations " ,
" kset " ,
" kdirs " ,
" ebot " ,
" eset " ,
" esetp " ,
" parallel_solver_for_Gk " ,
" padawan_mode " ,
]
default_arguments = dict (
infile = None ,
infile = None ,
outfile = None ,
outfile = None ,
scf_xcf_orientation = np . array ( [ 0 , 0 , 1 ] ) ,
scf_xcf_orientation = np . array ( [ 0 , 0 , 1 ] ) ,
@ -41,18 +56,158 @@ default_args = dict(
padawan_mode = True ,
padawan_mode = True ,
)
)
# parser = ArgumentParser()
# parser.add_argument('--input' , dest = 'infile' , default=None , help = 'Input file name')
def read_fdf ( path ) :
# parser.add_argument('--output' , dest = 'outfile', default=None , help = 'Output file name')
""" It reads the simulation parameters, magnetic entities and pairs from the fdf.
# parser.add_argument('--kset' , dest = 'kset' , default = 2 , type=int , help = 'k-space resolution of Jij calculation')
Args :
# parser.add_argument('--kdirs' , dest = 'kdirs' , default = 'xyz' , help = 'Definition of k-space dimensionality')
path : string
# parser.add_argument('--ebot' , dest = 'ebot' , default = None , type=float, help = 'Bottom energy of the contour')
The path to the . fdf file
# parser.add_argument('--eset' , dest = 'eset' , default = 42 , type=int , help = 'Number of energy points on the contour')
# parser.add_argument('--eset-p' , dest = 'esetp' , default = 1000 , type=int , help = 'Parameter tuning the distribution on the contour')
# cmd_line_args = parser.parse_args()
Returns :
fdf_arguments : dict
The read input arguments from the fdf file
magnetic_entities : list
It contains the dictionaries associated with the magnetic entities
pairs : dict
It contains the dictionaries associated with the pair information
"""
# read fdf file
fdf = fdfSileSiesta ( path )
fdf_arguments = dict ( )
InputFile = fdf . get ( " InputFile " )
if InputFile is not None :
fdf_arguments [ " infile " ] = InputFile
OutputFile = fdf . get ( " OutputFile " )
if OutputFile is not None :
fdf_arguments [ " outfile " ] = OutputFile
ScfXcfOrientation = fdf . get ( " ScfXcfOrientation " )
if ScfXcfOrientation is not None :
fdf_arguments [ " scf_xcf_orientation " ] = np . array ( ScfXcfOrientation )
XCF_Rotation = fdf . get ( " XCF_Rotation " )
if XCF_Rotation is not None :
rotations = [ ]
# iterate over rows
for rot in XCF_Rotation :
# convert row to dictionary
dat = np . array ( rot . split ( ) [ : 9 ] , dtype = float )
o = dat [ : 3 ]
vw = dat [ 3 : ] . reshape ( 2 , 3 )
rotations . append ( dict ( o = o , vw = vw ) )
fdf_arguments [ " ref_xcf_orientations " ] = rotations
Kset = fdf . get ( " INTEGRAL.Kset " )
if Kset is not None :
fdf_arguments [ " kset " ] = Kset
Kdirs = fdf . get ( " INTEGRAL.Kdirs " )
if Kdirs is not None :
fdf_arguments [ " kdirs " ] = Kdirs
# This is permitted because it means automatic Ebot definition
fdf_arguments [ " ebot " ] = fdf . get ( " INTEGRAL.Ebot " )
Eset = fdf . get ( " INTEGRAL.Eset " )
if Eset is not None :
fdf_arguments [ " eset " ] = Eset
Esetp = fdf . get ( " INTEGRAL.Esetp " )
if Esetp is not None :
fdf_arguments [ " esetp " ] = Esetp
ParallelSolver = fdf . get ( " GREEN.ParallelSolver " )
if ParallelSolver is not None :
fdf_arguments [ " parallel_solver_for_Gk " ] = ParallelSolver
PadawanMode = fdf . get ( " PadawanMode " )
if PadawanMode is not None :
fdf_arguments [ " padawan_mode " ] = PadawanMode
Pairs = fdf . get ( " Pairs " )
if Pairs is not None :
pairs = [ ]
# iterate over rows
for fdf_pair in Pairs :
# convert data
dat = np . array ( fdf_pair . split ( ) [ : 5 ] , dtype = int )
# create pair dictionary
my_pair = dict ( ai = dat [ 0 ] , aj = dat [ 1 ] , Ruc = np . array ( dat [ 2 : ] ) )
pairs . append ( my_pair )
MagneticEntities = fdf . get ( " MagneticEntities " )
if MagneticEntities is not None :
magnetic_entities = [ ]
for mag_ent in MagneticEntities :
row = mag_ent . split ( )
dat = [ ]
for string in row :
if string . find ( " # " ) != - 1 :
break
dat . append ( string )
if dat [ 0 ] in { " Cluster " , " cluster " } :
magnetic_entities . append ( dict ( atom = [ int ( _ ) for _ in dat [ 1 : ] ] ) )
continue
elif dat [ 0 ] in { " AtomShell " , " Atomshell " , " atomShell " , " atomshell " } :
magnetic_entities . append (
dict ( atom = int ( dat [ 1 ] ) , l = [ int ( _ ) for _ in dat [ 2 : ] ] )
)
continue
elif dat [ 0 ] in { " AtomOrbital " , " Atomorbital " , " tomOrbital " , " atomorbital " } :
magnetic_entities . append (
dict ( atom = int ( dat [ 1 ] ) , orb = [ int ( _ ) for _ in dat [ 2 : ] ] )
)
continue
elif dat [ 0 ] in { " Orbitals " , " orbitals " } :
magnetic_entities . append ( dict ( orb = [ int ( _ ) for _ in dat [ 1 : ] ] ) )
continue
else :
raise Exception ( " Unrecognizable magnetic entity in .fdf! " )
return fdf_arguments , magnetic_entities , pairs
def process_input_args (
default_arguments ,
fdf_arguments ,
command_line_arguments ,
accepted_inputs = ACCEPTED_INPUTS ,
) :
""" It returns the final simulation parameters based on the inputs.
The merging is done in the order of priority :
1. command line arguments
2. fdf arguments
3. default arguments
Args :
default_arguments : dict
Default arguments from grogupy
fdf_arguments : dict
Arguments read from the fdf input file
command_line_arguments : dict
Arguments from the command line
Returns :
dict
The final simulation parameters
"""
# iterate over fdf_arguments and update default arguments
for key , value in fdf_arguments . values ( ) :
if value is not None and key in accepted_inputs :
default_arguments [ key ] = value
# iterate over command_line_arguments and update default arguments
for key , value in command_line_arguments . values ( ) :
if value is not None and key in accepted_inputs :
default_arguments [ key ] = value
return default_arguments
def save_pickle ( outfile , data ) :
def save_pickle ( outfile , data ) :
@ -89,6 +244,64 @@ def load_pickle(infile):
return data
return data
def print_job_description ( simulation_parameters ) :
""" It prints the parameters and the description of the job.
Args :
simulation_parameters : dict
It contains the simulations parameters
"""
print (
" ================================================================================================================================================================ "
)
print ( " Input file: " )
print ( simulation_parameters [ " infile " ] )
print ( " Output file: " )
print ( simulation_parameters [ " outfile " ] )
print (
" Number of nodes in the parallel cluster: " ,
simulation_parameters [ " parallel_size " ] ,
)
if simulation_parameters [ " parallel_solver_for_Gk " ] :
print ( " solver used for Greens function calculation: parallel " )
else :
print ( " solver used for Greens function calculation: sequential " )
print (
" ================================================================================================================================================================ "
)
print ( " Cell [Ang]: " )
print ( simulation_parameters [ " cell " ] )
print (
" ================================================================================================================================================================ "
)
print ( " DFT axis: " )
print ( simulation_parameters [ " scf_xcf_orientation " ] )
print ( " Quantization axis and perpendicular rotation directions: " )
for ref in simulation_parameters [ " ref_xcf_orientations " ] :
print ( ref [ " o " ] , " --» " , ref [ " vw " ] )
print (
" ================================================================================================================================================================ "
)
print ( " Parameters for the contour integral: " )
print ( " Number of k points: " , simulation_parameters [ " kset " ] )
print ( " k point directions: " , simulation_parameters [ " kdirs " ] )
if simulation_parameters [ " automatic_ebot " ] :
print (
" Ebot: " ,
simulation_parameters [ " ebot " ] ,
" WARNING: This was automatically determined! " ,
)
else :
print ( " Ebot: " , simulation_parameters [ " ebot " ] )
print ( " Eset: " , simulation_parameters [ " eset " ] )
print ( " Esetp: " , simulation_parameters [ " esetp " ] )
print (
" ================================================================================================================================================================ "
)
def print_parameters ( simulation_parameters ) :
def print_parameters ( simulation_parameters ) :
""" It prints the simulation parameters for the grogu out.
""" It prints the simulation parameters for the grogu out.
@ -255,61 +468,3 @@ def print_runtime_information(times):
print (
print (
f " Calculate energies and magnetic components: { times [ ' end_time ' ] - times [ ' green_function_inversion_time ' ] : .3f } s "
f " Calculate energies and magnetic components: { times [ ' end_time ' ] - times [ ' green_function_inversion_time ' ] : .3f } s "
)
)
def print_job_description ( simulation_parameters ) :
""" It prints the parameters and the description of the job.
Args :
simulation_parameters : dict
It contains the simulations parameters
"""
print (
" ================================================================================================================================================================ "
)
print ( " Input file: " )
print ( simulation_parameters [ " infile " ] )
print ( " Output file: " )
print ( simulation_parameters [ " outfile " ] )
print (
" Number of nodes in the parallel cluster: " ,
simulation_parameters [ " parallel_size " ] ,
)
if simulation_parameters [ " parallel_solver_for_Gk " ] :
print ( " solver used for Greens function calculation: parallel " )
else :
print ( " solver used for Greens function calculation: sequential " )
print (
" ================================================================================================================================================================ "
)
print ( " Cell [Ang]: " )
print ( simulation_parameters [ " cell " ] )
print (
" ================================================================================================================================================================ "
)
print ( " DFT axis: " )
print ( simulation_parameters [ " scf_xcf_orientation " ] )
print ( " Quantization axis and perpendicular rotation directions: " )
for ref in simulation_parameters [ " ref_xcf_orientations " ] :
print ( ref [ " o " ] , " --» " , ref [ " vw " ] )
print (
" ================================================================================================================================================================ "
)
print ( " Parameters for the contour integral: " )
print ( " Number of k points: " , simulation_parameters [ " kset " ] )
print ( " k point directions: " , simulation_parameters [ " kdirs " ] )
if simulation_parameters [ " automatic_ebot " ] :
print (
" Ebot: " ,
simulation_parameters [ " ebot " ] ,
" WARNING: This was automatically determined! " ,
)
else :
print ( " Ebot: " , simulation_parameters [ " ebot " ] )
print ( " Eset: " , simulation_parameters [ " eset " ] )
print ( " Esetp: " , simulation_parameters [ " esetp " ] )
print (
" ================================================================================================================================================================ "
)