Skip to content

Commit

Permalink
Implement a new interface to the LAMMPS code
Browse files Browse the repository at this point in the history
  • Loading branch information
ttadano committed Oct 27, 2017
1 parent 50436ca commit b8f4b10
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 18 deletions.
96 changes: 85 additions & 11 deletions tools/displace.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
metavar='orig.cg',
help="xTAPP CG file with equilibrium atomic \
positions (default: None)")
parser.add_option('--LAMMPS',
metavar='orig.lammps',
help="LAMMPS structure file with equilibrium atomic positions (default: None)")

# Functions for VASP

Expand Down Expand Up @@ -101,7 +104,7 @@ def write_POSCAR(prefix, counter, header, nzerofills,
f.write("%s\n" % "1.0")

for i in range(3):
f.write("%20.14f %20.14f %20.14f\n" % (lavec[0][i],
f.write("%20.15f %20.15f %20.15f\n" % (lavec[0][i],
lavec[1][i],
lavec[2][i]))

Expand All @@ -118,7 +121,7 @@ def write_POSCAR(prefix, counter, header, nzerofills,

for i in range(len(disp)):
for j in range(3):
f.write("%20.16f" % (coord[i][j] + disp[i][j]))
f.write("%20.15f" % (coord[i][j] + disp[i][j]))
f.write("\n")
f.close()

Expand Down Expand Up @@ -656,7 +659,7 @@ def generate_QE_input(prefix, suffix, counter, nzerofills, list_namelist,

f.write("ATOMIC_POSITIONS crystal\n")
for i in range(nat):
f.write("%s %20.16f %20.16f %20.16f\n" % (kd_symbol[i],
f.write("%s %20.15f %20.15f %20.15f\n" % (kd_symbol[i],
x[i][0] + u[i, 0],
x[i][1] + u[i, 1],
x[i][2] + u[i, 2]))
Expand Down Expand Up @@ -879,7 +882,8 @@ def gen_CG(prefix, suffix, counter, nzerofills, str_header,
f.write("%s" % str_header)

for i in range(nat):
f.write("%i %20.16f %20.16f %20.16f\n" % (kd[i], x[i][0] + u[i, 0],
f.write("%i %20.15f %20.15f %20.15f\n" % (kd[i],
x[i][0] + u[i, 0],
x[i][1] + u[i, 1],
x[i][2] + u[i, 2]))

Expand Down Expand Up @@ -913,6 +917,53 @@ def gen_CG(prefix, suffix, counter, nzerofills, str_header,
f.close()


# Functions for LAMMPS

def read_lammps_structure(file_in):

f = open(file_in, 'r')
header_comment = f.readline()

common_settings = []

for line in f:
if "Atoms" in line:
break
common_settings.append(line.rstrip())

atoms = []
for line in f:
if line.strip():
atoms.append(line.rstrip().split())

atoms = np.array(atoms)
nat = len(atoms)
kd = np.array(atoms[:,1], dtype=np.int)
x = np.array(atoms[:,2:5], dtype=np.float64)

return common_settings, nat, x, kd


def write_lammps_structure(prefix, counter, header,
common_settings, nat, kd, x_cart, disp):

filename = prefix + str(counter).zfill(nzerofills) + ".lammps"
f = open(filename, 'w')
f.write("%s\n" % header)

for line in common_settings:
f.write("%s\n" % line)

f.write("%s\n\n" % "Atoms")
for i in range(nat):
f.write("%5d %3d" % (i + 1, kd[i]))
for j in range(3):
f.write("%20.15f" % (x_cart[i][j] + disp[i][j]))
f.write("\n")
f.write("\n")
f.close()


# Other functions

def parse_displacement_patterns(files_in):
Expand Down Expand Up @@ -1003,8 +1054,9 @@ def gen_displacement(counter_in, pattern, disp_mag, nat, invlavec):

poscar_header += ")"

for i in range(nat):
disp[i] = np.dot(disp[i], invlavec.T)
if invlavec is not None:
for i in range(nat):
disp[i] = np.dot(disp[i], invlavec.T)

return poscar_header, disp

Expand Down Expand Up @@ -1043,13 +1095,17 @@ def get_number_of_zerofill(npattern):
please type\n$ python displace.py -h"
exit(1)

if options.VASP is None and options.QE is None and options.xTAPP is None:
print "Error : Either --VASP, --QE, or --xTAPP option must be given."
conditions = [options.VASP is None,
options.QE is None,
options.xTAPP is None,
options.LAMMPS is None]

if conditions.count(True) == len(conditions):
print "Error : Either --VASP, --QE, --xTAPP, --LAMMPS option must be given."
exit(1)

elif options.VASP and options.QE or options.VASP and options.xTAPP or \
options.QE and options.xTAPP:
print "Error : --VASP, --QE, and --xTAPP cannot be given simultaneously."
elif len(conditions) - conditions.count(True) > 1:
print "Error : --VASP, --QE, --xTAPP, and --LAMMPS cannot be given simultaneously."
exit(1)

elif options.VASP:
Expand All @@ -1067,6 +1123,11 @@ def get_number_of_zerofill(npattern):
print "--xTAPP option is given: Generate input files for xTAPP."
print

elif options.LAMMPS:
code = "LAMMPS"
print "--LAMMPS option is given: Generate input files for LAMMPS."
print

# Assign the magnitude of displacements
if options.mag is None:
options.mag = "0.02"
Expand Down Expand Up @@ -1099,6 +1160,10 @@ def get_number_of_zerofill(npattern):
elif code == "xTAPP":
str_outfiles = "%s{counter}.cg" % prefix
file_original = options.xTAPP

elif code == "LAMMPS":
str_outfiles = "%s{counter}.lammps" % prefix
file_original = options.LAMMPS

# Read the original file
if code == "VASP":
Expand All @@ -1115,6 +1180,10 @@ def get_number_of_zerofill(npattern):
str_header, nat, nkd, aa, aa_inv, x_frac, kd = read_CG(file_original)
suffix = "cg"

elif code == "LAMMPS":
common_settings, nat, x_cart, kd = read_lammps_structure(file_original)
aa_inv = None

print "Original file : %s" % file_original
print "Output file format : %s" % str_outfiles
print "Magnitude of displacements : %s Angstrom" % disp_length
Expand All @@ -1139,6 +1208,7 @@ def get_number_of_zerofill(npattern):
list_ATOMIC_SPECIES, list_K_POINTS,
list_CELL_PARAMETERS, list_OCCUPATIONS,
nat, kd_symbol, x_frac, disp)

elif code == "xTAPP":
nsym = 1
symop = []
Expand All @@ -1149,5 +1219,9 @@ def get_number_of_zerofill(npattern):
gen_CG(prefix, suffix, counter, nzerofills, str_header, nat, kd,
x_frac, disp, nsym, symop, denom_tran, has_inv)

elif code == "LAMMPS":
write_lammps_structure(prefix, counter, header,
common_settings, nat, kd, x_cart, disp)

print
print "All input files are created."

0 comments on commit b8f4b10

Please sign in to comment.