mdkits 0.1.30__tar.gz → 0.2.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.

Files changed (52) hide show
  1. {mdkits-0.1.30 → mdkits-0.2.1}/PKG-INFO +1 -1
  2. {mdkits-0.1.30 → mdkits-0.2.1}/pyproject.toml +1 -1
  3. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/cli/extract.py +27 -16
  4. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/density.py +9 -3
  5. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/hb_distribution.py +1 -1
  6. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/md_cli.py +2 -0
  7. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/rdf.py +17 -3
  8. mdkits-0.2.1/src/mdkits/md_cli/vac.py +67 -0
  9. mdkits-0.1.30/src/mdkits/cli/,hb_distribution_down.py +0 -114
  10. mdkits-0.1.30/src/mdkits/cli/hartree_potential.py +0 -59
  11. mdkits-0.1.30/src/mdkits/cli/hartree_potential_ave.py +0 -84
  12. mdkits-0.1.30/src/mdkits/cli/hb.py +0 -101
  13. mdkits-0.1.30/src/mdkits/cli/packmol_input.py +0 -76
  14. {mdkits-0.1.30 → mdkits-0.2.1}/LICENSE +0 -0
  15. {mdkits-0.1.30 → mdkits-0.2.1}/README.md +0 -0
  16. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/__init__.py +0 -0
  17. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/__init__.py +0 -0
  18. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/adsorbate.py +0 -0
  19. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/build_bulk.py +0 -0
  20. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/build_cli.py +0 -0
  21. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/build_interface.py +0 -0
  22. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/build_solution.py +0 -0
  23. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/build_surface.py +0 -0
  24. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/cut_surface.py +0 -0
  25. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/supercell.py +0 -0
  26. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/build_cli/water.xyz +0 -0
  27. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/cli/convert.py +0 -0
  28. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/cli/data.py +0 -0
  29. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/cli/plot.py +0 -0
  30. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/config/__init__.py +0 -0
  31. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/config/settings.yml +0 -0
  32. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/dft_cli/cube.py +0 -0
  33. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/dft_cli/dft_cli.py +0 -0
  34. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/dft_cli/pdos.py +0 -0
  35. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/angle.py +0 -0
  36. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/dipole.py +0 -0
  37. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/monitor.py +0 -0
  38. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/msd.py +0 -0
  39. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/setting.py +0 -0
  40. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/md_cli/wrap.py +0 -0
  41. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/mdkits.py +0 -0
  42. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/.fig_operation.py.swp +0 -0
  43. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/__init__.py +0 -0
  44. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/arg_type.py +0 -0
  45. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/cp2k_input_parsing.py +0 -0
  46. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/encapsulated_ase.py +0 -0
  47. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/encapsulated_mda.py +0 -0
  48. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/fig_operation.py +0 -0
  49. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/numpy_geo.py +0 -0
  50. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/os_operation.py +0 -0
  51. {mdkits-0.1.30 → mdkits-0.2.1}/src/mdkits/util/out_err.py +0 -0
  52. {mdkits-0.1.30 → mdkits-0.2.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.1.30
3
+ Version: 0.2.1
4
4
  Summary: kits for md or dft
5
5
  License: MIT
6
6
  Keywords: molecular dynamics,density functional theory
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mdkits"
3
- version = "0.1.30"
3
+ version = "0.2.1"
4
4
  description = "kits for md or dft"
5
5
  readme = "README.md"
6
6
  authors = ["jxxcr <jixxcr@qq.com>"]
@@ -9,11 +9,12 @@ import MDAnalysis
9
9
  from MDAnalysis import Universe
10
10
 
11
11
 
12
- def write_to_xyz(u, frames, o, cut=None):
13
- with MDAnalysis.Writer(o, u.atoms.n_atoms, format='XYZ') as w:
12
+ def write_to_xyz(u, frames, o, select, cut=None):
13
+ ag = u.select_atoms(select)
14
+ with MDAnalysis.Writer(o, ag.atoms.n_atoms, format='XYZ') as w:
14
15
  for ts in u.trajectory:
15
16
  if ts.frame in frames:
16
- w.write(u)
17
+ w.write(ag)
17
18
  if cut:
18
19
  with open(o, 'r') as fi, open(o+'t', 'w') as fo:
19
20
  for i, line in enumerate(fi):
@@ -22,13 +23,18 @@ def write_to_xyz(u, frames, o, cut=None):
22
23
  os.replace(o+'t', o)
23
24
 
24
25
 
25
- def write_to_xyz_s(u, frames, cut=None):
26
+ def write_to_xyz_s(u, frames, select, cut=None):
26
27
  index = 0
28
+ ag = u.select_atoms(select)
29
+ if select:
30
+ dir = f'./coord/{"_".join(select.split())}'
31
+ else:
32
+ dir = './coord/all'
27
33
  for ts in u.trajectory:
28
34
  if ts.frame in frames:
29
- o = f'./coord/coord_{index:03d}'
30
- with MDAnalysis.Writer(o, u.atoms.n_atoms, format='XYZ') as w:
31
- w.write(u)
35
+ o = f'{dir}/coord_{index:03d}'
36
+ with MDAnalysis.Writer(o, ag.atoms.n_atoms, format='XYZ') as w:
37
+ w.write(ag)
32
38
  index += 1
33
39
  if cut:
34
40
  with open(o, 'r') as fi, open(o+'t', 'w') as fo:
@@ -39,10 +45,10 @@ def write_to_xyz_s(u, frames, cut=None):
39
45
 
40
46
  @click.command(name='extract')
41
47
  @click.argument('input_file_name', type=click.Path(exists=True), default=os_operation.default_file_name('*-pos-1.xyz', last=True))
42
- @click.option('-o', type=str, help='output file name', default='extracted.xyz', show_default=True)
43
48
  @click.option('-r', type=arg_type.FrameRange, help='frame range to slice', default='-1', show_default=True)
44
49
  @click.option('-c', help='output a coord.xyz', is_flag=True)
45
- def main(input_file_name, o, r, c):
50
+ @click.option("--select", type=str, help="select atoms to extract")
51
+ def main(input_file_name, r, c, select):
46
52
  """
47
53
  extract frames in trajectory file
48
54
  """
@@ -63,16 +69,21 @@ def main(input_file_name, o, r, c):
63
69
  cut = None
64
70
 
65
71
  if len(r) == 3 and r[-1] is not None:
66
- if not os.path.exists('./coord'):
67
- os.makedirs('./coord')
72
+ if select:
73
+ dir = f'./coord/{"_".join(select.split())}'
74
+ else:
75
+ dir = './coord/all'
76
+ if not os.path.exists(dir):
77
+ os.makedirs(dir)
68
78
  else:
69
79
  import shutil
70
- shutil.rmtree('./coord')
71
- os.makedirs('./coord')
72
- write_to_xyz_s(u, frames, cut=cut)
73
- click.echo(os.path.abspath('./coord'))
80
+ shutil.rmtree(dir)
81
+ os.makedirs(dir)
82
+ write_to_xyz_s(u, frames, select, cut=cut)
83
+ click.echo(os.path.abspath(dir))
74
84
  else:
75
- write_to_xyz(u, frames, o, cut=cut)
85
+ o = f"{os.path.basename(u.filename).split('.')[0]}_{'_'.join([str(i) for i in r])}_{'_'.join(select.split()) if select else 'all'}.xyz"
86
+ write_to_xyz(u, frames, o, select, cut=cut)
76
87
  click.echo(os.path.abspath(o))
77
88
 
78
89
 
@@ -118,14 +118,20 @@ class Density_distribution(AnalysisBase):
118
118
  @click.option('--group', type=str, help='group to analysis')
119
119
  @click.option('--atomic_mass', type=float, help='output density unit (g/cm3), should give atomic mass of element, else is concentration unit (mol/L)')
120
120
  @click.option('-o', type=str, help='output file name', default='density_{element}.dat', show_default=True)
121
- def main(filename, cell, o, element, atomic_mass, update_water, distance, angle, surface):
121
+ def main(filename, cell, o, group, atomic_mass, update_water, distance, angle, surface, r):
122
122
  """
123
123
  analysis density or concentration of element in a trajectory file
124
124
  """
125
125
 
126
- 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)
126
+ density_dist = Density_distribution(filename, cell, o=o, distance_judg=distance, angle_judg=angle, element=group, atomic_mass=atomic_mass, update_water=update_water, surface=surface)
127
127
 
