| 1 |
#! /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 |
which = 0 |
| 72 |
for l1 in range(2): |
| 73 |
for l2 in range(2): |
| 74 |
for l3 in range(2): |
| 75 |
lvals = numpy.array([l1,l2,l3]) |
| 76 |
value = math.pow(-1, numpy.dot(cell[i], lvals)) |
| 77 |
X[i][which] = value * e1 |
| 78 |
Y[i][which] = value * e2 |
| 79 |
Z[i][which] = value * e3 |
| 80 |
which = which+1 |
| 81 |
|
| 82 |
|
| 83 |
lp_array = numpy.zeros(0).reshape((0,3)) |
| 84 |
for i in range(8): |
| 85 |
lp_array = numpy.vstack((lp_array, corners[i])) |
| 86 |
|
| 87 |
bc_array = numpy.zeros(0).reshape((0,3)) |
| 88 |
for i in range(8): |
| 89 |
bc_array = numpy.vstack((bc_array, corners[i] + [0.5,0.5,0.5])) |
| 90 |
|
| 91 |
xy_array = numpy.zeros(0).reshape((0,3)) |
| 92 |
for i in range(8): |
| 93 |
xy_array = numpy.vstack((xy_array, corners[i] + [0.5,0.5,0.0])) |
| 94 |
|
| 95 |
xz_array = numpy.zeros(0).reshape((0,3)) |
| 96 |
for i in range(8): |
| 97 |
xz_array = numpy.vstack((xz_array, corners[i] + [0.5,0.0,0.5])) |
| 98 |
|
| 99 |
yz_array = numpy.zeros(0).reshape((0,3)) |
| 100 |
for i in range(8): |
| 101 |
yz_array = numpy.vstack((yz_array, corners[i] + [0.0,0.5,0.5])) |
| 102 |
|
| 103 |
known_case = False |
| 104 |
basic_array = numpy.zeros(0).reshape((0,3,3)) |
| 105 |
|
| 106 |
lp_part = numpy.zeros(0).reshape((0,3,3)) |
| 107 |
bc_part = numpy.zeros(0).reshape((0,3,3)) |
| 108 |
xy_part = numpy.zeros(0).reshape((0,3,3)) |
| 109 |
xz_part = numpy.zeros(0).reshape((0,3,3)) |
| 110 |
yz_part = numpy.zeros(0).reshape((0,3,3)) |
| 111 |
|
| 112 |
if (arrayType == 'X'): |
| 113 |
if (int(latticeType)): |
| 114 |
which = int(latticeType) - 1 |
| 115 |
basic_array = numpy.append(lp_array, X[which], axis=1) |
| 116 |
known_case = True |
| 117 |
if (arrayType == 'Y'): |
| 118 |
if (int(latticeType)): |
| 119 |
which = int(latticeType) - 1 |
| 120 |
basic_array = numpy.append(lp_array, Y[which], axis=1) |
| 121 |
known_case = True |
| 122 |
if (arrayType == 'Z'): |
| 123 |
if (int(latticeType)): |
| 124 |
which = int(latticeType) - 1 |
| 125 |
basic_array = numpy.append(lp_array, Z[which], axis=1) |
| 126 |
known_case = True |
| 127 |
if (latticeType.lower() == 'sc'): |
| 128 |
lp_part = numpy.append(lp_array, X[0]+Y[0]+Z[0], axis=1) |
| 129 |
basic_array = lp_part |
| 130 |
known_case = True |
| 131 |
if (latticeType.lower() == 'bcc'): |
| 132 |
lp_part = numpy.append(lp_array, X[0]+Y[0], axis=1) |
| 133 |
bc_part = numpy.append(bc_array, X[0]-Y[0], axis=1) |
| 134 |
basic_array = numpy.append(lp_part, bc_part, axis=0) |
| 135 |
known_case = True |
| 136 |
if (latticeType.lower() == 'fcc'): |
| 137 |
lp_part = numpy.append(lp_array, X[0]+Y[0]+Z[0], axis=1) |
| 138 |
xy_part = numpy.append(xy_array, X[0]-Y[0]-Z[0], axis=1) |
| 139 |
xz_part = numpy.append(xz_array, -X[0]-Y[0]+Z[0], axis=1) |
| 140 |
yz_part = numpy.append(yz_array, -X[0]+Y[0]-Z[0], axis=1) |
| 141 |
basic_array = numpy.append(lp_part, xy_part, axis=0) |
| 142 |
basic_array = numpy.append(basic_array, xz_part, axis=0) |
| 143 |
basic_array = numpy.append(basic_array, yz_part, axis=0) |
| 144 |
|
| 145 |
known_case = True |
| 146 |
|
| 147 |
|
| 148 |
if (not known_case): |
| 149 |
print "unhandled combination of lattice and dipole direction" |
| 150 |
print __doc__ |
| 151 |
|
| 152 |
bravais_lattice = numpy.zeros(0).reshape((0,6)) |
| 153 |
for i in range(latticeNumber): |
| 154 |
for j in range(latticeNumber): |
| 155 |
for k in range(latticeNumber): |
| 156 |
for l in range(len(basic_array)): |
| 157 |
lat_vec = numpy.array([[2*i, 2*j, 2*k, 0.0, 0.0, 0.0]]) |
| 158 |
bravais_lattice = numpy.append(bravais_lattice, lat_vec + basic_array[l], axis=0) |
| 159 |
|
| 160 |
outputFile = open(outputFileName, 'w') |
| 161 |
|
| 162 |
outputFile.write('<OpenMD version=2>\n') |
| 163 |
outputFile.write(' <MetaData>\n') |
| 164 |
outputFile.write(' molecule{\n') |
| 165 |
outputFile.write(' name = \"Q\";\n') |
| 166 |
outputFile.write(' \n') |
| 167 |
outputFile.write(' atom[0]{\n') |
| 168 |
outputFile.write(' type = \"Q\";\n') |
| 169 |
outputFile.write(' position(0.0, 0.0, 0.0);\n') |
| 170 |
outputFile.write(' orientation(0.0, 0.0, 0.0);\n') |
| 171 |
outputFile.write(' }\n') |
| 172 |
outputFile.write(' }\n') |
| 173 |
outputFile.write(' component{\n') |
| 174 |
outputFile.write(' type = \"Q\";\n') |
| 175 |
outputFile.write(' nMol = '+ repr(len(bravais_lattice)) + ';\n') |
| 176 |
outputFile.write(' }\n') |
| 177 |
|
| 178 |
outputFile.write(' ensemble = NVE;\n') |
| 179 |
outputFile.write(' forceField = \"Multipole\";\n') |
| 180 |
|
| 181 |
outputFile.write(' cutoffMethod = \"shifted_force\";\n') |
| 182 |
outputFile.write(' electrostaticScreeningMethod = \"damped\";\n') |
| 183 |
|
| 184 |
outputFile.write(' cutoffRadius = 9.0;\n') |
| 185 |
outputFile.write(' dampingAlpha = 0.18;\n') |
| 186 |
outputFile.write(' statFileFormat = \"TIME|TOTAL_ENERGY|POTENTIAL_ENERGY|KINETIC_ENERGY|TEMPERATURE|PRESSURE|VOLUME|CONSERVED_QUANTITY|ELECTROSTATIC_POTENTIAL\";\n') |
| 187 |
outputFile.write(' dt = 1.0;\n') |
| 188 |
outputFile.write(' runTime = 1.0;\n') |
| 189 |
outputFile.write(' sampleTime = 1.0;\n') |
| 190 |
outputFile.write(' statusTime = 1.0;\n') |
| 191 |
outputFile.write(' </MetaData>\n') |
| 192 |
outputFile.write(' <Snapshot>\n') |
| 193 |
outputFile.write(' <FrameData>\n'); |
| 194 |
outputFile.write(" Time: %.10g\n" % (0.0)) |
| 195 |
|
| 196 |
Hxx = 2.0 * latticeConstant * latticeNumber |
| 197 |
Hyy = 2.0 * latticeConstant * latticeNumber |
| 198 |
Hzz = 2.0 * latticeConstant * latticeNumber |
| 199 |
|
| 200 |
outputFile.write(' Hmat: {{%d, 0, 0}, {0, %d, 0}, {0, 0, %d}}\n' % (Hxx, Hyy, Hzz)) |
| 201 |
outputFile.write(' </FrameData>\n') |
| 202 |
outputFile.write(' <StuntDoubles>\n') |
| 203 |
sdFormat = 'pvqj' |
| 204 |
index = 0 |
| 205 |
|
| 206 |
for i in range(len(bravais_lattice)): |
| 207 |
xcart = latticeConstant*(bravais_lattice[i][0]) |
| 208 |
ycart = latticeConstant*(bravais_lattice[i][1]) |
| 209 |
zcart = latticeConstant*(bravais_lattice[i][2]) |
| 210 |
dx = bravais_lattice[i][3] |
| 211 |
dy = bravais_lattice[i][4] |
| 212 |
dz = bravais_lattice[i][5] |
| 213 |
|
| 214 |
dlen = math.sqrt(dx*dx + dy*dy + dz*dz) |
| 215 |
ctheta = dz / dlen |
| 216 |
theta = math.acos(ctheta) |
| 217 |
stheta = math.sqrt(1.0 - ctheta*ctheta) |
| 218 |
psi = 0.0 |
| 219 |
phi = math.atan2(dx/dlen, -dy/dlen) |
| 220 |
|
| 221 |
q = [0.0,0.0,0.0,0.0] |
| 222 |
q[0] = math.cos(theta/2)*math.cos((phi+psi)/2) |
| 223 |
q[1] = math.sin(theta/2)*math.cos((phi-psi)/2) |
| 224 |
q[2] = math.sin(theta/2)*math.sin((phi-psi)/2) |
| 225 |
q[3] = math.cos(theta/2)*math.sin((phi+psi)/2) |
| 226 |
|
| 227 |
qlen = math.sqrt(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]) |
| 228 |
q[0] = q[0]/qlen |
| 229 |
q[1] = q[1]/qlen |
| 230 |
q[2] = q[2]/qlen |
| 231 |
q[3] = q[3]/qlen |
| 232 |
|
| 233 |
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)) |
| 234 |
index = index+1 |
| 235 |
|
| 236 |
outputFile.write(" </StuntDoubles>\n") |
| 237 |
outputFile.write(" </Snapshot>\n") |
| 238 |
outputFile.write("</OpenMD>\n") |
| 239 |
outputFile.close() |
| 240 |
|
| 241 |
outputFile.close() |
| 242 |
|
| 243 |
def main(argv): |
| 244 |
|
| 245 |
arrayType = "A" |
| 246 |
haveOutputFileName = False |
| 247 |
latticeType = "fcc" |
| 248 |
latticeNumber = 3 |
| 249 |
latticeConstant = 4 |
| 250 |
try: |
| 251 |
opts, args = getopt.getopt(argv, "hxyzl:c:n:o:", ["help","array-type-X", "array-type-Y", "array-type-Z", "lattice=", "constant=", "output-file="]) |
| 252 |
except getopt.GetoptError: |
| 253 |
usage() |
| 254 |
sys.exit(2) |
| 255 |
for opt, arg in opts: |
| 256 |
if opt in ("-h", "--help"): |
| 257 |
usage() |
| 258 |
sys.exit() |
| 259 |
elif opt in ("-x", "--array-type-X"): |
| 260 |
arrayType = "X" |
| 261 |
elif opt in ("-y", "--array-type-Y"): |
| 262 |
arrayType = "Y" |
| 263 |
elif opt in ("-z", "--array-type-Z"): |
| 264 |
arrayType = "Z" |
| 265 |
elif opt in ("-l", "--lattice"): |
| 266 |
latticeType = arg |
| 267 |
elif opt in ("-c", "--constant"): |
| 268 |
latticeConstant = float(arg) |
| 269 |
elif opt in ("-n"): |
| 270 |
latticeNumber = int(arg) |
| 271 |
elif opt in ("-o", "--output-file"): |
| 272 |
outputFileName = arg |
| 273 |
haveOutputFileName = True |
| 274 |
if (not haveOutputFileName): |
| 275 |
usage() |
| 276 |
print "No output file was specified" |
| 277 |
sys.exit() |
| 278 |
|
| 279 |
createLattice(latticeType, latticeNumber, latticeConstant, arrayType, outputFileName); |
| 280 |
|
| 281 |
if __name__ == "__main__": |
| 282 |
if len(sys.argv) == 1: |
| 283 |
usage() |
| 284 |
sys.exit() |
| 285 |
main(sys.argv[1:]) |