Skip to content

Commit

Permalink
Fix the LAMMPS parser
Browse files Browse the repository at this point in the history
The parser now can read *.lammps file that contains charge entries.
Hopefully fix the issue #13
  • Loading branch information
ttadano committed Jun 22, 2020
1 parent 3e0bfdd commit f9d5dd1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tools/displace.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def get_number_of_zerofill(npattern):
suffix = "cg"

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

Expand Down Expand Up @@ -327,7 +327,7 @@ def get_number_of_zerofill(npattern):

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

elif code == "OpenMX":
openmx.write_OpenMX_input(
Expand Down
34 changes: 25 additions & 9 deletions tools/interface/LAMMPS.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ def read_lammps_structure(file_in):

atoms = np.array(atoms)
nat = len(atoms)
kd = np.array(atoms[:, 1], dtype=np.int)
x = np.array(atoms[:, 2:5], dtype=np.float64)
ncols = len(atoms[0,:])
if ncols == 5:
kd = np.array(atoms[:, 1], dtype=np.int)
x = np.array(atoms[:, 2:5], dtype=np.float64)
charges = None
elif ncols == 6:
kd = np.array(atoms[:, 1], dtype=np.int)
x = np.array(atoms[:, 3:6], dtype=np.float64)
charges = np.array(atoms[:,2], dtype=np.float64)

return common_settings, nat, x, kd
return common_settings, nat, x, kd, charges


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

filename = prefix + str(counter).zfill(nzerofills) + ".lammps"
f = open(filename, 'w')
Expand All @@ -49,12 +56,21 @@ def write_lammps_structure(prefix, counter, header, nzerofills,
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]))

if charge is None:
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")
else:
for i in range(nat):
f.write("%5d %3d %11.6f" % (i + 1, kd[i], charge[i]))
for j in range(3):
f.write("%20.15f" % (x_cart[i][j] + disp[i][j]))
f.write("\n")
f.write("\n")
f.write("\n")
f.close()


Expand Down

0 comments on commit f9d5dd1

Please sign in to comment.