128
- density_dist.run()
128
+ if r is not None:
129
+ if len(r) == 2:
130
+ density_dist.run(start=r[0], stop=r[1])
131
+ elif len(r) == 3:
132
+ density_dist.run(start=r[0], stop=r[1], step=r[2])
133
+ else:
134
+ density_dist.run()
129
135
 
130
136
 
131
137
  if __name__ == '__main__':
@@ -5,7 +5,7 @@ import click
5
5
  import MDAnalysis
6
6
  from MDAnalysis import Universe
7
7
  from MDAnalysis.analysis.base import AnalysisBase
8
- from mdkits.util import arg_type, os_operation, numpy_geo, encapsulated_mda
8
+ from mdkits.util import numpy_geo, encapsulated_mda
9
9
  import warnings, sys
10
10
  from .setting import common_setting
11
11
  warnings.filterwarnings("ignore")
@@ -5,6 +5,7 @@ from mdkits.md_cli import (
5
5
  angle,
6
6
  density,
7
7
  hb_distribution,
8
+ vac,
8
9
  rdf,
9
10
  msd,
10
11
  monitor,
@@ -21,6 +22,7 @@ cli.add_command(density.main)
21
22
  cli.add_command(dipole.main)
22
23
  cli.add_command(angle.main)
23
24
  cli.add_command(hb_distribution.main)
25
+ cli.add_command(vac.main)
24
26
  cli.add_command(rdf.main)
25
27
  cli.add_command(msd.main)
26
28
  cli.add_command(monitor.main)
@@ -2,9 +2,20 @@ import MDAnalysis as mda
2
2
  from MDAnalysis.analysis import rdf
3
3
  import numpy as np
4
4
  import click
5
+ from scipy import integrate
5
6
  from mdkits.util import arg_type
6
7
 
7
8
 
9
+ def calculate_Gab(r_values, gab_values):
10
+ dr = r_values[1] - r_values[0]
11
+
12
+ integrand = 4 * np.pi * r_values**2 * gab_values
13
+
14
+ G_ab = np.cumsum(integrand) * dr
15
+
16
+ return G_ab
17
+
18
+
8
19
  @click.command(name="rdf")
9
20
  @click.argument("filename", type=click.Path(exists=True))
10
21
  @click.option('--cell', type=arg_type.Cell, help='set cell, a list of lattice, --cell x,y,z or x,y,z,a,b,c')
@@ -18,10 +29,13 @@ def main(filename, cell, group, range, r):
18
29
  u.dimensions = cell
19
30
  o = f"rdf_{'_'.join(group).replace(' ', '_')}.dat"
20
31
 
32
+ rho = 32/(9.86**3)
33
+
21
34
  group1 = u.select_atoms(group[0])
22
35
  group2 = u.select_atoms(group[1])
23
36
 
24
- crdf = rdf.InterRDF(group1, group2, verbose=True, range=(range[0], range[1]), norm='density')
37
+ crdf = rdf.InterRDF(group1, group2, verbose=True, range=(range[0], range[1]), norm='rdf')
38
+
25
39
 
26
40
  if r is not None:
27
41
  if len(r) == 2:
@@ -31,8 +45,8 @@ def main(filename, cell, group, range, r):
31
45
  else:
32
46
  crdf.run()
33
47
 
34
- combin = np.column_stack((crdf.results.bins, crdf.results.rdf))
35
- np.savetxt(o, combin, header="A\tgr", fmt="%.5f", delimiter='\t')
48
+ combin = np.column_stack((crdf.results.bins, crdf.results.rdf, calculate_Gab(crdf.results.bins, crdf.results.rdf)*rho))
49
+ np.savetxt(o, combin, header="A\tgr\tNr", fmt="%.5f", delimiter='\t')
36
50
 
37
51
 
38
52
  if __name__ == "__main__":
@@ -0,0 +1,67 @@
1
+ import numpy as np
2
+ import click
3
+ import MDAnalysis
4
+ from MDAnalysis import Universe
5
+ from MDAnalysis.analysis.base import AnalysisBase
6
+ from mdkits.util import os_operation, arg_type
7
+
8
+
9
+ class Velocity_AutoCorrelation(AnalysisBase):
10
+ def __init__(self, filename, select, dt=0.001):
11
+ u = Universe(filename)
12
+ u.trajectory.ts.dt = dt
13
+ self.u = u
14
+ self.atomgroup = u.select_atoms(select)
15
+
16
+ super(Velocity_AutoCorrelation, self).__init__(self.atomgroup.universe.trajectory, verbose=True)
17
+
18
+ def _prepare(self):
19
+ self.cvv = []
20
+ self.v0 = self.atomgroup.positions
21
+ self.normalize = 1/np.sum(self.v0*self.v0)
22
+ self.cvv.append(np.sum(self.v0*self.v0)*self.normalize)
23
+
24
+
25
+ def _append(self, cvv):
26
+ self.cvv.append(cvv*self.normalize)
27
+
28
+ def _single_frame(self):
29
+ cvv = np.sum(self.atomgroup.positions*self.v0)
30
+ self._append(cvv)
31
+
32
+ def _conclude(self):
33
+ self.cvv = np.array(self.cvv)
34
+
35
+ sf = self.cvv.shape[0]
36
+ f = np.abs(np.fft.fft(self.cvv))
37
+
38
+ faxis = np.fft.fftfreq(sf, d=1/sf)
39
+ pf = np.where(faxis>0)
40
+ faxis = faxis[pf]
41
+ f = f[pf]
42
+
43
+ combine = np.column_stack((np.arange(len(self.cvv)), self.cvv))
44
+
45
+ np.savetxt('vac.dat', combine, fmt='%.5f', header="frame\tvac")
46
+ np.savetxt('f.dat', np.column_stack((faxis, f)), fmt='%.5f')
47
+
48
+
49
+ @click.command(name="vac")
50
+ @click.argument("filename", type=click.Path(exists=True), default=os_operation.default_file_name('*-vel-1.xyz', last=True))
51
+ @click.option("--select", type=str, default="all", help="atom selection", show_default=True)
52
+ @click.option('-r', type=arg_type.FrameRange, help='range of frame to analysis')
53
+ def main(filename, select, r):
54
+ """analysis velocity autocorrelation function"""
55
+ a = Velocity_AutoCorrelation(filename, select)
56
+
57
+ if r is not None:
58
+ if len(r) == 2:
59
+ a.run(start=r[0], stop=r[1])
60
+ elif len(r) == 3:
61
+ a.run(start=r[0], stop=r[1], step=r[2])
62
+ else:
63
+ a.run()
64
+
65
+
66
+ if __name__ == '__main__':
67
+ main()
@@ -1,114 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- import numpy as np
4
- import argparse
5
- import MDAnalysis
6
- from MDAnalysis import Universe
7
- from MDAnalysis.analysis.base import AnalysisBase
8
- from util import cp2k_input_parsing
9
- import warnings
10
- warnings.filterwarnings("ignore")
11
-
12
-
13
- class Hb_distribution(AnalysisBase):
14
- def __init__(self, filename, cell, surface, dt=0.001, hb_distance=3.5, hb_angle=35, bin_size=0.2):
15
- u = Universe(filename)
16
- u.trajectory.ts.dt = dt
17
- u.dimensions = cell
18
- self.u = u
19
- self.atomgroup = u.select_atoms("all")
20
- self.hb_distance = hb_distance
21
- self.hb_angle = hb_angle
22
- self.bin_size = bin_size
23
- self.surface = surface
24
- self.frame_count = 0
25
- super(Hb_distribution, self).__init__(self.atomgroup.universe.trajectory, verbose=True)
26
-
27
- def _prepare(self):
28
- bin_num = int(self.u.dimensions[2] / self.bin_size) + 2
29
- self.donor = np.zeros(bin_num, dtype=np.float64)
30
-
31
- def _append(self, hb_d):
32
- bins_d = np.floor(hb_d / self.bin_size).astype(int) + 1
33
-
34
- bins_d = bins_d[bins_d < len(self.donor)]
35
-
36
- np.add.at(self.donor, bins_d, 1)
37
-
38
- self.frame_count += 1
39
-
40
- def _single_frame(self):
41
- o_group = self.atomgroup.select_atoms("name O")
42
- o_pair = MDAnalysis.lib.distances.capped_distance(o_group.positions, o_group.positions, min_cutoff=0, max_cutoff=self.hb_distance, box=self.u.dimensions, return_distances=False)
43
-
44
- o0 = o_group[o_pair[:, 0]]
45
- o1 = o_group[o_pair[:, 1]]
46
-
47
- o0h1 = self.atomgroup[o0.indices + 1]
48
- o0h2 = self.atomgroup[o0.indices + 2]
49
-
50
- angle_o0h1_o0_o1 = np.degrees(
51
- MDAnalysis.lib.distances.calc_angles(o0h1.positions, o0.positions, o1.positions, box=self.u.dimensions)
52
- )
53
- angle_o0h2_o0_o1 = np.degrees(
54
- MDAnalysis.lib.distances.calc_angles(o0h2.positions, o0.positions, o1.positions, box=self.u.dimensions)
55
- )
56
-
57
- mid_z = (self.surface[0] + self.surface[1]) / 2
58
-
59
- condition_d = ((angle_o0h1_o0_o1 < self.hb_angle) | (angle_o0h2_o0_o1 < self.hb_angle)) & (o0.positions[:, 2] - o1.positions[:, 2] > 0)
60
- #condition_d = ((angle_o0h1_o0_o1 < self.hb_angle) | (angle_o0h2_o0_o1 < self.hb_angle)) & (((o0.positions[:, 2] < mid_z) & (o0.positions[:, 2] - o1.positions[:, 2] > 0)) | ((o0.positions[:, 2] > mid_z) & (o0.positions[:, 2] - o1.positions[:, 2] < 0)))
61
- #condition_a = ((angle_o1h1_o1_o0 < self.hb_angle) | (angle_o1h2_o1_o0 < self.hb_angle)) & (((o1.positions[:, 2] < mid_z) & (o1.positions[:, 2] - o0.positions[:, 2] > 1.5)) | ((o1.positions[:, 2] > mid_z) & (o1.positions[:, 2] - o0.positions[:, 2] < -1.5)))
62
-
63
- hb_d = (o0.positions[:, 2][condition_d] + o1.positions[:, 2][condition_d]) / 2
64
- #hb_a = (o0.positions[:, 2][condition_a] + o1.positions[:, 2][condition_a]) / 2
65
-
66
- self._append(hb_d)
67
-
68
- def _conclude(self):
69
- if self.frame_count > 0:
70
- average_donor = self.donor / self.frame_count
71
-
72
- bins_z = np.arange(len(self.donor)) * self.bin_size
73
-
74
- lower_z, upper_z = self.surface
75
- mask = (bins_z >= lower_z) & (bins_z <= upper_z)
76
- filtered_bins_z = bins_z[mask] - lower_z
77
- filtered_average_donor = average_donor[mask]
78
-
79
- combined_data = np.column_stack((filtered_bins_z, filtered_average_donor))
80
-
81
- filename = 'hb_distribution_down.dat'
82
- np.savetxt(filename, combined_data, header="Z\tDonor", fmt='%.5f', delimiter='\t')
83
-
84
-
85
- def parse_data(s):
86
- return [float(x) for x in s.replace(',', ' ').split()]
87
-
88
-
89
- def parse_r(s):
90
- return [int(x) for x in s.replace(':', ' ').split()]
91
-
92
-
93
- def parse_argument():
94
- parser = argparse.ArgumentParser(description="analysis hb distribution")
95
- parser.add_argument('filename', type=str, help='filename to analysis')
96
- parser.add_argument('--cp2k_input_file', type=str, help='input file name of cp2k, default is "input.inp"', default='input.inp')
97
- parser.add_argument('-r', type=parse_r, help='range of analysis', default=[0, -1, 1])
98
- parser.add_argument('--cell', type=parse_data, help='set cell, a list of lattice, --cell x,y,z or x,y,z,a,b,c')
99
- parser.add_argument('--surface', type=parse_data, help='[down_surface_z, up_surface_z]')
100
- parser.add_argument('--hb_param', type=parse_data, help='[hb_distance, hb_angle], default is [3.5, 35]', default=[3.5, 35])
101
-
102
- return parser.parse_args()
103
-
104
-
105
- def main():
106
- args = parse_argument()
107
- cell = cp2k_input_parsing.get_cell(args.cp2k_input_file, args.cell)
108
-
109
- hb_dist = Hb_distribution(args.filename, cell, args.surface, hb_distance=args.hb_param[0], hb_angle=args.hb_param[1])
110
- hb_dist.run(start=args.r[0], stop=args.r[1], step=args.r[2])
111
-
112
-
113
- if __name__ == '__main__':
114
- main()
@@ -1,59 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- ################################################
4
- # averange cp2k output(or some else file correspond to ase.io.read_cube_data) hartree.cube to z coordinate with python
5
- ## file path is need to pay attention
6
- ## cycle parameter is need to pay attention
7
- ## buck range is need to pay attention
8
- ################################################
9
-
10
- from numpy import empty, array, mean, append, concatenate
11
- from argparse import ArgumentParser
12
- from util import encapsulated_ase, os_operation
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 buck_potential(xaxe, potential, range):
22
- mix = concatenate((xaxe.reshape(-1, 1), potential.reshape(-1, 1)), axis=1)
23
- mask = (mix[:,0] >= range[0]) & (mix[:,0] <=range[1])
24
- buck_potential = mix[mask]
25
- ave_potential = mean(buck_potential[:,1])
26
- return ave_potential
27
-
28
-
29
- # set argument
30
- parser = ArgumentParser(description='to handle cp2k output file hartree cube, name should be "hartree-*.cube"')
31
- parser.add_argument('file_name', type=str, nargs='?', help='hartree cube file', default=os_operation.default_file_name('*-v_hartree-1_*.cube', last=True))
32
- parser.add_argument('-b', '--buck_range', type=array_type, help='parameter to calculate mean value of buck', default=None)
33
- parser.add_argument('-o', type=str, help='output file name, default is "out.put"', default='hartree.out')
34
-
35
- args = parser.parse_args()
36
-
37
-
38
- ## init output potential file's shape, and define a z axe
39
- init_array = encapsulated_ase.ave_potential(args.file_name)
40
- potential = empty((0, init_array[0].shape[0]))
41
- z_coordinates = array((init_array[1])).reshape(-1, 1)
42
-
43
- potential = encapsulated_ase.ave_potential(args.file_name)[0]
44
-
45
- aved = mean(potential, axis=0)
46
- total_potential = append(z_coordinates, potential.reshape(-1, 1), axis=1)
47
-
48
- ## if buck range is exit, out put a difference of potential
49
- if args.buck_range is not None:
50
- buck_potential = buck_potential(z_coordinates, potential, args.buck_range)
51
- print(buck_potential)
52
- with open('hartree_potential.dat', 'w') as f:
53
- f.write(f"{buck_potential}" + '\n')
54
-
55
- ## write output
56
- with open(args.o, 'w') as f:
57
- for value in total_potential:
58
- f.write(" ".join(map(str, value)) + '\n')
59
-
@@ -1,84 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- ################################################
4
- # averange cp2k output(or some else file correspond to ase.io.read_cube_data) hartree.cube to z coordinate with python
5
- ## file path is need to pay attention
6
- ## cycle parameter is need to pay attention
7
- ## buck range is need to pay attention
8
- ################################################
9
-
10
- from ase.io.cube import read_cube_data
11
- import numpy as np
12
- import argparse
13
-
14
- def array_type(string):
15
- number_list = string.split(',')
16
- number_array = np.array(number_list, dtype=int)
17
- return number_array
18
-
19
-
20
- def ave_potential(filepath):
21
- # is to average hartree file in z_coordinate
22
-
23
- ## read data from filepath
24
- data, atoms = read_cube_data(filepath)
25
-
26
- ## define need parameter
27
- npoints = data.shape[2]
28
- step_size = atoms.cell[2, 2] / ( npoints - 1 )
29
-
30
- ## average hartree file, and calculate z_coordinates
31
- z_coordinates = [i * step_size for i in range(npoints)]
32
- z_potential = 27.2114 * data[:, :, :].sum(axis=(0, 1)) / ( data.shape[0] * data.shape[1] )
33
- return z_potential, z_coordinates
34
-
35
-
36
- def buck_potential(xaxe, potential, range):
37
- mix = np.concatenate((xaxe.reshape(-1, 1), potential.reshape(-1, 1)), axis=1)
38
- mask = (mix[:,0] >= range[0]) & (mix[:,0] <=range[1])
39
- buck_potential = mix[mask]
40
- ave_potential = np.mean(buck_potential[:,1])
41
- return ave_potential
42
-
43
-
44
- # set argument
45
- parser = argparse.ArgumentParser(description='to handle cp2k output file hartree cube, name should be "hartree-*.cube"')
46
- parser.add_argument('folder_path', type=str, help='folder that contain all hartree cube file')
47
- parser.add_argument('cyc_range', type=array_type, help='cycle parameter, need to seperate with ",", similar with range() -- 1,201 1,201,10')
48
- parser.add_argument('-b', '--buck_range', type=array_type, help='parameter to calculate mean value of buck', default=None)
49
- parser.add_argument('-o', type=str, help='output file name, default is "out.put"', default='hartree.out')
50
-
51
- args = parser.parse_args()
52
-
53
-
54
- ## init output potential file's shape, and define a z axe
55
- init_array = ave_potential('{}/hartree-{}.cube'.format(args.folder_path, args.cyc_range[0]))
56
- potential = np.empty((0, init_array[0].shape[0]))
57
- z_coordinates = np.array((init_array[1])).reshape(-1, 1)
58
-
59
- ## average one hartree file
60
- if len(args.cyc_range) == 3:
61
- for i in range(args.cyc_range[0], args.cyc_range[1], args.cyc_range[2]):
62
- file_path = '{}/hartree-{}.cube'.format(args.folder_path, i)
63
- potential = np.append(potential, [ave_potential(file_path)[0]], axis=0)
64
- else:
65
- for i in range(args.cyc_range[0], args.cyc_range[1]):
66
- file_path = '{}/hartree-{}.cube'.format(args.folder_path, i)
67
- potential = np.append(potential, [ave_potential(file_path)[0]], axis=0)
68
-
69
- ## average every averaged harterr file, and append to z_coordinates
70
- #aved_potential = potential[:, :].sum(axis=0) / len(range(1, 201))
71
- aved = np.mean(potential, axis=0)
72
- total_potential = np.append(z_coordinates, aved.reshape(-1, 1), axis=1)
73
-
74
- ## if buck range is exit, out put a difference of potential
75
- if args.buck_range is not None:
76
- buck_potential = buck_potential(z_coordinates, aved, args.buck_range)
77
- with open(args.o + 'diff', 'w') as f:
78
- f.write("{}\t{}\t{}".format(aved[0], buck_potential, aved[0]-buck_potential))
79
-
80
- ## write output
81
- with open(args.o, 'w') as f:
82
- for value in total_potential:
83
- f.write(" ".join(map(str, value)) + '\n')
84
-
@@ -1,101 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- import argparse, multiprocessing, os
4
- import numpy as np
5
- from util import (
6
- structure_parsing,
7
- numpy_geo,
8
- os_operation,
9
- cp2k_input_parsing,
10
- )
11
-
12
-
13
- def hb_count(chunk, index, cell, filename, hb_distance=3.5, hb_angle=35):
14
- groups = structure_parsing.chunk_to_groups(chunk)
15
- groups_hb_list = []
16
- coefficients = numpy_geo.cell_to_wrap_coefficients(cell)
17
- for group in groups:
18
- group_hb_array = np.zeros((3, 1))
19
- present_index = index
20
- o_present = group[present_index].split()
21
- if o_present[0] == 'O':
22
- o_present = np.array(o_present[1:], dtype=np.float64)
23
- group_hb_array[2, 0] += 1
24
- for other_index in range(2, len(group)):
25
- o_other = group[other_index].split()
26
- if o_other[0] == 'O':
27
- o_other = np.array(o_other[1:], dtype=np.float64)
28
- oo_distance, o_other = numpy_geo.unwrap(o_present, o_other, coefficients, max=0)
29
- if oo_distance < hb_distance and oo_distance > 1:
30
- _, o_present_h1 = numpy_geo.unwrap(o_present, np.array(group[present_index+1].split()[1:], dtype=np.float64), coefficients)
31
- _, o_present_h2 = numpy_geo.unwrap(o_present, np.array(group[present_index+2].split()[1:], dtype=np.float64), coefficients)
32
- _, o_other_h1 = numpy_geo.unwrap(o_other, np.array(group[other_index+1].split()[1:], dtype=np.float64), coefficients)
33
- _, o_other_h2 = numpy_geo.unwrap(o_other, np.array(group[other_index+2].split()[1:], dtype=np.float64), coefficients)
34
-
35
- o_present_o_other_h1_angle = numpy_geo.vector_vector_angle(o_present-o_other, o_other_h1-o_other)
36
- o_present_o_other_h2_angle = numpy_geo.vector_vector_angle(o_present-o_other, o_other_h2-o_other)
37
- if o_present_o_other_h1_angle < hb_angle or o_present_o_other_h2_angle < hb_angle:
38
- group_hb_array[0, 0] += 1
39
- o_other_o_present_h1_angle = numpy_geo.vector_vector_angle(o_other-o_present, o_present_h1-o_present)
40
- o_other_o_present_h2_angle = numpy_geo.vector_vector_angle(o_other-o_present, o_present_h2-o_present)
41
- if o_other_o_present_h1_angle < hb_angle or o_other_o_present_h2_angle < hb_angle:
42
- group_hb_array[1, 0] += 1
43
- groups_hb_list.append(group_hb_array)
44
- groups_hb_array = np.vstack(groups_hb_list)
45
- group_hb_acc_array = np.sum(groups_hb_array[0::3], axis=0).reshape(1, -1)
46
- group_hb_don_array = np.sum(groups_hb_array[1::3], axis=0).reshape(1, -1)
47
- group_hb_num_array = np.sum(groups_hb_array[2::3], axis=0).reshape(1, -1)
48
- group_hb_array = np.vstack([group_hb_acc_array, group_hb_don_array, group_hb_num_array])
49
- np.save(filename, group_hb_array)
50
-
51
-
52
- def parse_data(s):
53
- return [float(x) for x in s.replace(',', ' ').split()]
54
-
55
- def parse_argument():
56
- parser = argparse.ArgumentParser(description="analysis an O atom's hydrogen bond in water")
57
- parser.add_argument('index', type=int, help='index of target atom in coord.xyz, or all of hb distribution on z')
58
- parser.add_argument('input_file_name', type=str, nargs='?', help='input file name', default=os_operation.default_file_name('wraped.xyz', last=True))
59
- parser.add_argument('--cp2k_input_file', type=str, help='input file name of cp2k, default is "input.inp"', default='input.inp')
60
- parser.add_argument('--cell', type=parse_data, help='set cell, a list of lattice, --cell x,y,z or x,y,z,a,b,c')
61
- parser.add_argument('--hb_param', type=parse_data, help='[hb_distance, hb_angle], default is [3.5, 35]', default=[3.5, 35])
62
- parser.add_argument('--process', type=int, help='paralle process number default is 28', default=28)
63
- parser.add_argument('--temp', help='keep temp file', action='store_false')
64
-
65
- return parser.parse_args()
66
-
67
- def main():
68
- args = parse_argument()
69
- output = f'./hb_{args.index}.dat'
70
- cell = cp2k_input_parsing.get_cell(args.cp2k_input_file, args.cell)
71
- chunks = structure_parsing.xyz_to_chunks(args.input_file_name, args.process)
72
- temp_dir = f'{os.environ.get("TEMP_DIR")}/{os.getpid()}'
73
- os_operation.make_temp_dir(temp_dir, delete=args.temp)
74
-
75
- for index, chunk in enumerate(chunks):
76
- t = multiprocessing.Process(target=hb_count, args=[chunk, args.index, cell, f'{temp_dir}/chunk_{index}.temp'])
77
- t.start()
78
-
79
- for t in multiprocessing.active_children():
80
- t.join()
81
-
82
- chunks_array_list = []
83
- for i in range(len(chunks)):
84
- chunk_array = np.load(f'{temp_dir}/chunk_{i}.temp.npy')
85
- chunks_array_list.append(chunk_array)
86
- chunks_array = np.vstack(chunks_array_list)
87
- chunks_array = np.mean(chunks_array, axis=1)
88
-
89
- with open(output, 'w') as f:
90
- f.write(f"# {args.index}\n")
91
- f.write(f"accepter : {chunks_array[0]:.2f}\n")
92
- f.write(f"donor : {chunks_array[1]:.2f}\n")
93
- f.write(f"total : {chunks_array[0]+chunks_array[1]:.2f}\n")
94
- print(f"# {args.index}")
95
- print(f"accepter : {chunks_array[0]:.2f}")
96
- print(f"donor : {chunks_array[1]:.2f}")
97
- print(f"total : {chunks_array[0]+chunks_array[1]:.2f}")
98
-
99
-
100
- if __name__ == '__main__':
101
- main()
@@ -1,76 +0,0 @@
1
- import argparse
2
-
3
-
4
- def parse_cell(s):
5
- return [float(x) for x in s.replace(',', ' ').split()]
6
-
7
-
8
- def parse_argument():
9
- parser = argparse.ArgumentParser(description='generate packmol input file with give parameter')
10
- parser.add_argument('--size', type=int, help='water size default is 30', default=30)
11
- parser.add_argument('--cell', type=parse_cell, help='input box size(a,b,c)')
12
- parser.add_argument('--addwat', type=int, help='add some additional water, default is 0', default=0)
13
- parser.add_argument('--ioncon', type=float, help='concentration of sol box, default is 0.0', default=0.0)
14
- parser.add_argument('--tolerance', type=float, help='tolerance of packmol, default is 2.5', default=2.5)
15
- parser.add_argument('--watpath', type=str, help='water xyz file path', default='C:\\home\\.can\\temp\\packmol\\default\\water.xyz')
16
- parser.add_argument('--ionpath', type=str, help='ion xyz file path')
17
- parser.add_argument('-o', type=str, help='output file name, default is "input.pm"', default='input.pm')
18
- parser.add_argument('--output', type=str, help='output file name of packmol, default is "solbox.xyz"', default='solbox.xyz')
19
-
20
- return parser.parse_args()
21
-
22
-
23
- def get_water_number():
24
- water_number = water_volume / water_size
25
-
26
- return int(round(water_number, 0))
27
-
28
-
29
- def get_ion_number(concentration):
30
- ion_number = ( (concentration * avogadro) / 1e+27 ) * water_volume
31
-
32
- return int(round(ion_number, 0))
33
-
34
-
35
- def main():
36
- global water_volume, water_size, avogadro
37
- args = parse_argument()
38
- water_volume = args.cell[0] * args.cell[1] * args.cell[2]
39
- water_size = args.size
40
- avogadro = 6.02214179e+23
41
- water_number = get_water_number() + args.addwat
42
- ion_number = get_ion_number(args.ioncon)
43
-
44
- if ion_number == 0:
45
- packmol_input_str = f"""
46
- tolerance {args.tolerance}
47
- filetype xyz
48
- output {args.output}
49
- pbc {args.cell[3]} {args.cell[4]} {args.cell[5]}
50
- structure {args.watpath}
51
- number {water_number}
52
- inside box 2. 2. 2. {args.cell[0]-2} {args.cell[1]-2} {args.cell[2]-2}
53
- end structure
54
- """
55
- else:
56
- packmol_input_str = f"""
57
- tolerance {args.tolerance}
58
- filetype xyz
59
- output {args.output}
60
- pbc {args.cell[3]} {args.cell[4]} {args.cell[5]}
61
- structure {args.watpath}
62
- number {water_number}
63
- inside box 2. 2. 2. {args.cell[0]-2} {args.cell[1]-2} {args.cell[2]-2}
64
- end structure
65
- structure {args.ionpath}
66
- number {ion_number}
67
- inside box 2. 2. 2. {args.cell[0]-2} {args.cell[1]-2} {args.cell[2]-2}
68
- end structure
69
- """
70
-
71
- with open(args.o, 'w') as f:
72
- f.write(packmol_input_str)
73
-
74
-
75
- if __name__ == '__main__':
76
- main()
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes