<jupyter_start><jupyter_text>DO NACsThis file demonstrates how to run the calculations of the NACs in the KS space, using QE.In particular, this example is designed to run the calculations in a serial fashion - without scheduling procedures (e.g. on a personal laptop). This is quire useful for debugging and development purposes.So, lets start by loading the required modules<jupyter_code>import os
import sys

# Fisrt, we add the location of the library to test to the PYTHON path
if sys.platform=="cygwin":
    from cyglibra_core import *
elif sys.platform=="linux" or sys.platform=="linux2":
    from liblibra_core import *
    

from libra_py import hpc_utils
from libra_py import data_read
from libra_py import data_outs
from libra_py import units
from libra_py import QE_methods
from libra_py.workflows.nbra import step2
#import libra_py.workflows.nbra.step2_analysis as step2a

import numpy as np
#from matplotlib.mlab import griddata

import matplotlib.pyplot as plt   # plots
%matplotlib inline 

plt.rc('axes', titlesize=24)      # fontsize of the axes title
plt.rc('axes', labelsize=20)      # fontsize of the x and y labels
plt.rc('legend', fontsize=20)     # legend fontsize
plt.rc('xtick', labelsize=16)    # fontsize of the tick labels
plt.rc('ytick', labelsize=16)    # fontsize of the tick labels

plt.rc('figure.subplot', left=0.2)
plt.rc('figure.subplot', right=0.95)
plt.rc('figure.subplot', bottom=0.13)
plt.rc('figure.subplot', top=0.88)

colors = {}

colors.update({"11": "#8b1a0e"})  # red       
colors.update({"12": "#FF4500"})  # orangered 
colors.update({"13": "#B22222"})  # firebrick 
colors.update({"14": "#DC143C"})  # crimson   

colors.update({"21": "#5e9c36"})  # green
colors.update({"22": "#006400"})  # darkgreen  
colors.update({"23": "#228B22"})  # forestgreen
colors.update({"24": "#808000"})  # olive      

colors.update({"31": "#8A2BE2"})  # blueviolet
colors.update({"32": "#00008B"})  # darkblue  

colors.update({"41": "#2F4F4F"})  # darkslategray

clrs_index = ["11", "21", "31", "41", "12", "22", "32", "13","23", "14", "24"]<jupyter_output>/projects/academic/cyberwksp21/Software/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > already registered; second conversion method ignored.
  return f(*args, **kwds)
/projects/academic/cyberwksp21/Software/Conda/Miniconda3/envs/libra/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: to-Python converter for boost::python::detail::container_element<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >, false> > already registered; second conversion method ignored.
  return f(*args, **kwds)
/projects/academic/cyberwksp21/Software/Conda/Miniconda3/envs/libra/lib/python3.6/import[...]<jupyter_text>Assume we have already produced a QE MD trajectory and it is stored in the file **x0.md.out** (which we copied in the present directory).We need to also create a **x0.scf.in** file that contains the parameters for QE calculations (the type of calculation should be *scf*). The file should not contain the atomic coordiantes section, but should contain the cell parameters sections or occupations if they are used. Place the file in the current directory.Also create a **x0.exp.in** file (also to be placed in the present directory). It shall describe the procedured for the wavefunction "export" operation - mainly the location and names of atomic pseudopotentials and the correct prefix for the files. The following section will clean up the previous results and temporary directory (BEWARE!!! you may not always want to do this for it will delete expensive results)<jupyter_code># Remove the previous results and temporary working directory from the previous runs
os.system("rm -r res")
os.system("rm -r wd")

# Create the new results directory
os.system("mkdir res")
rd = os.getcwd()+"/res"          # where all the results stuff will go<jupyter_output><empty_output><jupyter_text>We'll use **QE_methods.out2inp()** function to convert the MD trajectory into a bunch of input files for SCF calculation - this is something we'll need for NAC calculations. In this case, you need to setup the *iinit* and *ifinal* variables which determine which steps of the original MD trajectory will be used to produce the input files and subsequenctly used in the NACs calculationsAll these files will be generated in the temporarily-created **wd** directory. The system then "cd" into that directory to start the consecutive operations in that directory.<jupyter_code>PWSCF = os.environ['PWSCF62']
print(PWSCF)
help(QE_methods.out2inp)
iinit = 0
ifinal = 50

QE_methods.out2inp("x0.md.out","x0.scf.in","wd","x0.scf", iinit, ifinal, 1)
os.system("cp x0.exp.in wd");<jupyter_output><empty_output><jupyter_text>Next - define the parameters used by the **step2.run()** (and other functions called inside, so look for the description all all suitable parameters). The meaning of the most parameters is quite intuitive. Let me just clarify a couple less-obvious points:In this example, I do the calculations directly, so without "parallelizing" via the batch system, so specify "BATCH_SYSTEM":NoneThe system in this example has 56 electrons, so the HOMO would correspond to number 28 and LUMO to number 29. In this example, we use more orbitals - those below HOMO and above LUMO: minband = 20 and maxband = 39, so we could study the HOMO-LUMO transitions as well as all other types of relaxation. In all, there are 20 orbitals included in our present active space. The resulting files will contain matrixes 40 by 40 - because we plot alpha and beta channels. Just a reminder: the orbital indexing starts from 1.<jupyter_code>help(step2.run)
params = { "EXE"       :F"{PWSCF}/pw.x", 
           "EXE_EXPORT":F"{PWSCF}/pw_export.x",
           "BATCH_SYSTEM":None,
           "start_indx":0, "stop_indx":30, "dt":1.0*units.fs2au, 
           "prefix0":"x0.scf", 
           "nac_method":1, 
           "minband":20, "maxband":39, 
           "minband_soc":20, "maxband_soc":39, 
           "compute_Hprime":True, 
           "wd":"wd",
           "rd":rd,
           "verbosity":0
         }

os.chdir("wd")
step2.run(params)
os.chdir("../")<jupyter_output>The time to run the QE calculations =  0.01
The time to run the QE calculations =  0.01
path= Root
The total # of k-points (spin-polarized) including up and down components is:  2
The time to get the basic parameters about your QE calculations =  0.02
printing prefix:   curr0/x0.export
Reading index from file  wd/curr0/x0.export/index.xml
path= Root
 nspin =  2  nk =  2  nbnd =  40  efermi =  0.1035115128851777  alat =  1.89  omega =  1089.429480162654  tpiba =  3.32443667046539  tpiba2 =  3.32443667046539
 Direct lattice vectors: 
 a1 =  8.91510449256 -0.02931884235 -0.00453723984
 a2 =  -4.482941481899999 7.678748407050002 -0.0005173497
 a3 =  -0.004824402660000001 -0.00262325385 15.9447227247
 Reciprocal lattice vectors: 
 b1 =  0.7061356696551128 0.412250130250828 0.0002814799367690439
 b2 =  0.002696221652374109 0.8198305306489485 0.0001356957591637749
 b3 =  0.0002010258715444394 0.0001439107367195997 0.3940605780990116
 K points: 
0  weight =  1.0  k =  0.0 0.0 0.0
1  weight =  [...]
{'fraction_non_alphanumeric': 0.11239078633836377, 'fraction_numerical': 0.07678051363516018, 'mean_word_length': 4.526700804681785, 'pattern_counts': {'":': 29, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '267648', 'license': 'CC0-1.0', 'n_tokens_mistral': 2831, 'n_tokens_neox': 2456, 'n_words': 802, 'path': '6_nac_workflow/step2/DO_NACs.ipynb', 'repo_name': 'compchem-cybertraining/Tutorials_QE_and_eQE', 'size': '7554'}