Skip to content

Commit c1f2df9

Browse files
committed
Included the mapping3 stuff in the cp2k and mopac workflows
1 parent 71ca44c commit c1f2df9

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

src/libra_py/packages/mopac/methods.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
from libra_py import units
3535
from libra_py import scan
3636
from libra_py import regexlib as rgl
37+
from libra_py import data_conv
3738

3839
import libra_py.packages.cp2k.methods as CP2K_methods
3940
import libra_py.workflows.nbra.mapping2 as mapping2
41+
import libra_py.workflows.nbra.mapping3 as mapping3
4042
import libra_py.workflows.nbra.step3 as step3
4143

4244

@@ -516,6 +518,7 @@ def mopac_compute_adi(q, params, full_id):
516518
mopac_jobid = params[itraj]["mopac_jobid"] = F"timestep_{timestep}_traj_{itraj}"
517519
mopac_input_prefix = params[itraj]["mopac_input_prefix"]
518520
mopac_output_prefix = params[itraj]["mopac_output_prefix"]
521+
active_space = params[itraj]["active_space"]
519522
dt = params[itraj]["dt"]
520523
do_Lowdin = params[itraj]["do_Lowdin"]
521524

@@ -594,13 +597,26 @@ def mopac_compute_adi(q, params, full_id):
594597
ci_ovlp_curr = None
595598
if do_Lowdin:
596599
ident_curr = U_curr.T() * S_curr.real() * U_curr
597-
ovlp_sd_curr = mapping2.ovlp_mat_arb(configs_curr, configs_curr, ident_curr, False).real()
600+
# The original (older) approach
601+
#ovlp_sd_curr = mapping2.ovlp_mat_arb(configs_curr, configs_curr, ident_curr, False).real()
602+
603+
# The new way:
604+
# I don't like this way - we need to fix it later
605+
ident_curr = data_conv.MATRIX2nparray(ident_curr).real # MATRIX -> real np array
606+
ovlp_sd_curr = mapping3.ovlp_mat_arb(configs_curr, configs_curr, ident_curr, active_space) # do the calculations
607+
ovlp_sd_curr = data_conv.nparray2MATRIX( ovlp_sd_curr ) # real np array -> MATRIX
608+
598609
ovlp_sd_curr.scale(-1, 0, sqt2)
599610
ovlp_sd_curr.scale(0, -1, sqt2)
600611
ovlp_sd_curr.scale(0, 0, 0.5)
601612

602613
ident_prev = U_prev.T() * S_prev.real() * U_prev
603-
ovlp_sd_prev = mapping2.ovlp_mat_arb(configs_prev, configs_prev, ident_prev, False).real()
614+
#ovlp_sd_prev = mapping2.ovlp_mat_arb(configs_prev, configs_prev, ident_prev, False).real()
615+
616+
ident_prev = data_conv.MATRIX2nparray(ident_prev).real # MATRIX -> real np array
617+
ovlp_sd_prev = mapping3.ovlp_mat_arb(configs_prev, configs_prev, ident_prev, active_space) # do the calculations
618+
ovlp_sd_prev = data_conv.nparray2MATRIX( ovlp_sd_prev ) # complex np array -> CMATRIX
619+
604620
ovlp_sd_prev.scale(-1, 0, sqt2)
605621
ovlp_sd_prev.scale(0, -1, sqt2)
606622
ovlp_sd_prev.scale(0, 0, 0.5)
@@ -620,14 +636,25 @@ def mopac_compute_adi(q, params, full_id):
620636
ci_ovlp_curr = U_curr.T() * ovlp_ci_curr.real() * U_curr
621637
else:
622638
S_curr = MO_curr.T() * MO_curr
623-
ovlp_sd_curr = mapping2.ovlp_mat_arb(configs_curr, configs_curr, S_curr, False).real()
639+
#ovlp_sd_curr = mapping2.ovlp_mat_arb(configs_curr, configs_curr, S_curr, False).real()
640+
641+
S_curr = data_conv.MATRIX2nparray(S_curr).real # MATRIX -> real np array
642+
ovlp_sd_curr = mapping3.ovlp_mat_arb(configs_curr, configs_curr, S_curr, active_space) # do the calculations
643+
ovlp_sd_curr = data_conv.nparray2MATRIX( ovlp_sd_curr ) # complex np array -> MATRIX
644+
624645
ovlp_sd_curr.scale(-1, 0, sqt2)
625646
ovlp_sd_curr.scale(0, -1, sqt2)
626647
ovlp_sd_curr.scale(0, 0, 0.5)
627648
ci_ovlp_curr = CI_curr.T() * ovlp_sd_curr * CI_curr
628649

629650
# Time-overlap in the SD basis
630-
time_ovlp_sd = mapping2.ovlp_mat_arb(configs_prev, configs_curr, mo_st, False).real()
651+
#time_ovlp_sd = mapping2.ovlp_mat_arb(configs_prev, configs_curr, mo_st, False).real()
652+
653+
mo_st = data_conv.MATRIX2nparray(mo_st).real # MATRIX -> real np array
654+
time_ovlp_sd = mapping3.ovlp_mat_arb(configs_prev, configs_curr, mo_st, active_space) # do the calculations
655+
time_ovlp_sd = data_conv.nparray2MATRIX( time_ovlp_sd ) # complex np array -> MATRIX
656+
657+
631658
# Scaling to account for SAC prefactors:
632659
time_ovlp_sd.scale(-1, 0, sqt2)
633660
time_ovlp_sd.scale(0, -1, sqt2)

