ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/samples/Madelung/quadrupoles/buildQuadrupolarArray
Revision: 1921
Committed: Thu Aug 1 18:23:07 2013 UTC (12 years ago) by gezelter
File size: 11029 byte(s)
Log Message:
Fixed a few DumpWriter / FlucQ bugs.  Still working on Ewald, updated 
Quadrupolar test structures.

File Contents

# User Rev Content
1 gezelter 1916 #! /usr/bin/env python
2    
3     """Quadrupolar Lattice Builder
4    
5     Creates cubic lattices of quadrupoles to test the
6     quadrupole-quadrupole interaction code.
7    
8     Usage: buildQuadrupolarArray
9    
10     Options:
11     -h, --help show this help
12     -x, --array-type-X use one of the basic "X" arrays
13     -y, --array-type-Y use one of the basic "Y" arrays
14     -z, --array-type-Z use one of the basic "Z" arrays
15     -l, --lattice=... use the specified lattice ( SC, FCC, or BCC )
16     -c, --constant=... use the specified lattice constant
17     -n use the specified number of unit cells
18     -o, --output-file=... use specified output (.xyz) file
19    
20     Type "A" arrays have nearest neighbor strings of antiparallel dipoles.
21    
22     Type "B" arrays have nearest neighbor strings of antiparallel dipoles
23     if the dipoles are contained in a plane perpendicular to the dipole
24     direction that passes through the dipole.
25    
26     Example:
27     buildQuadrupolarArray -l fcc -c 5 -n 3 -o FCC.md
28    
29     """
30    
31     __author__ = "Dan Gezelter (gezelter@nd.edu)"
32     __version__ = "$Rev: 1914 $"
33     __date__ = "$LastChangedDate: 2013-07-29 11:34:04 -0400 (Mon, 29 Jul 2013) $"
34    
35     __copyright__ = "Copyright (c) 2013 by the University of Notre Dame"
36     __license__ = "OpenMD"
37    
38     import sys
39     import getopt
40     import string
41     import math
42     import numpy
43    
44     def usage():
45     print __doc__
46    
47     def createLattice(latticeType, latticeNumber, latticeConstant, arrayType, outputFileName):
48     # The following section creates 24 basic arrays from Luttinger and
49     # Tisza:
50    
51     # The six unit vectors are: 3 spatial and 3 to describe the
52     # orientation of the dipole.
53    
54     e1 = numpy.array([1.0,0.0,0.0])
55     e2 = numpy.array([0.0,1.0,0.0])
56     e3 = numpy.array([0.0,0.0,1.0])
57    
58     # Parameters describing the 8 basic arrays:
59     cell = numpy.array([[0,0,0],[0,0,1],[1,0,0],[0,1,0],
60     [1,1,0],[0,1,1],[1,0,1],[1,1,1]])
61     # order in which the basic arrays are constructed in the l loops below:
62     corners = numpy.array([[0,0,0],[0,0,1],[0,1,0],[0,1,1],
63     [1,0,0],[1,0,1],[1,1,0],[1,1,1]])
64    
65     X = numpy.zeros(192).reshape((8,8,3))
66     Y = numpy.zeros(192).reshape((8,8,3))
67     Z = numpy.zeros(192).reshape((8,8,3))
68    
69     # create the 24 basic arrays using Eq. 12 in Luttinger & Tisza:
70     for i in range(8):
71 gezelter 1921 # The X and Y arrays are cubic rotations of the Z array, so we
72     # need to re-order them to match the numbering scheme in
73     # Luttinger & Tisza:
74     if (i > 0 and i < 4):
75     iX = 1 + (i + 1) % 3
76     iY = 1 + (i ) % 3
77     elif (i > 3 and i < 7):
78     iX = 4 + (i - 2) % 3
79     iY = 4 + (i ) % 3
80     else:
81     iX = i
82     iY = i
83 gezelter 1916 which = 0
84     for l1 in range(2):
85     for l2 in range(2):
86     for l3 in range(2):
87     lvals = numpy.array([l1,l2,l3])
88     value = math.pow(-1, numpy.dot(cell[i], lvals))
89 gezelter 1921 X[iX][which] = value * e1
90     Y[iY][which] = value * e2
91     Z[i][which] = value * e3
92 gezelter 1916 which = which+1
93    
94     lp_array = numpy.zeros(0).reshape((0,3))
95     for i in range(8):
96     lp_array = numpy.vstack((lp_array, corners[i]))
97    
98     bc_array = numpy.zeros(0).reshape((0,3))
99     for i in range(8):
100     bc_array = numpy.vstack((bc_array, corners[i] + [0.5,0.5,0.5]))
101    
102     xy_array = numpy.zeros(0).reshape((0,3))
103     for i in range(8):
104     xy_array = numpy.vstack((xy_array, corners[i] + [0.5,0.5,0.0]))
105    
106     xz_array = numpy.zeros(0).reshape((0,3))
107     for i in range(8):
108     xz_array = numpy.vstack((xz_array, corners[i] + [0.5,0.0,0.5]))
109    
110     yz_array = numpy.zeros(0).reshape((0,3))
111     for i in range(8):
112     yz_array = numpy.vstack((yz_array, corners[i] + [0.0,0.5,0.5]))
113    
114     known_case = False
115     basic_array = numpy.zeros(0).reshape((0,3,3))
116    
117     lp_part = numpy.zeros(0).reshape((0,3,3))
118     bc_part = numpy.zeros(0).reshape((0,3,3))
119     xy_part = numpy.zeros(0).reshape((0,3,3))
120     xz_part = numpy.zeros(0).reshape((0,3,3))
121     yz_part = numpy.zeros(0).reshape((0,3,3))
122    
123     if (arrayType == 'X'):
124     if (int(latticeType)):
125     which = int(latticeType) - 1
126     basic_array = numpy.append(lp_array, X[which], axis=1)
127     known_case = True
128     if (arrayType == 'Y'):
129     if (int(latticeType)):
130     which = int(latticeType) - 1
131     basic_array = numpy.append(lp_array, Y[which], axis=1)
132     known_case = True
133     if (arrayType == 'Z'):
134     if (int(latticeType)):
135     which = int(latticeType) - 1
136     basic_array = numpy.append(lp_array, Z[which], axis=1)
137     known_case = True
138     if (latticeType.lower() == 'sc'):
139     lp_part = numpy.append(lp_array, X[0]+Y[0]+Z[0], axis=1)
140     basic_array = lp_part
141     known_case = True
142     if (latticeType.lower() == 'bcc'):
143     lp_part = numpy.append(lp_array, X[0]+Y[0], axis=1)
144     bc_part = numpy.append(bc_array, X[0]-Y[0], axis=1)
145     basic_array = numpy.append(lp_part, bc_part, axis=0)
146     known_case = True
147     if (latticeType.lower() == 'fcc'):
148     lp_part = numpy.append(lp_array, X[0]+Y[0]+Z[0], axis=1)
149     xy_part = numpy.append(xy_array, X[0]-Y[0]-Z[0], axis=1)
150     xz_part = numpy.append(xz_array, -X[0]-Y[0]+Z[0], axis=1)
151     yz_part = numpy.append(yz_array, -X[0]+Y[0]-Z[0], axis=1)
152     basic_array = numpy.append(lp_part, xy_part, axis=0)
153     basic_array = numpy.append(basic_array, xz_part, axis=0)
154     basic_array = numpy.append(basic_array, yz_part, axis=0)
155    
156     known_case = True
157    
158    
159     if (not known_case):
160     print "unhandled combination of lattice and dipole direction"
161     print __doc__
162    
163     bravais_lattice = numpy.zeros(0).reshape((0,6))
164     for i in range(latticeNumber):
165     for j in range(latticeNumber):
166     for k in range(latticeNumber):
167     for l in range(len(basic_array)):
168     lat_vec = numpy.array([[2*i, 2*j, 2*k, 0.0, 0.0, 0.0]])
169     bravais_lattice = numpy.append(bravais_lattice, lat_vec + basic_array[l], axis=0)
170    
171     outputFile = open(outputFileName, 'w')
172    
173     outputFile.write('<OpenMD version=2>\n')
174     outputFile.write(' <MetaData>\n')
175     outputFile.write(' molecule{\n')
176     outputFile.write(' name = \"Q\";\n')
177     outputFile.write(' \n')
178     outputFile.write(' atom[0]{\n')
179     outputFile.write(' type = \"Q\";\n')
180     outputFile.write(' position(0.0, 0.0, 0.0);\n')
181     outputFile.write(' orientation(0.0, 0.0, 0.0);\n')
182     outputFile.write(' }\n')
183     outputFile.write(' }\n')
184     outputFile.write(' component{\n')
185     outputFile.write(' type = \"Q\";\n')
186     outputFile.write(' nMol = '+ repr(len(bravais_lattice)) + ';\n')
187     outputFile.write(' }\n')
188    
189     outputFile.write(' ensemble = NVE;\n')
190     outputFile.write(' forceField = \"Multipole\";\n')
191    
192     outputFile.write(' cutoffMethod = \"shifted_force\";\n')
193     outputFile.write(' electrostaticScreeningMethod = \"damped\";\n')
194    
195     outputFile.write(' cutoffRadius = 9.0;\n')
196     outputFile.write(' dampingAlpha = 0.18;\n')
197     outputFile.write(' statFileFormat = \"TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY|ELECTROSTATIC_POTENTIAL\";\n')
198     outputFile.write(' dt = 1.0;\n')
199     outputFile.write(' runTime = 1.0;\n')
200     outputFile.write(' sampleTime = 1.0;\n')
201     outputFile.write(' statusTime = 1.0;\n')
202     outputFile.write(' </MetaData>\n')
203     outputFile.write(' <Snapshot>\n')
204     outputFile.write(' <FrameData>\n');
205     outputFile.write(" Time: %.10g\n" % (0.0))
206    
207     Hxx = 2.0 * latticeConstant * latticeNumber
208     Hyy = 2.0 * latticeConstant * latticeNumber
209     Hzz = 2.0 * latticeConstant * latticeNumber
210    
211     outputFile.write(' Hmat: {{%d, 0, 0}, {0, %d, 0}, {0, 0, %d}}\n' % (Hxx, Hyy, Hzz))
212     outputFile.write(' </FrameData>\n')
213     outputFile.write(' <StuntDoubles>\n')
214     sdFormat = 'pvqj'
215     index = 0
216    
217     for i in range(len(bravais_lattice)):
218     xcart = latticeConstant*(bravais_lattice[i][0])
219     ycart = latticeConstant*(bravais_lattice[i][1])
220     zcart = latticeConstant*(bravais_lattice[i][2])
221     dx = bravais_lattice[i][3]
222     dy = bravais_lattice[i][4]
223     dz = bravais_lattice[i][5]
224    
225     dlen = math.sqrt(dx*dx + dy*dy + dz*dz)
226     ctheta = dz / dlen
227     theta = math.acos(ctheta)
228     stheta = math.sqrt(1.0 - ctheta*ctheta)
229     psi = 0.0
230     phi = math.atan2(dx/dlen, -dy/dlen)
231    
232     q = [0.0,0.0,0.0,0.0]
233     q[0] = math.cos(theta/2)*math.cos((phi+psi)/2)
234     q[1] = math.sin(theta/2)*math.cos((phi-psi)/2)
235     q[2] = math.sin(theta/2)*math.sin((phi-psi)/2)
236     q[3] = math.cos(theta/2)*math.sin((phi+psi)/2)
237    
238     qlen = math.sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3])
239     q[0] = q[0]/qlen
240     q[1] = q[1]/qlen
241     q[2] = q[2]/qlen
242     q[3] = q[3]/qlen
243    
244     outputFile.write("%10d %7s %g %g %1g %g %g %g %13e %13e %13e %13e %g %g %g\n" % (index, sdFormat, xcart, ycart, zcart, 0.0, 0.0, 0.0, q[0], q[1], q[2], q[3], 0.0, 0.0, 0.0))
245     index = index+1
246    
247     outputFile.write(" </StuntDoubles>\n")
248     outputFile.write(" </Snapshot>\n")
249     outputFile.write("</OpenMD>\n")
250     outputFile.close()
251    
252     outputFile.close()
253    
254     def main(argv):
255    
256     arrayType = "A"
257     haveOutputFileName = False
258     latticeType = "fcc"
259     latticeNumber = 3
260     latticeConstant = 4
261     try:
262     opts, args = getopt.getopt(argv, "hxyzl:c:n:o:", ["help","array-type-X", "array-type-Y", "array-type-Z", "lattice=", "constant=", "output-file="])
263     except getopt.GetoptError:
264     usage()
265     sys.exit(2)
266     for opt, arg in opts:
267     if opt in ("-h", "--help"):
268     usage()
269     sys.exit()
270     elif opt in ("-x", "--array-type-X"):
271     arrayType = "X"
272     elif opt in ("-y", "--array-type-Y"):
273     arrayType = "Y"
274     elif opt in ("-z", "--array-type-Z"):
275     arrayType = "Z"
276     elif opt in ("-l", "--lattice"):
277     latticeType = arg
278     elif opt in ("-c", "--constant"):
279     latticeConstant = float(arg)
280     elif opt in ("-n"):
281     latticeNumber = int(arg)
282     elif opt in ("-o", "--output-file"):
283     outputFileName = arg
284     haveOutputFileName = True
285     if (not haveOutputFileName):
286     usage()
287     print "No output file was specified"
288     sys.exit()
289    
290     createLattice(latticeType, latticeNumber, latticeConstant, arrayType, outputFileName);
291    
292     if __name__ == "__main__":
293     if len(sys.argv) == 1:
294     usage()
295     sys.exit()
296     main(sys.argv[1:])

Properties

Name Value
svn:executable *