Final cube analysis


In [54]:
import quantumpropagator as qp
import matplotlib.pyplot as plt

%matplotlib ipympl

plt.rcParams.update({'font.size': 8})

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as pltfrom 
from ipywidgets import interact,fixed #, interactive, fixed, interact_manual
import ipywidgets as widgets
from matplotlib import cm

import pickle

# name_data_file = '/home/alessio/n-Propagation/newExtrapolated_allCorrection.pickle'
name_data_file = '/home/alessio/n-Propagation/newExtrapolated_gammaExtrExag.pickle'
# dataDict = np.load('/home/alessio/n-Propagation/datanewoneWithNACnow.npy')[()]
# # name_data_file = '/home/alessio/n-Propagation/NAC_2_1_little_exagerated.pickle'

with open(name_data_file, "rb") as input_file:
    data = pickle.load(input_file)

%load_ext Cython

# data.keys()


The Cython extension is already loaded. To reload it, use:
  %reload_ext Cython

In [55]:
# name_data_file2 = 'NAC_2_1_little_exagerated.pickle'
# with open(name_data_file2, "rb") as input_file:
#     data2 = pickle.load(input_file)

# name_data_file3 = 'newExtrapolated_gammaExtrExag.pickle'
# with open(name_data_file3, "rb") as input_file:
#     data3 = pickle.load(input_file)

In [56]:
# pot = data['potCube']
# pot2= data2['potCube']
# pot3 = data3['potCube']

# np.all(pot == pot3)

VISUALIZE POTENTIAL DIFFERENCE PART


In [63]:
pot = data['potCube']
data['potCube'].shape

print(pot.shape)

qp.find_numpy_index_minumum(pot), pot[29, 28, 55, 0]


(55, 56, 160, 8)
Out[63]:
((29, 28, 55, 0), 0.0)

In [67]:
%matplotlib ipympl
pot_difference_AU = pot[15:-15,15:-15,30:-30,2] - pot[15:-15,15:-15,30:-30,3]

#phiC, gamC, theC, phiD, gamD, theD = (27,25,85, 4, 7, 24)
#pot_difference_AU = pot[phiC-phiD:phiC+phiD,gamC-gamD:gamC+gamD,theC-theD:theC+theD,2] - pot[phiC-phiD:phiC+phiD,gamC-gamD:gamC+gamD,theC-theD:theC+theD,3]

pot_difference = qp.fromHartoEv(pot_difference_AU)
print(qp.find_numpy_index_minumum(pot_difference))
b = pd.Series(pot_difference.flatten())
b.describe()
b.hist(bins=100)


(0, 0, 10)
Out[67]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f5f3a2aac50>

In [70]:
plt.close('all')
phiC, gamC, theC, phiD, gamD, theD = (27,26,85, 2, 2, 24)
pot_difference_AU = pot[phiC-phiD:phiC+phiD,gamC-gamD:gamC+gamD,theC-theD:theC+theD,2] - pot[phiC-phiD:phiC+phiD,gamC-gamD:gamC+gamD,theC-theD:theC+theD,3]

pot_difference = qp.fromHartoEv(pot_difference_AU)
print(qp.find_numpy_index_minumum(pot_difference))
b = pd.Series(pot_difference.flatten())
b.describe()
b.hist(bins=100)


(0, 3, 37)
Out[70]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f5f39dc2a90>

In [59]:
%matplotlib ipympl

dp = 7
dg = 7
dt = 20
mask = pot_difference[22-dp:22+dp,22-dg:22+dg,110-dt:110+dt]
c = pd.Series(mask.flatten())
c.describe()
#c.hist()


Out[59]:
count    0.0
mean     NaN
std      NaN
min      NaN
25%      NaN
50%      NaN
75%      NaN
max      NaN
dtype: float64

In [60]:
diff_0_1_all = pot[:,:,:,1]-pot[:,:,:,0]
diff_2_3_all = pot[:,:,:,3]-pot[:,:,:,2]

In [62]:
diff_0_1 = np.zeros_like(diff_0_1_all) + 999
diff_0_1[15:-15,15:-15,30:-30] = diff_0_1_all[15:-15,15:-15,30:-30]

diff_2_3 = np.zeros_like(diff_2_3_all) + 999
diff_2_3[15:-15,15:-15,30:-30] = diff_2_3_all[15:-15,15:-15,30:-30]


save_pot_diff = True
dictio = {}
a = 0
if save_pot_diff:
    filename = '/home/alessio/IMPORTANTS/VISUALIZE_ENERGY_DIFFERENCE/PotDiff{:04}.h5'.format(a)
    # I reput the zeros out.
    dictio['diff'] = qp.fromHartoEv(diff_0_1)
    dictio['lab'] = 'Diff 0 1'
    qp.writeH5fileDict(filename, dictio)
    a = a + 1
    
if save_pot_diff:
    filename = '/home/alessio/IMPORTANTS/VISUALIZE_ENERGY_DIFFERENCE/PotDiff{:04}.h5'.format(a)
    # I reput the zeros out.
    dictio['diff'] = qp.fromHartoEv(diff_2_3)
    dictio['lab'] = 'Diff 2 3'
    qp.writeH5fileDict(filename, dictio)

a = 0
for i in range(8):
    a = a + 1
    thisState = np.zeros_like(diff_0_1_all) + 999
    thisState[15:-15,15:-15,30:-30] = pot[15:-15,15:-15,30:-30,i]
    dictio = {}
    if save_pot_diff:
        filename = '/home/alessio/IMPORTANTS/VISUALIZE_ENERGY_DIFFERENCE/Energy{:04}.h5'.format(a)
        dictio['diff'] = qp.fromHartoEv(thisState)
        dictio['lab'] = i
        qp.writeH5fileDict(filename, dictio)

In [ ]:

Coordinates


In [9]:
from quantumpropagator import fromLabelsToFloats, labTranformA

phis_ext = labTranformA(data['phis'])
gams_ext = labTranformA(data['gams'])
thes_ext = labTranformA(data['thes'])

phiV_ext, gamV_ext, theV_ext = fromLabelsToFloats(data)

# take step
dphi = phis_ext[0] - phis_ext[1]
dgam = gams_ext[0] - gams_ext[1]
dthe = thes_ext[0] - thes_ext[1]

# take range
range_phi = phis_ext[-1] - phis_ext[0]
range_gam = gams_ext[-1] - gams_ext[0]
range_the = thes_ext[-1] - thes_ext[0]

phis = phis_ext[15:-15]
gams = gams_ext[15:-15]
thes = thes_ext[30:-30]
phiV = phiV_ext[15:-15]
gamV = gamV_ext[15:-15]
theV = theV_ext[30:-30]