src/libra_py/workflows/nbra/mapping3.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
2020
"""
2121

22-
import os
23-
import sys
24-
import math
22+
import os, sys, math
23+
import numpy as np
2524

2625
# Fisrt, we add the location of the library to test to the PYTHON path
2726
if sys.platform == "cygwin":
@@ -54,7 +53,7 @@ def ovlp_arb(_SD1, _SD2, S, active_space=None, verbose=False):
5453
5554
"""
5655

57-
nbasis = S.num_of_rows
56+
nbasis = S.shape[0] #num_of_rows
5857

5958
SD1, SD2 = [], []
6059

@@ -87,7 +86,7 @@ def ovlp_arb(_SD1, _SD2, S, active_space=None, verbose=False):
8786
if (I * J) > 0:
8887
i = abs(I) - 1
8988
j = abs(J) - 1
90-
s[indx_I, indx_J] = S.get(i, j).real
89+
s[indx_I, indx_J] = S[i, j] # .real #S.get(i, j).real
9190
else:
9291
s[indx_I, indx_J] = 0.0
9392

@@ -100,7 +99,7 @@ def ovlp_arb(_SD1, _SD2, S, active_space=None, verbose=False):
10099

101100

102101

103-
def ovlp_mat_arb(SD1, SD2, S, active_space):
102+
def ovlp_mat_arb(SD1, SD2, S, active_space=None):
104103
"""Compute a matrix of overlaps in the SD basis
105104
106105
Args:
@@ -126,12 +125,13 @@ def ovlp_mat_arb(SD1, SD2, S, active_space):
126125
"""
127126

128127
N, M = len(SD1), len(SD2)
129-
res = CMATRIX(N, M)
128+
res = np.zeros( (N, M), dtype=np.float64 ) #CMATRIX(N, M)
130129

131130
for n in range(0, N):
132131
for m in range(0, M):
133-
val = ovlp_arb(SD1[n], SD2[m], S, active_space, 0)
134-
res.set(n, m, val)
132+
res[n, m] = ovlp_arb(SD1[n], SD2[m], S, active_space, 0)
133+
#res.set(n, m, val)
134+
#res[n, m] = val
135135

136136
return res
137137

src/libra_py/workflows/nbra/step3.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
elif sys.platform == "linux" or sys.platform == "linux2":
4444
from liblibra_core import *
4545

46-
from . import mapping, step2_many_body, step3_many_body
46+
from . import mapping, mapping3, step2_many_body, step3_many_body
4747
import util.libutil as comn
4848
import libra_py.packages.cp2k.methods as CP2K_methods
4949
import libra_py.units as units
@@ -2717,7 +2717,8 @@ def compute_sd_overlaps_in_parallel(step, params):
27172717

27182718
start_time = params['start_time']
27192719
res_dir_1 = params['path_to_npz_files']
2720-
active_space = params['active_space']
2720+
active_space = params.get('active_space', None)
2721+
active_space2 = ( np.array(active_space) + 1 ).tolist() # conversion to a different convention
27212722
sd_states_reindexed_sorted = params['sd_states_reindexed_sorted']
27222723

27232724
t2 = time.time()
@@ -2739,24 +2740,27 @@ def compute_sd_overlaps_in_parallel(step, params):
27392740
# Computing the overlaps for SDs
27402741
t2 = time.time()
27412742
if params['apply_orthonormalization']:
2742-
s_sd_1 = mapping.ovlp_mat_arb(
2743+
s_sd_1 = mapping3.ovlp_mat_arb(
27432744
sd_states_reindexed_sorted[step],
27442745
sd_states_reindexed_sorted[step],
27452746
s_ks_1,
2746-
use_minimal=False,
2747-
use_mo_approach=False).real
2748-
s_sd_2 = mapping.ovlp_mat_arb(
2747+
active_space2)
2748+
#use_minimal=False,
2749+
#use_mo_approach=False).real
2750+
s_sd_2 = mapping3.ovlp_mat_arb(
27492751
sd_states_reindexed_sorted[step + 1],
27502752
sd_states_reindexed_sorted[step + 1],
27512753
s_ks_2,
2752-
use_minimal=False,
2753-
use_mo_approach=False).real
2754+
active_space2)
2755+
#use_minimal=False,
2756+
#use_mo_approach=False).real
27542757

2755-
st_sd = mapping.ovlp_mat_arb(sd_states_reindexed_sorted[step],
2758+
st_sd = mapping3.ovlp_mat_arb(sd_states_reindexed_sorted[step],
27562759
sd_states_reindexed_sorted[step + 1],
27572760
st_ks,
2758-
use_minimal=False,
2759-
use_mo_approach=False).real
2761+
active_space2)
2762+
#use_minimal=False,
2763+
#use_mo_approach=False).real
27602764
# s_sd_1 = data_conv.MATRIX2nparray(s_sd_1)
27612765
# s_sd_2 = data_conv.MATRIX2nparray(s_sd_2)
27622766
# st_sd = data_conv.MATRIX2nparray(st_sd)

0 commit comments

Comments
 (0)