stm-sim 0.1__tar.gz
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.
- stm_sim-0.1/LICENSE +21 -0
- stm_sim-0.1/PKG-INFO +19 -0
- stm_sim-0.1/README.md +5 -0
- stm_sim-0.1/setup.cfg +4 -0
- stm_sim-0.1/setup.py +26 -0
- stm_sim-0.1/stm_sim/__init__.py +0 -0
- stm_sim-0.1/stm_sim/stm.py +247 -0
- stm_sim-0.1/stm_sim.egg-info/PKG-INFO +19 -0
- stm_sim-0.1/stm_sim.egg-info/SOURCES.txt +10 -0
- stm_sim-0.1/stm_sim.egg-info/dependency_links.txt +1 -0
- stm_sim-0.1/stm_sim.egg-info/requires.txt +1 -0
- stm_sim-0.1/stm_sim.egg-info/top_level.txt +1 -0
stm_sim-0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 pj.ren
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
stm_sim-0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: stm_sim
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: An STM simulation python library.
|
|
5
|
+
Home-page: https://gitee.com/pjren/stm_sim
|
|
6
|
+
Author: Renpj
|
|
7
|
+
Author-email: 0403114076@163.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: ase
|
|
14
|
+
|
|
15
|
+
# stm_sim
|
|
16
|
+
|
|
17
|
+
An STM simulation python library from PARCHG by VASP.
|
|
18
|
+
Please check the example code in example folder.
|
|
19
|
+
|
stm_sim-0.1/README.md
ADDED
stm_sim-0.1/setup.cfg
ADDED
stm_sim-0.1/setup.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
|
|
3
|
+
with open("README.md", "r", encoding='utf-8') as f:
|
|
4
|
+
long_description = f.read()
|
|
5
|
+
|
|
6
|
+
install_requires = [
|
|
7
|
+
'ase',
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
setup(
|
|
11
|
+
name='stm_sim',
|
|
12
|
+
version='0.1',
|
|
13
|
+
packages=['stm_sim'],
|
|
14
|
+
url='https://gitee.com/pjren/stm_sim',
|
|
15
|
+
license='MIT',
|
|
16
|
+
author='Renpj',
|
|
17
|
+
author_email='0403114076@163.com',
|
|
18
|
+
description='An STM simulation python library.',
|
|
19
|
+
long_description=long_description,
|
|
20
|
+
long_description_content_type="text/markdown",
|
|
21
|
+
install_requires=install_requires,
|
|
22
|
+
classifiers=[
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
],
|
|
26
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
from ase.calculators.vasp import VaspChargeDensity
|
|
3
|
+
from ase.dft.stm import dos2current
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class STM:
|
|
7
|
+
"""
|
|
8
|
+
Get STM from VASP PARCHG.
|
|
9
|
+
|
|
10
|
+
TODO: Export 2d data for external program plot.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
def __init__(self, bias=None):
|
|
14
|
+
self.atoms = None
|
|
15
|
+
self.density = None
|
|
16
|
+
self.ngridpoints = np.array([0, 0, 0])
|
|
17
|
+
if bias is None or bias == 0:
|
|
18
|
+
"TODO: Read from INCAR EINT"
|
|
19
|
+
self.bias = 0.1
|
|
20
|
+
self.bias_range = (0, 0.1)
|
|
21
|
+
elif type(bias) in (list, tuple):
|
|
22
|
+
self.bias = np.abs(bias).max()
|
|
23
|
+
self.bias_range = bias
|
|
24
|
+
elif type(bias) in (float, int):
|
|
25
|
+
self.bias = bias
|
|
26
|
+
self.bias_range = sorted((0, bias))
|
|
27
|
+
self.height = None
|
|
28
|
+
self.scan_mode = None
|
|
29
|
+
self.x, self.y, self.data = None, None, None
|
|
30
|
+
|
|
31
|
+
def read_parchg(self, filename='PARCHG'):
|
|
32
|
+
print("Reading PARCHG file now...\n")
|
|
33
|
+
vasp_charge = VaspChargeDensity(filename)
|
|
34
|
+
self.density = vasp_charge.chg[-1]
|
|
35
|
+
self.atoms = vasp_charge.atoms[-1]
|
|
36
|
+
self.ngridpoints = np.array(self.density.shape)
|
|
37
|
+
# Read scaling factor and unit cell of the crystal structure.
|
|
38
|
+
self.unit_cell = self.atoms.get_cell()
|
|
39
|
+
self.cell_lengths = np.sqrt(np.dot(self.unit_cell, self.unit_cell.transpose()).diagonal())
|
|
40
|
+
self.zinterval = self.cell_lengths[2] / self.ngridpoints[2]
|
|
41
|
+
|
|
42
|
+
del vasp_charge
|
|
43
|
+
print("Done!\n")
|
|
44
|
+
|
|
45
|
+
def scan_current(self, height=None, bottom=False, repeat=(1, 1), plot=True, startpoint=None):
|
|
46
|
+
|
|
47
|
+
if height is None:
|
|
48
|
+
height = 2
|
|
49
|
+
if bottom:
|
|
50
|
+
height = self.atoms.positions[:, 2].min() - height
|
|
51
|
+
else:
|
|
52
|
+
height = self.atoms.positions[:, 2].max() + height
|
|
53
|
+
|
|
54
|
+
self.scan_mode = 'constant_current'
|
|
55
|
+
self.height = height
|
|
56
|
+
|
|
57
|
+
n2 = height / self.cell_lengths[2] * self.ngridpoints[2] # this means scanning must be in c direction
|
|
58
|
+
dn2 = n2 - np.floor(n2)
|
|
59
|
+
n2 = int(n2) % self.ngridpoints[2]
|
|
60
|
+
# Get the averaged current. 这里使用的是 最大/最小值的平均值,而不是总的平均值
|
|
61
|
+
averaged_current = ((1 - dn2) * self.density[:, :, n2].ptp()
|
|
62
|
+
+ dn2 * self.density[:, :, (n2 + 1) % self.ngridpoints[2]].ptp())
|
|
63
|
+
averaged_current = dos2current(self.bias, averaged_current)
|
|
64
|
+
density = self.density.reshape((-1, self.ngridpoints[2]))
|
|
65
|
+
density = dos2current(self.bias, density)
|
|
66
|
+
heights = self.find_heights(density, averaged_current, bottom=bottom, startpoint=startpoint)
|
|
67
|
+
s0 = heights.shape = self.density.shape[:2]
|
|
68
|
+
heights = np.tile(heights, repeat)
|
|
69
|
+
s = heights.shape
|
|
70
|
+
|
|
71
|
+
ij = np.indices(s, dtype=float).reshape((2, -1)).T
|
|
72
|
+
x, y = np.dot(ij / s0, self.atoms.cell[:2, :2]).T.reshape((2,) + s)
|
|
73
|
+
|
|
74
|
+
self.x = x
|
|
75
|
+
self.y = y
|
|
76
|
+
self.data = heights
|
|
77
|
+
|
|
78
|
+
if plot:
|
|
79
|
+
self.plot(x, y, heights, reverse=bottom, absolute=True)
|
|
80
|
+
return x, y, heights
|
|
81
|
+
|
|
82
|
+
def find_heights(self, density, current, bottom=False, startpoint=None):
|
|
83
|
+
assert current > 0
|
|
84
|
+
heights = np.empty(density.shape[0])
|
|
85
|
+
self.current = current
|
|
86
|
+
for i, den in enumerate(density):
|
|
87
|
+
if bottom:
|
|
88
|
+
n = 1
|
|
89
|
+
if startpoint is not None:
|
|
90
|
+
n = int(startpoint * self.ngridpoints[2])
|
|
91
|
+
while n < self.ngridpoints[2]:
|
|
92
|
+
if den[n] > current:
|
|
93
|
+
break
|
|
94
|
+
n += 1
|
|
95
|
+
else:
|
|
96
|
+
n = 1
|
|
97
|
+
c1, c2 = den[n-1:n+1]
|
|
98
|
+
heights[i] = (n - (c2 - current) / (c2 - c1)) * self.zinterval
|
|
99
|
+
else:
|
|
100
|
+
n = self.ngridpoints[2] - 1
|
|
101
|
+
if startpoint is not None:
|
|
102
|
+
n = int(startpoint * self.ngridpoints[2])
|
|
103
|
+
while n > 0:
|
|
104
|
+
if den[n] > current:
|
|
105
|
+
break
|
|
106
|
+
n -= 1
|
|
107
|
+
else:
|
|
108
|
+
n = self.ngridpoints[2] - 1
|
|
109
|
+
c2, c1 = den[n:n+2]
|
|
110
|
+
heights[i] = (n + (c2 - current) / (c2 - c1)) * self.zinterval
|
|
111
|
+
if not c1 <= current <= c2:
|
|
112
|
+
if i != 0:
|
|
113
|
+
heights[i] = heights[i-1]
|
|
114
|
+
else:
|
|
115
|
+
raise ValueError("Density values error!")
|
|
116
|
+
return heights
|
|
117
|
+
|
|
118
|
+
def scan_height(self, height=None, repeat=(1, 1), bottom=False, plot=True, startpoint=None):
|
|
119
|
+
if height is None:
|
|
120
|
+
height = 2
|
|
121
|
+
if bottom:
|
|
122
|
+
height = self.atoms.positions[:, 2].min() - height
|
|
123
|
+
else:
|
|
124
|
+
height = self.atoms.positions[:, 2].max() + height
|
|
125
|
+
|
|
126
|
+
self.scan_mode = 'constant_height'
|
|
127
|
+
self.height = height
|
|
128
|
+
|
|
129
|
+
nz = self.ngridpoints[2]
|
|
130
|
+
ldos = self.density.reshape((-1, nz))
|
|
131
|
+
|
|
132
|
+
I = np.empty(ldos.shape[0])
|
|
133
|
+
|
|
134
|
+
zp = height / self.atoms.cell[2, 2] * nz
|
|
135
|
+
dz = zp - np.floor(zp)
|
|
136
|
+
zp = int(zp) % nz
|
|
137
|
+
|
|
138
|
+
for i, a in enumerate(ldos):
|
|
139
|
+
I[i] = dos2current(self.bias, (1 - dz) * a[zp] + dz * a[(zp + 1) % nz])
|
|
140
|
+
|
|
141
|
+
s0 = I.shape = self.density.shape[:2]
|
|
142
|
+
I = np.tile(I, repeat)
|
|
143
|
+
s = I.shape
|
|
144
|
+
|
|
145
|
+
ij = np.indices(s, dtype=float).reshape((2, -1)).T
|
|
146
|
+
x, y = np.dot(ij / s0, self.atoms.cell[:2, :2]).T.reshape((2,) + s)
|
|
147
|
+
|
|
148
|
+
self.x = x
|
|
149
|
+
self.y = y
|
|
150
|
+
self.data = I
|
|
151
|
+
|
|
152
|
+
if plot:
|
|
153
|
+
self.plot(x, y, I)
|
|
154
|
+
# Return scan with axes in Angstrom.
|
|
155
|
+
return x, y, I
|
|
156
|
+
|
|
157
|
+
def dI_dz(self, scan_mode='constant_current', height=None, bottom=False, repeat=(1, 1), startpoint=None):
|
|
158
|
+
assert scan_mode == self.scan_mode
|
|
159
|
+
|
|
160
|
+
if scan_mode == 'constant_height':
|
|
161
|
+
if self.x is None or height != self.height:
|
|
162
|
+
self.x, self.y, self.data = self.scan(scan_mode=scan_mode, height=height,
|
|
163
|
+
bottom=bottom, repeat=repeat, startpoint=startpoint, plot=False)
|
|
164
|
+
height_plus = self.height + self.zinterval
|
|
165
|
+
data_plus = self.scan(scan_mode='constant_height', height=height_plus,
|
|
166
|
+
bottom=bottom, repeat=repeat, startpoint=startpoint)[-1]
|
|
167
|
+
dI = data_plus - self.data
|
|
168
|
+
|
|
169
|
+
elif scan_mode == 'constant_current':
|
|
170
|
+
if (repeat[0] != 1 or repeat[1] != 1) or self.x is None or height != self.height:
|
|
171
|
+
self.x, self.y, self.data = self.scan(scan_mode='constant_current', height=height,
|
|
172
|
+
bottom=bottom, repeat=(1, 1), startpoint=startpoint, plot=False)
|
|
173
|
+
height_plus = self.data + self.zinterval
|
|
174
|
+
nz = self.ngridpoints[2]
|
|
175
|
+
ldos = self.density.reshape((-1, nz))
|
|
176
|
+
height_plus = height_plus.reshape((-1,))
|
|
177
|
+
|
|
178
|
+
I = np.empty(ldos.shape[0])
|
|
179
|
+
zp = height_plus / self.atoms.cell[2, 2] * nz
|
|
180
|
+
dz = zp - np.floor(zp)
|
|
181
|
+
zp = np.asarray(zp, int) % nz
|
|
182
|
+
|
|
183
|
+
for i, a in enumerate(ldos):
|
|
184
|
+
I[i] = dos2current(self.bias, (1 - dz[i]) * a[zp[i]] + dz[i] * a[(zp[i] + 1) % nz])
|
|
185
|
+
|
|
186
|
+
s0 = I.shape = self.density.shape[:2]
|
|
187
|
+
data_plus = np.tile(I, repeat)
|
|
188
|
+
dI = data_plus - self.current
|
|
189
|
+
|
|
190
|
+
return dI / self.zinterval
|
|
191
|
+
|
|
192
|
+
def scan(self, scan_mode='constant_current', height=None, bottom=False, repeat=(1, 1), plot=True, startpoint=None):
|
|
193
|
+
scan_mode_options = ['constant_height', 'constant_current']
|
|
194
|
+
if scan_mode not in scan_mode_options:
|
|
195
|
+
raise ValueError("Scan mode options: ", scan_mode_options)
|
|
196
|
+
|
|
197
|
+
if scan_mode == 'constant_current':
|
|
198
|
+
scan_func = self.scan_current
|
|
199
|
+
elif scan_mode == 'constant_height':
|
|
200
|
+
scan_func = self.scan_height
|
|
201
|
+
data = scan_func(height=height, bottom=bottom, repeat=repeat, plot=plot, startpoint=startpoint)
|
|
202
|
+
return data
|
|
203
|
+
|
|
204
|
+
def plot(self, x, y, data, scan_mode=None, reverse=False, absolute=False):
|
|
205
|
+
"""
|
|
206
|
+
Suggest colormap: afmhot, gist_heat
|
|
207
|
+
:param absolute:
|
|
208
|
+
:param y:
|
|
209
|
+
:param x:
|
|
210
|
+
:param reverse:
|
|
211
|
+
:param scan_mode: constant_height, constant_current
|
|
212
|
+
:param data:
|
|
213
|
+
:return:
|
|
214
|
+
"""
|
|
215
|
+
import matplotlib
|
|
216
|
+
matplotlib.use('Agg')
|
|
217
|
+
import matplotlib.pyplot as plt
|
|
218
|
+
# import matplotlib.cm as cm
|
|
219
|
+
|
|
220
|
+
if scan_mode is None:
|
|
221
|
+
scan_mode = self.scan_mode
|
|
222
|
+
|
|
223
|
+
plt.figure()
|
|
224
|
+
plt.rcParams['figure.max_open_warning'] = 50
|
|
225
|
+
plt.gca(aspect='equal')
|
|
226
|
+
plt.axis('off')
|
|
227
|
+
plt.xticks(())
|
|
228
|
+
plt.yticks(())
|
|
229
|
+
cm = plt.cm.get_cmap('%s' % 'gist_heat')
|
|
230
|
+
if not absolute:
|
|
231
|
+
if scan_mode == 'constant_current':
|
|
232
|
+
if reverse:
|
|
233
|
+
minh = data.max() # reference point
|
|
234
|
+
data = minh - data
|
|
235
|
+
else:
|
|
236
|
+
minh = data.min()
|
|
237
|
+
data = data - minh
|
|
238
|
+
plt.contourf(x, y, data, 900, cmap=cm)
|
|
239
|
+
plt.colorbar()
|
|
240
|
+
if scan_mode == 'constant_height':
|
|
241
|
+
mode_label = 'H'
|
|
242
|
+
elif scan_mode == 'constant_current':
|
|
243
|
+
mode_label = 'C'
|
|
244
|
+
else:
|
|
245
|
+
mode_label = 'None'
|
|
246
|
+
print("Not support scan mode,", scan_mode)
|
|
247
|
+
plt.savefig(mode_label + '_' + str(round(self.height, 3)) + '.png', dpi=300, bbox_inches='tight')
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: stm_sim
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: An STM simulation python library.
|
|
5
|
+
Home-page: https://gitee.com/pjren/stm_sim
|
|
6
|
+
Author: Renpj
|
|
7
|
+
Author-email: 0403114076@163.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: ase
|
|
14
|
+
|
|
15
|
+
# stm_sim
|
|
16
|
+
|
|
17
|
+
An STM simulation python library from PARCHG by VASP.
|
|
18
|
+
Please check the example code in example folder.
|
|
19
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ase
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
stm_sim
|