header = '         Labels extr.        internal extr.     dq      range\n'
string = 'Phi -> {:8.4f} {:8.4f} {:8.4f} {:8.4f} {:8.4f} {:8.4f}\nGam -> {:8.4f} {:8.4f} {:8.4f} {:8.4f} {:8.4f} {:8.4f}\nThe -> {:8.4f} {:8.4f} {:8.4f} {:8.4f} {:8.4f} {:8.4f}'
out = (header + string).format(phiV_ext[-1],phiV_ext[0],phis_ext[-1],phis_ext[0],dphi,range_phi,
                               gamV_ext[-1],gamV_ext[0],gams_ext[-1],gams_ext[0],dgam,range_gam,
                               theV_ext[-1],theV_ext[0],thes_ext[-1],thes_ext[0],dthe,range_the)
print(out)


         Labels extr.        internal extr.     dq      range
Phi ->   0.1250  -0.1450  12.5000 -14.5000  -0.5000  27.0000
Gam ->   0.4294   0.1344  24.6050   7.7030  -0.3070  16.9020
The ->   0.5806   1.2008  66.5340 137.6000   0.4470 -71.0660

NACS ANALYSIS


In [10]:
nacs = data['smoCube']

# take out zeros
NACS = nacs[15:-15,15:-15,30:-30]

# select the two states
print(NACS.shape, nacs.shape)

pL, gL, tL, sL, dL, coorL =  NACS.shape


(25, 26, 100, 8, 8, 3) (55, 56, 160, 8, 8, 3)

In [17]:
#%%time

n=10

makeGraph = True

states_to_consider = 2

if makeGraph:
    for s1 in range(states_to_consider):
        for s2 in range(s1):

            a = np.abs(NACS[:,:,:,s1,s2,0].flatten())
            binZ = [0.0000000000000001, 0.0000001, 0.000001, 0.00001,0.0001,0.001,0.01,0.1]

            # thing here is the integer where I plot the bar (x position)
            thing = np.arange(len(binZ)-1)
            label_names = [ '{}'.format(x) for x in binZ ]


            counts, bins = np.histogram(a,bins=binZ)
            fig, ax0 = plt.subplots(1,1)
            ax0.bar(thing,counts)
            plt.xticks(thing,label_names)
            plt.title('Nacs values between states {} {}'.format(s1,s2))

            for xy in zip(thing, counts):
                ax0.annotate('{}'.format(xy[1]), xy=xy)



In [18]:
cart = 0
s1 = 5
s2 = 4
p = 22
g=5
t=77                 
elem = np.abs(NACS[p,g,t,s1,s2,cart])
neighbors = np.abs(np.array([NACS[p+1,g,t,s1,s2,cart],
                             NACS[p-1,g,t,s1,s2,cart],
                             NACS[p,g+1,t,s1,s2,cart],
                             NACS[p,g-1,t,s1,s2,cart],
                             NACS[p,g,t+1,s1,s2,cart],
                             NACS[p,g,t-1,s1,s2,cart]]))
lol = neighbors - elem
differences = np.amin(lol)
print('{} {} {} {}'.format(elem, neighbors, lol, differences))
print('States({},{}) -> Cube({:2},{:2},{:2}): {:5.3e}'.format(s1,s2,p,g,t,differences))


1.6770772077807276e-06 [7.13985268e-05 2.87791758e-05 5.41729945e-05 4.19757212e-05
 2.06009194e-05 2.05771630e-05] [6.97214496e-05 2.71020986e-05 5.24959173e-05 4.02986440e-05
 1.89238422e-05 1.89000858e-05] 1.8900085763046227e-05
States(5,4) -> Cube(22, 5,77): 1.890e-05

In [19]:
NACS

cart = 0
for s1 in range(sL):
    for s2 in range(s1):
        #for p in qp.log_progress(range(pL),every=1,size=(pL)):
        for p in range(1,pL-1):
            for g in range(1,gL-1):
                for t in range(1,tL-1):
                    elem = np.abs(NACS[p,g,t,s1,s2,cart])
                    neighbors = np.abs(np.array([NACS[p+1,g,t,s1,s2,cart],
                                                 NACS[p-1,g,t,s1,s2,cart],
                                                 NACS[p,g+1,t,s1,s2,cart],
                                                 NACS[p,g-1,t,s1,s2,cart],
                                                 NACS[p,g,t+1,s1,s2,cart],
                                                 NACS[p,g,t-1,s1,s2,cart]]))
                    differences = neighbors - elem
                    #print('{} {} {}'.format(elem, neighbors, differences))
                    if np.all(differences > 0.0001):
                         print('States({},{}) -> Cube({:2},{:2},{:2}): {:5.3e}'.format(s1,s2,p,g,t,differences))

NACS visualization


In [20]:
# AAA is the plane at which I want to study the "only" point
AAA = NACS[10,:,:,1,2,2]
gam_That, the_That = np.unravel_index(AAA.argmin(), AAA.shape)
10, gam_That, the_That

phis[10],gams[gam_That],thes[the_That]


Out[20]:
(-2.0, 16.615, 92.458)

here we try to make interpolated "unified" NAC values for S_2 - S_1


In [21]:
%%cython --annotate --compile-args=-fopenmp --link-args=-fopenmp --force

### #%%cython

### #%%cython --annotate

import numpy as np
cimport numpy as np
cimport cython
from cython.parallel import prange


@cython.boundscheck(False)
@cython.wraparound(False)
@cython.cdivision(True)
@cython.nonecheck(False)
cdef void neigh(double [:,:,:,:] nacs_2_1, double [:,:,:,::1] bigger_2_1_nacs):
    cdef:
        int pL = 25, gL = 26, tL = 100,coorL=3
        int p1,g1,t1,p2,g2,t2,coor,tuplL,pg
        double thresh

    thresh = 0.0001
    
    tuplL = pL*gL
    
    for coor in range(coorL):
        #for pg in prange(tuplL, nogil=True, schedule='dynamic',num_threads=16):
        for pg in range(tuplL):
            p1 = pg // gL
            g1 = pg % gL
            for t1 in range(tL):
#                 for p2 in range(pL):
#                     for g2 in range(gL):
#                         for t2 in range(tL):
#                             if abs(nacs_2_1[p1,g1,t1,coor]) < 0.000001:
#                                 bigger_2_1_nacs[p1,g1,t1,coor] = nacs_2_1[p1,g1,t1,coor]*100
#                             elif abs(nacs_2_1[p1,g1,t1,coor]) < 0.00001:
                                bigger_2_1_nacs[p1,g1,t1,coor] = nacs_2_1[p1,g1,t1,coor]*100
                     
