-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathxyztopsi4.py
More file actions
181 lines (146 loc) · 5.48 KB
/
xyztopsi4.py
File metadata and controls
181 lines (146 loc) · 5.48 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import numpy as np
mw_elements = {'H': 1.00794, 'He': 4.002602, 'Li': 6.941,
'Be': 9.012182, 'B': 10.811, 'C': 12.0107,
'N': 14.0067,'O': 15.9994,'F': 18.9984032,
'Ne': 20.1797,'Na': 22.98976928,'Mg': 24.305,
'Al': 26.9815386,'Si': 28.0855,'P': 30.973762,
'S': 32.065,'Cl': 35.453,'Ar': 39.948,
'K': 39.0983,'Ca': 40.078,'Sc': 44.955912,
'Ti': 47.867,'V': 50.9415, 'Cr': 51.9961,
'Mn': 54.938045,'Fe': 55.845,'Co': 58.933195,
'Ni': 58.6934,'Cu': 63.546,'Zn': 65.409,
'Ga': 69.723,'Ge': 72.64,'As': 74.9216,
'Se': 78.96,'Br': 79.904,'Kr': 83.798,
'Rb': 85.4678,'Sr': 87.62, 'Y': 88.90585,
'Zr': 91.224,'Nb': 92.90638,'Mo': 95.94,
'Tc': 98.9063,'Ru': 101.07,'Rh': 102.9055,
'Pd': 106.42,'Ag': 107.8682,'Cd': 112.411,
'In': 114.818,'Sn': 118.71,'Sb': 121.76,
'Te': 127.6,'I': 126.90447,'Xe': 131.293,
'Cs': 132.9054519,'Ba': 137.327,'La': 138.90547,
'Ce': 140.116,'Pr': 140.90465,'Nd': 144.242,
'Pm': 146.9151,'Sm': 150.36,'Eu': 151.964,
'Gd': 157.25,'Tb': 158.92535,'Dy': 162.5,
'Ho': 164.93032,'Er': 167.259,'Tm': 168.93421,
'Yb': 173.04,'Lu': 174.967,'Hf': 178.49,
'Ta': 180.9479,'W': 183.84,'Re': 186.207,
'Os': 190.23,'Ir': 192.217,'Pt': 195.084,
'Au': 196.966569,'Hg': 200.59,'Tl': 204.3833,
'Pb': 207.2,'Bi': 208.9804,'Po': 208.9824,
'At': 209.9871,'Rn': 222.0176,'Fr': 223.0197,
'Ra': 226.0254,'Ac': 227.0278,'Th': 232.03806,
'Pa': 231.03588,'U': 238.02891,'Np': 237.0482,
'Pu': 244.0642,'Am': 243.0614,'Cm': 247.0703,
'Bk': 247.0703,'Cf': 251.0796,'Es': 252.0829,
'Fm': 257.0951,'Md': 258.0951,'No': 259.1009,
'Lr': 262,'Rf': 267,'Db': 268,'Sg': 271,
'Bh': 270,'Hs': 269,'Mt': 278,'Ds': 281,
'Rg': 281,'Cn': 285,'Nh': 284,'Fl': 289,
'Mc': 289,'Lv': 292,'Ts': 294,'Og': 294,
'ZERO': 0}
class Tinkermol:
def __init__(self,filenm):
self.fn = filenm
self.n_atoms = 0
self.atom_map = []
self.masses = []
self.volume = []
self.xyz = []
self.frames = 0
self.pbc = False
self.extra = 1
self.get_xyz()
def read_arc_file(self):
f = open(self.fn)
data = f.readlines()
f.close()
raw_arc = [l.strip('\n') for l in data]
n_atoms = float(data[0].split()[0])
#
try:
lt = float(data[1].split()[1])
self.extra = 2
self.pbc = True
except:
self.pbc = False
self.extra = 1
self.n_atoms = n_atoms
lines_per_frame = (n_atoms+self.extra)
raw_np = np.array(raw_arc)
per_frame = np.reshape(raw_np,(int(raw_np.shape[0]/lines_per_frame), int(lines_per_frame)))
return per_frame
def get_xyz(self):
raw_np = self.read_arc_file()
n_atoms = float(raw_np[0][0].split()[0])
xyz_cords = []
box_lattice = []
for k,frm in enumerate(raw_np):
for line in frm[self.extra:]:
l2 = line.split()[2:5]
xyz_cords.append([float(a) for a in l2])
if k == 0:
self.atom_map.append(line.split()[1])
self.masses.append(mw_elements[line.split()[1]])
if self.pbc:
box_lattice.append([float(a) for a in frm[1].split()[0:3]])
self.atom_map = np.array(self.atom_map)
self.frames = raw_np.shape[0]
self.xyz = np.reshape(np.array(xyz_cords),(raw_np.shape[0],int(n_atoms),3))
if self.pbc:
self.volume = np.prod(np.array(box_lattice),axis=1)
### write psi4 input file
def writeinput(xyzfn,options={},sampleinput=None):
mol = Tinkermol(xyzfn)
## options dictionary
baseoptions = {
'memory': 1,
'threads': 1,
'dimer': 'False',
'units': 'angstron',
'basis': '6-311G(d,p)',
'scf_type': 'df',
'optimize': None,
'gradient': None,
'return_wfn': False,
'energy': 'mp2',
'bsse_type': 'cp',
}
if len(options.keys() == 0):
options = baseoptions
else:
for key in baseoptions.keys():
try:
options[key]
except:
options[key] = baseoptions[key]
#####
template = f"""memory {options['memory']}
set_num_threads({options['threads']})
molecule mol {{
0 1
"""
atomlist = mol.atom_map
coords = mol.xyz[0]
if options['dimer'] == 'homo':
split = int(mol.n_atoms/2)
elif options['dimer'] == 'mol-water':
split = int(mol.n_atoms - 3)
for k, atm in enumerate(atomlist):
line = f" {atm}{coords[k][0]:18.10f}{coords[k][1]:18.10f}{coords[k][2]:18.10f}\n"
if k == split:
line += '--\n'
template += line
template += f"""
no_com
no_reorient
units {options['units']}
}}\n"""
setopt = f"""
set {{
basis {options['basis']}
scf_type {options['scf_type']}
guess sad
}}
"""
template += setopt
return template