Tutorials
This part of the project documentation focuses on examples usage of EStA.
General related¶
- Read
xyzfile data.
Example
#import esta.general.aadhaar as aadh [this also works]
#aad = aadh.Aadhaar()
from esta import Xat # import Xat class
Xat.read_xyz(filename='x.xyz')
- Substitution of atoms by other atom or gp of atoms.
Example
import glob
import esta.general.substitute_atom as substitute
atomid = 10
xyzfile = 'path_0000.xyz'
xyz_subs_file = 'methyl.xyz' # taken from lib_xyz in esta
# atomid = 62
# xyzfile = 'de_SUB_path_all_all.xyz'
# xyz_subs_file = 'H.xyz'
atom_id_subs = 1 #Generally.. C-atom Must be the first atom in the substituent
part
print('list of files: {}'.format(xyzfile))
substitute.substitute_atom_by_atoms(atomid=atomid, atom_id_subs=atom_id_subs,\
xyzfile=xyzfile, xyz_subs_file=xyz_subs_file)
- Read
poscarfile data.
Example
import esta.vaspBag.inout.crystal_lattice as clatt
xlatt = clatt.Crystal_Lattice("POSCAR", ''./)
# or xlatt=clatt.CrystalLattice()
xlatt.read_poscar()
print('atomic positions: {}'.format(xlatt.tau_cartesian))
print('atomic positions in crystal coordinates: {}'.format(xlatt.tau_direct))
xlatt.get_cell_matrix
#array([[7.35205746, 0. , 0. ],
# [3.67602873, 6.36706853, 0. ],
# [3.67602873, 2.12235618, 6.00292978]])
xlatt.get_cell_vectors
#(array([7.35205746, 0. , 0. ]),
# array([3.67602873, 6.36706853, 0. ]),
# array([3.67602873, 2.12235618, 6.00292978]))
xlatt.LV1
#array([7.35205746, 0. , 0. ])
xlatt.LV3
#array([3.67602873, 2.12235618, 6.00292978])
xlatt.real_volume
#281.0034678144921 in A^3
# print each atom type
xlatt.get_each_atm_type
#[1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
# print no. of atoms of each type
xlatt.get_natm_type
#array([ 4, 4, 14])
*Similary other method of the xlatt object can be excessed; currently all available methods are:*
# 'atm_type', 'each_atm_type', 'filename', 'get_all_atoms_labels', 'get_atm_type', 'get_cell_matrix',
# 'get_cell_vectors', 'get_dispPOSCAR', 'get_each_atm_type', 'get_grouped_list', 'get_natm_type',
# 'get_neach_type', 'get_poscar', 'get_rVolume', 'get_reciprocal_lattice', 'get_selectivePOSCAR',
# 'get_unique_list', 'is_cartesian', 'is_crystal', 'is_selective_dynamics', 'l_SelectDynamics',
# 'l_crystal', 'location', 'natm_type', 'natoms', 'read_poscar', 'real_volume', 'reciprocal_lattice',
# 'tau_cartesian', 'tau_cartestain', 'tau_direct', 'to_cartesian', 'to_crystal'
- Rename_files_using_index_for_ANY (collection of xyz or poscar files).
Example
import glob
import esta.general.rename_general as rename
#files = glob.glob("SUB_de_SUB*.xyz")
files = glob.glob("rlx*.xyz")
#--for keeping part of the file--for example: [0,-2] part is kept ; last part is removed
first_index=False # if false mean 2nd index is also taken!
str_indx = [0,-2] #,[4,-2]] # for first_index = False
#str_indx = [[0,-2] ,[4,-2]] # ALSO can be used**
#--for removing begining part of the file--for example: [0,3]; this part is removed; last is kept
#first_index=True
#str_indx = [0,3] # for first index=True
for ifile in files:
print('ifile is: {}'.format(ifile))
rename.to_file_any(ifile, str_indx, first_indx_only=first_index, file_extension='xyz') #POSCAR' )
VASP related¶
- Create input file for the vasp calculations.
Example
import esta.vaspBag.vaspin as vaspin
vaspobj = vaspin.vasp()
vaspobj.get_vasp_input(poscar_name='POSCAR')
- Create supercell from the input POSCAR
Example
from esta.general import operation as op
from esta import Xlat
poscar_files = glob.glob('*POSCAR')
for poscar_file in poscar_files:
pos_obj = Xlat(poscar_file)
obj = op.Transform(pos_obj)
obj.get_supercell_([1,1,2]) # 1x1x2 Supercell creation
print('get sposcar:')
obj.get_sposcar_('S_'+str(poscar_file))
- Create POSCAR with selective tags
Example
import numpy as np
import glob
import esta.vaspBag.inout.crystal_lattice as clatt
import esta.general.aadhaar as aad
aad_obj = aad.Aadhaar()
filename= 'Ir111.vasp'
fix_atoms_list = ['1-8'] #,'30','8','29']
fix_direction = 'xyz' # 'z' # 'xy'
files = glob.glob(filename)
for posfile in files:
xlatt = clatt.CrystalLattice(posfile)
xlatt.read_poscar()
pos=xlatt.tau_cartesian
symb, _, _ = xlatt.get_all_atoms_labels()
natom = xlatt.natoms
lv1 = xlatt.LV1
lv2 = xlatt.LV2
lv3 = xlatt.LV3
fle ="_".join( i for i in posfile.split("_")[0:-1] ) + str('POSCAR')
xlatt.get_selectivePOSCAR_adv(ldisp=True, disp_atoms_num=fix_atoms_list,\
fix_direction=fix_direction, outfile='fix_'+str(fle))
- Get forces, and poscar from the vasp xml
Example
import esta
from esta.vaspBag.inout import crystal_lattice as clatt
from esta.general import aadhaar
from esta.vaspBag.inout import xml_vasp_adv
import numpy as np
aad = aadhaar.Aadhaar()
print ("")
print ('***********************************************')
print ("reading forces from vasprun.xml file ...")
out_xmla = xml_vasp_adv.read_vasp_xml('vasprun.xml')
celll = out_xmla[0]
position_scaled = out_xmla[1]
symbol= out_xmla[2]
forces = out_xmla[-1]
print("forces are: ")
forc = []
for j in range(np.shape(forces)[0]):
print(("{0:9.6f} {1:9.6f} {2:9.6f} {3:6.4f}".format( forces[j][0],\
forces[j][1], forces[j][2], np.linalg.norm(forces[j]))))
forc.append(np.linalg.norm(forces[j]))
print("Lattice vectors/Cell:")
print(celll)
print("positions in scaled coordinates:")
print(position_scaled)
aad.get_poscar(out_xmla[0], out_xmla[1], out_xmla[2], 'vaspxml')
- Read POSCARs for reactants and products in a reaction and generate intermediate structures.
Example
import numpy as np
from esta.vaspBag.inout.crystal_lattice import CrystalLattice
import esta.general.get_configs as get_configs
output = CrystalLattice(filename = 'ach3oh_00_POSCAR', location = "./")
output.get_poscar()
atompositions = output.tau_cartesian
output2 = CrystalLattice(filename = 'cxyz_POSCAR', location = "./")
output2.get_poscar()
poscar_obj2 = output2 #.get_poscar()
atompositions2 = output2.tau_cartesian
N = 9
configurations = get_configs.get_atomic_configurations(N, atompositions, atompositions2)
print(configurations[1])
get_configs.get_poscar_images(N, poscar_obj, poscar_obj2)
Quanutm-Espresso related¶
- Create qe input file for QE calculations with option 1*
Example
import glob
import esta.qeBag.gen_qeinput_advv as gen_qeinput
ps_info = ('pbesol', '_v1.*')
posfiles=glob.glob('*POSCAR')
for ifile in posfiles:
gen_qeinput.get_qe_input(ifile, ps_info, lprint_cell ='angstrom',\
cal_type='vc-relax', lcopy_pseudo=True, l_pseudo_GVRB=True)
- Create qe input file for QE calculations with option2:
Example
import glob
import esta.qeBag.gen_qeinput_advv as gen_qeinput
#location = '~/pslibrary.1.0.0'
ps_info = (
# 'pbesol', '-*rrkjus_*',
# 'pbesol', '-*kjpaw_*',
'pbe', '-*kjpaw_*',
)
cal_type = 'relax'
# scf
# vc-relax
poscar_files = '1POSCAR'
qe_parameters = \
{
'&CONTROL': {
'calculation': cal_type,
'restart_mode': 'from_scratch',
'prefix': 'ir',
'nstep': 400,
'max_seconds': 386000,
'pseudo_dir': './',
'outdir': './tmp',
'tstress': '.true.',
'tprnfor': '.true.',
'verbosity': 'low',
},
'&SYSTEM': {
# 'ecutwfc': 60.0,
# 'ecutrho': 240.0,
},
'&ELECTRONS': {
"electron_maxstep" : 400,
#"conv_thr" : '1.0d-8',
"mixing_beta" : 0.3,
#"diagonalization" :"cg",
},
'&IONS': {
'ion_dynamics': 'bfgs'
},
'&CELL': {
'cell_dynamics': 'bfgs',
#"press_conv_thr" :'1.0d',
# ! cell_dofree ='volume',!'2Dxy', shape
#"cell_dofree" : 'shape', #'z', #'volume', #!'2Dxy',
# shape --shape keeps vol fixed and changes
# lattce param ; 'z'--> only the z component
# of axis 3 (v3_z) is moved
},
# 'K_POINTS': {
# 'k-grid': [1, 1, 8, # k-grid
# 0, 0, 0,], # shift
# # 'k-grid': 'gamma',
# }
}
posfiles=glob.glob(poscar_files)
for ifile in posfiles:
qe_parameters["&CONTROL"]['outdir'] += "_"+str(ifile)
qe_parameters["&CONTROL"]['prefix'] += '_'+str(ifile)
gen_qeinput.get_qe_input2(ifile, ps_info, qe_parameters,
kwargs=None, lprint_cell ='angstrom',
cal_type=cal_type, lcopy_pseudo=True)
- Generate displacements from atomic positions in the poscar for vibrational calculations.
Example
import numpy as np
import esta
import esta.phonon.atm_displacements_selective_general_disp as atmdisp
print('generating postion* files for displacement of selected atoms')
qe_part_file='qe_part' #<-------not need to get poscar file s........MAKE It better ....TODO
posfile='fix_3_init_bi_POSCAR' #fix_rlx_3_4c_1_1e_POSCARPOSCAR'
delta_x = 0.02 # ang
atmdisp.gen_disp(posfile, qe_part_file, delta_x)
- Get the electronic band gap from qe xml file
Example
import numpy as np
import glob
from esta import cf
import esta.qeBag.band_gap_xml as band_gap
xmls=glob.glob("*.xml")
for xmlfile in xmls:
egap, vbmdict, cbmdict = band_gap.eband_gap(xmlfile)
#print ("bandgap : {} eV".format(egap))
##print ("bandgap : {} eV".format(egap*cf.har2ev))
#print("vbM dict: {} ".format(vbmdict))
#print("cbm dict: {} ".format(cbmdict))
ORCA related files¶
- Create ORCA input files for atomic relaxation from many xyz files: opt calculations
Example
import glob
import esta.orcaBag.input_orca as iorca
import numpy as np
cal_type = 'OPT'
nproc='10'
memory='1000'
#-----functional and basis(may contain additional tags) together-----------
functional = "BP86"
basis = " def2-SVP def2/J RIJCOSX "
#-----None, True, or exact words-------------------------------------------
dispersion='D3Zero' #True or None # always needed!!
#-----None or some solvent-------------------------------------------------
solvent=None
#-----None or some txt-----------------------------------------------------
#extra_tags = {'tag1': 'int=ultrafine','tag2':'nosymm'}
extra_tags = {'tag3':'NoUseSym '}
#---charge and spin multiplicuty=2S+1 ; for unparied e- => spin-multi = 2;
# unpaired=1
charge = 2
multiplicity = 2
#--------------------------------------------------------------------------
xyz_file_list = glob.glob("*.xyz")
print('xyz files are:', format(xyz_file_list))
for ii in xyz_file_list:
print('--**--**'*10)
orca_obj = iorca.GenerateInp(ii, charge, multiplicity, cal_type)
orca_obj.write_inp(functional=functional,basis=basis,dispersion=dispersion,\
nproc=nproc, memory=memory, solvent=None, extra_tags=extra_tags)