#     return(bigger_2_1_nacs)

def neighbor(nacs_2_1,bigger_2_1_nacs):
    return np.asarray(neigh(nacs_2_1,bigger_2_1_nacs))

print('done')


done
Out[21]:
Cython: _cython_magic_47b07cb903d4602d84506078d8a2f400.pyx

Generated by Cython 0.29.13

Yellow lines hint at Python interaction.
Click on a line that starts with a "+" to see the C code that Cython generated for it.

 01: 
+02: ### #%%cython
  __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_1) < 0) __PYX_ERR(0, 2, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 03: 
 04: ### #%%cython --annotate
 05: 
+06: import numpy as np
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_numpy, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_np, __pyx_t_1) < 0) __PYX_ERR(0, 6, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
 07: cimport numpy as np
 08: cimport cython
 09: from cython.parallel import prange
 10: 
 11: 
 12: @cython.boundscheck(False)
 13: @cython.wraparound(False)
 14: @cython.cdivision(True)
 15: @cython.nonecheck(False)
+16: cdef void neigh(double [:,:,:,:] nacs_2_1, double [:,:,:,::1] bigger_2_1_nacs):
static void __pyx_f_46_cython_magic_47b07cb903d4602d84506078d8a2f400_neigh(__Pyx_memviewslice __pyx_v_nacs_2_1, __Pyx_memviewslice __pyx_v_bigger_2_1_nacs) {
  int __pyx_v_pL;
  int __pyx_v_gL;
  int __pyx_v_tL;
  int __pyx_v_coorL;
  int __pyx_v_p1;
  int __pyx_v_g1;
  int __pyx_v_t1;
  int __pyx_v_coor;
  int __pyx_v_tuplL;
  int __pyx_v_pg;
  CYTHON_UNUSED double __pyx_v_thresh;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("neigh", 0);
/* … */
  /* function exit code */
  __Pyx_RefNannyFinishContext();
}
 17:     cdef:
+18:         int pL = 25, gL = 26, tL = 100,coorL=3
  __pyx_v_pL = 25;
  __pyx_v_gL = 26;
  __pyx_v_tL = 0x64;
  __pyx_v_coorL = 3;
 19:         int p1,g1,t1,p2,g2,t2,coor,tuplL,pg
 20:         double thresh
 21: 
+22:     thresh = 0.0001
  __pyx_v_thresh = 0.0001;
 23: 
+24:     tuplL = pL*gL
  __pyx_v_tuplL = (__pyx_v_pL * __pyx_v_gL);
 25: 
+26:     for coor in range(coorL):
  __pyx_t_1 = __pyx_v_coorL;
  __pyx_t_2 = __pyx_t_1;
  for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) {
    __pyx_v_coor = __pyx_t_3;
 27:         #for pg in prange(tuplL, nogil=True, schedule='dynamic',num_threads=16):
+28:         for pg in range(tuplL):
    __pyx_t_4 = __pyx_v_tuplL;
    __pyx_t_5 = __pyx_t_4;
    for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) {
      __pyx_v_pg = __pyx_t_6;
+29:             p1 = pg // gL
      __pyx_v_p1 = (__pyx_v_pg / __pyx_v_gL);
+30:             g1 = pg % gL
      __pyx_v_g1 = (__pyx_v_pg % __pyx_v_gL);
+31:             for t1 in range(tL):
      __pyx_t_7 = __pyx_v_tL;
      __pyx_t_8 = __pyx_t_7;
      for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
        __pyx_v_t1 = __pyx_t_9;
 32: #                 for p2 in range(pL):
 33: #                     for g2 in range(gL):
 34: #                         for t2 in range(tL):
 35: #                             if abs(nacs_2_1[p1,g1,t1,coor]) < 0.000001:
 36: #                                 bigger_2_1_nacs[p1,g1,t1,coor] = nacs_2_1[p1,g1,t1,coor]*100
 37: #                             elif abs(nacs_2_1[p1,g1,t1,coor]) < 0.00001:
+38:                                 bigger_2_1_nacs[p1,g1,t1,coor] = nacs_2_1[p1,g1,t1,coor]*100
        __pyx_t_10 = __pyx_v_p1;
        __pyx_t_11 = __pyx_v_g1;
        __pyx_t_12 = __pyx_v_t1;
        __pyx_t_13 = __pyx_v_coor;
        __pyx_t_14 = __pyx_v_p1;
        __pyx_t_15 = __pyx_v_g1;
        __pyx_t_16 = __pyx_v_t1;
        __pyx_t_17 = __pyx_v_coor;
        *((double *) ( /* dim=3 */ ((char *) (((double *) ( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_bigger_2_1_nacs.data + __pyx_t_14 * __pyx_v_bigger_2_1_nacs.strides[0]) ) + __pyx_t_15 * __pyx_v_bigger_2_1_nacs.strides[1]) ) + __pyx_t_16 * __pyx_v_bigger_2_1_nacs.strides[2]) )) + __pyx_t_17)) )) = ((*((double *) ( /* dim=3 */ (( /* dim=2 */ (( /* dim=1 */ (( /* dim=0 */ (__pyx_v_nacs_2_1.data + __pyx_t_10 * __pyx_v_nacs_2_1.strides[0]) ) + __pyx_t_11 * __pyx_v_nacs_2_1.strides[1]) ) + __pyx_t_12 * __pyx_v_nacs_2_1.strides[2]) ) + __pyx_t_13 * __pyx_v_nacs_2_1.strides[3]) ))) * 100.0);
      }
    }
  }
 39: 
 40: #     return(bigger_2_1_nacs)
 41: 
