Skip to content

Commit

Permalink
fix negf
Browse files Browse the repository at this point in the history
  • Loading branch information
freude committed May 29, 2020
1 parent 9e36c53 commit 1ff3e69
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
3 changes: 1 addition & 2 deletions nanonet/negf/cfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ def gen_poles_and_residues(self, cutoff=50):
self.cutoff = cutoff

b_mat = [1 / (2.0 * np.sqrt((2 * (j + 1) - 1) * (2 * (j + 1) + 1))) for j in range(0, cutoff - 1)]
b_mat = np.matrix(np.diag(b_mat, -1)) + np.matrix(np.diag(b_mat, 1))
b_mat = np.diag(b_mat, -1) + np.diag(b_mat, 1)

poles, residues = eig(b_mat)

residues = np.array(np.matrix(residues))
residues = 0.25 * np.array([np.abs(residues[0, j]) ** 2 / (poles[j] ** 2) for j in range(residues.shape[0])])

self.fd_poles_coords = poles
Expand Down
3 changes: 1 addition & 2 deletions nanonet/negf/continued_fraction_representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ def approximant_diff(energy, poles, residues):
def poles_and_residues(cutoff=2):

b_mat = [1 / (2.0 * np.sqrt((2*(j+1) - 1)*(2*(j+1) + 1))) for j in range(0, cutoff-1)]
b_mat = np.matrix(np.diag(b_mat, -1)) + np.matrix(np.diag(b_mat, 1))
b_mat = np.diag(b_mat, -1) + np.diag(b_mat, 1)

poles, residues = eig(b_mat)

residues = np.array(np.matrix(residues))
# arg = np.argmax(np.abs(residues), axis=0)

residues = 0.25 * np.array([np.abs(residues[0, j])**2 / (poles[j] ** 2) for j in range(residues.shape[0])])
Expand Down
28 changes: 14 additions & 14 deletions nanonet/negf/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ def rotate(self, axis, theta):
:return:
"""
if axis == 'x':
rot_mat = np.matrix([[1.0, 0.0, 0.0],
[0.0, np.cos(theta), -np.sin(theta)],
[0.0, np.sin(theta), np.cos(theta)]])
rot_mat = np.array([[1.0, 0.0, 0.0],
[0.0, np.cos(theta), -np.sin(theta)],
[0.0, np.sin(theta), np.cos(theta)]])
elif axis == 'y':
rot_mat = np.matrix([[np.cos(theta), 0.0, np.sin(theta)],
[0.0, 1.0, 0.0],
[-np.sin(theta), 0.0, np.cos(theta)]])
rot_mat = np.array([[np.cos(theta), 0.0, np.sin(theta)],
[0.0, 1.0, 0.0],
[-np.sin(theta), 0.0, np.cos(theta)]])
elif axis == 'z':
rot_mat = np.matrix([[np.cos(theta), -np.sin(theta), 0.0],
[np.sin(theta), np.cos(theta), 0.0],
[0.0, 0.0, 1.0]])
rot_mat = np.array([[np.cos(theta), -np.sin(theta), 0.0],
[np.sin(theta), np.cos(theta), 0.0],
[0.0, 0.0, 1.0]])
else:
raise ValueError('Wrong axis')

Expand Down Expand Up @@ -144,7 +144,7 @@ def _transform(self, coords1, translate):

if len(self._rot_mat) > 0:
for item in self._rot_mat:
coords[j] = np.array(np.matrix(item) * np.matrix(coords[j]).T).T[0]
coords[j] = np.dot(item * coords[j].T).T[0]

return coords

Expand All @@ -159,7 +159,7 @@ def _inv_transform(self, coords1, translate):

if len(self._rot_mat) > 0:
for item in reversed(self._rot_mat):
coords[j] = np.array(np.linalg.inv(np.matrix(item)) * np.matrix(coords[j]).T).T[0]
coords[j] = np.dot(np.linalg.inv(item), coords[j].T).T[0]

if isinstance(translate, np.ndarray):
coords[j] = coords[j] + np.squeeze(translate)
Expand Down Expand Up @@ -208,9 +208,9 @@ def add_screening(self, eps, mol_y_length, spacing):
vec[eps[0]] = 1.0
vec = np.array(vec)

rot_mat = np.matrix(np.identity(3))
rot_mat = np.identity(3)
# rot_mat[:2, :2] = np.matrix(np.sqrt(1.0 - self._rot_mat[0][1:, 1:]**2))
rot_mat[:2, :2] = np.matrix(self._rot_mat[0][1:, 1:])
rot_mat[:2, :2] = self._rot_mat[0][1:, 1:]
rot_mat[0, 1] = -rot_mat[0, 1]
rot_mat[1, 0] = -rot_mat[1, 0]
# rot_mat = np.linalg.inv(rot_mat)
Expand All @@ -219,7 +219,7 @@ def add_screening(self, eps, mol_y_length, spacing):
# rot_mat[0, 0] = -rot_mat[0, 0]
# rot_mat[1, 1] = -rot_mat[1, 1]

vec = np.array(rot_mat * np.matrix(vec).T).T[0]
vec = np.dot(rot_mat, vec.T).T[0]

dist = X[0] * vec[0] + X[1] * vec[1] + X[2] * vec[2] + eps[1] + \
0.5 * mol_y_length * (1.0 - np.sin(1.13446)) + \
Expand Down
2 changes: 1 addition & 1 deletion nanonet/negf/recursive_greens_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def mat_mul(list_of_matrices):
unity = np.eye(list_of_matrices[num_of_mat - 1].shape[0])

for j, item in enumerate(list_of_matrices):
list_of_matrices[j] = np.matrix(item)
list_of_matrices[j] = item

for j in range(9, -1, -1):
unity = list_of_matrices[j] * unity
Expand Down

0 comments on commit 1ff3e69

Please sign in to comment.