-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path_inpcrd.py
74 lines (59 loc) · 1.61 KB
/
_inpcrd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
def __get_line(data, iatom):
"""
Generate the string based on data[iatom] and data[iatom+1]
Parameters:
data : list (natom, 3), float
iatom: intger
"""
line = ""
x, y, z = data[iatom]
line += '%12.7f' % x
line += '%12.7f' % y
line += '%12.7f' % z
if iatom+1 < len(data):
x, y, z = data[iatom+1]
line += '%12.7f' % x
line += '%12.7f' % y
line += '%12.7f' % z
line += '\n'
return line
def print_inpcrd(fname, crd, vel=None, box=None, time=None):
"""
Save Amber Inpcrd format into fname
Parameters
----------
crd : list (natom, 3), float, coordinates
vel : list (natom, 3), float, velocities
box : list (3), float, box dimensions
time: float, time in picosecond
"""
fout = open(fname, 'w')
title = "default_name\n"
fout.write(title)
natom = len(crd)
if vel is None:
line_natom = '%5d' % natom + '\n'
else:
line_natom = '%5d' % natom + '%15.7f' % time + '\n'
fout.write(line_natom)
for ii in range(0, natom, 2):
line = __get_line(crd, ii)
fout.write(line)
if vel is not None:
for ii in range(0, natom, 2):
line = __get_line(vel, ii)
fout.write(line)
# Print Box Information
if box is not None:
angle = 90.0
line = ""
line += '%12.7f' % box[0]
line += '%12.7f' % box[1]
line += '%12.7f' % box[2]
line += '%12.7f' % angle
line += '%12.7f' % angle
line += '%12.7f' % angle
line += '\n'
fout.write(line)
fout.close()