diff --git a/tools/plot-tools/README.md b/tools/plot-tools/README.md index 4fd99d9244..aac183260b 100644 --- a/tools/plot-tools/README.md +++ b/tools/plot-tools/README.md @@ -147,27 +147,3 @@ Then, the following command will output parsed partial DOS to directory `PDOS_FI abacus-plot -d -o ``` -### Dipole and Absorption - -```python - -from abacus_plot.dipole import Dipole -from abacus_plot.dipole import Absorption -import matplotlib.pyplot as plt - -dipolefile = './SPIN1_DIPOLE' -dipole = Dipole(dipolefile, dt=0.0024) -Efile=[["efield_0.dat"],["efield_1.dat"],["efield_2.dat"]] -#Efile is a 2D list, Efile[i][j] is the jth Efield data file in ith direction -Abs = Absorption(dipolefile, Efile, dt=0.0024) - -fig1, ax1 = plt.subplots() -fig1, ax1 = dipole.plot_dipole(fig1, ax1) -fig1.savefig('dipole.png') - -fig2, ax2 = plt.subplots() -x_range = [0, 20] -fig2, ax2 = Abs.plot_abs( - fig2, ax2, x_range=x_range, unit='eV') -fig2.savefig('abs.png') -``` diff --git a/tools/plot-tools/examples/N2/out_abs.png b/tools/plot-tools/examples/N2/out_abs.png deleted file mode 100644 index de1943927b..0000000000 Binary files a/tools/plot-tools/examples/N2/out_abs.png and /dev/null differ diff --git a/tools/plot-tools/examples/N2/out_dipole.png b/tools/plot-tools/examples/N2/out_dipole.png deleted file mode 100644 index d88d87ad8d..0000000000 Binary files a/tools/plot-tools/examples/N2/out_dipole.png and /dev/null differ diff --git a/tools/plot-tools/abacus_plot/dipole.py b/tools/rt-tddft-tools/dipole.py similarity index 100% rename from tools/plot-tools/abacus_plot/dipole.py rename to tools/rt-tddft-tools/dipole.py diff --git a/tools/plot-tools/examples/N2/ABACUS-INPUT b/tools/rt-tddft-tools/examples/Absorpation-N2/ABACUS-INPUT similarity index 100% rename from tools/plot-tools/examples/N2/ABACUS-INPUT rename to tools/rt-tddft-tools/examples/Absorpation-N2/ABACUS-INPUT diff --git a/tools/plot-tools/examples/N2/ABACUS-STRU b/tools/rt-tddft-tools/examples/Absorpation-N2/ABACUS-STRU similarity index 100% rename from tools/plot-tools/examples/N2/ABACUS-STRU rename to tools/rt-tddft-tools/examples/Absorpation-N2/ABACUS-STRU diff --git a/tools/plot-tools/examples/N2/Abs_plot.py b/tools/rt-tddft-tools/examples/Absorpation-N2/Abs_plot.py similarity index 100% rename from tools/plot-tools/examples/N2/Abs_plot.py rename to tools/rt-tddft-tools/examples/Absorpation-N2/Abs_plot.py diff --git a/tools/plot-tools/examples/N2/N_ONCV_PBE-1.0.upf b/tools/rt-tddft-tools/examples/Absorpation-N2/N_ONCV_PBE-1.0.upf similarity index 100% rename from tools/plot-tools/examples/N2/N_ONCV_PBE-1.0.upf rename to tools/rt-tddft-tools/examples/Absorpation-N2/N_ONCV_PBE-1.0.upf diff --git a/tools/plot-tools/examples/N2/N_gga_10au_100Ry_2s2p1d.orb b/tools/rt-tddft-tools/examples/Absorpation-N2/N_gga_10au_100Ry_2s2p1d.orb similarity index 100% rename from tools/plot-tools/examples/N2/N_gga_10au_100Ry_2s2p1d.orb rename to tools/rt-tddft-tools/examples/Absorpation-N2/N_gga_10au_100Ry_2s2p1d.orb diff --git a/tools/plot-tools/examples/N2/SPIN1_DIPOLE b/tools/rt-tddft-tools/examples/Absorpation-N2/SPIN1_DIPOLE similarity index 100% rename from tools/plot-tools/examples/N2/SPIN1_DIPOLE rename to tools/rt-tddft-tools/examples/Absorpation-N2/SPIN1_DIPOLE diff --git a/tools/plot-tools/examples/N2/efield_0.dat b/tools/rt-tddft-tools/examples/Absorpation-N2/efield_0.dat similarity index 100% rename from tools/plot-tools/examples/N2/efield_0.dat rename to tools/rt-tddft-tools/examples/Absorpation-N2/efield_0.dat diff --git a/tools/plot-tools/examples/N2/efield_1.dat b/tools/rt-tddft-tools/examples/Absorpation-N2/efield_1.dat similarity index 100% rename from tools/plot-tools/examples/N2/efield_1.dat rename to tools/rt-tddft-tools/examples/Absorpation-N2/efield_1.dat diff --git a/tools/plot-tools/examples/N2/out_spectra.dat b/tools/rt-tddft-tools/examples/Absorpation-N2/out_spectra.dat similarity index 100% rename from tools/plot-tools/examples/N2/out_spectra.dat rename to tools/rt-tddft-tools/examples/Absorpation-N2/out_spectra.dat diff --git a/tools/rt-tddft-tools/examples/ground-state-projection-Si/INPUT b/tools/rt-tddft-tools/examples/ground-state-projection-Si/INPUT new file mode 100644 index 0000000000..32fa580202 --- /dev/null +++ b/tools/rt-tddft-tools/examples/ground-state-projection-Si/INPUT @@ -0,0 +1,37 @@ +INPUT_PARAMETERS +basis_type lcao + +ecutwfc 100 +scf_nmax 100 +scf_thr 1e-6 + +calculation md +esolver_type tddft +md_type nve +md_nstep 2500 +md_dt 0.002 +md_tfirst 0 + +td_vext 1 +td_vext_dire 3 +td_stype 1 +td_ttype 0 +td_tstart 1 +td_tend 5000 +td_lcut1 0.01 +td_lcut2 0.99 +td_gauss_freq 0.96 +td_gauss_phase 0.0 +td_gauss_sigma 0.5 +td_gauss_t0 1200 +td_gauss_amp 0.1 + +out_dipole 1 +out_efield 1 +out_current 1 +out_current_k 1 + +out_wfc_lcao 1 +out_mat_hs 1 +out_app_flag 0 +out_interval 25 \ No newline at end of file diff --git a/tools/rt-tddft-tools/examples/ground-state-projection-Si/KPT b/tools/rt-tddft-tools/examples/ground-state-projection-Si/KPT new file mode 100644 index 0000000000..f7fffe21ba --- /dev/null +++ b/tools/rt-tddft-tools/examples/ground-state-projection-Si/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +8 8 8 0 0 0 \ No newline at end of file diff --git a/tools/rt-tddft-tools/examples/ground-state-projection-Si/On1.dat b/tools/rt-tddft-tools/examples/ground-state-projection-Si/On1.dat new file mode 100644 index 0000000000..d745542ce9 --- /dev/null +++ b/tools/rt-tddft-tools/examples/ground-state-projection-Si/On1.dat @@ -0,0 +1,101 @@ +7.812499853032692752e-03 7.812500279798491667e-03 7.812350082550026734e-03 7.812350082567939488e-03 6.686717854768583909e-18 1.273966279961955695e-20 1.281536489683403687e-20 2.436224928051321290e-17 1.455721960673305505e-20 +7.812499853032699691e-03 7.812500279798476055e-03 7.812350082258740641e-03 7.812350082365753998e-03 1.490247763194331891e-17 1.077391542540353658e-17 9.648851966739274479e-18 2.698813529540607934e-17 3.969790221977746295e-20 +7.812499853032702293e-03 7.812500279798481259e-03 7.812350082258744978e-03 7.812350082365754865e-03 1.338629013537693114e-17 1.040157544868407331e-17 8.023705175726225935e-18 2.818645043139415115e-17 2.152965149171645697e-19 +7.812499853032704028e-03 7.812500279798481259e-03 7.812350082258739774e-03 7.812350082365751396e-03 1.050061327306201373e-17 1.018748243646475980e-17 1.255526088916916614e-17 2.884255147975228781e-17 9.256801281552135578e-19 +7.812499853032684079e-03 7.812500279798443095e-03 7.812350082258605333e-03 7.812350082365557974e-03 1.110234188146072923e-16 5.476475696791553340e-17 9.458349117056311261e-17 7.886970031758802209e-17 3.443302604107927034e-17 +7.812499853032585199e-03 7.812500279797884514e-03 7.812350082257480365e-03 7.812350082363527480e-03 1.221025990081458542e-15 5.277097822561900040e-16 8.042486056611601589e-16 6.609800012573974879e-16 3.388298157432289595e-16 +7.812499853032228714e-03 7.812500279794808850e-03 7.812350082251317759e-03 7.812350082352021927e-03 7.688773607708341558e-15 3.222952618985768202e-15 4.719067260205915655e-15 4.031146146161859528e-15 1.884039370417977416e-15 +7.812499853031174869e-03 7.812500279782960688e-03 7.812350082226447029e-03 7.812350082305783740e-03 3.459153926335484060e-14 1.423009475135000606e-14 2.065106717651520955e-14 1.758670007424376872e-14 7.474971242608616118e-15 +7.812499853028622224e-03 7.812500279747522022e-03 7.812350082146477144e-03 7.812350082159213484e-03 1.228145204190944378e-13 4.981559865801570222e-14 7.232334033967236660e-14 6.002620078048621925e-14 2.330673017550618989e-14 +7.812499853023407645e-03 7.812500279660945443e-03 7.812350081934199032e-03 7.812350081777151914e-03 3.610941462883710220e-13 1.446487842594735793e-13 2.106461858849508682e-13 1.682485411779086762e-13 5.969979759489234567e-14 +7.812499853014897092e-03 7.812500279486930127e-03 7.812350081463906824e-03 7.812350080947388573e-03 8.986578228190934686e-13 3.554742578353971945e-13 5.197792228478134614e-13 3.957470702999447474e-13 1.276867248607976924e-13 +7.812499853005088098e-03 7.812500279205564918e-03 7.812350080604125828e-03 7.812350079464436790e-03 1.902129002541687645e-12 7.419716841836609477e-13 1.090168097358521198e-12 7.836573236885160296e-13 2.269353059419004219e-13 +7.812499853000657614e-03 7.812500278866488929e-03 7.812350079367172580e-03 7.812350077389442968e-03 3.385603051914610680e-12 1.299293649069382529e-12 1.919379016255142377e-12 1.289038721443987301e-12 3.261388284048605778e-13 +7.812499853009330364e-03 7.812500278626734532e-03 7.812350078155607877e-03 7.812350075432913411e-03 4.901700794298826520e-12 1.845807442333131019e-12 2.742383323432933970e-12 1.711872500631155452e-12 3.618101175167228489e-13 +7.812499853018082911e-03 7.812500278590924635e-03 7.812350077802290675e-03 7.812350074866239967e-03 5.396993520182899994e-12 2.001504125631436744e-12 2.981955563864776735e-12 1.839553005394764809e-12 3.385082846655620411e-13 +7.812499852932987786e-03 7.812500278033927478e-03 7.812350078412555986e-03 7.812350075183738599e-03 4.315407145162125193e-12 1.703056079344719690e-12 2.468677803485621447e-12 2.361762504659291149e-12 6.950218203357612152e-13 +7.812499852466974273e-03 7.812500273374220830e-03 7.812350074989517223e-03 7.812350066099102777e-03 6.283159864873798714e-12 3.169681657633534525e-12 4.281083262384277953e-12 7.474396685349264012e-12 3.134461378552293558e-12 +7.812499851005201730e-03 7.812500254476032260e-03 7.812350047197313789e-03 7.812350009764495659e-03 3.267183280083109047e-11 1.552890608038603436e-11 2.153012832021432507e-11 2.999039571018929183e-11 1.192963004046087639e-11 +7.812499847572922963e-03 7.812500200162266970e-03 7.812349942262116105e-03 7.812349812582107186e-03 1.418939026414260175e-10 6.257923727216895362e-11 8.890829388137152469e-11 9.827167982682776205e-11 3.508698292183345656e-11 +7.812499841149679949e-03 7.812500076640842978e-03 7.812349656646455642e-03 7.812349297842300852e-03 4.531185304792351007e-10 1.911716241251917738e-10 2.754704942626815632e-10 2.605143014572550335e-10 8.366148061447493069e-11 +7.812499831578885272e-03 7.812499846019973354e-03 7.812349034944595511e-03 7.812348211501761626e-03 1.153088037609147093e-09 4.718569550809047194e-10 6.864440626384909332e-10 5.765652531795112974e-10 1.666204089618884149e-10 +7.812499820987390577e-03 7.812499492320172136e-03 7.812347918113238948e-03 7.812346312754753913e-03 2.447702082586668115e-09 9.771504459394998477e-10 1.432182592776262639e-09 1.085202190312603517e-09 2.797335493584696527e-10 +7.812499814740346896e-03 7.812499062254251760e-03 7.812346269952624885e-03 7.812343587535403380e-03 4.418222801594663738e-09 1.724018381710924485e-09 2.543369039502271716e-09 1.745678194287174871e-09 3.925477856832722905e-10 +7.812499819669653858e-03 7.812498690802675665e-03 7.812344360995931644e-03 7.812340529108604235e-03 6.791658385448597663e-09 2.589635535318124385e-09 3.843587174577796148e-09 2.388121726329547615e-09 4.486778634736386646e-10 +7.812499836541287289e-03 7.812498540333734538e-03 7.812342867626963228e-03 7.812338223696329957e-03 8.770998199078791133e-09 3.264672608722082367e-09 4.871569121144878528e-09 2.769177408961638509e-09 4.069975426300912668e-10 +7.812499844218311236e-03 7.812498550624985029e-03 7.812342564980947340e-03 7.812337706375470196e-03 9.284480356680769592e-09 3.391579366265826169e-09 5.070184887145676427e-09 2.882656183351129511e-09 3.547336710690416432e-10 +7.812499781849658459e-03 7.812497938502010325e-03 7.812343184217111422e-03 7.812337931984741912e-03 8.187553284667456409e-09 3.083966817157662608e-09 4.539467182508874874e-09 3.660704609143170800e-09 6.855413362771258625e-10 +7.812499539571283146e-03 7.812494543140142793e-03 7.812341152959785887e-03 7.812332057382916951e-03 8.841744470361763275e-09 3.960847677671831129e-09 5.566699818414017084e-09 7.988727728025107941e-09 2.269703900840955374e-09 +7.812498977478036198e-03 7.812484406984244664e-03 7.812326615005588636e-03 7.812302905420510403e-03 2.180228070163895656e-08 1.051910237351932575e-08 1.469509777326951620e-08 2.154800783639236158e-08 6.441336062768101019e-09 +7.812497994380795431e-03 7.812462264526452878e-03 7.812281302555792832e-03 7.812220353796601319e-03 6.797441971956459514e-08 3.112683845546636387e-08 4.428691811001559565e-08 5.250018216563952165e-08 1.458559667171380079e-08 +7.812496642031469159e-03 7.812423582450244049e-03 7.812180052545585236e-03 7.812045025095691250e-03 1.780202938069342282e-07 7.735204086169203320e-08 1.116600602934448646e-07 1.089078623714063587e-07 2.722494382585283444e-08 +7.812495230981619278e-03 7.812368096507126165e-03 7.811998844602665269e-03 7.811742231074614295e-03 3.842368801176499279e-07 1.602847291236858473e-07 2.337376488854461481e-07 1.935971465318801878e-07 4.285591415854843683e-08 +7.812494328139583770e-03 7.812303379348786367e-03 7.811729874197701103e-03 7.811305756875472177e-03 7.032546837354541918e-07 2.835793382204843004e-07 4.166897389954705580e-07 2.982177140607078031e-07 5.728193039849254671e-08 +7.812494550142056599e-03 7.812245427258719503e-03 7.811398810282921268e-03 7.810782527030078054e-03 1.113727748184818239e-06 4.354043797212895802e-07 6.437087438942030785e-07 4.008686263785850362e-07 6.449845579325761372e-08 +7.812496138080336598e-03 7.812212893856464342e-03 7.811072727768756351e-03 7.810279691796943348e-03 1.541461156476913746e-06 5.846309847418375274e-07 8.688045986117029490e-07 4.729147334166597758e-07 5.986995545985544601e-08 +7.812498445556872832e-03 7.812213704232950744e-03 7.810843583203532815e-03 7.809932136645577130e-03 1.870616030668633253e-06 6.884156571567480939e-07 1.027329365299366220e-06 4.981846542090092702e-07 4.512119076652669270e-08 +7.812499643314411817e-03 7.812227465998996048e-03 7.810777050788949953e-03 7.809818584425421741e-03 1.996915864576686549e-06 7.162014155120878158e-07 1.070908963295831547e-06 5.007358000999807850e-07 3.290430957355282637e-08 +7.812497004583882597e-03 7.812192420099366673e-03 7.810833005781974391e-03 7.809841229764222931e-03 1.921887432159646985e-06 6.874135529587402941e-07 1.023172530687733249e-06 5.684268623121463193e-07 4.737660114594148372e-08 +7.812487977686922644e-03 7.812008194689230509e-03 7.810787695955377988e-03 7.809619485122610769e-03 1.857942469276308112e-06 7.085479518432960039e-07 1.035821288261976948e-06 8.540461262419201573e-07 1.176737671272773021e-07 +7.812471748767348123e-03 7.811562352071302860e-03 7.810207234515143850e-03 7.808473164261869534e-03 2.285569265615626913e-06 9.854058759137348325e-07 1.409932401056303498e-06 1.539858543220769961e-06 2.640648030851998174e-07 +7.812450529143469789e-03 7.810779042843053223e-03 7.808519956579640028e-03 7.805560882451594018e-03 3.896605580814575925e-06 1.787075451064486949e-06 2.548005225924580296e-06 2.765201026029978535e-06 4.813926593788763635e-07 +7.812429661862023596e-03 7.809674641149721812e-03 7.805202887404326904e-03 7.800181116207064586e-03 7.390363320579293810e-06 3.354519377221000757e-06 4.824207063860702588e-06 4.537698916556045439e-06 7.287005859073173523e-07 +7.812416165084923141e-03 7.808393536111879127e-03 7.800038510484820671e-03 7.792149825718211638e-03 1.316122584248707086e-05 5.776773434575371999e-06 8.402178779544433807e-06 6.667369014382867723e-06 9.343828152441929552e-07 +7.812415835781623234e-03 7.807194132714686402e-03 7.793337863448148058e-03 7.782082517240840498e-03 2.099925837947448981e-05 8.887746642244384300e-06 1.307323485563547160e-05 8.770203536976671789e-06 1.021168349833567159e-06 +7.812430158111208570e-03 7.806368467992530306e-03 7.786000020659196962e-03 7.771393248244110735e-03 2.996771098010651084e-05 1.224706928486793432e-05 1.820790009944723024e-05 1.037469218978934016e-05 9.437824387095230784e-07 +7.812454690656026220e-03 7.806110337177065567e-03 7.779316215103107730e-03 7.761914895057454335e-03 3.858110769296473004e-05 1.524525220567434296e-05 2.288872843530340110e-05 1.112352046586807781e-05 7.209921399975341084e-07 +7.812480201788416824e-03 7.806386805941349476e-03 7.774529785912486640e-03 7.755223553030285953e-03 4.528347453745602184e-05 1.731960264508936400e-05 2.622053730063316743e-05 1.100113352190226156e-05 4.399041900332164704e-07 +7.812496176044654919e-03 7.806891664948079936e-03 7.772291495159932770e-03 7.751926368829008263e-03 4.907275643454239819e-05 1.820754084061740197e-05 2.772288834078687984e-05 1.046061247568982606e-05 2.225225911981681611e-07 +7.812495292061822673e-03 7.807139215375609106e-03 7.772241751786874986e-03 7.751242393952807209e-03 5.001574978626547913e-05 1.812741955189118513e-05 2.764027203504243102e-05 1.032613486388670125e-05 1.665620513368287718e-07 +7.812476894523122731e-03 7.806683943209593787e-03 7.772945300038862533e-03 7.751111453457110168e-03 4.940863028517055046e-05 1.778892355151607562e-05 2.700354558676601411e-05 1.144278173216673945e-05 2.931356705096467600e-07 +7.812447633371830819e-03 7.805360622923213781e-03 7.772280325110742481e-03 7.748841300394401430e-03 4.946498788292683508e-05 1.819664607815776332e-05 2.735932394244346047e-05 1.421182877230432772e-05 5.348146728831700359e-07 +7.812418676200951796e-03 7.803399072295380545e-03 7.768182598560221565e-03 7.742056677893807692e-03 5.260502689341779259e-05 2.029938517503130136e-05 3.022889388385826916e-05 1.827918656212739249e-05 7.737969837445373764e-07 +7.812400713050573174e-03 7.801328899352429937e-03 7.759458933900293363e-03 7.729571012333778281e-03 6.059554765283085880e-05 2.461554399679295580e-05 3.650070756930909251e-05 2.260937471593158608e-05 9.062974796379607276e-07 +7.812399402924678250e-03 7.799725111593778897e-03 7.746317787884777345e-03 7.711834931169255294e-03 7.387281172230948569e-05 3.099207090489362784e-05 4.602122468061838116e-05 2.595267368927323958e-05 8.916091203328781368e-07 +7.812413332542555815e-03 7.798951317677097449e-03 7.730372562608386205e-03 7.690803617564479985e-03 9.132598392869010779e-05 3.860912329843406692e-05 5.757879489393928250e-05 2.744243129201358010e-05 7.582080085956336064e-07 +7.812435655750508100e-03 7.799045564899258556e-03 7.714106581128725958e-03 7.669307408003667517e-03 1.106354824953435383e-04 4.624173039586804786e-05 6.930319478072197116e-05 2.696493794476126531e-05 5.706638856372884918e-07 +7.812458049977899846e-03 7.799779002849843365e-03 7.700032119112999729e-03 7.650185626982551265e-03 1.290317728818038228e-04 5.267491242189746055e-05 7.931021912472004868e-05 2.510498190276937440e-05 3.874743003157170213e-07 +7.812474472833470102e-03 7.800806553791946735e-03 7.689895100482323394e-03 7.635495440478613609e-03 1.441671433054891155e-04 5.710082886942940348e-05 8.631673803264112315e-05 2.275885910941017286e-05 2.386244849668603841e-07 +7.812482976849034755e-03 7.801806678970187037e-03 7.684226346611384290e-03 7.626043122362352773e-03 1.547629942338338998e-04 5.933866733362661114e-05 8.998326647379967301e-05 2.069121747385026391e-05 1.297730912415325758e-07 +7.812485232220344605e-03 7.802559641047198541e-03 7.682363107231317788e-03 7.621351204389437833e-03 1.608167121281512204e-04 5.980453704693076267e-05 9.088196765691194143e-05 1.927999912557097661e-05 5.844008953976879205e-08 +7.812484687099224487e-03 7.802969819103481100e-03 7.682863284657014818e-03 7.620020195549746453e-03 1.633555907751381572e-04 5.927321903152686335e-05 9.015594799946130046e-05 1.851857110723650212e-05 2.355680679308437475e-08 +7.812484528579055273e-03 7.803053725096873068e-03 7.684099485053701856e-03 7.620313644105695082e-03 1.639054050789472161e-04 5.855667006084784424e-05 8.904796951092744850e-05 1.818147643885591132e-05 2.259562066722161082e-08 +7.812486347732097020e-03 7.802906138662985686e-03 7.684792010505495964e-03 7.620734657771241656e-03 1.639180799370792388e-04 5.823836154829621197e-05 8.849453651262909287e-05 1.801056113072297418e-05 4.482718225915012074e-08 +7.812489966877368686e-03 7.802652857458577430e-03 7.684311301855815610e-03 7.620397450278489949e-03 1.643642387066439835e-04 5.854960502899452695e-05 8.891359154098924097e-05 1.782919431049579911e-05 7.161912630444491773e-08 +7.812494127122805894e-03 7.802404580937485380e-03 7.682698807419341414e-03 7.619109876382451629e-03 1.655862811202974880e-04 5.939615713527549305e-05 9.021286715380141135e-05 1.757035112025118347e-05 8.559997302272443172e-08 +7.812497470211249989e-03 7.802228932425433333e-03 7.680464665858448801e-03 7.617210995022639063e-03 1.673906019698739671e-04 6.048444806446939652e-05 9.196185539774789648e-05 1.725117344749978250e-05 8.071052106673271989e-08 +7.812499262283496664e-03 7.802147068445501599e-03 7.678284905384741635e-03 7.615288498122666817e-03 1.692825327983098758e-04 6.147641588181483141e-05 9.362872093630432619e-05 1.693047970507380231e-05 6.424811185473353517e-08 +7.812499556017950091e-03 7.802145493693739449e-03 7.676725520415324244e-03 7.613906859695971675e-03 1.707300961208414974e-04 6.211532079841483437e-05 9.478777861569192588e-05 1.666872075534763098e-05 4.957518521111539337e-08 +7.812498898940323407e-03 7.802189426919653448e-03 7.676076529785660213e-03 7.613428103579155878e-03 1.713654284443885114e-04 6.229347725606795285e-05 9.523952736898054429e-05 1.649883460424523220e-05 4.584613527028352739e-08 +7.812497920560946760e-03 7.802232495060661827e-03 7.676319544958354509e-03 7.613946242661542678e-03 1.710785375910244487e-04 6.205778441104415428e-05 9.502791401655731585e-05 1.641215865889956077e-05 5.255976528493730751e-08 +7.812497066894792501e-03 7.802227167898124344e-03 7.677201581430874618e-03 7.615314113993682313e-03 1.700042512425950004e-04 6.156635540337338387e-05 9.437552276658168148e-05 1.636184653588275881e-05 6.184665501771761686e-08 +7.812496511241781051e-03 7.802139573436450704e-03 7.678360934842314196e-03 7.617224476854871258e-03 1.684368934514004535e-04 6.102002790153284524e-05 9.357839679933613655e-05 1.628189975863044079e-05 6.526686105702234742e-08 +7.812496219646037840e-03 7.801963573583982695e-03 7.679448409179731941e-03 7.619307392520942475e-03 1.667211245983212084e-04 6.059647760585791217e-05 9.290647870527361698e-05 1.611438596915572326e-05 5.944474959016087870e-08 +7.812496067262236082e-03 7.801724521784449314e-03 7.680207555690407410e-03 7.621215867234738643e-03 1.651611118942663268e-04 6.040796446319642645e-05 9.254061247558314075e-05 1.583289243326745281e-05 4.721294373152034348e-08 +7.812495939725520519e-03 7.801468805562560005e-03 7.680500815485480186e-03 7.622682332336906674e-03 1.639704408479166744e-04 6.049154736383084284e-05 9.255705934859457618e-05 1.545276710389118145e-05 3.486730501181152877e-08 +7.812495810392372161e-03 7.801245471614342251e-03 7.680293265591961113e-03 7.623542163437857511e-03 1.632627294083275303e-04 6.082500272239638590e-05 9.294827781949960212e-05 1.502481172788627132e-05 2.836530457701504368e-08 +7.812495774057383324e-03 7.801090398214164875e-03 7.679617741755038161e-03 7.623730980268567277e-03 1.630687270832232910e-04 6.135328767953494530e-05 9.365818359531991294e-05 1.461705702769232774e-05 3.062975683152378586e-08 +7.812496004572946559e-03 7.801019097885079565e-03 7.678544236128501121e-03 7.623267186730509938e-03 1.633636498553494383e-04 6.201144366886053398e-05 9.461157972898225999e-05 1.429342797726595519e-05 4.043850989161355651e-08 +7.812496631779798119e-03 7.801027496962795009e-03 7.677165776783217294e-03 7.622229199252808160e-03 1.640937838916600819e-04 6.273706605913448688e-05 9.572723457634188516e-05 1.409693806672889080e-05 5.277965583598395105e-08 +7.812497593986529945e-03 7.801096856079874943e-03 7.675599630972139084e-03 7.620731771399200105e-03 1.651974699868906436e-04 6.347246017827182240e-05 9.691547544110199126e-05 1.404137420550190033e-05 6.090756096056601143e-08 +7.812498566204971115e-03 7.801199754440974084e-03 7.673992897753495815e-03 7.618903661828040075e-03 1.666176502970805691e-04 6.416043472906765414e-05 9.806960623076769253e-05 1.411294308233202020e-05 5.993589060455973356e-08 +7.812499053771074925e-03 7.801305349386283491e-03 7.672518875246725489e-03 7.616869257773883906e-03 1.683046089823451085e-04 6.473936921646154048e-05 9.906343259329801248e-05 1.428210110113845229e-05 5.027682857905558417e-08 +7.812498632159666813e-03 7.801382900472925326e-03 7.671356652224933619e-03 7.614739595271466377e-03 1.702096434999436484e-04 6.514310541558802512e-05 9.976321818125709177e-05 1.452125443129783517e-05 3.829448713707502261e-08 +7.812497201837249015e-03 7.801403862531090978e-03 7.670657640407920266e-03 7.612615855838451850e-03 1.722743768132731137e-04 6.530927069172183942e-05 1.000534417096700466e-04 1.481781435146641011e-05 3.294263590754535029e-08 +7.812495078364333281e-03 7.801344666489945685e-03 7.670510553714322832e-03 7.610600036568103931e-03 1.744227893749939232e-04 6.519571551979745270e-05 9.986799788108100028e-05 1.517179567317124298e-05 4.016604303805187084e-08 +7.812492900103195845e-03 7.801192644470767747e-03 7.670919899304099940e-03 7.608803560422339532e-03 1.765599991482183864e-04 6.479804001506211746e-05 9.921318396850725772e-05 1.557572355818140049e-05 5.876129580872593247e-08 +7.812491399909044648e-03 7.800954310441960901e-03 7.671806713972414808e-03 7.607344211055998458e-03 1.785775612115598305e-04 6.415814227891146265e-05 9.817148076228197353e-05 1.599052210317778022e-05 8.069995376715356099e-08 +7.812491115931742038e-03 7.800660131530765505e-03 7.673033286305866278e-03 7.606329970254107307e-03 1.803626974654734159e-04 6.335517272175504935e-05 9.688053494765318523e-05 1.633939801180696436e-05 9.591747241806178274e-08 +7.812492133591250783e-03 7.800359190254140332e-03 7.674441600347642854e-03 7.605837575408820259e-03 1.818080321303487473e-04 6.248181849103899717e-05 9.549537823929271684e-05 1.653082719052810295e-05 9.833364655358530313e-08 +7.812494031046210430e-03 7.800102179172256622e-03 7.675896495846616999e-03 7.605897118576439818e-03 1.828226666389231193e-04 6.161441159967244615e-05 9.414446198404529656e-05 1.650237702724804381e-05 8.885369315965530215e-08 +7.812496052543584438e-03 7.799921303838168625e-03 7.677317282524499797e-03 7.606490090774489093e-03 1.833430573543588750e-04 6.079269373977964908e-05 9.289859503958730949e-05 1.625765820792788300e-05 7.334301113257308106e-08 +7.812497439077231015e-03 7.799819160821133690e-03 7.678687734277541560e-03 7.607558169686876905e-03 1.833426694457979708e-04 6.001769729579950902e-05 9.176364274852043203e-05 1.587269546633251967e-05 5.755832196158116801e-08 +7.812497729013648771e-03 7.799773549843452315e-03 7.680039522150496067e-03 7.609017003352169274e-03 1.828346147238102306e-04 5.926707271268964972e-05 9.069961910013031267e-05 1.546620639546001242e-05 4.367983950618309385e-08 +7.812496926672149108e-03 7.799752994451267067e-03 7.681416702438653189e-03 7.610766790791871801e-03 1.818667647155675722e-04 5.851800025715518221e-05 8.965562716129177984e-05 1.515316230951711319e-05 3.122579787001255668e-08 +7.812495468274187685e-03 7.799731951055652486e-03 7.682835526327059031e-03 7.612698745924777015e-03 1.805102346395485047e-04 5.776728284319049658e-05 8.860630501187015645e-05 1.500776599250491295e-05 2.081738234097757612e-08 +7.812494016638638072e-03 7.799697603207485230e-03 7.684256601122156811e-03 7.614700518728856164e-03 1.788464912402624996e-04 5.704162388654450915e-05 8.757577061659674008e-05 1.505214344464923625e-05 1.619689641452411641e-08 +7.812493190330011515e-03 7.799648584005202875e-03 7.685580722774925863e-03 7.616663927961365814e-03 1.769587121590053330e-04 5.639621921786125067e-05 8.664108488644773742e-05 1.526756760774609803e-05 2.164868747164934285e-08 +7.812493299653834079e-03 7.799590748379032698e-03 7.686670407032592141e-03 7.618494928507740273e-03 1.749302970073336380e-04 5.590279367022501475e-05 8.591411849626973997e-05 1.561254289370475563e-05 3.696860078954675002e-08 +7.812494265631523410e-03 7.799534011930964357e-03 7.687386700992878373e-03 7.620121303322026016e-03 1.728492941645273838e-04 5.563158007306383187e-05 8.550992286051971704e-05 1.603327927725472439e-05 5.520836506281878338e-08 +7.812495719581083985e-03 7.799488670675083432e-03 7.687630571093129368e-03 7.621494785823084046e-03 1.708138484432252554e-04 5.563085091837701400e-05 8.551007496670540967e-05 1.646635384646213534e-05 6.626114818767479494e-08 +7.812497205244232044e-03 7.799460270436679374e-03 7.687372984260292669e-03 7.622586576308315945e-03 1.689329458115936781e-04 5.591130652985255368e-05 8.593512815630114645e-05 1.684156091513745103e-05 6.387890909022737881e-08 diff --git a/tools/rt-tddft-tools/examples/ground-state-projection-Si/STRU b/tools/rt-tddft-tools/examples/ground-state-projection-Si/STRU new file mode 100644 index 0000000000..cec713581f --- /dev/null +++ b/tools/rt-tddft-tools/examples/ground-state-projection-Si/STRU @@ -0,0 +1,22 @@ +ATOMIC_SPECIES +Si 28.085 ../../../../tests/PP_ORB/Si_ONCV_PBE-1.0.upf + +NUMERICAL_ORBITAL +../../../../tests/PP_ORB/Si_gga_8au_100Ry_2s2p1d.orb + +LATTICE_CONSTANT +10.2 // add lattice constant + +LATTICE_VECTORS +0.5 0.5 0.0 +0.5 0.0 0.5 +0.0 0.5 0.5 + +ATOMIC_POSITIONS +Cartesian //Cartesian or Direct coordinate. + +Si // Element type +0.0 // magnetism +2 // number of atoms +0.00 0.00 0.00 m 0 0 0 +0.25 0.25 0.25 m 0 0 0 \ No newline at end of file diff --git a/tools/rt-tddft-tools/examples/ground-state-projection-Si/projection.py b/tools/rt-tddft-tools/examples/ground-state-projection-Si/projection.py new file mode 100644 index 0000000000..10fa518c2a --- /dev/null +++ b/tools/rt-tddft-tools/examples/ground-state-projection-Si/projection.py @@ -0,0 +1,111 @@ +import numpy as np +import matplotlib.pyplot as plt +class Projection: + def __init__(self, stepref, klist, steps, fdir='./OUT.ABACUS', wfc_dir='', s_dir=''): + self.stepref = stepref + self.klist = klist + self.steps = steps + self.wfc_dir = fdir + wfc_dir + self.s_dir = fdir + s_dir + wfc_ref, Ocp_ref = self.read_wfc(klist[0]+1, stepref+1, dir=self.wfc_dir) + self.nband = len(Ocp_ref) + self.nlocal = len(wfc_ref[0]) + + def read_wfc(self, kpoint, nstep, dir='.'): + file = dir+'/WFC_NAO_K'+str(kpoint)+'_ION'+str(nstep)+'.txt' + read_flag=0 + with open(file,'r') as f: + for line in f: + if('bands' in line): + bands=int(line.split()[0]) + elif('orbitals' in line): + orbitals=int(line.split()[0]) + wavef0=np.zeros([bands,orbitals],dtype=complex) + Ocp=np.zeros(bands,dtype=float) + elif('(band)' in line): + read_flag=0 + i=int(line.split()[0])-1 + j=0 + elif('Occupations' in line): + Ocp[i]=float(line.split()[0]) + read_flag=1 + continue + elif(read_flag==1): + tmp=line.split() + for l in range(len(tmp)//2): + wavef0[i][j]=complex(float(tmp[2*l]),float(tmp[2*l+1])) + j+=1 + return wavef0,Ocp + + def CSC(self, Cd,Sk,C): + Cdag=np.conjugate(Cd).transpose() + return np.matmul(Cdag,np.matmul(Sk,C)) + def CSC2(self, Cd,Sk,C): + CSC1=self.CSC(Cd,Sk,C) + return CSC1*CSC1.conjugate() + + def S_read(self, kpoint,nstep,dir='.'): + file = dir+'/'+str(nstep)+'_data-'+str(kpoint)+'-S' + count=0 + fir=1 + with open(file, 'r') as f1: + for line in f1: + tmp=line.split() + if(fir==1): + dim=int(tmp[0]) + i=0 + Sk=np.zeros([dim,dim],dtype=complex) + fir=0 + for j in range(dim): + c_s=eval(tmp[j+1]) + Sk[i][j]=complex(c_s[0],c_s[1]) + else: + for j in range(dim-i): + c_s=eval(tmp[j]) + Sk[i][i+j]=complex(c_s[0],c_s[1]) + i+=1 + if(i==0): + break + for i in range(dim): + for j in range(i): + Sk[i][j]=Sk[j][i].conjugate() + return Sk + + def cal_Pnm(self, ik, nstep, wfc_ref): + wfc_t,Ocp_t=self.read_wfc(ik+1, nstep+1, dir=self.wfc_dir) + S_t=self.S_read(ik,nstep,dir=self.s_dir) + Pnm=np.zeros([self.nband,self.nband],dtype=float) + for a in range(self.nband): + for b in range(self.nband): + Pnm[a][b] = self.CSC2(wfc_ref[a],S_t,wfc_t[b]).real + return Pnm, Ocp_t + + def cal_On_single(self, ik, nstep, wfc_ref): + Pnm, Ocp_t = self.cal_Pnm(ik, nstep, wfc_ref) + On = np.zeros(self.nband,dtype=float) + On = Ocp_t @ Pnm + return On + + def save_On_all(self): + for ik in self.klist: + wfc_ref,Ocp_ref=self.read_wfc(ik+1, self.stepref+1, dir=self.wfc_dir) + On_tot = np.zeros([len(steps),self.nband],dtype=float) + for n, nstep in enumerate(steps): + On_tot[n] = self.cal_On_single(ik, nstep, wfc_ref) + np.savetxt('On_'+str(ik)+'.dat', On_tot) + + +if __name__ == "__main__": + #the kpoints you need, check kpoints file to get the index, for this example, 0 means gamma point + klist=[0, 1] + #the steps you need, check STRU_MD file to get the index + start_step = 0 + end_step = 10005 + out_interval = 25 + steps = range(start_step, end_step, out_interval) + #the ground state step + stepref=0 + #Ground state projection + pro=Projection(0, klist, steps) + #save the Occupation infos to file + pro.save_On_all() \ No newline at end of file diff --git a/tools/rt-tddft-tools/overlap_generator.py b/tools/rt-tddft-tools/overlap_generator.py new file mode 100644 index 0000000000..d86f1af940 --- /dev/null +++ b/tools/rt-tddft-tools/overlap_generator.py @@ -0,0 +1,241 @@ +from pyatb.easy_use import stru_analyzer +from pyabacus import ModuleNAO as nao +from pyabacus import ModuleBase as base +import numpy as np +from collections import Counter +import pyatb +from pyatb.easy_use import stru_analyzer +import re +Bohr=0.5291772105638411 +class overlap_R: + def __init__(self, orb_file_dir, atoms0, atomst): + # get orbital information from the structure + orb_file_list = list(atoms0.info['basis'].values()) + orb_file_list = [orb_file_dir + orbfile for orbfile in orb_file_list] + orb_file_num = len(orb_file_list) + + symbols = atoms0.get_chemical_symbols() + element_counts = Counter(symbols) + unique_elements = set(symbols) + assert orb_file_num == len(unique_elements), f"The number of orbitals{orb_file_num}does not match the number of unique elements{len(unique_elements)}!" + + # Build orbital collection + self.orb = nao.RadialCollection() + self.orb.build(orb_file_num, orb_file_list, 'o') + + # Standardize the orbital grid + rmax = self.orb.rcut_max * 2.0 + dr = 0.01 + nr = int(rmax/dr) + 1 + self.orb.set_uniform_grid(True, nr, rmax, 'i', True) + + # Print basic orbital information + ntype = self.orb.ntype + lmax = self.orb.lmax + + # Initialize the integrator + self.S_intor = nao.TwoCenterIntegrator() + self.S_intor.tabulate(self.orb, self.orb, 'S', nr, rmax) + + # Retrieve orbital index sorting from the structure + # Determine the correspondence between the basis set indices and orbital information + self.lattice_vector = atoms0.get_cell()[:] / Bohr + self.atom_positions_c = atoms0.get_positions() / Bohr + self.atom_positions_ct = atomst.get_positions() / Bohr + self.cal_R_direct_coor() + + self.iw2it = dict() + self.iw2positions_c = dict() + self.iw2positions_ct = dict() + self.iw2iL = dict() + self.iw2iN = dict() + self.iw2im = dict() + count = 0 + count_atom = 0 + for it, element in enumerate(unique_elements): + for ia in range(element_counts[element]): + for iL in range(self.orb.lmax_(it)+1): + for iN in range(self.orb.nzeta(it, iL)): + for im in range(2*iL+1): + self.iw2it[count] = it + self.iw2positions_c[count] = self.atom_positions_c[count_atom] + self.iw2positions_ct[count] = self.atom_positions_ct[count_atom] + self.iw2iL[count] = iL + self.iw2iN[count] = iN + if im%2 == 0: + self.iw2im[count] = ((im+1) // 2) * -1 + else: + self.iw2im[count] = ((im+1) // 2) * 1 + + count = count + 1 + count_atom = count_atom + 1 + + def cal_R_direct_coor(self): + rcut=self.orb.rcut_max*np.ones(len(self.atom_positions_c),dtype=float) + print(rcut) + Ncell = NeighbourCell(self.lattice_vector, self.atom_positions_c, self.atom_positions_ct, rcut) + self.R_direct_coor = np.array(Ncell.check_interaction_neighbours()) + + def cal_overlap(self): + basis_num = len(self.iw2it) + self.SR = np.zeros((self.R_direct_coor.shape[0], basis_num, basis_num), dtype=float) + for iR, R_coor in enumerate(self.R_direct_coor): + for row in range(basis_num): + for col in range(basis_num): + result = self.__cal_S(row, col, R_coor) + self.SR[iR, row, col] = result[0] + return self.SR + + def __cal_S(self, iw1, iw2, dR): + dR = dR @ self.lattice_vector + dtau = self.iw2positions_c[iw2] - self.iw2positions_ct[iw1] + R = dR + dtau + + result = self.S_intor.calculate( + self.iw2it[iw1], + self.iw2iL[iw1], + self.iw2iN[iw1], + self.iw2im[iw1], + self.iw2it[iw2], + self.iw2iL[iw2], + self.iw2iN[iw2], + self.iw2im[iw2], + R, True) + + return result + def cal_Sk(self,kpoint_direct_coor): + basis_num = len(self.iw2it) + Sk = np.zeros([basis_num, basis_num], dtype=complex) + for iR in range(self.R_direct_coor.shape[0]): + arg = np.inner(kpoint_direct_coor, self.R_direct_coor[iR]) * 2 * np.pi + phase = complex(np.cos(arg), np.sin(arg)) + Sk = Sk + phase * self.SR[iR] + return Sk +def read_kpoints(file='.'): + file=file+'/kpoints' + with open(file,'r') as f: + read_flag=0 + for line in f: + if('nkstot now' in line): + nks_tot=int(line.split()[3]) + kpoints=np.zeros([nks_tot,3],dtype=float) + if(read_flag==1): + tmp=line.split() + kpoints[ik]=np.array([float(tmp[1]),float(tmp[2]),float(tmp[3])]) + ik+=1 + if(ik==nks_tot): + break + if('WEIGHT' in line): + read_flag=1 + ik=0 + return kpoints + +class NeighbourCell: + def __init__(self, lattice_vectors, atom_positions0, atom_positionst, cutoff_radii): + """ + Initialize lattice vectors, atom positions, and cutoff radii for each atom. + - lattice_vectors: Lattice vectors + - atom_positions: Atom positions + - cutoff_radii: Cutoff radii for each atom + """ + if len(lattice_vectors) != 3 or len(atom_positions0) == 0 or len(cutoff_radii) != len(atom_positions0): + raise ValueError("Invalid lattice vectors, atom positions or cutoff radii") + + self.lattice_vectors = np.array(lattice_vectors) + self.atom_positions0 = np.array(atom_positions0) + self.atom_positionst = np.array(atom_positionst) + self.cutoff_radii = np.array(cutoff_radii) + self.natoms = len(atom_positions0) + + def calculate_distance_to_neighbour(self, atom_index1, atom_index2, translation_vector): + """ + Calculate the distance between any two atoms + """ + if atom_index1 < 0 or atom_index1 >= self.natoms or \ + atom_index2 < 0 or atom_index2 >= self.natoms: + raise IndexError("Atom index out of range") + + displacement = self.atom_positionst[atom_index2] - self.atom_positions0[atom_index1] + (self.lattice_vectors@np.array(translation_vector).T).T + + # Return the Euclidean distance + return np.linalg.norm(displacement) + + def check_interaction_neighbours(self): + """ + Check for interactions between atoms in the unit cell and atoms in neighbouring unit cells. + atom_index: Index of the atom to check + translation_vector: The translation vector for the neighbouring unit cell + Returns a list of translation vectors for all neighbouring cells with interactions. + """ + interactions = [] # List to store translation vectors of neighbouring cells with interactions + # Loop over translation vectors + for t in range(-5, 5): + for u in range(-5, 5): + for v in range(-5, 5): + # Create a translation vector + neighbour_translation = np.array([t, u, v]) + # Loop through each atom in the unit cell and check interactions with atoms in neighbouring cells + if_find = False + for i in range(self.natoms): + for j in range(self.natoms): + distance = self.calculate_distance_to_neighbour(i, j, neighbour_translation) + # if overlap exists, add the translation vector to the list + if distance <= (self.cutoff_radii[i] + self.cutoff_radii[j]): + interactions.append(neighbour_translation) + if_find = True + break + if if_find: + break + return interactions + +def save_upper_triangle_as_matrix(matrix, filename): + # Open the file for writing + with open(filename, 'w') as f: + f.write(f'{matrix.shape[0]} ') + # Iterate over each row + for i in range(matrix.shape[0]): + # Extract the upper triangular part of the row + row = matrix[i, i:] + row_str = ' '.join(f'({x.real:.8e},{x.imag:.8e})' for x in row) + f.write(row_str + '\n') + +def overlap_gen(stepref: int, klist, steps, stru_dir='./OUT.ABACUS/STRU', orb_file_dir='',kpoits_dir='./OUT.ABACUS'): + """Generate overlap files for moved atoms + :params stepref: the ground state step + :params klist: the list for needed kpoints + :params steps: the list for needed steps + :params stru_dir: the directory for STRU files + :params orb_file_dir: the directory for orb files, same as 'orbital_dir' in the INPUT + :params kpoits_dir: the directory for kpoints files + """ + #read in ref STRU + with open(stru_dir+'/STRU_MD_'+str(stepref), 'r') as fd: + atoms0 = stru_analyzer.read_abacus_stru(fd, verbose=True) + #read in kpoints + kpt=read_kpoints(kpoits_dir) + #loop over steps + for n, nstep in enumerate(steps): + #read in time t STRU + with open(stru_dir+'/STRU_MD_'+str(nstep), 'r') as fd: + atomst = stru_analyzer.read_abacus_stru(fd, verbose=True) + SR_tmp = overlap_R(orb_file_dir, atoms0, atomst) + SR_tmp.cal_overlap() + #loop over kpoints needed + for ik in klist: + Sk_ik = SR_tmp.cal_Sk(kpt[ik]) + save_upper_triangle_as_matrix(Sk_ik, f'{nstep}_data-{ik}-S') + + +#warning : pyatb and pyabacus are required, install them first +if __name__ == "__main__": + #the kpoints you need, check kpoints file to get the index + klist=[0] + #the steps you need, check STRU_MD file to get the index + start_step = 0 + end_step = 20 + out_interval = 5 + steps = range(start_step, end_step, out_interval) + #the ground state step + stepref=0 + #generate overlap files for moved atoms + overlap_gen(stepref, klist, steps) diff --git a/tools/rt-tddft-tools/projection.py b/tools/rt-tddft-tools/projection.py new file mode 100644 index 0000000000..80d54504b1 --- /dev/null +++ b/tools/rt-tddft-tools/projection.py @@ -0,0 +1,111 @@ +import numpy as np +import matplotlib.pyplot as plt +class Projection: + def __init__(self, stepref, klist, steps, fdir='./OUT.ABACUS', wfc_dir='', s_dir=''): + self.stepref = stepref + self.klist = klist + self.steps = steps + self.wfc_dir = fdir + wfc_dir + self.s_dir = fdir suffix + s_dir + wfc_ref, Ocp_ref = self.read_wfc(klist[0]+1, stepref+1, dir=self.wfc_dir) + self.nband = len(Ocp_ref) + self.nlocal = len(wfc_ref[0]) + + def read_wfc(self, kpoint, nstep, dir='.'): + file = dir+'/WFC_NAO_K'+str(kpoint)+'_ION'+str(nstep)+'.txt' + read_flag=0 + with open(file,'r') as f: + for line in f: + if('bands' in line): + bands=int(line.split()[0]) + elif('orbitals' in line): + orbitals=int(line.split()[0]) + wavef0=np.zeros([bands,orbitals],dtype=complex) + Ocp=np.zeros(bands,dtype=float) + elif('(band)' in line): + read_flag=0 + i=int(line.split()[0])-1 + j=0 + elif('Occupations' in line): + Ocp[i]=float(line.split()[0]) + read_flag=1 + continue + elif(read_flag==1): + tmp=line.split() + for l in range(len(tmp)//2): + wavef0[i][j]=complex(float(tmp[2*l]),float(tmp[2*l+1])) + j+=1 + return wavef0,Ocp + + def CSC(self, Cd,Sk,C): + Cdag=np.conjugate(Cd).transpose() + return np.matmul(Cdag,np.matmul(Sk,C)) + def CSC2(self, Cd,Sk,C): + CSC1=self.CSC(Cd,Sk,C) + return CSC1*CSC1.conjugate() + + def S_read(self, kpoint,nstep,dir='.'): + file = dir+'/'+str(nstep)+'_data-'+str(kpoint)+'-S' + count=0 + fir=1 + with open(file, 'r') as f1: + for line in f1: + tmp=line.split() + if(fir==1): + dim=int(tmp[0]) + i=0 + Sk=np.zeros([dim,dim],dtype=complex) + fir=0 + for j in range(dim): + c_s=eval(tmp[j+1]) + Sk[i][j]=complex(c_s[0],c_s[1]) + else: + for j in range(dim-i): + c_s=eval(tmp[j]) + Sk[i][i+j]=complex(c_s[0],c_s[1]) + i+=1 + if(i==0): + break + for i in range(dim): + for j in range(i): + Sk[i][j]=Sk[j][i].conjugate() + return Sk + + def cal_Pnm(self, ik, nstep, wfc_ref): + wfc_t,Ocp_t=self.read_wfc(ik+1, nstep+1, dir=self.wfc_dir) + S_t=self.S_read(ik,nstep,dir=self.s_dir) + Pnm=np.zeros([self.nband,self.nband],dtype=float) + for a in range(self.nband): + for b in range(self.nband): + Pnm[a][b] = self.CSC2(wfc_ref[a],S_t,wfc_t[b]).real + return Pnm, Ocp_t + + def cal_On_single(self, ik, nstep, wfc_ref): + Pnm, Ocp_t = self.cal_Pnm(ik, nstep, wfc_ref) + On = np.zeros(self.nband,dtype=float) + On = Ocp_t @ Pnm + return On + + def save_On_all(self): + for ik in self.klist: + wfc_ref,Ocp_ref=self.read_wfc(ik+1, self.stepref+1, dir=self.wfc_dir) + On_tot = np.zeros([len(steps),self.nband],dtype=float) + for n, nstep in enumerate(steps): + On_tot[n] = self.cal_On_single(ik, nstep, wfc_ref) + np.savetxt('On_'+str(ik)+'.dat', On_tot) + + +if __name__ == "__main__": + #the kpoints you need, check kpoints file to get the index + klist=[0] + #the steps you need, check STRU_MD file to get the index + start_step = 0 + end_step = 20 + out_interval = 5 + steps = range(start_step, end_step, out_interval) + #the ground state step + stepref=0 + #Ground state projection + pro=Projection(0, klist, steps) + #save the Occupation infos to file + pro.save_On_all() \ No newline at end of file