From f9d5dd1ab8d175b806f1f5cccd91e69c57618d3a Mon Sep 17 00:00:00 2001 From: Terumasa TADANO Date: Mon, 22 Jun 2020 23:16:30 +0900 Subject: [PATCH] Fix the LAMMPS parser The parser now can read *.lammps file that contains charge entries. Hopefully fix the issue #13 --- tools/displace.py | 4 ++-- tools/interface/LAMMPS.py | 34 +++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tools/displace.py b/tools/displace.py index 2190c10d..5c0ea45e 100644 --- a/tools/displace.py +++ b/tools/displace.py @@ -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 @@ -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( diff --git a/tools/interface/LAMMPS.py b/tools/interface/LAMMPS.py index 2c199766..406786d8 100644 --- a/tools/interface/LAMMPS.py +++ b/tools/interface/LAMMPS.py @@ -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') @@ -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()