mdkits 0.1.29__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of mdkits might be problematic. Click here for more details.

@@ -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
-
mdkits/cli/hb.py DELETED
@@ -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()