+42: def neighbor(nacs_2_1,bigger_2_1_nacs):
/* Python wrapper */
static PyObject *__pyx_pw_46_cython_magic_47b07cb903d4602d84506078d8a2f400_1neighbor(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_46_cython_magic_47b07cb903d4602d84506078d8a2f400_1neighbor = {"neighbor", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_46_cython_magic_47b07cb903d4602d84506078d8a2f400_1neighbor, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_46_cython_magic_47b07cb903d4602d84506078d8a2f400_1neighbor(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_nacs_2_1 = 0;
  PyObject *__pyx_v_bigger_2_1_nacs = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("neighbor (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_nacs_2_1,&__pyx_n_s_bigger_2_1_nacs,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_nacs_2_1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_bigger_2_1_nacs)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("neighbor", 1, 2, 2, 1); __PYX_ERR(0, 42, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "neighbor") < 0)) __PYX_ERR(0, 42, __pyx_L3_error)
      }
    } else if (PyTuple_GET_SIZE(__pyx_args) != 2) {
      goto __pyx_L5_argtuple_error;
    } else {
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    }
    __pyx_v_nacs_2_1 = values[0];
    __pyx_v_bigger_2_1_nacs = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("neighbor", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 42, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("_cython_magic_47b07cb903d4602d84506078d8a2f400.neighbor", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_46_cython_magic_47b07cb903d4602d84506078d8a2f400_neighbor(__pyx_self, __pyx_v_nacs_2_1, __pyx_v_bigger_2_1_nacs);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_46_cython_magic_47b07cb903d4602d84506078d8a2f400_neighbor(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_nacs_2_1, PyObject *__pyx_v_bigger_2_1_nacs) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("neighbor", 0);
/* … */
  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("_cython_magic_47b07cb903d4602d84506078d8a2f400.neighbor", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}
/* … */
  __pyx_tuple__26 = PyTuple_Pack(2, __pyx_n_s_nacs_2_1, __pyx_n_s_bigger_2_1_nacs); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);
/* … */
  __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_46_cython_magic_47b07cb903d4602d84506078d8a2f400_1neighbor, NULL, __pyx_n_s_cython_magic_47b07cb903d4602d84); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_neighbor, __pyx_t_1) < 0) __PYX_ERR(0, 42, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(2, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_home_alessio_cache_ipython_cyth, __pyx_n_s_neighbor, 42, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 42, __pyx_L1_error)
+43:     return np.asarray(neigh(nacs_2_1,bigger_2_1_nacs))
  __Pyx_XDECREF(__pyx_r);
  __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_np); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_asarray); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_4 = __Pyx_PyObject_to_MemoryviewSlice_dsdsdsds_double(__pyx_v_nacs_2_1, PyBUF_WRITABLE); if (unlikely(!__pyx_t_4.memview)) __PYX_ERR(0, 43, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_to_MemoryviewSlice_d_d_d_dc_double(__pyx_v_bigger_2_1_nacs, PyBUF_WRITABLE); if (unlikely(!__pyx_t_5.memview)) __PYX_ERR(0, 43, __pyx_L1_error)
  __pyx_t_2 = __Pyx_void_to_None(__pyx_f_46_cython_magic_47b07cb903d4602d84506078d8a2f400_neigh(__pyx_t_4, __pyx_t_5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __PYX_XDEC_MEMVIEW(&__pyx_t_4, 1);
  __pyx_t_4.memview = NULL;
  __pyx_t_4.data = NULL;
  __PYX_XDEC_MEMVIEW(&__pyx_t_5, 1);
  __pyx_t_5.memview = NULL;
  __pyx_t_5.data = NULL;
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  __pyx_t_1 = (__pyx_t_6) ? __Pyx_PyObject_Call2Args(__pyx_t_3, __pyx_t_6, __pyx_t_2) : __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_2);
  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;
 44: 
+45: print('done')
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_tuple__28, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
/* … */
  __pyx_tuple__28 = PyTuple_Pack(1, __pyx_n_u_done); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 45, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__28);
  __Pyx_GIVEREF(__pyx_tuple__28);

In [22]:
%%time
state1 = 2
state2 = 1
nacs_2_1 = NACS[:,:,:,state1,state2,:]
nacs_other = NACS[:,:,:,state2,state1,:]

print(np.all(nacs_2_1 == -nacs_other))

print(nacs_2_1.shape)
bigger_2_1_nacs = np.zeros_like(nacs_2_1)

neighbor(nacs_2_1,bigger_2_1_nacs)


saveFile = False

dictio = {}

a=0

if saveFile:
    for coord in range(3):
        filename = '/home/alessio/k-nokick/IMPORTANTS/VISUALIZE_NACS/newNacSmoother/Nac{:04}.h5'.format(a)
        # I reput the zeros out.
        external = np.pad(vector[:,:,:,coord], ((15,15),(15,15),(30,30)), 'constant')
        dictio['NACS'] = external
        dictio['state1'] = state1
        dictio['state2'] = state2
        dictio['cart'] = coord
        qp.writeH5fileDict(filename, dictio)
        a += 1
        filename = '/home/alessio/k-nokick/IMPORTANTS/VISUALIZE_NACS/newNacSmoother/Nac{:04}.h5'.format(a)
        dictio['NACS'] = np.pad(nacs_2_1[:,:,:,coord], ((15,15),(15,15),(30,30)), 'constant')
        dictio['state1'] = state1
        dictio['state2'] = state2
        dictio['cart'] = coord
        qp.writeH5fileDict(filename, dictio)
        a += 1


True
(25, 26, 100, 3)
CPU times: user 22.6 ms, sys: 19.9 ms, total: 42.5 ms
Wall time: 40.2 ms

In [23]:
# PUT TRUE IF YOU WANT TO EXAGERATE AND CHANGE THE NACS
do_it = False


nacs_2_1 = nacs[:,:,:,1,2,:]
bigger_2_1_nacs = np.empty_like(nacs_2_1)

#print(bigger_2_1_nacs.shape)

pL,gL,tL,coorL = bigger_2_1_nacs.shape

for p in qp.log_progress(pL,every=1,size=(len(pL))):
    for g in range(gL):
        for t in range(tL):
            for coor in range(coorL):
                elem = nacs_2_1[p,g,t,coor] 
                if np.abs(elem) > 0.0001:
                    
                    first = 2
                    secon = 4
                    
                    # proximity(6)
                    bigger_2_1_nacs[p+1,g,t,coor] = elem/first
                    bigger_2_1_nacs[p-1,g,t,coor] = elem/first
                    bigger_2_1_nacs[p,g+1,t,coor] = elem/first
                    bigger_2_1_nacs[p,g-1,t,coor] = elem/first
                    bigger_2_1_nacs[p,g,t+1,coor] = elem/first
                    bigger_2_1_nacs[p,g,t-1,coor] = elem/first
                    
                    # Corners (8)
                    bigger_2_1_nacs[p+1,g+1,t+1,coor] = elem/secon     # 000
                    bigger_2_1_nacs[p+1,g+1,t-1,coor] = elem/secon     
                    bigger_2_1_nacs[p+1,g-1,t+1,coor] = elem/secon
                    bigger_2_1_nacs[p+1,g-1,t-1,coor] = elem/secon     # 011
                    bigger_2_1_nacs[p-1,g+1,t+1,coor] = elem/secon     # 000
                    bigger_2_1_nacs[p-1,g+1,t-1,coor] = elem/secon     
                    bigger_2_1_nacs[p-1,g-1,t+1,coor] = elem/secon
                    bigger_2_1_nacs[p-1,g-1,t-1,coor] = elem/secon     # 011

                    # Half sides (12)
                    bigger_2_1_nacs[p+1,g,t+1,coor] = elem/secon
                    bigger_2_1_nacs[p+1,g,t-1,coor] = elem/secon
                    bigger_2_1_nacs[p-1,g,t+1,coor] = elem/secon
                    bigger_2_1_nacs[p-1,g,t-1,coor] = elem/secon
                    bigger_2_1_nacs[p+1,g+1,t,coor] = elem/secon
                    bigger_2_1_nacs[p+1,g-1,t,coor] = elem/secon
                    bigger_2_1_nacs[p-1,g+1,t,coor] = elem/secon
                    bigger_2_1_nacs[p-1,g-1,t,coor] = elem/secon
                    bigger_2_1_nacs[p,g+1,t+1,coor] = elem/secon
                    bigger_2_1_nacs[p,g+1,t-1,coor] = elem/secon
                    bigger_2_1_nacs[p,g-1,t+1,coor] = elem/secon
                    bigger_2_1_nacs[p,g-1,t-1,coor] = elem/secon

                    
                    # 2 distant (6)
                    bigger_2_1_nacs[p+2,g,t,coor] = elem/secon
                    bigger_2_1_nacs[p-2,g,t,coor] = elem/secon
                    bigger_2_1_nacs[p,g+2,t,coor] = elem/secon
                    bigger_2_1_nacs[p,g-2,t,coor] = elem/secon
                    bigger_2_1_nacs[p,g,t+2,coor] = elem/secon
                    bigger_2_1_nacs[p,g,t-2,coor] = elem/secon
                 
                    #print('{} {} {} {} {}'.format(p,g,t,coor,elem))
                else:
                    bigger_2_1_nacs[p,g,t,coor] = elem

                   
                    

if do_it:
    data_new = data
    name_data_file_new = 'NAC_2_1_little_exagerated.pickle'
    print(data_new.keys())
    nacs[:,:,:,1,2,:] = bigger_2_1_nacs
    nacs[:,:,:,2,1,:] = -bigger_2_1_nacs
    data_new['smoCube'] = nacs
    pickle.dump( data_new, open( name_data_file_new, "wb" ) )


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-23-08df5e00d016> in <module>
     10 pL,gL,tL,coorL = bigger_2_1_nacs.shape
     11 
---> 12 for p in qp.log_progress(pL,every=1,size=(len(pL))):
     13     for g in range(gL):
     14         for t in range(tL):

TypeError: object of type 'int' has no len()

DIPOLES visualization


In [11]:
dipo = data['dipCUBE']
DIPO = dipo[15:-15,15:-15,30:-30]
dipo.shape, DIPO.shape


Out[11]:
((55, 56, 160, 3, 8, 8), (25, 26, 100, 3, 8, 8))

In [12]:
plt.close('all')
def do3dplot(xs,ys,zss):
    'with mesh function'
    fig = plt.figure(figsize=(9,9))
    ax = fig.add_subplot(111, projection='3d')
    X,Y = np.meshgrid(ys,xs)
    #ax.set_zlim(-1, 1)
    #ax.scatter(X, Y, zss)
    ax.plot_surface(X, Y, zss,cmap=cm.coolwarm, linewidth=1, antialiased=False)
    fig.canvas.layout.height = '800px'
    fig.tight_layout()

def visualize_this_thing(thing,state1,state2,cart,kind,dim):

    along = ['X','Y','Z']
    print('DIPOLE between state ({},{}) along {} - Doing cut in {} with value ({:8.4f},{:8.4f}) - shape: {}'.format(state1,
                                                                state2,
                                                                along[cart],
                                                                kind,
                                                                dimV[kind][dim],
                                                                dims[kind][dim],
                                                                thing.shape))
    if kind == 'Phi':
        pot = thing[dim,:,:,cart,state1,state2]
        print('Looking at DIPOLE with indexes [{},:,:,{},{},{}]'.format(dim,cart,state1,state2))
        do3dplot(gams,thes,pot)
    elif kind == 'Gam':
        print('Looking at DIPOLE with indexes [:,{},:,{},{},{}]'.format(dim,cart,state1,state2))
        pot = thing[:,dim,:,cart,state1,state2]
        do3dplot(phis,thes,pot)
    elif kind == 'The':
        print('Looking at DIPOLE with indexes [:,:,{},{},{},{}]'.format(dim,cart,state1,state2))
        pot = thing[:,:,dim,cart,state1,state2]
        do3dplot(phis,gams,pot)


dimV = { 'Phi': phiV, 'Gam': gamV, 'The': theV } # real values
dims = { 'Phi': phis, 'Gam': gams, 'The': thes } # for labels

kinds = ['Phi','Gam','The']

def fun_pot2D(kind,state1, state2, cart,dim):
    visualize_this_thing(DIPO, state1, state2, cart, kind, dim)
    
def nested(kinds):
    dimensionV = dimV[kinds]
    interact(fun_pot2D, kind=fixed(kinds), 
             state1 = widgets.IntSlider(min=0,max=7,step=1,value=0,continuous_update=False), 
             state2 = widgets.IntSlider(min=0,max=7,step=1,value=1,continuous_update=False), 
             cart = widgets.IntSlider(min=0,max=2,step=1,value=2,continuous_update=False), 
             dim = widgets.IntSlider(min=0,max=(len(dimensionV)-1),step=1,value=0,continuous_update=False))

interact(nested, kinds = ['Gam','Phi','The']);



In [49]:
import ipyvolume as ipv

def do3dplot2(xs,ys,zss):
    X,Y = np.meshgrid(ys,xs)
    ipv.figure()
    ipv.plot_surface(X, zss, Y, color="orange")
    ipv.plot_wireframe(X, zss, Y, color="red")
    ipv.show()

Minimum geometry is found by getting the minimum on the ground state potential


In [13]:
pot = data['potCube'] - data['potCube'].min()
A = pot
# find the minimum index having the shape
phi_min, gam_min, the_min, state_min = np.unravel_index(A.argmin(), A.shape)
phi_min, gam_min, the_min, state_min


Out[13]:
(29, 28, 55, 0)

CI geometry by taking the maximum NAC value between 0 and 1


In [14]:
nacs.shape


Out[14]:
(55, 56, 160, 8, 8, 3)

In [15]:
B = nacs[:,:,:,:,1,0]

In [16]:
# this should be absolute value
phi_ci, gam_ci, the_ci, cart_ci = np.unravel_index(B.argmax(), B.shape)
np.unravel_index(B.argmax(), B.shape)


Out[16]:
(19, 32, 62, 2)

In [17]:
phis_ext[16],gams_ext[15],thes_ext[112]


Out[17]:
(-6.5, 12.308, 87.542000000000002)

In [18]:
phi_ci, gam_ci, the_ci = [16,15,112]

Product/reactant catcher

Here I want to generate the cubes of 1 and 0 to catch different regions of my cube.

So, now I want to do this. I want to create several cubes with different regions (basically the cubes are of 1 and 0). A is FC region, B is PRODUCT region and C is REACTANT


In [19]:
# I start by making a cube of 0.

# boolean that creates (and overwrite) the file 
create_mask_file = False

ZERO = np.zeros_like(pot[:,:,:,0])
print(ZERO.shape)

region_a = np.zeros_like(ZERO)
region_b = np.zeros_like(ZERO)
region_c = np.zeros_like(ZERO)

#   for pi, p in qp.log_progress(enumerate(phis_n),every=1,size=(len(phis_n))):

# p_linea_a = 18
# g_linea_S = 30
# t_linea_b = 112

p_linea_a, g_linea_S, t_linea_b = 18, 30, 112

m_coeff,q_coeff = 1.7,75

for p,phi in qp.log_progress(enumerate(phis_ext),every=1,size=(len(phis_ext))):
    for g,gam in enumerate(gams_ext):
        lineValue_theta =  m_coeff * g + q_coeff
        for t,the in enumerate(thes_ext):
            if p > p_linea_a:
                region_a[p,g,t] = 1
            if p <= p_linea_a:
                if t > lineValue_theta:
                    region_c[p,g,t] = 1
                else:
                    region_b[p,g,t] = 1


#                 if t > t_linea_b and g < g_linea_S:
#                     region_c[p,g,t] = 1
#                 else:
#                     region_b[p,g,t] = 1
                
            # to paint cubes on the verge I make zero the sides values
            if p==0 or g == 0 or t == 0 or p == len(phis_ext)-1 or g == len(gams_ext)-1 or t == len(thes_ext)-1:
                region_a[p,g,t] = 0
                region_b[p,g,t] = 0
                region_c[p,g,t] = 0

regions = [{'label' : 'FC', 'cube': region_a},{'label' : 'reactants', 'cube': region_b},{'label' : 'products', 'cube': region_c}]

if create_mask_file:
    print('I created the regions pickle file')
    pickle.dump(regions, open('regions.pickle', "wb" ) )
else:
    qp.warning("file region NOT written, check the variable 'create_mask_file' if you want to write region file")


(55, 56, 160)

*****************************************************************************************************
*                                                                                                   *
*  file region NOT written, check the variable 'create_mask_file' if you want to write region file  *
*                                                                                                   *
*****************************************************************************************************



HERE THE REGIONS FOR ADVANCED MASKS


In [21]:
# I start by making a cube of 0.

# boolean that creates (and overwrite) the file 
create_adv_mask_files = False

ZERO = np.zeros_like(pot[:,:,:,0])
ones = np.ones_like(pot[:,:,:,0])
print(ZERO.shape)

mask_CI = np.zeros_like(ZERO)
mask_AFC = np.zeros_like(ZERO)

# 18, 30, 112

#p_cube1, p_cube2, g_cube1, g_cube2, t_cube1, t_cube2 = 12, 29, 15, 32, 82, 142
p_CI_cube1, p_CI_cube2, g_CI_cube1, g_CI_cube2, t_CI_cube1, t_CI_cube2 = 12, 29, 15, 32, 82, 142 

p_AFC_cube1, p_AFC_cube2, g_AFC_cube1, g_AFC_cube2, t_AFC_cube1, t_AFC_cube2 = 0, 54, 0, 55, 85, 159 

for p,phi in qp.log_progress(enumerate(phis_ext),every=1,size=(len(phis_ext))):
    for g,gam in enumerate(gams_ext):
        for t,the in enumerate(thes_ext):
            if p > p_CI_cube1 and p < p_CI_cube2 and g > g_CI_cube1 and g < g_CI_cube2 and t > t_CI_cube1 and t < t_CI_cube2:
                mask_CI[p,g,t] = 1

            if p > p_AFC_cube1 and p < p_AFC_cube2 and g > g_AFC_cube1 and g < g_AFC_cube2 and t > t_AFC_cube1 and t < t_AFC_cube2:
                mask_AFC[p,g,t] = 1
            # to paint cubes on the verge I make zero the sides values
            if p==0 or g == 0 or t == 0 or p == len(phis_ext)-1 or g == len(gams_ext)-1 or t == len(thes_ext)-1:
                ones[p,g,t] = 0
                mask_AFC[p,g,t] = 0


masks_only_one = [{'label' : 'All', 'cube': ones, 'states':[0,1,2,3,4,5,6,7], 'show' : False}]

masks          = [
                  {'label' : 'All', 'cube': ones,   'states':[0,1,2,3,4,5,6,7],  'show' : False},
                  {'label' : 'AfterFC',  'cube': mask_AFC, 'states':[0,1,2,3,4,5,6,7],  'show' : True},
                  {'label' : 'CI',  'cube': mask_CI, 'states':[0,1,2,3,4,5,6,7],  'show' : True},
                 ]

#                  {'label' : 'Mask CI', 'cube': mask_a, 'states':[0,1]}]

#masks          = [{'label' : 'Mask', 'cube': ones, 'states':[0,1,2,3,4,5,6,7]}]


if create_adv_mask_files:
    print('I created the regions pickle file')
    pickle.dump(masks_only_one, open('advanced_masks_onlyONE.pickle', "wb" ))
    pickle.dump(masks, open('advanced_masks.pickle', "wb" ))

else:
    qp.warning("file advanced_masks NOT written, check the variable 'create_adv_mask_files' if you want to write region file")


(55, 56, 160)

******************************************************************************************************************
*                                                                                                                *
*  file advanced_masks NOT written, check the variable 'create_adv_mask_files' if you want to write region file  *
*                                                                                                                *
******************************************************************************************************************



Here I check the direction of the permanent dipoles.


In [22]:
# dipo_min = dipo[phi_min, gam_min, the_min]
# dipo_ci = dipo[phi_ci, gam_ci, the_ci]
# difference_dipo = dipo_ci - dipo_min

# for i in range(8):
#     permanent = difference_dipo[:,i,i]
#     print('S_{} -> {}'.format(i,permanent))

In [23]:
# dipo_min[:,1,2],dipo_min[:,0,1],dipo_min[:,0,6],dipo_min[:,0,3],dipo_min[:,0,2],dipo_min[:,0,7]

temporary cells for last correction sign


In [24]:
# npy = '/home/alessio/Desktop/NAC_CORRECTION_NOVEMBER2018/dataprova.npy'
# dictio = np.load(npy)[()]
# dictio.keys()

In [25]:
# NACS2 = dictio['nacCUBE']
# NACS2.shape

In [26]:
# def do3dplot(xs,ys,zss):
#     'with mesh function'
#     fig = plt.figure(figsize=(9,9))
#     ax = fig.add_subplot(111, projection='3d')
#     X,Y = np.meshgrid(ys,xs)
#     #ax.set_zlim(-1, 1)
#     #ax.scatter(X, Y, zss)
#     ax.plot_wireframe(X, Y, zss)
#     fig.tight_layout()

# def visualize_this_thing(thing,state1,state2,cart,kind,dim):
#     print(thing.shape)
#     print('\nWARNING, this is not fully correct!!! Not SMO and not really what you think\n')

#     along = ['Phi','Gam','The']
#     print('NAC between state ({},{}) along {}\nDoing cut in {} with value ({:8.4f},{:8.4f})'.format(state1,
#                                                                 state2,
#                                                                 along[cart],
#                                                                 kind,
#                                                                 dimV[kind][dim],
#                                                                 dims[kind][dim]))
#     if kind == 'Phi':
#         pot = thing[dim,:,:,state1,state2,0,cart]
#         print('\nLooking at SMO with indexes [{},:,:,{},{},{}]'.format(dim, state1,state2,cart))
#         do3dplot(gams,thes,pot)
#     elif kind == 'Gam':
#         print('\nLooking at SMO with indexes [:,{},:,{},{},{}]'.format(dim, state1,state2,cart))
#         pot = thing[:,dim,:,state1,state2,0,cart]
#         do3dplot(phis,thes,pot)
#     elif kind == 'The':
#         print('\nLooking at SMO with indexes [:,:,{},{},{},{}]'.format(dim, state1,state2,cart))
#         pot = thing[:,:,dim,state1,state2,0,cart]
#         do3dplot(phis,gams,pot)


# dimV = { 'Phi': phiV, 'Gam': gamV, 'The': theV } # real values
# dims = { 'Phi': phis, 'Gam': gams, 'The': thes } # for labels

# kinds = ['Phi','Gam','The']

# def fun_pot2D(kind,state1, state2, cart,dim):
#     visualize_this_thing(NACS2, state1, state2, cart, kind, dim)
    
# def nested(kinds):
#     dimensionV = dimV[kinds]
#     interact(fun_pot2D, kind=fixed(kinds), state1 = widgets.IntSlider(min=0,max=7,step=1,value=0), state2 = widgets.IntSlider(min=0,max=7,step=1,value=0), cart = widgets.IntSlider(min=0,max=2,step=1,value=0), dim = widgets.IntSlider(min=0,max=(len(dimensionV)-1),step=1,value=0))

# interact(nested, kinds = ['Phi','Gam','The']);

sign flipper on extrapolated SMO cube

you used the cells below to correct NAC on the main plane... it was still flipping


In [27]:
# print(data.keys())
# data_new = data
# nacs_new = data['smoCube']
# NACS_new = nacs_new[15:-15,15:-15,30:-30]
# print(NACS_new.shape,nacs_new.shape)

# phi_ext_000_000 = 29
# phi_prev = 28
# phi_next = 30

# new_nacs = np.copy(nacs)

# for g in range(56):
#     for t in range(160):
#         not_correct  = nacs[phi_ext_000_000,g,t]
#         correct_prev = nacs[phi_prev       ,g,t]
#         correct_next = nacs[phi_next       ,g,t]
#         #if np.linalg.norm(not_correct) > 0.001:
#         #        print('{} {}\nThis {} \nMiddle {}\n After {}'.format(g,t,correct_prev[:,:,1], not_correct[:,:,1],correct_next[:,:,1]))
#         for state1 in range(8):
#             for state2 in range(8):
#                 for cart in range(3):
#                     value_prev = correct_prev[state1,state2,cart]
#                     value_this = not_correct [state1,state2,cart]
#                     value_next = correct_next[state1,state2,cart]
#                     average = (value_prev + value_next)/2
#                     if np.sign(average) == np.sign(value_this):
#                         new_value = value_this
#                     else:
#                         new_value = -value_this 
#                     new_nacs[phi_ext_000_000,g,t,state1,state2,cart] = new_value

In [28]:
# def do3dplot(xs,ys,zss):
#     'with mesh function'
#     fig = plt.figure(figsize=(9,9))
#     ax = fig.add_subplot(111, projection='3d')
#     X,Y = np.meshgrid(ys,xs)
#     #ax.set_zlim(-1, 1)
#     #ax.scatter(X, Y, zss)
#     ax.plot_wireframe(X, Y, zss)
#     fig.tight_layout()

# def visualize_this_thing(thing,state1,state2,cart,kind,dim):
#     print(thing.shape)

#     along = ['Phi','Gam','The']
#     print('NAC between state ({},{}) along {}\nDoing cut in {} with value ({:8.4f},{:8.4f})'.format(state1,
#                                                                 state2,
#                                                                 along[cart],
#                                                                 kind,
#                                                                 dimV[kind][dim],
#                                                                 dims[kind][dim]))
#     if kind == 'Phi':
#         pot = thing[dim,:,:,state1,state2,cart]
#         print('\nLooking at SMO with indexes [{},:,:,{},{},{}]'.format(dim, state1,state2,cart))
#         do3dplot(gams_ext,thes_ext,pot)
#     elif kind == 'Gam':
#         print('\nLooking at SMO with indexes [:,{},:,{},{},{}]'.format(dim, state1,state2,cart))
#         pot = thing[:,dim,:,state1,state2,cart]
#         do3dplot(phis_ext,thes_ext,pot)
#     elif kind == 'The':
#         print('\nLooking at SMO with indexes [:,:,{},{},{},{}]'.format(dim, state1,state2,cart))
#         pot = thing[:,:,dim,state1,state2,cart]
#         do3dplot(phis_ext,gams_ext,pot)


# dimV = { 'Phi': phiV_ext, 'Gam': gamV_ext, 'The': theV_ext } # real values
# dims = { 'Phi': phis_ext, 'Gam': gams_ext, 'The': thes_ext } # for labels

# kinds = ['Phi','Gam','The']

# def fun_pot2D(kind,state1, state2, cart,dim):
#     visualize_this_thing(new_nacs, state1, state2, cart, kind, dim)
    
# def nested(kinds):
#     dimensionV = dimV[kinds]
#     interact(fun_pot2D, kind=fixed(kinds), state1 = widgets.IntSlider(min=0,max=7,step=1,value=0), state2 = widgets.IntSlider(min=0,max=7,step=1,value=0), cart = widgets.IntSlider(min=0,max=2,step=1,value=0), dim = widgets.IntSlider(min=0,max=(len(dimensionV)-1),step=1,value=0))

# interact(nested, kinds = ['Phi','Gam','The']);

Things regarding writing down the Pickle file


In [29]:
#name_data_file_new = 'newExtrapolated_allCorrectionSECOND.pickle'
#data_new.keys()

In [30]:
# data_new['smoCube'] = new_nacs
# pickle.dump( data_new, open( name_data_file_new, "wb" ) )

those cells here are used to visualize in 3d space the dipoles/nac


In [31]:
folder = '.'
a=0

saveFile = False

for state1 in range(8):
    for state2 in range(state1):
        for cart in range(3):
            dictio = {}
            cartL = ['X','Y','Z']
            print('Nacs ({},{}) along {} -> {:04}'.format(state1,state2,cartL[cart],a))
            a+=1
            
            if saveFile:
                filename = 'Nac{:04}.h5'.format(a)
                dictio['NACS'] = nacs[:,:,:,state1,state2,cart]
                dictio['state1'] = state1
                dictio['state2'] = state2
                dictio['cart'] = cart
                qp.writeH5fileDict(filename, dictio)


Nacs (1,0) along X -> 0000
Nacs (1,0) along Y -> 0001
Nacs (1,0) along Z -> 0002
Nacs (2,0) along X -> 0003
Nacs (2,0) along Y -> 0004
Nacs (2,0) along Z -> 0005
Nacs (2,1) along X -> 0006
Nacs (2,1) along Y -> 0007
Nacs (2,1) along Z -> 0008
Nacs (3,0) along X -> 0009
Nacs (3,0) along Y -> 0010
Nacs (3,0) along Z -> 0011
Nacs (3,1) along X -> 0012
Nacs (3,1) along Y -> 0013
Nacs (3,1) along Z -> 0014
Nacs (3,2) along X -> 0015
Nacs (3,2) along Y -> 0016
Nacs (3,2) along Z -> 0017
Nacs (4,0) along X -> 0018
Nacs (4,0) along Y -> 0019
Nacs (4,0) along Z -> 0020
Nacs (4,1) along X -> 0021
Nacs (4,1) along Y -> 0022
Nacs (4,1) along Z -> 0023
Nacs (4,2) along X -> 0024
Nacs (4,2) along Y -> 0025
Nacs (4,2) along Z -> 0026
Nacs (4,3) along X -> 0027
Nacs (4,3) along Y -> 0028
Nacs (4,3) along Z -> 0029
Nacs (5,0) along X -> 0030
Nacs (5,0) along Y -> 0031
Nacs (5,0) along Z -> 0032
Nacs (5,1) along X -> 0033
Nacs (5,1) along Y -> 0034
Nacs (5,1) along Z -> 0035
Nacs (5,2) along X -> 0036
Nacs (5,2) along Y -> 0037
Nacs (5,2) along Z -> 0038
Nacs (5,3) along X -> 0039
Nacs (5,3) along Y -> 0040
Nacs (5,3) along Z -> 0041
Nacs (5,4) along X -> 0042
Nacs (5,4) along Y -> 0043
Nacs (5,4) along Z -> 0044
Nacs (6,0) along X -> 0045
Nacs (6,0) along Y -> 0046
Nacs (6,0) along Z -> 0047
Nacs (6,1) along X -> 0048
Nacs (6,1) along Y -> 0049
Nacs (6,1) along Z -> 0050
Nacs (6,2) along X -> 0051
Nacs (6,2) along Y -> 0052
Nacs (6,2) along Z -> 0053
Nacs (6,3) along X -> 0054
Nacs (6,3) along Y -> 0055
Nacs (6,3) along Z -> 0056
Nacs (6,4) along X -> 0057
Nacs (6,4) along Y -> 0058
Nacs (6,4) along Z -> 0059
Nacs (6,5) along X -> 0060
Nacs (6,5) along Y -> 0061
Nacs (6,5) along Z -> 0062
Nacs (7,0) along X -> 0063
Nacs (7,0) along Y -> 0064
Nacs (7,0) along Z -> 0065
Nacs (7,1) along X -> 0066
Nacs (7,1) along Y -> 0067
Nacs (7,1) along Z -> 0068
Nacs (7,2) along X -> 0069
Nacs (7,2) along Y -> 0070
Nacs (7,2) along Z -> 0071
Nacs (7,3) along X -> 0072
Nacs (7,3) along Y -> 0073
Nacs (7,3) along Z -> 0074
Nacs (7,4) along X -> 0075
Nacs (7,4) along Y -> 0076
Nacs (7,4) along Z -> 0077
Nacs (7,5) along X -> 0078
Nacs (7,5) along Y -> 0079
Nacs (7,5) along Z -> 0080
Nacs (7,6) along X -> 0081
Nacs (7,6) along Y -> 0082
Nacs (7,6) along Z -> 0083

those to make the wall on extrapolated gamma values


In [32]:
# lol2 is the new function to be added 
phi_index = 16
theta_index = 81
state_index = 0

lol = pot[phi_index,:,theta_index,state_index]

num = 15
constant = 0.001
lol2 = np.zeros_like(lol)
for i in range(num):
    lol2[i] = constant * (i-num)**2
    #print('{} {} {}'.format(i,num,i-num))

In [33]:
fig = plt.figure()
plt.title('Gamma wall')
plt.xlabel('Gamma')
plt.ylabel('Energy')
plt.plot(lol)
plt.plot(lol2+lol);



In [33]:
newpot = np.zeros_like(pot)

for p in range(55):
    for t in range(160):
        for s in range(8):
            newpot[p,:,t,s] = pot[p,:,t,s] + lol2

In [34]:
do_it = False
if do_it:
    data_new = data
    name_data_file_new = 'newExtrapolated_gammaExtrExag.pickle'
    data_new.keys()
    data_new['potCube'] = newpot
    pickle.dump( data_new, open( name_data_file_new, "wb" ) )
else:
    qp.warning('Here it is set to false, new file is NOT created')



******************************************************
*                                                    *
*  Here it is set to false, new file is NOT created  *
*                                                    *
******************************************************




In [35]:
fig = plt.figure()
phi = 20
the = 100
plt.plot(pot[phi,:,the,1])
plt.plot(newpot[phi,:,the,1]);


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-35-7f509c5c857c> in <module>()
      3 the = 100
      4 plt.plot(pot[phi,:,the,1])
----> 5 plt.plot(newpot[phi,:,the,1]);

NameError: name 'newpot' is not defined

In [ ]: