mdkits 0.1a4__tar.gz → 0.1.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.
Potentially problematic release.
This version of mdkits might be problematic. Click here for more details.
- {mdkits-0.1a4 → mdkits-0.1.1}/PKG-INFO +20 -2
- {mdkits-0.1a4 → mdkits-0.1.1}/README.md +19 -1
- {mdkits-0.1a4 → mdkits-0.1.1}/pyproject.toml +1 -1
- mdkits-0.1.1/src/mdkits/cli/density.py +134 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/plot.py +4 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/mdkits.py +2 -1
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/numpy_geo.py +3 -2
- mdkits-0.1a4/src/mdkits/cli/cmdline.py +0 -41
- mdkits-0.1a4/src/mdkits/cli/cp2k_input.py +0 -479
- mdkits-0.1a4/src/mdkits/cli/density.py +0 -89
- mdkits-0.1a4/src/mdkits/cli/density2.py +0 -91
- mdkits-0.1a4/src/mdkits/cli/log.py +0 -64
- mdkits-0.1a4/src/mdkits/cli/matplot.py +0 -60
- {mdkits-0.1a4 → mdkits-0.1.1}/LICENSE +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/__init__.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/,hb_distribution_down.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/adsorbate.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/build_bulk.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/build_interface.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/build_surface.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/convert.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/cube.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/cut_surface.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/data.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/extract.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/hartree_potential.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/hartree_potential_ave.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/hb.py +0 -0
- /mdkits-0.1a4/src/mdkits/cli/,hb_distribution.py → /mdkits-0.1.1/src/mdkits/cli/hb_distribution.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/packmol_input.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/pdos.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/supercell.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/cli/wrap.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/config/__init__.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/config/settings.yml +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/__init__.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/arg_type.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/cp2k_input_parsing.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/encapsulated_ase.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/encapsulated_mda.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/fig_operation.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/os_operation.py +0 -0
- {mdkits-0.1a4 → mdkits-0.1.1}/src/mdkits/util/structure_parsing.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: mdkits
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: tools for md or dft
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: molecular dynamics,density functional theory
|
|
@@ -28,7 +28,25 @@ Description-Content-Type: text/markdown
|
|
|
28
28
|
```bash
|
|
29
29
|
pip install mdkits --upgrade
|
|
30
30
|
```
|
|
31
|
+
|
|
31
32
|
### 密度分布
|
|
33
|
+
`density`用于分析体系中的某种元素沿z轴的密度分布, 如分析体系中的`O`元素沿z轴的密度分布, `--element`选项指定元素使用`MDAnalysis`的[选择语言](https://userguide.mdanalysis.org/stable/selections.html):
|
|
34
|
+
```bash
|
|
35
|
+
mdkits density [FILENAME] --element="name H" --cell [FILENAME]
|
|
36
|
+
```
|
|
37
|
+
这样会输出一个文件名为`density_name_H.dat`的文件, 第一列为z轴坐标, 第二列为浓度分布, 单位为 mol/L. 如果想输出为单位为 $g/cm^3$ 的密度分布, 可以指定`--atomic_mass` 选项, 如:
|
|
38
|
+
```bash
|
|
39
|
+
mdkits density [FILENAME] --element="name H" --cell [FILENAME] --atomic_mass=1.00784
|
|
40
|
+
```
|
|
41
|
+
则输出单位为 $g/cm^3$ 的密度分布. 可以指定表面原子来将密度分布归一化到表面, 如:
|
|
42
|
+
```bash
|
|
43
|
+
mdkits density [FILENAME] --element="name O" --cell 10,10,10 --atomic_mass=18.01528 --surface="name Pt and name Ru"
|
|
44
|
+
```
|
|
45
|
+
这样会将密度分布归一化到表面, 同时以O原子的位置作为水分子的位置分析处理水分子的密度分布. 对于体系中存在 $OH^-$ 离子的体系可以使用`--update_water`的选项在每一帧更新水分子的位置, 不需要额外指定元素, 如:
|
|
46
|
+
```bash
|
|
47
|
+
mdkits density [FILENAME] --update_water --cell 10,10,10 --atomic_mass=18.01528 --surface="name Pt and name Ru"
|
|
48
|
+
```
|
|
49
|
+
输出的文件名为`density_water.dat`.
|
|
32
50
|
|
|
33
51
|
### 氢键
|
|
34
52
|
|
|
@@ -102,7 +120,7 @@ mdkits convert -c structure.cif -o structure_xyz
|
|
|
102
120
|
1. `--nor`: 对数据进行归一化处理
|
|
103
121
|
2. `--gaus`: 对数据进行高斯过滤
|
|
104
122
|
3. `--fold`: 堆数据进行折叠平均
|
|
105
|
-
4. `--err`: 计算数据的误差棒
|
|
123
|
+
4. `--err`: 计算数据的误差棒
|
|
106
124
|
等
|
|
107
125
|
|
|
108
126
|
### 绘图工具
|
|
@@ -3,7 +3,25 @@
|
|
|
3
3
|
```bash
|
|
4
4
|
pip install mdkits --upgrade
|
|
5
5
|
```
|
|
6
|
+
|
|
6
7
|
### 密度分布
|
|
8
|
+
`density`用于分析体系中的某种元素沿z轴的密度分布, 如分析体系中的`O`元素沿z轴的密度分布, `--element`选项指定元素使用`MDAnalysis`的[选择语言](https://userguide.mdanalysis.org/stable/selections.html):
|
|
9
|
+
```bash
|
|
10
|
+
mdkits density [FILENAME] --element="name H" --cell [FILENAME]
|
|
11
|
+
```
|
|
12
|
+
这样会输出一个文件名为`density_name_H.dat`的文件, 第一列为z轴坐标, 第二列为浓度分布, 单位为 mol/L. 如果想输出为单位为 $g/cm^3$ 的密度分布, 可以指定`--atomic_mass` 选项, 如:
|
|
13
|
+
```bash
|
|
14
|
+
mdkits density [FILENAME] --element="name H" --cell [FILENAME] --atomic_mass=1.00784
|
|
15
|
+
```
|
|
16
|
+
则输出单位为 $g/cm^3$ 的密度分布. 可以指定表面原子来将密度分布归一化到表面, 如:
|
|
17
|
+
```bash
|
|
18
|
+
mdkits density [FILENAME] --element="name O" --cell 10,10,10 --atomic_mass=18.01528 --surface="name Pt and name Ru"
|
|
19
|
+
```
|
|
20
|
+
这样会将密度分布归一化到表面, 同时以O原子的位置作为水分子的位置分析处理水分子的密度分布. 对于体系中存在 $OH^-$ 离子的体系可以使用`--update_water`的选项在每一帧更新水分子的位置, 不需要额外指定元素, 如:
|
|
21
|
+
```bash
|
|
22
|
+
mdkits density [FILENAME] --update_water --cell 10,10,10 --atomic_mass=18.01528 --surface="name Pt and name Ru"
|
|
23
|
+
```
|
|
24
|
+
输出的文件名为`density_water.dat`.
|
|
7
25
|
|
|
8
26
|
### 氢键
|
|
9
27
|
|
|
@@ -77,7 +95,7 @@ mdkits convert -c structure.cif -o structure_xyz
|
|
|
77
95
|
1. `--nor`: 对数据进行归一化处理
|
|
78
96
|
2. `--gaus`: 对数据进行高斯过滤
|
|
79
97
|
3. `--fold`: 堆数据进行折叠平均
|
|
80
|
-
4. `--err`: 计算数据的误差棒
|
|
98
|
+
4. `--err`: 计算数据的误差棒
|
|
81
99
|
等
|
|
82
100
|
|
|
83
101
|
### 绘图工具
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import click
|
|
5
|
+
from MDAnalysis import Universe
|
|
6
|
+
from MDAnalysis.analysis.base import AnalysisBase
|
|
7
|
+
from mdkits.util import (
|
|
8
|
+
arg_type,
|
|
9
|
+
numpy_geo,
|
|
10
|
+
encapsulated_mda,
|
|
11
|
+
os_operation,
|
|
12
|
+
)
|
|
13
|
+
import warnings, sys
|
|
14
|
+
warnings.filterwarnings("ignore")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Density_distribution(AnalysisBase):
|
|
18
|
+
def __init__(self, filename, cell, o, element, atomic_mass, update_water, distance_judg, angle_judg, surface, dt=0.001, bin_size=0.2, return_index=False):
|
|
19
|
+
u = Universe(filename)
|
|
20
|
+
u.trajectory.ts.dt = dt
|
|
21
|
+
u.dimensions = cell
|
|
22
|
+
|
|
23
|
+
self.u = u
|
|
24
|
+
self.atomgroup = u.select_atoms("all")
|
|
25
|
+
self.bin_size = bin_size
|
|
26
|
+
self.frame_count = 0
|
|
27
|
+
self.return_index = return_index
|
|
28
|
+
self.surface = surface
|
|
29
|
+
self.atomic_mass = atomic_mass
|
|
30
|
+
self.update_water = update_water
|
|
31
|
+
self.element = element
|
|
32
|
+
|
|
33
|
+
if element is None and update_water is False:
|
|
34
|
+
sys.exit("Please specify the element to analysis or use --update-water option")
|
|
35
|
+
|
|
36
|
+
if self.update_water:
|
|
37
|
+
self.distance_judg = distance_judg
|
|
38
|
+
self.angle_judg = angle_judg
|
|
39
|
+
|
|
40
|
+
if o == 'density_{element}.dat':
|
|
41
|
+
if self.update_water:
|
|
42
|
+
self.o = "density_water.dat"
|
|
43
|
+
else:
|
|
44
|
+
self.o = f"density_{element.replace(' ', '_')}.dat"
|
|
45
|
+
else:
|
|
46
|
+
self.o = o
|
|
47
|
+
|
|
48
|
+
if surface is not None:
|
|
49
|
+
self.surface_group = self.atomgroup.select_atoms(f"{surface}")
|
|
50
|
+
if self.surface_group.n_atoms == 0:
|
|
51
|
+
sys.exit("Please specify the correct surface group")
|
|
52
|
+
else:
|
|
53
|
+
self.surface_group = False
|
|
54
|
+
|
|
55
|
+
super(Density_distribution, self).__init__(self.atomgroup.universe.trajectory, verbose=True)
|
|
56
|
+
|
|
57
|
+
def _prepare(self):
|
|
58
|
+
self.bin_num = int(self.u.dimensions[2] / self.bin_size) + 2
|
|
59
|
+
self.density_distribution = np.zeros(self.bin_num, dtype=np.float64)
|
|
60
|
+
if self.surface_group:
|
|
61
|
+
self.surface_pos = np.zeros(2)
|
|
62
|
+
|
|
63
|
+
def _append(self, z):
|
|
64
|
+
bins = np.floor(z / self.bin_size).astype(int) + 1
|
|
65
|
+
np.add.at(self.density_distribution, bins, 1)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _single_frame(self):
|
|
69
|
+
if self.update_water:
|
|
70
|
+
o_group = self.atomgroup.select_atoms("name O")
|
|
71
|
+
h_group = self.atomgroup.select_atoms("name H")
|
|
72
|
+
|
|
73
|
+
o, oh1, oh2 = encapsulated_mda.update_water(self, o_group, h_group, distance_judg=self.distance_judg, angle_judg=self.angle_judg, return_index=self.return_index)
|
|
74
|
+
|
|
75
|
+
self._append(o.positions[:, 2])
|
|
76
|
+
|
|
77
|
+
else:
|
|
78
|
+
group = self.atomgroup.select_atoms(f"{self.element}")
|
|
79
|
+
self._append(group.positions[:, 2])
|
|
80
|
+
|
|
81
|
+
if self.surface_group:
|
|
82
|
+
lower_z, upper_z = numpy_geo.find_surface(self.surface_group.positions[:, 2], layer_tolerance=1, surface_tolerance=5)
|
|
83
|
+
self.surface_pos[0] += lower_z
|
|
84
|
+
self.surface_pos[1] += upper_z
|
|
85
|
+
|
|
86
|
+
self.frame_count += 1
|
|
87
|
+
|
|
88
|
+
def _conclude(self):
|
|
89
|
+
if self.frame_count > 0:
|
|
90
|
+
V = self.u.dimensions[0] * self.u.dimensions[1] * self.bin_size
|
|
91
|
+
|
|
92
|
+
if self.atomic_mass:
|
|
93
|
+
density_distribution = (self.density_distribution * self.atomic_mass * 1.660539 / V) / self.frame_count
|
|
94
|
+
else:
|
|
95
|
+
density_distribution = (self.density_distribution * (10000/6.02) / V) / self.frame_count
|
|
96
|
+
|
|
97
|
+
bins_z = np.arange(len(self.density_distribution)) * self.bin_size
|
|
98
|
+
|
|
99
|
+
if self.surface:
|
|
100
|
+
lower_z = self.surface_pos[0] / self.frame_count
|
|
101
|
+
upper_z = self.surface_pos[1] / self.frame_count
|
|
102
|
+
|
|
103
|
+
mask = (bins_z >= lower_z) & (bins_z <= upper_z)
|
|
104
|
+
filtered_bins_z = bins_z[mask] - lower_z
|
|
105
|
+
filtered_density_distribution = density_distribution[mask]
|
|
106
|
+
|
|
107
|
+
conbined_data = np.column_stack((filtered_bins_z, filtered_density_distribution))
|
|
108
|
+
else:
|
|
109
|
+
conbined_data = np.column_stack((bins_z, density_distribution))
|
|
110
|
+
|
|
111
|
+
np.savetxt(self.o, conbined_data, header="Z\tdensity", fmt='%.5f', delimiter='\t')
|
|
112
|
+
|
|
113
|
+
@click.command(name='density')
|
|
114
|
+
@click.argument('filename', type=click.Path(exists=True), default=os_operation.default_file_name('*-pos-1.xyz', last=True))
|
|
115
|
+
@click.option('--cell', type=arg_type.Cell, help='set cell from cp2k input file or a list of lattice: --cell x,y,z or x,y,z,a,b,c', default='input.inp', show_default=True)
|
|
116
|
+
@click.option('--element', type=str, help='element to analysis')
|
|
117
|
+
@click.option('--atomic_mass', type=float, help='output density unit (g/cm3), should give atomic mass of element, else is concentration unit (mol/L)')
|
|
118
|
+
@click.option('-o', type=str, help='output file name', default='density_{element}.dat', show_default=True)
|
|
119
|
+
@click.option('--update_water', is_flag=True, help='update water with distance or angle judgment')
|
|
120
|
+
@click.option('--distance', type=float, help='update water distance judgment', default=1.2, show_default=True)
|
|
121
|
+
@click.option('--angle', type=(float, float), help='update water angle judgment')
|
|
122
|
+
@click.option('--surface', type=str, help='surface element')
|
|
123
|
+
def main(filename, cell, o, element, atomic_mass, update_water, distance, angle, surface):
|
|
124
|
+
"""
|
|
125
|
+
analysis density or concentration of element in a trajectory file
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
density_dist = Density_distribution(filename, cell, o=o, distance_judg=distance, angle_judg=angle, element=element, atomic_mass=atomic_mass, update_water=update_water, surface=surface)
|
|
129
|
+
|
|
130
|
+
density_dist.run()
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
if __name__ == '__main__':
|
|
134
|
+
main()
|
|
@@ -252,6 +252,10 @@ def mode_error(data_dict, figure, **kwargs):
|
|
|
252
252
|
@click.option('--error', help='set error mode', is_flag=True)
|
|
253
253
|
@click.option('-m', help='output mode: show, save, all, default is save', type=click.Choice(['show', 'save', 'all']), default='save')
|
|
254
254
|
def main(yaml_file, int_ticks, error, m):
|
|
255
|
+
"""
|
|
256
|
+
a plot tool, read yaml file to plot
|
|
257
|
+
"""
|
|
258
|
+
|
|
255
259
|
kwargs = locals()
|
|
256
260
|
figure_dict = {}
|
|
257
261
|
for yaml_file in yaml_file:
|
|
@@ -5,6 +5,7 @@ from mdkits.cli import (
|
|
|
5
5
|
extract,
|
|
6
6
|
data,
|
|
7
7
|
plot,
|
|
8
|
+
density
|
|
8
9
|
)
|
|
9
10
|
|
|
10
11
|
|
|
@@ -12,7 +13,6 @@ from mdkits.cli import (
|
|
|
12
13
|
@click.pass_context
|
|
13
14
|
@click.version_option()
|
|
14
15
|
def cli(ctx):
|
|
15
|
-
print(ctx)
|
|
16
16
|
"""tools for md or dft"""
|
|
17
17
|
pass
|
|
18
18
|
|
|
@@ -22,6 +22,7 @@ cli.add_command(wrap.main)
|
|
|
22
22
|
cli.add_command(extract.main)
|
|
23
23
|
cli.add_command(data.main)
|
|
24
24
|
cli.add_command(plot.main)
|
|
25
|
+
cli.add_command(density.main)
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
if __name__ == '__main__':
|
|
@@ -97,7 +97,7 @@ def unwrap(atom1, atom2, coefficients, max=0, total=False):
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
def find_surface(surface_group:np.ndarray, layer_tolerance=1, surface_tolerance=5):
|
|
100
|
-
sort_group =
|
|
100
|
+
sort_group = np.sort(surface_group)
|
|
101
101
|
layer_mean = []
|
|
102
102
|
current_layer = [sort_group[0]]
|
|
103
103
|
for i in range(1, len(sort_group)):
|
|
@@ -106,6 +106,7 @@ def find_surface(surface_group:np.ndarray, layer_tolerance=1, surface_tolerance=
|
|
|
106
106
|
else:
|
|
107
107
|
layer_mean.append(np.mean(current_layer))
|
|
108
108
|
current_layer = [sort_group[i]]
|
|
109
|
+
layer_mean.append(np.mean(current_layer))
|
|
109
110
|
|
|
110
111
|
if len(current_layer) == 1:
|
|
111
112
|
return layer_mean[0]
|
|
@@ -115,4 +116,4 @@ def find_surface(surface_group:np.ndarray, layer_tolerance=1, surface_tolerance=
|
|
|
115
116
|
index = np.argmax(diff > 5)
|
|
116
117
|
return (layer_mean[index], layer_mean[index + 1])
|
|
117
118
|
else:
|
|
118
|
-
return layer_mean[-1]
|
|
119
|
+
return (layer_mean[-1], layer_mean[0])
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"""Command line"""
|
|
2
|
-
import click
|
|
3
|
-
from click import Context
|
|
4
|
-
|
|
5
|
-
from mdkits import __version__
|
|
6
|
-
from mdkits.config import settings
|
|
7
|
-
from mdkits.log import init_log
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
@click.group(invoke_without_command=True)
|
|
11
|
-
@click.pass_context
|
|
12
|
-
@click.option(
|
|
13
|
-
'-V',
|
|
14
|
-
'--version',
|
|
15
|
-
is_flag=True,
|
|
16
|
-
help='Show version and exit.'
|
|
17
|
-
) # If it's true, it will override `settings.VERBOSE`
|
|
18
|
-
@click.option('-v', '--verbose', is_flag=True, help='Show more info.')
|
|
19
|
-
@click.option(
|
|
20
|
-
'--debug',
|
|
21
|
-
is_flag=True,
|
|
22
|
-
help='Enable debug.'
|
|
23
|
-
) # If it's true, it will override `settings.DEBUG`
|
|
24
|
-
def main(ctx: Context, version: str, verbose: bool, debug: bool):
|
|
25
|
-
"""Main commands"""
|
|
26
|
-
if version:
|
|
27
|
-
click.echo(__version__)
|
|
28
|
-
elif ctx.invoked_subcommand is None:
|
|
29
|
-
click.echo(ctx.get_help())
|
|
30
|
-
else:
|
|
31
|
-
if verbose:
|
|
32
|
-
settings.set('VERBOSE', True)
|
|
33
|
-
if debug:
|
|
34
|
-
settings.set('DEBUG', True)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
@main.command()
|
|
38
|
-
def run():
|
|
39
|
-
"""Run command"""
|
|
40
|
-
init_log()
|
|
41
|
-
click.echo('run......')
|
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
# is to generate cp2k input file
|
|
4
|
-
import argparse
|
|
5
|
-
import shutil
|
|
6
|
-
import os
|
|
7
|
-
from ase.io import read, write
|
|
8
|
-
from pymatgen.core.structure import Structure
|
|
9
|
-
from pymatgen.io.cp2k.inputs import (
|
|
10
|
-
Cp2kInput,
|
|
11
|
-
Section,
|
|
12
|
-
Keyword,
|
|
13
|
-
Cell,
|
|
14
|
-
Coord,
|
|
15
|
-
Kind
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def insert_section(strs, section_name, section):
|
|
20
|
-
|
|
21
|
-
# to insert subsection to a high level section
|
|
22
|
-
insert = Cp2kInput.from_str(strs)
|
|
23
|
-
section.insert(insert.get_section(section_name))
|
|
24
|
-
|
|
25
|
-
return section
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def add_keyword(keyword, section):
|
|
29
|
-
|
|
30
|
-
# to add keyword in a section
|
|
31
|
-
section.add(Keyword.from_str(keyword))
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def Global(
|
|
35
|
-
run_type="ENEGRY",
|
|
36
|
-
project_name="cp2k",
|
|
37
|
-
print_level="MEDIUM",
|
|
38
|
-
walltime=107000
|
|
39
|
-
):
|
|
40
|
-
|
|
41
|
-
# global section
|
|
42
|
-
Global = Section("GLOBAL")
|
|
43
|
-
|
|
44
|
-
add_keyword(f"RUN_TYPE {run_type}", Global)
|
|
45
|
-
add_keyword(f"PROJECT_NAME {project_name}", Global)
|
|
46
|
-
add_keyword(f"PRINT_LEVEL {print_level}", Global)
|
|
47
|
-
add_keyword(f"WALLTIME {walltime}", Global)
|
|
48
|
-
|
|
49
|
-
return Global
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def motion(
|
|
53
|
-
constraint_list=None,
|
|
54
|
-
cell_opt=False,
|
|
55
|
-
geo_opt=False
|
|
56
|
-
):
|
|
57
|
-
|
|
58
|
-
# motion section
|
|
59
|
-
motion = Section("MOTION")
|
|
60
|
-
|
|
61
|
-
## constraint subsection
|
|
62
|
-
if constraint_list != None:
|
|
63
|
-
strs = f"""
|
|
64
|
-
&CONSTRAINT
|
|
65
|
-
&FIXED_ATOMS
|
|
66
|
-
LIST {constraint_list}
|
|
67
|
-
&END FIXED_ATOMS
|
|
68
|
-
&END CONSTRAINT
|
|
69
|
-
"""
|
|
70
|
-
insert_section(strs, "CONSTRAINT", motion)
|
|
71
|
-
|
|
72
|
-
## cell_opt subsection
|
|
73
|
-
if cell_opt:
|
|
74
|
-
strs = f"""
|
|
75
|
-
&CELL_OPT
|
|
76
|
-
OPTIMIZER BFGS
|
|
77
|
-
MAX_ITER 200
|
|
78
|
-
&END CELL_OPT
|
|
79
|
-
"""
|
|
80
|
-
insert_section(strs, "CELL_OPT", motion)
|
|
81
|
-
|
|
82
|
-
## geo_opt subsection
|
|
83
|
-
if geo_opt:
|
|
84
|
-
strs = f"""
|
|
85
|
-
&GEO_OPT
|
|
86
|
-
TYPE MINIMIZATION
|
|
87
|
-
OPTIMIZER BFGS
|
|
88
|
-
MAX_ITER 500
|
|
89
|
-
&END GEO_OPT
|
|
90
|
-
"""
|
|
91
|
-
insert_section(strs, "GEO_OPT", motion)
|
|
92
|
-
|
|
93
|
-
return motion
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def force_eval(
|
|
97
|
-
structure,
|
|
98
|
-
method="QUICKSTEP",
|
|
99
|
-
data_path="/public/software/cp2k-2022.1-intel/cp2k-2022.1/data",
|
|
100
|
-
charge=None,
|
|
101
|
-
ot=False,
|
|
102
|
-
hse=False
|
|
103
|
-
):
|
|
104
|
-
|
|
105
|
-
# force_eval section
|
|
106
|
-
force_eval = Section("FORCE_EVAL")
|
|
107
|
-
add_keyword(f"METHOD {method}", force_eval)
|
|
108
|
-
|
|
109
|
-
## dft subsection
|
|
110
|
-
dft = Section("DFT")
|
|
111
|
-
add_keyword(f"BASIS_SET_FILE_NAME {data_path}/BASIS_MOLOPT", dft)
|
|
112
|
-
add_keyword(f"POTENTIAL_FILE_NAME {data_path}/GTH_POTENTIALS", dft)
|
|
113
|
-
if isinstance(charge, int):
|
|
114
|
-
dft.add_keyword(f"CHARGE {charge}", dft)
|
|
115
|
-
|
|
116
|
-
### mgrid subsubsection
|
|
117
|
-
strs = """
|
|
118
|
-
&MGRID
|
|
119
|
-
CUTOFF 400
|
|
120
|
-
&END MGRID
|
|
121
|
-
"""
|
|
122
|
-
insert_section(strs, "MGRID", dft)
|
|
123
|
-
|
|
124
|
-
### qs subsubsection
|
|
125
|
-
strs = """
|
|
126
|
-
&QS
|
|
127
|
-
EPS_DEFAULT 1.0E-13
|
|
128
|
-
EXTRAPOLATION ASPC
|
|
129
|
-
EXTRAPOLATION_ORDER 2
|
|
130
|
-
&END QS
|
|
131
|
-
"""
|
|
132
|
-
insert_section(strs, "QS", dft)
|
|
133
|
-
|
|
134
|
-
### scf subsubsection
|
|
135
|
-
if ot:
|
|
136
|
-
strs = """
|
|
137
|
-
&SCF
|
|
138
|
-
SCF_GUESS RESTART
|
|
139
|
-
EPS_SCF 3.0E-6
|
|
140
|
-
MAX_SCF 50
|
|
141
|
-
|
|
142
|
-
&OUTER_SCF
|
|
143
|
-
EPS_SCF 3.0E-6
|
|
144
|
-
MAX_SCF 20
|
|
145
|
-
&END OUTER_SCF
|
|
146
|
-
|
|
147
|
-
&OT
|
|
148
|
-
MINIMIZER DIIS
|
|
149
|
-
PRECONDITIONER FULL_SINGLE_INVERSE
|
|
150
|
-
&END OT
|
|
151
|
-
&END SCF
|
|
152
|
-
"""
|
|
153
|
-
insert_section(strs, dft)
|
|
154
|
-
else:
|
|
155
|
-
strs = """
|
|
156
|
-
&SCF
|
|
157
|
-
SCF_GUESS RESTART
|
|
158
|
-
EPS_SCF 3.0E-7
|
|
159
|
-
MAX_SCF 500
|
|
160
|
-
ADDED_MOS 500
|
|
161
|
-
CHOLESKY INVERSE
|
|
162
|
-
|
|
163
|
-
&SMEAR ON
|
|
164
|
-
METHOD FERMI_DIRAC
|
|
165
|
-
&END SMEAR
|
|
166
|
-
|
|
167
|
-
&DIAGONALIZATION
|
|
168
|
-
ALGORITHM STANDARD
|
|
169
|
-
&END DIAGONALIZATION
|
|
170
|
-
|
|
171
|
-
&MIXING
|
|
172
|
-
METHOD BROYDEN_MIXING
|
|
173
|
-
ALPHA 0.15
|
|
174
|
-
BETA 1.0
|
|
175
|
-
NBROYDEN 16
|
|
176
|
-
&END MIXING
|
|
177
|
-
|
|
178
|
-
&PRINT
|
|
179
|
-
|
|
180
|
-
&RESTART
|
|
181
|
-
ADD_LAST NUMERIC
|
|
182
|
-
|
|
183
|
-
&EACH
|
|
184
|
-
QS_SCF 50
|
|
185
|
-
&END EACH
|
|
186
|
-
&END RESTART
|
|
187
|
-
&END PRINT
|
|
188
|
-
&END SCF
|
|
189
|
-
"""
|
|
190
|
-
insert_section(strs, "SCF", dft)
|
|
191
|
-
|
|
192
|
-
### xc subsubsection
|
|
193
|
-
if hse:
|
|
194
|
-
strs = f"""
|
|
195
|
-
&XC
|
|
196
|
-
|
|
197
|
-
&VDW_POTENTIAL
|
|
198
|
-
DISPERSION_FUNCTIONAL PAIR_POTENTIAL
|
|
199
|
-
|
|
200
|
-
&PAIR_POTENTIAL
|
|
201
|
-
TYPE DFTD3
|
|
202
|
-
PARAMETER_FILE_NAME {data_path}/dftd3.dat
|
|
203
|
-
REFERENCE_FUNCTIONAL PBE
|
|
204
|
-
&END PAIR_POTENTIAL
|
|
205
|
-
&END VDW_POTENTIAL
|
|
206
|
-
|
|
207
|
-
&XC_FUNCTIONAL
|
|
208
|
-
|
|
209
|
-
&XWPBE
|
|
210
|
-
SCALE_X -0.25
|
|
211
|
-
SCALE_X0 1.0
|
|
212
|
-
OMEGA 0.11
|
|
213
|
-
&END XWPBE
|
|
214
|
-
|
|
215
|
-
&PBE
|
|
216
|
-
SCALE_X 0.0
|
|
217
|
-
SCALE_C 1.0
|
|
218
|
-
&END PBE
|
|
219
|
-
&END XC_FUNCTIONAL
|
|
220
|
-
|
|
221
|
-
&HF
|
|
222
|
-
FRACTION 0.25
|
|
223
|
-
|
|
224
|
-
&INTERACTION_POTENTIAL
|
|
225
|
-
POTENTIAL_TYPE SHORTRANGE
|
|
226
|
-
OMEGA 0.11
|
|
227
|
-
T_C_G_DATA
|
|
228
|
-
&END INTERACTION_POTENTIAL
|
|
229
|
-
|
|
230
|
-
&SCREENING
|
|
231
|
-
EPS_SCHWARZ 1.0E-6
|
|
232
|
-
SCREEN_ON_INITIAL_P .FALSE.
|
|
233
|
-
&END SCREENING
|
|
234
|
-
|
|
235
|
-
&MEMORY
|
|
236
|
-
MAX_MEMORY 3000
|
|
237
|
-
EPS_STORAGE_SCALING 0.1
|
|
238
|
-
&END MEMORY
|
|
239
|
-
|
|
240
|
-
&PERIODIC
|
|
241
|
-
NUMPER_OF_SHELLS 0
|
|
242
|
-
&END PERIODIC
|
|
243
|
-
&END HF
|
|
244
|
-
&END XC
|
|
245
|
-
"""
|
|
246
|
-
insert_section(strs, "XC", dft)
|
|
247
|
-
else:
|
|
248
|
-
strs = f"""
|
|
249
|
-
&XC
|
|
250
|
-
|
|
251
|
-
&XC_FUNCTIONAL PBE
|
|
252
|
-
&END XC_FUNCTIONAL
|
|
253
|
-
|
|
254
|
-
&VDW_POTENTIAL
|
|
255
|
-
DISPERSION_FUNCTIONAL PAIR_POTENTIAL
|
|
256
|
-
|
|
257
|
-
&PAIR_POTENTIAL
|
|
258
|
-
TYPE DFTD3
|
|
259
|
-
PARAMETER_FILE_NAME {data_path}/dftd3.dat
|
|
260
|
-
REFERENCE_FUNCTIONAL PBE
|
|
261
|
-
&END PAIR_POTENTIAL
|
|
262
|
-
&END VDW_POTENTIAL
|
|
263
|
-
&END XC
|
|
264
|
-
"""
|
|
265
|
-
insert_section(strs, "XC", dft)
|
|
266
|
-
|
|
267
|
-
### print subsubsection
|
|
268
|
-
strs = """
|
|
269
|
-
&PRINT
|
|
270
|
-
|
|
271
|
-
&E_DENSITY_CUBE
|
|
272
|
-
ADD_LAST NUMERIC
|
|
273
|
-
|
|
274
|
-
&EACH
|
|
275
|
-
GEO_OPT 0
|
|
276
|
-
&END EACH
|
|
277
|
-
&END E_DENSITY_CUBE
|
|
278
|
-
|
|
279
|
-
&PDOS
|
|
280
|
-
COMPONENTS .TRUE.
|
|
281
|
-
NLUMO -1
|
|
282
|
-
ADD_LAST NUMERIC
|
|
283
|
-
|
|
284
|
-
&EACH
|
|
285
|
-
MD 50
|
|
286
|
-
GEO_OPT 0
|
|
287
|
-
&END EACH
|
|
288
|
-
&END PDOS
|
|
289
|
-
|
|
290
|
-
&MO_CUBES
|
|
291
|
-
NHOMO 5
|
|
292
|
-
NLUMO 5
|
|
293
|
-
WRITE_CUBE F
|
|
294
|
-
ADD_LAST NUMERIC
|
|
295
|
-
|
|
296
|
-
&EACH
|
|
297
|
-
MD 50
|
|
298
|
-
GEO_OPT 0
|
|
299
|
-
&END EACH
|
|
300
|
-
&END MO_CUBES
|
|
301
|
-
|
|
302
|
-
&V_HARTREE_CUBE ON
|
|
303
|
-
STRIDE 8 8 1
|
|
304
|
-
APPEND T
|
|
305
|
-
|
|
306
|
-
&EACH
|
|
307
|
-
MD 50
|
|
308
|
-
GEO_OPT 0
|
|
309
|
-
&END EACH
|
|
310
|
-
&END V_HARTREE_CUBE
|
|
311
|
-
&END PRINT
|
|
312
|
-
"""
|
|
313
|
-
insert_section(strs, "PRINT", dft)
|
|
314
|
-
|
|
315
|
-
force_eval.insert(dft)
|
|
316
|
-
|
|
317
|
-
## subsys subsection
|
|
318
|
-
subsys = Section("SUBSYS")
|
|
319
|
-
|
|
320
|
-
### cell subsubsection
|
|
321
|
-
cell = Cell(structure.lattice)
|
|
322
|
-
subsys.insert(cell)
|
|
323
|
-
|
|
324
|
-
### coord subsubsection
|
|
325
|
-
coord = Section("COORD")
|
|
326
|
-
add_keyword("@INCLUDE ./coord.xyz", coord)
|
|
327
|
-
subsys.insert(coord)
|
|
328
|
-
|
|
329
|
-
### kind subsubsection
|
|
330
|
-
for atom in structure.species:
|
|
331
|
-
kind = Kind(atom, basis_set=None, potential=None)
|
|
332
|
-
subsys.insert(kind)
|
|
333
|
-
|
|
334
|
-
force_eval.insert(subsys)
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return force_eval
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
parser = argparse.ArgumentParser(description='generate cp2k input file')
|
|
341
|
-
parser.add_argument('input_file_name', type=str, help='input file name')
|
|
342
|
-
parser.add_argument('--cell', nargs="+", help='set cell, a list of lattice, [x, y, z] or [x, y, z, a, b, c]')
|
|
343
|
-
parser.add_argument('--bp', type=str, nargs="?", default=None, help='a file contains all basis_set and potential information')
|
|
344
|
-
## function args of golbal
|
|
345
|
-
parser.add_argument('--run_type', type=str, nargs="?", default="ENEGRY", help='specie run_type keyword of global')
|
|
346
|
-
parser.add_argument('--project_name', type=str, nargs="?", default="cp2k", help='specie project_name keyword of global')
|
|
347
|
-
parser.add_argument('--print_level', type=str, nargs="?", default="MEDIUM", help='specie print_level keyword of global')
|
|
348
|
-
parser.add_argument('--walltime', type=int, nargs="?", default=107000, help='specie walltime keyword of global')
|
|
349
|
-
## function args of motion
|
|
350
|
-
parser.add_argument('--constraint_list', type=str, nargs="?", default=None, help='specie constranit_list keyword of motion')
|
|
351
|
-
parser.add_argument('--cell_opt', type=bool, nargs="?", default=False, help='specie cell_opt section of motion')
|
|
352
|
-
parser.add_argument('--geo_opt', type=bool, nargs="?", default=False, help='specie geo_opt section of motion')
|
|
353
|
-
## function args of force_eval
|
|
354
|
-
parser.add_argument('--method', type=str, nargs="?", default="QUICKSTEP", help='specie methon keyword of force_eval')
|
|
355
|
-
parser.add_argument('--charge', type=int, nargs="?", default=None, help='specie charge keyword of force_eval')
|
|
356
|
-
parser.add_argument('--ot', type=bool, nargs="?", default=False, help='specie scf type is ot(else is smear) of force_eval')
|
|
357
|
-
parser.add_argument('--hse', type=bool, nargs="?", default=False, help='specie xc type is hse(else is pbe) of force_eval')
|
|
358
|
-
args = parser.parse_args()
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
if args.input_file_name[-3:] == "xyz":
|
|
363
|
-
with open(args.input_file_name, 'r') as f:
|
|
364
|
-
data = f.readline().strip()
|
|
365
|
-
if not isinstance(int(data), int):
|
|
366
|
-
atom_number = sum(1 for line in f if line.strip)
|
|
367
|
-
|
|
368
|
-
add_line = f"{int(atom_number+1)}\n\n"
|
|
369
|
-
with open(args.input_file_name, 'r') as g:
|
|
370
|
-
gile = g.readlines()
|
|
371
|
-
gile.insert(0, add_line)
|
|
372
|
-
with open(args.input_file_name, 'w') as g:
|
|
373
|
-
g.writelines(gile)
|
|
374
|
-
|
|
375
|
-
if args.bp == None:
|
|
376
|
-
bp_dict = {
|
|
377
|
-
'Pt': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q18'],
|
|
378
|
-
'O': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q6'],
|
|
379
|
-
'C': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q4'],
|
|
380
|
-
'Cs': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q9'],
|
|
381
|
-
'Li': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q3'],
|
|
382
|
-
'Ne': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q8'],
|
|
383
|
-
'Ru': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q16'],
|
|
384
|
-
'Ag': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q11'],
|
|
385
|
-
'Ir': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q17'],
|
|
386
|
-
'C': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q4'],
|
|
387
|
-
'H': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q1'],
|
|
388
|
-
'F': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q7'],
|
|
389
|
-
'Na': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q9'],
|
|
390
|
-
'K': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q9'],
|
|
391
|
-
'Cl': ['DZVP-MOLOPT-SR-GTH', 'GTH-PBE-q7']
|
|
392
|
-
}
|
|
393
|
-
else:
|
|
394
|
-
bp_dict = {}
|
|
395
|
-
with open(args.bp, 'r') as f:
|
|
396
|
-
for line in f:
|
|
397
|
-
key, value1, value2 = line.strip().split()
|
|
398
|
-
bp_dict[key] = [value1, value2]
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if args.input_file_name[-3:] == "cif":
|
|
402
|
-
atoms = read(args.input_file_name)
|
|
403
|
-
atoms.write("POSCAR")
|
|
404
|
-
structure = Structure.from_file("POSCAR")
|
|
405
|
-
os.remove("POSCAR")
|
|
406
|
-
|
|
407
|
-
elif args.input_file_name[-3:] == "xyz":
|
|
408
|
-
atoms = read(args.input_file_name, format="xyz")
|
|
409
|
-
atoms.set_cell(args.cell)
|
|
410
|
-
atoms.write("POSCAR", format="vasp")
|
|
411
|
-
structure = Structure.from_file("POSCAR")
|
|
412
|
-
os.remove("POSCAR")
|
|
413
|
-
|
|
414
|
-
Global = Global(
|
|
415
|
-
run_type=args.run_type,
|
|
416
|
-
project_name=args.project_name,
|
|
417
|
-
print_level=args.print_level,
|
|
418
|
-
walltime=args.walltime
|
|
419
|
-
)
|
|
420
|
-
motion = motion(
|
|
421
|
-
constraint_list=args.constraint_list,
|
|
422
|
-
cell_opt=args.cell_opt,
|
|
423
|
-
geo_opt=args.geo_opt
|
|
424
|
-
)
|
|
425
|
-
force_eval = force_eval(
|
|
426
|
-
structure,
|
|
427
|
-
method=args.method,
|
|
428
|
-
charge=args.charge,
|
|
429
|
-
ot=args.ot,
|
|
430
|
-
hse=args.hse
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
used_bp_dict = {}
|
|
434
|
-
for atom in structure.species:
|
|
435
|
-
if str(atom) in bp_dict:
|
|
436
|
-
used_bp_dict[str(atom)] = bp_dict[str(atom)]
|
|
437
|
-
|
|
438
|
-
for key, value in used_bp_dict.items():
|
|
439
|
-
print(key, value)
|
|
440
|
-
add_keyword(f"BASIS_SET {value[0]}", force_eval.by_path(f"SUBSYS/{key}"))
|
|
441
|
-
add_keyword(f"POTENTIAL {value[1]}", force_eval.by_path(f"SUBSYS/{key}"))
|
|
442
|
-
|
|
443
|
-
if args.input_file_name[-3:] == "cif":
|
|
444
|
-
atoms = read(args.input_file_name)
|
|
445
|
-
atoms.write("temp.xyz")
|
|
446
|
-
with open("temp.xyz", 'r') as f:
|
|
447
|
-
coord = ''
|
|
448
|
-
for i, line in enumerate(f):
|
|
449
|
-
if i < 2:
|
|
450
|
-
continue
|
|
451
|
-
coord += f" {' '.join(line.split()[0:4])}\n"
|
|
452
|
-
|
|
453
|
-
with open("coord.xyz", 'w') as f:
|
|
454
|
-
f.write(coord)
|
|
455
|
-
os.remove("temp.xyz")
|
|
456
|
-
|
|
457
|
-
elif args.input_file_name[-3:] == "xyz":
|
|
458
|
-
with open(args.input_file_name, 'r') as f:
|
|
459
|
-
coord = ''
|
|
460
|
-
for i, line in enumerate(f):
|
|
461
|
-
if i < 2:
|
|
462
|
-
continue
|
|
463
|
-
coord += f" {' '.join(line.split()[0:4])}\n"
|
|
464
|
-
|
|
465
|
-
with open("coord.xyz", 'w') as f:
|
|
466
|
-
f.write(coord)
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
inp = Cp2kInput.from_str(
|
|
470
|
-
Global.get_str()+
|
|
471
|
-
motion.get_str()+
|
|
472
|
-
force_eval.get_str()
|
|
473
|
-
)
|
|
474
|
-
inp.write_file("input.inp")
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
# copy sub script
|
|
478
|
-
sub_script_path = "/public/home/jxxcr/script/sub_cp2k"
|
|
479
|
-
shutil.copy2(sub_script_path, ".")
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
import click
|
|
5
|
-
import MDAnalysis
|
|
6
|
-
from MDAnalysis import Universe
|
|
7
|
-
from MDAnalysis.analysis.base import AnalysisBase
|
|
8
|
-
from mdkits.util import cp2k_input_parsing, numpy_geo, encapsulated_mda
|
|
9
|
-
import warnings
|
|
10
|
-
warnings.filterwarnings("ignore")
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class Density_distribution(AnalysisBase):
|
|
14
|
-
def __init__(self, filename, cell, o, distance_judg, angle_judg, dt=0.001, bin_size=0.2, return_index=False):
|
|
15
|
-
u = Universe(filename)
|
|
16
|
-
u.trajectory.ts.dt = dt
|
|
17
|
-
u.dimensions = cell
|
|
18
|
-
|
|
19
|
-
self.u = u
|
|
20
|
-
self.o = o
|
|
21
|
-
self.distance_judg = distance_judg
|
|
22
|
-
self.angle_judg = angle_judg
|
|
23
|
-
self.atomgroup = u.select_atoms("all")
|
|
24
|
-
self.mid_z = u.dimensions[2]/2
|
|
25
|
-
self.bin_size = bin_size
|
|
26
|
-
self.frame_count = 0
|
|
27
|
-
self.return_index = return_index
|
|
28
|
-
|
|
29
|
-
super(Density_distribution, self).__init__(self.atomgroup.universe.trajectory, verbose=True)
|
|
30
|
-
|
|
31
|
-
def _prepare(self):
|
|
32
|
-
self.bin_num = int(self.u.dimensions[2] / self.bin_size) + 2
|
|
33
|
-
self.density_distribution = np.zeros(self.bin_num, dtype=np.float64)
|
|
34
|
-
if self.surface:
|
|
35
|
-
self.surface_pos = ()
|
|
36
|
-
|
|
37
|
-
def _append(self, z):
|
|
38
|
-
bins = np.floor(z / self.bin_size).astype(int) + 1
|
|
39
|
-
np.add.at(self.density_distribution, bins, 1)
|
|
40
|
-
|
|
41
|
-
def _single_frame(self):
|
|
42
|
-
if self.water:
|
|
43
|
-
o_group = self.atomgroup.select_atoms("name O")
|
|
44
|
-
h_group = self.atomgroup.select_atoms("name H")
|
|
45
|
-
|
|
46
|
-
o, oh1, oh2 = encapsulated_mda.update_water(self, o_group, h_group, distance_judg=self.distance_judg, angle_judg=self.angle_judg, return_index=self.return_index)
|
|
47
|
-
|
|
48
|
-
self._append(o.positions[:, 2])
|
|
49
|
-
|
|
50
|
-
else:
|
|
51
|
-
group = self.atomgroup.select_atoms(f"name {self.element}")
|
|
52
|
-
self._append(group.positions[:, 2])
|
|
53
|
-
|
|
54
|
-
self.
|
|
55
|
-
self.frame_count += 1
|
|
56
|
-
|
|
57
|
-
def _conclude(self):
|
|
58
|
-
if self.frame_count > 0:
|
|
59
|
-
V = self.u.dimensions[0] * self.u.dimensions[1] * self.bin_size
|
|
60
|
-
|
|
61
|
-
if self.water:
|
|
62
|
-
density_distribution = (self.density_distribution * (15.999+1.008*2) * 1.660539 / V) / self.frame_count
|
|
63
|
-
else:
|
|
64
|
-
density_distribution = (self.density_distribution * (10000/6.02) / V) / self.frame_count
|
|
65
|
-
|
|
66
|
-
bins_z = np.arange(len(self.density_distribution)) * self.bin_size
|
|
67
|
-
|
|
68
|
-
surface = self.find_surface(self.atomgroup.select_atoms("name Pt"))
|
|
69
|
-
|
|
70
|
-
lower_z, upper_z = surface
|
|
71
|
-
mask = (bins_z >= lower_z) & (bins_z <= upper_z)
|
|
72
|
-
filtered_bins_z = bins_z[mask] - lower_z
|
|
73
|
-
filtered_density_distribution = density_distribution[mask]
|
|
74
|
-
conbined_data = np.column_stack((filtered_bins_z, filtered_density_distribution))
|
|
75
|
-
|
|
76
|
-
np.savetxt(self.o, conbined_data, header="Z\tdensity", fmt='%.5f', delimiter='\t')
|
|
77
|
-
|
|
78
|
-
@click.command(name='density')
|
|
79
|
-
@click.argument('filename', type=click.Path(exists=True), default=os_operation.default_file_name('*-pos-1.xyz', last=True))
|
|
80
|
-
@click.option('--cell', type=arg_type.Cell, help='set xyz file cell, --cell x,y,z,a,b,c')
|
|
81
|
-
@click.option('--cell', type=arg_type.Cell, help='set cell from cp2k input file or a list of lattice: --cell x,y,z or x,y,z,a,b,c', default='input.inp', show_default=True)
|
|
82
|
-
@click.option('-o', type=str, help='output file name', default='density.dat', show_default=True)
|
|
83
|
-
def main(filename, cell, o):
|
|
84
|
-
density_dist = Density_distribution(filename, cell, o=o)
|
|
85
|
-
density_dist.run()
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if __name__ == '__main__':
|
|
89
|
-
main()
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
import os, sys, argparse
|
|
4
|
-
import numpy as np
|
|
5
|
-
import math
|
|
6
|
-
import multiprocessing
|
|
7
|
-
from util import (
|
|
8
|
-
structure_parsing,
|
|
9
|
-
cp2k_input_parsing,
|
|
10
|
-
os_operation,
|
|
11
|
-
atom_count,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def array_type(string):
|
|
16
|
-
number_list = string.split(',')
|
|
17
|
-
number_array = array(number_list, dtype=float)
|
|
18
|
-
return number_array
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def get_cell(cp2k_input_file, cell=None):
|
|
22
|
-
if cell is None:
|
|
23
|
-
cell = cp2k_input_parsing.parse_cell(cp2k_input_file)
|
|
24
|
-
else:
|
|
25
|
-
cell = cell
|
|
26
|
-
if len(cell) == 3:
|
|
27
|
-
cell.extend([90.0, 90.0, 90.0])
|
|
28
|
-
|
|
29
|
-
return cell
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def parse_cell(s):
|
|
33
|
-
if s == None:
|
|
34
|
-
return None
|
|
35
|
-
return [float(x) for x in s.replace(',', ' ').split()]
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# set argument
|
|
39
|
-
def parse_argument():
|
|
40
|
-
parser = argparse.ArgumentParser(description='calculate water density destribution alone z axis')
|
|
41
|
-
|
|
42
|
-
parser.add_argument('input_file_name', type=str, nargs='?', help='input file name', default=os_operation.default_file_name('*-pos-1.xyz', last=True))
|
|
43
|
-
#parser.add_argument('-a', type=str, help='atom to statistic', default='O')
|
|
44
|
-
parser.add_argument('-o', type=str, help='output file name, default is "density.dat"', default='density.dat')
|
|
45
|
-
parser.add_argument('-r', type=array_type, help='bulk range')
|
|
46
|
-
parser.add_argument('--cp2k_input_file', type=str, help='input file name of cp2k, default is "input.inp"', default='input.inp')
|
|
47
|
-
parser.add_argument('--cell', type=parse_cell, help='set cell, a list of lattice, [x,y,z] or [x,y,z,a,b,c]')
|
|
48
|
-
parser.add_argument('--process', type=int, help='paralle process number default is 28', default=28)
|
|
49
|
-
parser.add_argument('--temp', help='keep temp file', action='store_false')
|
|
50
|
-
|
|
51
|
-
return parser.parse_args()
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def main():
|
|
55
|
-
args = parse_argument()
|
|
56
|
-
bin_size = 0.2
|
|
57
|
-
cell = get_cell(args.cp2k_input_file, args.cell)
|
|
58
|
-
temp_dir = f'{os.environ.get("TEMP_DIR")}/{os.getpid()}'
|
|
59
|
-
os_operation.make_temp_dir(temp_dir, delete=args.temp)
|
|
60
|
-
chunks = structure_parsing.xyz_to_chunks(args.input_file_name, args.process)
|
|
61
|
-
group = structure_parsing.chunk_to_groups(chunks[0])[0]
|
|
62
|
-
atom_names = structure_parsing.atom_name_parse(group)
|
|
63
|
-
for atom_name in atom_names:
|
|
64
|
-
for index, chunk in enumerate(chunks):
|
|
65
|
-
t = multiprocessing.Process(target=atom_count.atom_number_count, args=[chunk, bin_size, cell[2], atom_name, f'{temp_dir}/chunk_{index}.temp'])
|
|
66
|
-
t.start()
|
|
67
|
-
|
|
68
|
-
for t in multiprocessing.active_children():
|
|
69
|
-
t.join()
|
|
70
|
-
|
|
71
|
-
chunks_array_list = []
|
|
72
|
-
for i in range(len(chunks)):
|
|
73
|
-
chunk_array = np.load(f'{temp_dir}/chunk_{i}.temp.npy')
|
|
74
|
-
chunks_array_list.append(chunk_array)
|
|
75
|
-
chunks_array = np.vstack(chunks_array_list)
|
|
76
|
-
chunks_array = np.mean(chunks_array, axis=0)
|
|
77
|
-
if atom_name == 'O':
|
|
78
|
-
chunks_array = chunks_array * (15.999+1.0080*2) * 1.660539 / (cell[0]*cell[1]*bin_size)
|
|
79
|
-
with open(f'density_water.dat', 'w') as f:
|
|
80
|
-
for i in range(len(chunks_array)):
|
|
81
|
-
f.write(str((i+1)*bin_size) + '\t' + str(chunks_array[i]) + '\n')
|
|
82
|
-
|
|
83
|
-
chunks_array = chunks_array * (10000/6.02) / (cell[0]*cell[1]*bin_size)
|
|
84
|
-
with open(f'density_{atom_name}.dat', 'w') as f:
|
|
85
|
-
for i in range(len(chunks_array)):
|
|
86
|
-
f.write(str((i+1)*bin_size) + '\t' + str(chunks_array[i]) + '\n')
|
|
87
|
-
|
|
88
|
-
print(f"density analysis of {atom_name} is done")
|
|
89
|
-
|
|
90
|
-
if __name__ == '__main__':
|
|
91
|
-
main()
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"""Log"""
|
|
2
|
-
import logging
|
|
3
|
-
import os
|
|
4
|
-
from logging.config import dictConfig
|
|
5
|
-
|
|
6
|
-
from mdkits.config import settings
|
|
7
|
-
|
|
8
|
-
os.makedirs(settings.LOGPATH, exist_ok=True)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def verbose_formatter(verbose: int) -> str:
|
|
12
|
-
"""formatter factory"""
|
|
13
|
-
if verbose is True:
|
|
14
|
-
return 'verbose'
|
|
15
|
-
return 'simple'
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def update_log_level(debug: bool, level: str) -> str:
|
|
19
|
-
"""update log level"""
|
|
20
|
-
if debug is True:
|
|
21
|
-
level_num = logging.DEBUG
|
|
22
|
-
else:
|
|
23
|
-
level_num = logging.getLevelName(level)
|
|
24
|
-
settings.set('LOGLEVEL', logging.getLevelName(level_num))
|
|
25
|
-
return settings.LOGLEVEL
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
def init_log() -> None:
|
|
29
|
-
"""Init log config."""
|
|
30
|
-
log_level = update_log_level(settings.DEBUG, str(settings.LOGLEVEL).upper())
|
|
31
|
-
|
|
32
|
-
log_config = {
|
|
33
|
-
"version": 1,
|
|
34
|
-
"disable_existing_loggers": False,
|
|
35
|
-
"formatters": {
|
|
36
|
-
'verbose': {
|
|
37
|
-
'format': '%(asctime)s %(levelname)s %(name)s %(process)d %(thread)d %(message)s',
|
|
38
|
-
},
|
|
39
|
-
'simple': {
|
|
40
|
-
'format': '%(asctime)s %(levelname)s %(name)s %(message)s',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
"handlers": {
|
|
44
|
-
"console": {
|
|
45
|
-
"formatter": verbose_formatter(settings.VERBOSE),
|
|
46
|
-
'level': 'DEBUG',
|
|
47
|
-
"class": "logging.StreamHandler",
|
|
48
|
-
},
|
|
49
|
-
'file': {
|
|
50
|
-
'class': 'logging.handlers.RotatingFileHandler',
|
|
51
|
-
'level': 'DEBUG',
|
|
52
|
-
'formatter': verbose_formatter(settings.VERBOSE),
|
|
53
|
-
'filename': os.path.join(settings.LOGPATH, 'all.log'),
|
|
54
|
-
'maxBytes': 1024 * 1024 * 1024 * 200, # 200M
|
|
55
|
-
'backupCount': '5',
|
|
56
|
-
'encoding': 'utf-8'
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
"loggers": {
|
|
60
|
-
'': {'level': log_level, 'handlers': ['console']},
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
dictConfig(log_config)
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
|
|
3
|
-
import numpy as np
|
|
4
|
-
import matplotlib.pyplot as plt
|
|
5
|
-
import argparse
|
|
6
|
-
import os
|
|
7
|
-
from matplotlib import use as muse
|
|
8
|
-
muse('Agg')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def parse_slice(s):
|
|
12
|
-
if s == None:
|
|
13
|
-
return None
|
|
14
|
-
return [int(x) for x in s.replace(':', ' ').split()]
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def parse_argument():
|
|
18
|
-
parser = argparse.ArgumentParser(description='extract pos file from output file')
|
|
19
|
-
|
|
20
|
-
parser.add_argument('input_file_name', type=str, help='input file name')
|
|
21
|
-
parser.add_argument('-o', type=str, help='output file name, default is "out.xyz"', default='out.png')
|
|
22
|
-
parser.add_argument('-u', type=parse_slice, help='which clume to use, look like gnuplot u 1:2', default=[0, 1])
|
|
23
|
-
parser.add_argument('--label', type=str, help='line name')
|
|
24
|
-
parser.add_argument('--dpi', type=int, help='image dpi, default is 300', default=300)
|
|
25
|
-
parser.add_argument('--err', help='plot err line', action='store_true')
|
|
26
|
-
|
|
27
|
-
return parser.parse_args()
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def plot_data(x, y, dpi, label, name):
|
|
31
|
-
fig, ax = plt.subplots(dpi=dpi)
|
|
32
|
-
ax.plot(x, y, label=label)
|
|
33
|
-
ax.legend()
|
|
34
|
-
fig.savefig(name)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def plot_err(x, y, dpi, label, name):
|
|
38
|
-
fig, ax = plt.subplots(dpi=dpi)
|
|
39
|
-
ax.scatter(x, y, label=label)
|
|
40
|
-
line = np.linspace(np.amax(x), np.amin(x), 1000)
|
|
41
|
-
ax.plot(line, line)
|
|
42
|
-
ax.legend()
|
|
43
|
-
fig.savefig(name)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def main():
|
|
47
|
-
args = parse_argument()
|
|
48
|
-
if args.label == None:
|
|
49
|
-
args.label = args.input_file_name
|
|
50
|
-
data = np.loadtxt(args.input_file_name)
|
|
51
|
-
if args.err:
|
|
52
|
-
plot_err(data[:, 0], data[:, 1], dpi=args.dpi, label=args.label, name=args.o)
|
|
53
|
-
else:
|
|
54
|
-
plot_data(data[:, 0], data[:, 1], dpi=args.dpi, label=args.label, name=args.o)
|
|
55
|
-
|
|
56
|
-
print(os.path.abspath(args.o))
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if __name__ == '__main__':
|
|
60
|
-
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/mdkits-0.1a4/src/mdkits/cli/,hb_distribution.py → /mdkits-0.1.1/src/mdkits/cli/hb_distribution.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|