-
Notifications
You must be signed in to change notification settings - Fork 0
/
efcalc.py
executable file
·159 lines (151 loc) · 6.42 KB
/
efcalc.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
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
#! /usr/bin/env python
import sys
import copy
import operator
import numpy as np
import readarc
import readkey
from analyze2 import analyze2 as analyze
def e_f(nsolatoms,optlist,epsilon,sigma,charge,n,x,y,z,atomtype,conv):
elist = np.zeros(n)
flist = np.zeros((n,len(optlist),3))
for i in xrange(n):
for j in xrange(nsolatoms):
for l in xrange(len(optlist)):
if j == optlist[l]:
optatomnum = l
break
else:
optatomnum = -1
for k in xrange(nsolatoms,len(x[i])):
ep1 = epsilon[atomtype[i][j]]
ep2 = epsilon[atomtype[i][k]]
sig1 = sigma[atomtype[i][j]]
sig2 = sigma[atomtype[i][k]]
r = np.array([x[i][j]-x[i][k],y[i][j]-y[i][k],z[i][j]-z[i][k]])
q1 = charge[atomtype[i][j]]
q2 = charge[atomtype[i][k]]
if ep1 != 0 and ep2 != 0:
elist[i] += analyze.e_lj(ep1,ep2,sig1,sig2,r)
if optatomnum != -1:
flist[i][optatomnum] += analyze.f_lj(ep1,ep2,sig1,sig2,r)
if q1 != 0 and q2 != 0:
elist[i] += analyze.ecoul(conv,q1,q2,r)
if optatomnum != -1:
flist[i][optatomnum] += analyze.fcoul(conv,q1,q2,r)
return elist, flist
def de_df(nsolatoms,optatoms,optlist,epsilon,sigma,charge,n,x,y,z,atomtype,conv):
delist = np.zeros((n,3*len(optatoms)))
dflist = np.zeros((n,3*len(optatoms),len(optlist),3))
for i in xrange(n):
for j in xrange(len(optlist)):
h = optlist[j]
g = -1
for u in xrange(len(optatoms)):
if atomtype[i][h] == optatoms[u]:
g = u
break
else:
print "Something terrible has happened."
sys.exit()
for k in xrange(nsolatoms,len(x[i])):
ep1 = epsilon[atomtype[i][h]]
ep2 = epsilon[atomtype[i][k]]
sig1 = sigma[atomtype[i][h]]
sig2 = sigma[atomtype[i][k]]
r = np.array([x[i][h]-x[i][k],y[i][h]-y[i][k],z[i][h]-z[i][k]])
q1 = charge[atomtype[i][h]]
q2 = charge[atomtype[i][k]]
if ep1 != 0 and ep2 != 0:
(delist[i][3*g], delist[i][3*g+1], dflist[i][3*g][j],
dflist[i][3*g+1][j]) = map(operator.add, (delist[i][3*g],
delist[i][3*g+1], dflist[i][3*g][j], dflist[i][3*g+1][j]),
analyze.dedf_lj(ep1,ep2,sig1,sig2,r))
if q1 != 0 and q2 != 0:
(delist[i][3*g+2], dflist[i][3*g+2][j]) = map(operator.add,
(delist[i][3*g+2], dflist[i][3*g+2][j]),
analyze.dedf_coul(conv,q1,q2,r))
return delist, dflist
def de_df_chcomp(nsolatoms,chcomptype,epsilon,sigma,charge,n,x,y,z,atomtype,conv):
delist = []
dflist = []
for i in xrange(n):
de = 0
df = []
for j in xrange(nsolatoms):
if atomtype[i][j] == chcomptype:
dfi = np.zeros(3)
for k in xrange(nsolatoms,len(x[i])):
r = np.array([x[i][j]-x[i][k],y[i][j]-y[i][k],z[i][j]-z[i][k]])
q1 = charge[atomtype[i][j]]
q2 = charge[atomtype[i][k]]
if q1 != 0 and q2 != 0:
(de, dfi) = map(operator.add, (de, dfi),
analyze.dedf_coul(conv,q1,q2,r))
df.append(dfi)
else:
df.append(np.zeros(3))
delist.append(de)
dflist.append(df)
return np.array(delist), np.array(dflist)
def dipquad(charge,n,nsolatoms,x,y,z,atomtype):
debye = 4.803205
diplist = np.zeros((n,3))
quadlist = np.zeros((n,6))
for i in xrange(n):
for j in xrange(nsolatoms):
diplist[i] += charge[atomtype[i][j]]*np.array([x[i][j],y[i][j],z[i][j]])
rsqi = x[i][j]**2 + y[i][j]**2 + z[i][j]**2
quadlist[i][0] += charge[atomtype[i][j]]*(3*x[i][j]**2 - rsqi)
quadlist[i][1] += charge[atomtype[i][j]]*(3*y[i][j]**2 - rsqi)
quadlist[i][2] += charge[atomtype[i][j]]*(3*z[i][j]**2 - rsqi)
quadlist[i][3] += charge[atomtype[i][j]]*(3*x[i][j]*y[i][j])
quadlist[i][4] += charge[atomtype[i][j]]*(3*x[i][j]*z[i][j])
quadlist[i][5] += charge[atomtype[i][j]]*(3*y[i][j]*z[i][j])
diplist *= debye
quadlist *= debye
return diplist, quadlist
def ddipdquad(optatoms,optlist,n,x,y,z,atomtype):
debye = 4.803205
ddiplist = np.zeros((n,3*len(optatoms),3))
dquadlist = np.zeros((n,3*len(optatoms),6))
for i in xrange(n):
for j in xrange(len(optlist)):
h = optlist[j]
g = -1
for u in xrange(len(optatoms)):
if atomtype[i][h] == optatoms[u]:
g = u
break
else:
print "Something terrible has happened."
sys.exit()
rsqi = x[i][h]**2 + y[i][h]**2 + z[i][h]**2
ddiplist[i][3*g+2] += np.array([x[i][h],y[i][h],z[i][h]])
dquadlist[i][3*g+2][0] += 3*x[i][h]**2 - rsqi
dquadlist[i][3*g+2][1] += 3*y[i][h]**2 - rsqi
dquadlist[i][3*g+2][2] += 3*z[i][h]**2 - rsqi
dquadlist[i][3*g+2][3] += 3*x[i][h]*y[i][h]
dquadlist[i][3*g+2][4] += 3*x[i][h]*z[i][h]
dquadlist[i][3*g+2][5] += 3*y[i][h]*z[i][h]
ddiplist *= debye
dquadlist *= debye
return ddiplist, dquadlist
def ddip_dquad_chcomp(nsolatoms,chcomptype,charge,n,x,y,z,atomtype):
debye = 4.803205
ddiplist = np.zeros((n,3))
dquadlist = np.zeros((n,6))
for i in xrange(n):
for j in xrange(nsolatoms):
if atomtype[i][j] == chcomptype:
rsqi = x[i][j]**2 + y[i][j]**2 + z[i][j]**2
ddiplist[i] += np.array([x[i][j],y[i][j],z[i][j]])
dquadlist[i][0] += 3*x[i][j]**2 - rsqi
dquadlist[i][1] += 3*y[i][j]**2 - rsqi
dquadlist[i][2] += 3*z[i][j]**2 - rsqi
dquadlist[i][3] += 3*x[i][j]*y[i][j]
dquadlist[i][4] += 3*x[i][j]*z[i][j]
dquadlist[i][5] += 3*y[i][j]*z[i][j]
ddiplist *= debye
dquadlist *= debye
return ddiplist, dquadlist