Skip to content

Commit

Permalink
adding templates for running and getting V-scans; adjusting the E-fie…
Browse files Browse the repository at this point in the history
…ld procedute
  • Loading branch information
ondrejkrejci committed Feb 28, 2022
1 parent 9380965 commit 3038211
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 14 deletions.
19 changes: 13 additions & 6 deletions E_field/bias_to_cube_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,16 @@ def create_biased_cube(geom,V_tip, final_pot_name='final_pot_opt_'+str(zer)+'.cu
!!! beware CP2K code is super strict, only the python save_cube is working properly for writing the cube file as it seems. #
'''
print ("Going to create KPFM (metallic) tip-sample electrostatic field -- for given geometry and creates cube file:", final_pot_name);
pos = geom.positions;
tmp_pos=geom.get_scaled_positions()
tmp_pos=np.modf(tmp_pos)[0]
lvs = np.array(geom.get_cell()) ; print ("D: tmp_pos",tmp_pos); print ("D: lvs",lvs)
pos = np.array(tmp_pos).dot(lvs) # used instead, so the geometry would be folded to the original cell ##
print ("D: pos",pos)
#pos = geom.positions;
n_at = len(pos)
mol_xyz = np.zeros((n_at,4))
mol_xyz[:,:3]=pos
mol_xyz[:,3] =geom.get_atomic_numbers()
lvs = geom.get_cell()
print("copying atoms around the cell, because of PBC")
pos2= copy_arround_borders(pos,lvs,0.1)
g_vec = ddd.copy()
Expand Down Expand Up @@ -507,7 +511,6 @@ def create_biased_cube(geom,V_tip, final_pot_name='final_pot_opt_'+str(zer)+'.cu
print ("debug: optind", optind)
print("optimizing the field through iterations, all in C++")
Varr = opt_V(n_add, ndim, optind, Varr, zer, precond,inner_step=inner_step, idx=idx)
# !!!! still some weird behaviour on the edges .... !!!! #
print ("fully optimized potential - going to saving;")
if save_npy or (save != "cube"): #-> save == "npy" or save == "both" #
np.save(final_pot_name+"npy",Varr[n_add:nx+n_add,:,n_add:nz+n_add])
Expand All @@ -527,13 +530,17 @@ def create_biased_cube2(geom,V_tip, final_pot_name='final_pot_opt_'+str(zer)+'.c
!!! beware CP2K code is super strict, only the python save_cube is working properly for writing the cube file as it seems. #
'''
print ("Going to create KPFM (metallic) tip-sample electrostatic field -- for given geometry and creates cube file:", final_pot_name);
pos = geom.positions;
elements = np.array(geom.get_atomic_numbers(),dtype=np.int32)
tmp_pos=geom.get_scaled_positions()
tmp_pos=np.modf(tmp_pos)[0]
lvs = np.array(geom.get_cell()) #; print ("D: tmp_pos",tmp_pos); print ("D: lvs",lvs)
pos = np.array(tmp_pos).dot(lvs) # used instead, so the geometry would be folded to the original cell ##
#print ("D: pos",pos)
#pos = geom.positions;
n_at = len(pos)
elements = np.array(geom.get_atomic_numbers(),dtype=np.int32)
mol_xyz = np.zeros((n_at,4))
mol_xyz[:,:3]=pos
mol_xyz[:,3] =geom.get_atomic_numbers()
lvs = geom.get_cell()
print("copying atoms around the cell, because of PBC")
pos2,elements2= copy_arround_borders2(pos,elements,lvs,0.1)
g_vec = ddd.copy()
Expand Down
13 changes: 7 additions & 6 deletions kpfm_sim_result_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ def write_atoms(self, atoms_model, is_fixed, belongs_to, simplistic = False):
model_part_id = self.write_model_part(atom_belongs_to[0], atom_belongs_to[1])
model_part_ids.append(model_part_id)
if debug:
print ("model_part_ids:",model_part_ids)
print ("debug: len(is_fixed)",len(is_fixed))
print ("debug: len(model_part_ids)",len(model_part_ids))
print ("debug: model_part_ids:",model_part_ids)
print ("debug: len(is_fixed)",len(is_fixed))
print ("debug: len(model_part_ids)",len(model_part_ids))
for atom_i, atom in enumerate(atoms_model):
cur.execute("INSERT INTO atoms VALUES(?,?,?,?)",
(atom_i, atom.symbol, is_fixed[atom_i], model_part_ids[atom_i]))
Expand Down Expand Up @@ -946,7 +946,7 @@ def derivate_force(s, forces):


def calc_force_curve_from_energy(result_db, x, y, V, ignore_first = False):
debug = True
# debug = True
energies = []
s = []
with result_db:
Expand Down Expand Up @@ -1002,7 +1002,7 @@ def calc_force_curve(result_db, x, y, V):
atomic_forces = result_db.get_atomic_forces(scan_point_id, tip_top_atoms)
if debug:
print ("debug: atomic_forces", atomic_forces)
print ("debug: len(atomic_forces)", scan_point_id, len(atomic_forces))
print ("debug: len(atomic_forces)", scan_point_id, len(atomic_forces))
if atomic_forces is not None:
ss.append(s)
forces.append(np.sum(atomic_forces[:,1])*au_to_N)
Expand Down Expand Up @@ -1030,7 +1030,8 @@ def extract_charges_descent(result_db, x, y, V):
#traj = Trajectory(traj_file, "w")
with result_db:
scan_points = result_db.get_all_s_scan_points(x, y, V)
print("D scan_points",scan_points)
if debug:
print("D scan_points",scan_points)
lcharges = []
for point in scan_points:
atoms, charges = result_db.extract_atoms_object(point[0], get_charges = True)
Expand Down
11 changes: 9 additions & 2 deletions scripts/mpi_create_Efield.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import math
from optparse import OptionParser

from E_field.bias_to_cube_c import create_biased_cube
from E_field.bias_to_cube_c import create_biased_cube, create_biased_cube2
from kpfm_sim_result_db import Result_db, prepare_db_for_small


Expand Down Expand Up @@ -60,6 +60,8 @@
db_file = "e_fields.db"
e_field_folder = "E_field"

atom_style = "OPLS" # "stiff" or "OPLS" - if "stiff", then the electrostatic field is fixed for 1Angstrom around each atom; if "OPLS", then it is fixed for 80% of the vdW sphere defined by the OPLS force-field #

cc = 11.0 # !!! IMPORTANT !!! the maximum "height" of the bottom (sample) atoms ; because of xzy - height refers to y in xyz file !!! IMPORTANT !!! #

inx = 320 ; # amount of division points in /x/ direction #
Expand Down Expand Up @@ -132,7 +134,12 @@ def one_create_potential(db_file,rank,idx, cc=11.0):
geom = ft_db.extract_atoms_object(idx, get_charges=False, get_model=False);
if debug:
print ("debug:geom", geom)
create_biased_cube2(geom,V_tip,final_pot_name=final_pot_name(idx),cube_head=cube_head, cc=cc,idx=idx, save=save);
if atom_style == "stiff" :
create_biased_cube(geom,V_tip,final_pot_name=final_pot_name(idx),cube_head=cube_head, cc=cc,idx=idx, save=save);
elif atom_style == "OPLS" :
create_biased_cube2(geom,V_tip,final_pot_name=final_pot_name(idx),cube_head=cube_head, cc=cc,idx=idx, save=save);
else:
print ("Unknown 'atom_style', aborting"); sys.exit()
return idx

def write_to_db(db_file,idx):
Expand Down
49 changes: 49 additions & 0 deletions slurm_script_templates/combine_results_Vscans.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
module load gcc/9.3.0 openmpi/4.0.3 cp2k/7.1-omp
export OMP_NUM_THREADS=1
ulimit -s unlimited
export ppath=/scratch/project_2003835/programs_KPFM
export PYTHONPATH=$PYTHONPATH:$ppath/CP2k_mtools3:$ppath/DFT_gridIO3:$ppath/KPFM_FEM3:$ppath/KPFM_sim3
KPFM_GLOBAL_SCRIPTS=$ppath/KPFM_sim3/scripts

# **************************************************************************************************** #
# #
# script for putting all the results from all the KPFM workers to be saved in the global results db #
# #
# **************************************************************************************************** #

echo "start combining results from different workers"

GR='glob_res/afm_copy.db' # adjust the global results name #
bu=$GR
bu+='.bak'

echo $GR $bu

cp $GR $bu

# adjust the voltages, where it was calculated #
vol="0.31 0.2 -0.2 -0.31 -2.0 -1.7 -1.5 -1.3 -1 -0.7 -0.5 -0.3 -0.1 -0.05 -0.01 0.01 0.05 0.1 0.3 0.5 0.7 1 1.3 1.5 1.7 2.0"
vol+=" 1000.0"


for i in {0..0}; # adjust amount of y points #
do
for j in {0..0}; # adjust amout of x points #
do
for vi in $vol;
do
ar=kpfm_res_$i
ar+=_$j
ar+=_$vi.db # adjust the input db file name(s) #
echo $ar
wr=worker_$i
wr+=_$j
wr+=_$vi
python3 $KPFM_GLOBAL_SCRIPTS/copy_scan_points_and_wfn_files.py -i $ar -o $GR # -w $vi wfn_data # -k ## -k -- if kpts are necessary ##
done
done
done

echo "Done, done"

68 changes: 68 additions & 0 deletions slurm_script_templates/create_V_scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

## to creat input and running files for 2 tip-descents and multiple Voltages ##
# first try whatever point (in this nomenclature it will be 0 0 )) #
# to prepare files for the first y line then have - true - in the if #
grdb=glob_res/kpfm.db
#global results db file#
cpdb=false
# copy database #
dbf="kpfm_res_"
if true ; then
b=0
Af=0
#Vf="2.0 1.7 1.5 1.3 1.0 0.7 0.5 0.3 -0.3 -0.5 -0.7 -1.0 -1.3 -1.5 -1.7 -2.0"
Vf="1000.0 2.0 1.7 1.5 1.3 1 0.7 0.5 0.31 0.3 0.2 0.1 0.05 0.01 -0.01 -0.05 -0.1 -0.2 -0.3 -0.31 -0.5 -0.7 -1 -1.3 -1.5 -1.7 -2.0"
for Vi in $Vf; do
echo $b $Af $Vi
y="`echo $b`";
x="`echo $Af`";
V="`echo $Vi`"
#sed "s/BBB/$y/g" pdtt_V.template > pdtt.tmp ;
#sed "s/AAA/$x/g" pdtt.tmp > pdtt_$b.$Af.tmp ;
#sed "s/CCC/$V/g" pdtt_$b.$Af.tmp > pdtt_$b.$Af.$Vi.py;
#rm pdtt.tmp pdtt_$b.$Af.tmp
sed "s/BBB/$y/g" pdtt_V_run.template > pdtt_run.tmp ;
sed "s/AAA/$x/g" pdtt_run.tmp > rw_$b.$Af.tmp ;
sed "s/CCC/$V/g" rw_$b.$Af.tmp > rw_$b.$Af.$Vi.slrm;
rm pdtt_run.tmp rw_$b.$Af.tmp
if $cpdb; then
tdbf=$dbf
tdbf+=$b
tdbf+=_$Af
tdbf+=_$Vi
tdbf+=.db
echo $tdbf
cp $grdb $tdbf
fi
done
fi
if false ; then
b=0
Af=1
Vf="2.0 1.7 1.5 1.3 1.0 0.7 0.5 0.3 -0.3 -0.5 -0.7 -1.0 -1.3 -1.5 -1.7 -2.0"
#Vf="2.0 1.7 1.5 1.3 0.7 0.5 0.3 -0.3 -0.5 -0.7 -1.3 -1.5 -1.7 -2.0"
for Vi in $Vf; do
echo $b $Af $Vi
y="`echo $b`";
x="`echo $Af`";
V="`echo $Vi`"
sed "s/BBB/$y/g" pdtt_V.template > pdtt.tmp ;
sed "s/AAA/$x/g" pdtt.tmp > pdtt_$b.$Af.tmp ;
sed "s/CCC/$V/g" pdtt_$b.$Af.tmp > pdtt_$b.$Af.$Vi.py;
rm pdtt.tmp pdtt_$b.$Af.tmp
sed "s/BBB/$y/g" pdtt_V_run.template > pdtt_run.tmp ;
sed "s/AAA/$x/g" pdtt_run.tmp > rw_$b.$Af.tmp ;
sed "s/CCC/$V/g" rw_$b.$Af.tmp > rw_$b.$Af.$Vi.slrm;
rm pdtt_run.tmp rw_$b.$Af.tmp
if $cpdb; then
tdbf=$dbf
tdbf+=$b
tdbf+=_$Af
tdbf+=_$Vi
tdbf+=.db
echo $tdbf
cp $grdb $tdbf
fi
done
fi
22 changes: 22 additions & 0 deletions slurm_script_templates/get_single_Vscan_charges.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
# check modules.txt for updating following lines: # module purge
#module load gcc/9.3.0 openmpi/4.0.3 cp2k/7.1-omp
export OMP_NUM_THREADS=1
ulimit -s unlimited
export ppath=./programs_KPFM #
export PYTHONPATH=$PYTHONPATH:$ppath/CP2k_mtools3:$ppath/DFT_gridIO3:$ppath/KPFM_FEM3:$ppath/KPFM_sim3 #:$ppath/pycp2k
export PYTHONPATH=$PYTHONPATH:/u/88/krejcio1/unix/WORK/lib_cp2k_copy/
KPFM_GLOBAL_SCRIPTS=$ppath/KPFM_sim3/scripts
ORIG_DIR=`pwd`

## after adjust the modules above and PYTHONPATH, this script will allow to get Mulliken charges from the descent tip scan (style metallic) with different voltage ##

if true ; then
y=0.0 ## adjust /x/ and /y/ as well as voltages /Vf/ <- for chanrges those which are lower than -100 and larges than +100 makes sense ##
x=0.0 ## look at wiki for more details ##
Vf="102.0 101.7 101.5 101.3 101.0 100.7 100.5 100.3 100.1 100.05 100.01 -100.01 -100.05 -100.01 -100.1 -100.3 -100.5 -100.7 -101.0 -101.3 -101.5 -101.7 -102.0"
Vf+=" -100.31 -100.2 100.2 100.31 1000.0"
for Vi in $Vf; do
python3 $KPFM_GLOBAL_SCRIPTS/extract_descend_tip_charges.py -i glob_res/afm.db -p $x $y -V $Vi
done
fi
26 changes: 26 additions & 0 deletions slurm_script_templates/get_single_Vscan_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# check modules.txt for updating following lines: # module purge
#module load gcc/9.3.0 openmpi/4.0.3 cp2k/7.1-omp
export OMP_NUM_THREADS=1
ulimit -s unlimited
export ppath=./programs_KPFM #
export PYTHONPATH=$PYTHONPATH:$ppath/CP2k_mtools3:$ppath/DFT_gridIO3:$ppath/KPFM_FEM3:$ppath/KPFM_sim3 #:$ppath/pycp2k
export PYTHONPATH=$PYTHONPATH:/u/88/krejcio1/unix/WORK/lib_cp2k_copy/
KPFM_GLOBAL_SCRIPTS=$ppath/KPFM_sim3/scripts
ORIG_DIR=`pwd`

## after adjust the modules above and PYTHONPATH, this script will allow to get energies and forces (and also atomic forces) for predefined voltages in Vf ##

if true ; then
y=0.0 ## adjust /x/ and /y/ as well as voltages /Vf/ <- for chanrges those which are around 0 should be the most important (other left here for cross-checking) ##
x=0.0 ## look at wiki for more details ##
Vf="1000.0"
Vf+=" -0.31 -0.2 0.2 0.31 -100.31 -100.2 100.2 100.31"
Vf+=" 0.1 0.05 0.01 -0.01 -0.05 -0.1 100.1 100.05 100.01 -100.01 -100.05 -100.1"
Vf+=" 102.0 101.7 101.5 101.3 101.0 100.7 100.5 100.3 -100.3 -100.5 -100.7 -101.0 -101.3 -101.5 -101.7 -102.0"
Vf+=" 2.0 1.7 1.5 1.3 1.0 0.7 0.5 0.3 -0.3 -0.5 -0.7 -1.0 -1.3 -1.5 -1.7 -2.0"
for Vi in $Vf; do
echo "x y V:" $x $y $Vi
python3 $KPFM_GLOBAL_SCRIPTS/extract_descend_tip_data.py -i glob_res/afm.db -p $x $y -V $Vi -n -N # -n -- no atomic forces -N -- no geometry
done
fi
22 changes: 22 additions & 0 deletions slurm_script_templates/submit_single_V_scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

## to creat input and running files for 2 tip-descents with different voltages ##
# first try whatever point (in this nomenclature it will be 0 0 )) #
# to prepare files for the first y line then have - true - in the if #
if true ; then
b=0
Af=0
Vf="1000.0 2.0 1.7 1.5 1.3 1 0.7 0.5 0.31 0.3 0.2 0.1 0.05 0.01 -0.01 -0.05 -0.1 -0.2 -0.3 -0.31 -0.5 -0.7 -1 -1.3 -1.5 -1.7 -2.0"
for Vi in $Vf; do
sbatch rw_$b.$Af.$Vi.slrm ;
done
fi
if false ; then
b=0
Af=1
Vf="2.0 1.7 1.5 1.3 1 0.7 0.5 0.3 -0.3 -0.5 -0.7 -1.0 -1.3 -1.5 -1.7 -2.0"
for Vi in $Vf; do
echo rw_$b.$Af.$Vi.slrm ;
sbatch rw_$b.$Af.$Vi.slrm ;
done
fifi

0 comments on commit 3038211

Please sign in to comment.