ONV 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
nv/p1.py ADDED
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Created on Mon Oct 7 11:48:14 2024
5
+
6
+ @author: ollywhaites
7
+ """
8
+ from sys import path
9
+ path.append('/Users/ollywhaites/Documents/Documents/PhD/Python/Libraries/')
10
+
11
+ import numpy as np
12
+ import NV_Library as nv
13
+
14
+
15
+ def rot_mat(a,b):
16
+
17
+ R = np.array([[np.cos(a)*np.cos(b),np.cos(b)*np.sin(a),-np.sin(b)],
18
+ [-np.sin(a),np.cos(a),0],
19
+ [np.sin(b)*np.cos(a),np.sin(b)*np.sin(a),np.cos(b)]])
20
+
21
+ return R
22
+ def find_axisCoup(Adiag,axis = 'D'):
23
+
24
+ rot = {'A':{'a':0,'b':np.radians(109.5)},
25
+ 'B':{'a':0*np.radians(120),'b':np.radians(109.5)},
26
+ 'C':{'a':0*np.radians(240),'b':np.radians(109.5)},
27
+ 'D':{'a':0,'b':0}}
28
+
29
+ R = rot_mat(rot[axis]['a'], rot[axis]['b'])
30
+
31
+ return np.dot(np.dot(R,Adiag),R.T)
32
+
33
+
34
+ def tensor_prod(operators,i,j,PN):
35
+
36
+ axis = {0:'x',
37
+ 1: 'y',
38
+ 2: 'z'}
39
+
40
+ HQ = 0
41
+ for n in range(3):
42
+ #m = n
43
+ for m in range(3):
44
+ HQ += PN[n][m]*operators['I%s'%axis[n]][i]*operators['I%s'%axis[m]][j]
45
+
46
+
47
+ return HQ
48
+
49
+
50
+ def construct_H0(operators,params,spins,bath,Tin):
51
+
52
+
53
+
54
+ H0 = 0
55
+ if params['lab'] == True:
56
+ H0 += params['omega_e']*operators['Sz'] + params['zfs_NV']*operators['Sz']*operators['Sz']
57
+
58
+ Hi = 0
59
+ Hij = 0
60
+ k = 0
61
+ for i in spins:
62
+
63
+ r1 = {'x':bath.loc[i].iloc[1]['pos'][0]*1e-10,
64
+ 'y':bath.loc[i].iloc[1]['pos'][1]*1e-10,
65
+ 'z':bath.loc[i].iloc[1]['pos'][2]*1e-10}
66
+
67
+
68
+ if bath.loc[i].iloc[0]['Species'] == 'N':
69
+ Adiag = np.array([[-2*np.pi*113.83e6,0,0],[0,-2*np.pi*113.83e6,0],[0,0,-2*np.pi*159.7e6]])
70
+ Pdiag = np.array([[0,0,0],[0,0,0],[0,0,0]])
71
+ else:
72
+
73
+ Adiag = np.array([[2*np.pi*81.32e6,0,0],[0,2*np.pi*81.32e6,0],[0,0,2*np.pi*114.03e6]])
74
+ Pdiag = np.array([[2*np.pi*1.32e6,0,0],[0,2*np.pi*1.32e6,0],[0,0,2*np.pi*2.65e6]])
75
+ Pdiag = np.array([[2*np.pi*0,0,0],[0,2*np.pi*0,0],[0,0,-2*np.pi*3.97e6]])
76
+
77
+ #AN = find_axisCoup(Adiag,axis = bath.loc[i]['JT_axis'].iloc[1])
78
+ PN = find_axisCoup(Pdiag,axis = bath.loc[i]['JT_axis'].iloc[1])
79
+
80
+ if Tin == True:
81
+ AN = find_axisCoup(Adiag,axis = bath.loc[i]['JT_axis'].iloc[1])[2]
82
+
83
+ Hi += (params['D']*operators['Iz'][2*k + 0] + 2*np.pi*params['gamma_N']*params['B0']*operators['Iz'][2*k + 1]
84
+ + (AN[2]*operators['Iz'][2*k + 1] + AN[0]*operators['Ix'][2*k + 1] + AN[1]*operators['Iy'][2*k + 1])*operators['Iz'][2*k + 0]
85
+ #+ tensor_prod(operators,2*k + 1,2*k + 1,PN)
86
+ + 2*np.pi*1e3*(bath.loc[i]['Az'].iloc[1]*operators['Iz'][2*k + 0])*operators['Sz']
87
+ + params['Omega_RF']*(np.sin(params['RF_phase'])*operators['Ix'][2*k + 0] + np.cos(params['RF_phase'])*operators['Iy'][2*k + 0]))
88
+
89
+ elif Tin == False:
90
+ AN = find_axisCoup(Adiag,axis = bath.loc[i]['JT_axis'].iloc[1])
91
+
92
+ Hi += (2*np.pi*params['gamma_e']*params['B0']*operators['Iz'][2*k + 0] + 2*np.pi*params['gamma_N']*params['B0']*operators['Iz'][2*k + 1]
93
+ + tensor_prod(operators,2*k + 0,2*k + 1,AN)
94
+ #+ (AN[2]*operators['Iz'][2*k + 1] + AN[0]*operators['Ix'][2*k + 1] + AN[1]*operators['Iy'][2*k + 1])*operators['Iz'][2*k + 0]
95
+ + tensor_prod(operators,2*k + 1,2*k + 1,PN)
96
+ + 2*np.pi*1e3*(bath.loc[i]['Az'].iloc[1]*operators['Iz'][2*k + 0])*operators['Sz']
97
+ #+ 2*np.pi*1e3*(bath.loc[i]['Az'].iloc[1]*operators['Iz'][2*k + 0] + bath.loc[i]['Ax'].iloc[1]*operators['Ix'][2*k + 0] + bath.loc[i]['Ay'].iloc[1]*operators['Iy'][2*k + 0])*operators['Sz']
98
+ #+ 2*params['Omega']*(np.sin(params['omega_RF']*params['t'] - params['RF_phase'])*operators['Ix'][2*k + 0]))
99
+ )
100
+
101
+
102
+ for j in spins[k + 1:]:
103
+
104
+ r2 = {'x':bath.loc[j].iloc[1]['pos'][0]*1e-10,
105
+ 'y':bath.loc[j].iloc[1]['pos'][1]*1e-10,
106
+ 'z':bath.loc[j].iloc[1]['pos'][2]*1e-10}
107
+
108
+
109
+ Cij = 2*np.pi*nv.cc_coupling(r1,r2,params = params,species = 'e')
110
+
111
+ Hij += Cij*(operators['Iz'][2*k + 0]*operators['Iz'][2*k + 2] - (1/2)*(operators['Ix'][2*k + 0]*operators['Ix'][2*k + 2] + operators['Iy'][2*k + 0]*operators['Iy'][2*k + 2]))
112
+
113
+
114
+ k+=1
115
+ operators['H0'] = H0 + Hi + Hij
116
+
117
+ return operators,params
118
+
119
+
120
+ def LG4(operators,params,bath,spins,Tin):
121
+
122
+ D = params['D']
123
+ Om = params['Omega']
124
+ alpha = params['RF_phase']
125
+
126
+ operators,params = construct_H0(operators,params,spins,bath,Tin)
127
+ rho,coh, UA = nv.pulse_NV(operators,params,measure = 'x',)
128
+
129
+ params['D'] = -D
130
+ params['Omega'] = -Om
131
+ params['RF_phase'] = alpha
132
+
133
+ operators,params = construct_H0(operators,params,spins,bath,Tin)
134
+ rho,coh, UAm = nv.pulse_NV(operators,params,measure = 'x',)
135
+
136
+ params['D'] = D
137
+ params['Omega'] = Om
138
+ params['RF_phase'] = -alpha
139
+
140
+ operators,params = construct_H0(operators,params,spins,bath,Tin)
141
+ rho,coh, UB = nv.pulse_NV(operators,params,measure = 'x',)
142
+
143
+
144
+ params['D'] = -D
145
+ params['Omega'] = -Om
146
+ params['RF_phase'] = -alpha
147
+
148
+ operators,params = construct_H0(operators,params,spins,bath,Tin)
149
+ rho,coh, UBm = nv.pulse_NV(operators,params,measure = 'x',)
150
+
151
+ params['D'] = D
152
+ params['Omega'] = Om
153
+ params['RF_phase'] = alpha
154
+
155
+ U = UBm*UB*UAm*UA
156
+
157
+ return U
158
+
159
+
160
+
161
+ def LG(operators,params,bath,spins,Tin):
162
+
163
+ operators,params = construct_H0(operators,params,spins,bath,Tin)
164
+ rho,coh, U = nv.pulse_NV(operators,params,measure = 'x',)
165
+
166
+ return U
167
+
168
+ RF_protocols = {'LG': LG,
169
+ 'LG4': LG4}
170
+
171
+ def find_U(operators,params,bath,spins,Tin):
172
+
173
+ U = RF_protocols[params['RF_protocol']](operators,params,bath,spins,Tin)
174
+
175
+ return U
tools/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from plot_tools import add_arrow, add_text, colorline, make_segments
tools/plot_tools.py ADDED
@@ -0,0 +1,136 @@
1
+ #------------------------------------------------------------------------------------------------------------------
2
+ #------------------------------------------------------------------------------------------------------------------
3
+ #Oliver Whaites
4
+ #pol_tools.py A library of tools used to improve the presentations of plots.
5
+ #------------------------------------------------------------------------------------------------------------------
6
+ #------------------------------------------------------------------------------------------------------------------
7
+
8
+ #------------------------------------------------------------------------------------------------------------------
9
+ #Import modules needs
10
+ #------------------------------------------------------------------------------------------------------------------
11
+
12
+ import matplotlib.collections as mcoll
13
+ import numpy as np
14
+ import matplotlib.pyplot as plt
15
+
16
+
17
+
18
+ #------------------------------------------------------------------------------------------------------------------
19
+ #Functions in library
20
+ #------------------------------------------------------------------------------------------------------------------
21
+
22
+
23
+ def add_arrow(line, position=None, direction='right', size=15, color=None):
24
+ """
25
+ add an arrow to a line.
26
+
27
+ line: Line2D object
28
+ position: x-position of the arrow. If None, mean of xdata is taken
29
+ direction: 'left' or 'right'
30
+ size: size of the arrow in fontsize points
31
+ color: if None, line color is taken.
32
+ """
33
+ if color is None:
34
+ color = line.get_color()
35
+
36
+ xdata = line.get_xdata()
37
+ ydata = line.get_ydata()
38
+
39
+ if position is None:
40
+ position = xdata.mean()
41
+ # find closest index
42
+ start_ind = np.argmin(np.absolute(xdata - position))
43
+ if direction == 'right':
44
+ end_ind = start_ind + 1
45
+ else:
46
+ end_ind = start_ind - 1
47
+
48
+ line.axes.annotate('',
49
+ xytext=(xdata[start_ind], ydata[start_ind]),
50
+ xy=(xdata[end_ind], ydata[end_ind]),
51
+ arrowprops=dict(arrowstyle="-|>", color=color),
52
+ size=size
53
+ )
54
+
55
+ def add_text(line,label, position=None, direction='right', size=12, color=None,rotation = None,valign = None):
56
+ """
57
+ add an arrow to a line.
58
+
59
+ line: Line2D object
60
+ position: x-position of the arrow. If None, mean of xdata is taken
61
+ direction: 'left' or 'right'
62
+ size: size of the arrow in fontsize points
63
+ color: if None, line color is taken.
64
+ """
65
+ if color is None:
66
+ color = line.get_color()
67
+
68
+
69
+ if rotation is None:
70
+ rotation = 0
71
+
72
+ if valign is None:
73
+ valign = 'center'
74
+
75
+
76
+ xdata = line.get_xdata()
77
+ ydata = line.get_ydata()
78
+
79
+ if position is None:
80
+ position = xdata.mean()
81
+ # find closest index
82
+ start_ind = np.argmin(np.absolute(xdata - position))
83
+ if direction == 'right':
84
+ end_ind = start_ind + 1
85
+ else:
86
+ end_ind = start_ind - 1
87
+
88
+ line.axes.annotate(label,
89
+ xytext=(xdata[start_ind], ydata[start_ind]),
90
+ xy=(xdata[end_ind], ydata[end_ind]),rotation = rotation,fontsize = size,ha='center',va=valign,color= color
91
+ )
92
+
93
+
94
+ def colorline(
95
+ x, y, z=None, cmap=plt.get_cmap('copper'), norm=plt.Normalize(0.0, 1.0),
96
+ linewidth=3, alpha=1.0):
97
+ """
98
+ http://nbviewer.ipython.org/github/dpsanders/matplotlib-examples/blob/master/colorline.ipynb
99
+ http://matplotlib.org/examples/pylab_examples/multicolored_line.html
100
+ Plot a colored line with coordinates x and y
101
+ Optionally specify colors in the array z
102
+ Optionally specify a colormap, a norm function and a line width
103
+ """
104
+
105
+ # Default colors equally spaced on [0,1]:
106
+ if z is None:
107
+ z = np.linspace(0.0, 1.0, len(x))
108
+
109
+ # Special case if a single number:
110
+ if not hasattr(z, "__iter__"): # to check for numerical input -- this is a hack
111
+ z = np.array([z])
112
+
113
+ z = np.asarray(z)
114
+
115
+ segments = make_segments(x, y)
116
+ lc = mcoll.LineCollection(segments, array=z, cmap=cmap, norm=norm,
117
+ linewidth=linewidth, alpha=alpha)
118
+
119
+ ax = plt.gca()
120
+ ax.add_collection(lc)
121
+
122
+ return lc
123
+
124
+
125
+ def make_segments(x, y):
126
+ """
127
+ Create list of line segments from x and y coordinates, in the correct format
128
+ for LineCollection: an array of the form numlines x (points per line) x 2 (x
129
+ and y) array
130
+ """
131
+
132
+ points = np.array([x, y]).T.reshape(-1, 1, 2)
133
+ segments = np.concatenate([points[:-1], points[1:]], axis=1)
134
+ return segments
135
+
136
+