Skip to content

Commit 00d8c77

Browse files
thangcktpre-commit-ci[bot]daico007
authored
add "metal" Unit for Lammps (#1098)
* Update lammpsdata.py * Update lammpsdata.py * Update compound.py * Update compound.py * Update compound.py * Update compound.py * Update environment-dev-win.yml * Update environment-dev.yml * Update environment.yml * up * Update lammpsdata.py * Update lammpsdata.py * up * up * up * Update lammpsdata.py * Update lammpsdata.py * Delete oryx-build-commands.txt * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update lammpsdata.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update mbuild/formats/lammpsdata.py Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update mbuild/formats/lammpsdata.py Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com> * Update mbuild/formats/lammpsdata.py Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com> * Update mbuild/formats/lammpsdata.py Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com> * Update mbuild/formats/lammpsdata.py Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com> * Update mbuild/formats/lammpsdata.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Co Quach <43968221+daico007@users.noreply.github.com>
1 parent 7941ba4 commit 00d8c77

File tree

1 file changed

+55
-23
lines changed

1 file changed

+55
-23
lines changed

mbuild/formats/lammpsdata.py

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ def write_lammpsdata(
5959
'full', 'atomic', 'charge', 'molecular'
6060
see http://lammps.sandia.gov/doc/atom_style.html for more information
6161
on atom styles.
62-
unit_style : str, optional, default='real'
63-
Defines to unit style to be save in a LAMMPS data file. Current styles
64-
are supported: 'real', 'lj', see lammps unit style documentation:
65-
https://lammps.sandia.gov/doc/99/units.html for more information.
62+
unit_style: str, optional, default='real'
63+
Defines to unit style to be save in a LAMMPS data file. Defaults to
64+
'real' units. Current styles are supported: 'real', 'lj', 'metal'
65+
see https://lammps.sandia.gov/doc/99/units.html for more information
66+
on unit styles
6667
mins : list, optional, default=None
6768
Minimum box dimension in x, y, z directions, nm
6869
maxs : list, optional, default=None
@@ -162,7 +163,7 @@ def write_lammpsdata(
162163
atom_style
163164
)
164165
)
165-
if unit_style not in ["real", "lj"]:
166+
if unit_style not in ["real", "lj", "metal"]:
166167
raise ValueError(
167168
'Unit style "{}" is invalid or is not currently supported'.format(
168169
unit_style
@@ -305,10 +306,23 @@ def write_lammpsdata(
305306
* 10**-6
306307
)
307308
charges[np.isinf(charges)] = 0
308-
else:
309+
eng_unit_str = " "
310+
311+
elif unit_style == "real":
309312
sigma_conversion_factor = 1
310313
epsilon_conversion_factor = 1
311314
mass_conversion_factor = 1
315+
eng_unit_str = "kcal/mol"
316+
317+
elif unit_style == "metal":
318+
sigma_conversion_factor = 1 # unit in Angstrom
319+
epsilon_conversion_factor = 1 / 0.043364115 # kcal/mol to eV
320+
mass_conversion_factor = 1
321+
eng_unit_str = "eV"
322+
else:
323+
raise ValueError(
324+
"Currently only support 'real', 'lj', and 'metal' unit_styles."
325+
)
312326

313327
# Divide by conversion factor
314328
Lx = box.Lx * (1 / sigma_conversion_factor)
@@ -441,12 +455,13 @@ def write_lammpsdata(
441455
pair_coeff_label,
442456
unit_style,
443457
nbfix_in_data_file,
458+
eng_unit_str,
444459
)
445460

446461
# Write bond coefficients
447462
if bonds:
448463
_write_bond_information(
449-
structure, data, unique_bond_types, unit_style
464+
structure, data, unique_bond_types, unit_style, eng_unit_str
450465
)
451466

452467
# Write angle coefficients
@@ -457,6 +472,7 @@ def write_lammpsdata(
457472
unique_angle_types,
458473
use_urey_bradleys,
459474
unit_style,
475+
eng_unit_str,
460476
)
461477

462478
# Write dihedral coefficients
@@ -468,6 +484,7 @@ def write_lammpsdata(
468484
unit_style,
469485
use_rb_torsions,
470486
use_dihedrals,
487+
eng_unit_str,
471488
)
472489

473490
# Write improper coefficients
@@ -487,14 +504,14 @@ def write_lammpsdata(
487504
if atom_style == "atomic":
488505
atom_line = "{index:d}\t{type_index:d}\t{x:.6f}\t{y:.6f}\t{z:.6f}\n"
489506
elif atom_style == "charge":
490-
if unit_style == "real":
507+
if unit_style in ["real", "metal"]:
491508
atom_line = "{index:d}\t{type_index:d}\t{charge:.6f}\t{x:.6f}\t{y:.6f}\t{z:.6f}\n"
492509
elif unit_style == "lj":
493510
atom_line = "{index:d}\t{type_index:d}\t{charge:.4ef}\t{x:.6f}\t{y:.6f}\t{z:.6f}\n"
494511
elif atom_style == "molecular":
495512
atom_line = "{index:d}\t{zero:d}\t{type_index:d}\t{x:.6f}\t{y:.6f}\t{z:.6f}\n"
496513
elif atom_style == "full":
497-
if unit_style == "real":
514+
if unit_style in ["real", "metal"]:
498515
atom_line = "{index:d}\t{zero:d}\t{type_index:d}\t{charge:.6f}\t{x:.6f}\t{y:.6f}\t{z:.6f}\n"
499516
elif unit_style == "lj":
500517
atom_line = "{index:d}\t{zero:d}\t{type_index:d}\t{charge:.4e}\t{x:.6f}\t{y:.6f}\t{z:.6f}\n"
@@ -1167,6 +1184,7 @@ def _write_pair_information(
11671184
pair_coeff_label,
11681185
unit_style,
11691186
nbfix_in_data_file,
1187+
eng_unit_str,
11701188
):
11711189
"""Write nonbonded pair information to lammps data file."""
11721190
epsilons = (
@@ -1255,7 +1273,9 @@ def _write_pair_information(
12551273
else:
12561274
data.write("\nPairIJ Coeffs # modified lj\n")
12571275

1258-
data.write("# type1 type2\tepsilon (kcal/mol)\tsigma (Angstrom)\n")
1276+
data.write(
1277+
"# type1 type2\tepsilon (%s)\tsigma (Angstrom)\n" % eng_unit_str
1278+
)
12591279

12601280
for (type1, type2), (sigma, epsilon) in coeffs.items():
12611281
data.write(
@@ -1279,7 +1299,9 @@ def _write_pair_information(
12791299
"{}\t{:.5f}\t{:.5f}\n".format(idx, epsilon, sigma_dict[idx])
12801300
)
12811301
print("Copy these commands into your input script:\n")
1282-
print("# type1 type2\tepsilon (kcal/mol)\tsigma (Angstrom)\n")
1302+
print(
1303+
"# type1 type2\tepsilon (%s)\tsigma (Angstrom)\n" % eng_unit_str
1304+
)
12831305
for (type1, type2), (sigma, epsilon) in coeffs.items():
12841306
print(
12851307
"pair_coeff\t{0} \t{1} \t{2} \t\t{3} \t\t# {4} \t{5}".format(
@@ -1299,8 +1321,8 @@ def _write_pair_information(
12991321
else:
13001322
data.write("\nPair Coeffs # lj\n")
13011323

1302-
if unit_style == "real":
1303-
data.write("#\tepsilon (kcal/mol)\t\tsigma (Angstrom)\n")
1324+
if unit_style in ["real", "metal"]:
1325+
data.write("#\tepsilon (%s)\t\tsigma (Angstrom)\n" % eng_unit_str)
13041326
elif unit_style == "lj":
13051327
data.write("#\treduced_epsilon \t\treduced_sigma \n")
13061328
for idx, epsilon in sorted(epsilon_dict.items()):
@@ -1311,11 +1333,13 @@ def _write_pair_information(
13111333
)
13121334

13131335

1314-
def _write_bond_information(structure, data, unique_bond_types, unit_style):
1336+
def _write_bond_information(
1337+
structure, data, unique_bond_types, unit_style, eng_unit_str
1338+
):
13151339
"""Write Bond Coeffs section of lammps data file."""
13161340
data.write("\nBond Coeffs # harmonic\n")
1317-
if unit_style == "real":
1318-
data.write("#\tk(kcal/mol/angstrom^2)\t\treq(angstrom)\n")
1341+
if unit_style == "real" or unit_style == "metal":
1342+
data.write("#\tk(%s/angstrom^2)\t\treq(angstrom)\n" % eng_unit_str)
13191343
elif unit_style == "lj":
13201344
data.write("#\treduced_k\t\treduced_req\n")
13211345
sorted_bond_types = {
@@ -1335,7 +1359,12 @@ def _write_bond_information(structure, data, unique_bond_types, unit_style):
13351359

13361360

13371361
def _write_angle_information(
1338-
structure, data, unique_angle_types, use_urey_bradleys, unit_style
1362+
structure,
1363+
data,
1364+
unique_angle_types,
1365+
use_urey_bradleys,
1366+
unit_style,
1367+
eng_unit_str,
13391368
):
13401369
"""Write Angle Coeffs section of lammps data file."""
13411370
sorted_angle_types = {
@@ -1345,7 +1374,8 @@ def _write_angle_information(
13451374
if use_urey_bradleys:
13461375
data.write("\nAngle Coeffs # charmm\n")
13471376
data.write(
1348-
"#\tk(kcal/mol/rad^2)\t\ttheteq(deg)\tk(kcal/mol/angstrom^2)\treq(angstrom)\n"
1377+
"#\tk(%s/rad^2)\t\ttheteq(deg)\tk(%s/angstrom^2)\treq(angstrom)\n"
1378+
% (eng_unit_str, eng_unit_str)
13491379
)
13501380
for params, idx in sorted_angle_types.items():
13511381
data.write("{}\t{}\t{:.5f}\t{:.5f}\t{:.5f}\n".format(idx, *params))
@@ -1356,7 +1386,7 @@ def _write_angle_information(
13561386
if unit_style == "lj":
13571387
data.write("#\treduced_k\t\ttheteq(deg)\n")
13581388
else:
1359-
data.write("#\tk(kcal/mol/rad^2)\t\ttheteq(deg)\n")
1389+
data.write("#\tk(%s/rad^2)\t\ttheteq(deg)\n" % eng_unit_str)
13601390

13611391
for params, idx in sorted_angle_types.items():
13621392
data.write(
@@ -1378,6 +1408,7 @@ def _write_dihedral_information(
13781408
unit_style,
13791409
use_rb_torsions,
13801410
use_dihedrals,
1411+
eng_unit_str,
13811412
):
13821413
"""Write Dihedral Coeffs section of lammps data file."""
13831414
sorted_dihedral_types = {
@@ -1388,9 +1419,10 @@ def _write_dihedral_information(
13881419
}
13891420
if use_rb_torsions:
13901421
data.write("\nDihedral Coeffs # opls\n")
1391-
if unit_style == "real":
1422+
if unit_style == "real" or unit_style == "metal":
13921423
data.write(
1393-
"#\tf1(kcal/mol)\tf2(kcal/mol)\tf3(kcal/mol)\tf4(kcal/mol)\n"
1424+
"#\tf1(%s)\tf2(%s)\tf3(%s)\tf4(%s)\n"
1425+
% (eng_unit_str, eng_unit_str, eng_unit_str, eng_unit_str)
13941426
)
13951427
elif unit_style == "lj":
13961428
data.write("#\tf1\tf2\tf3\tf4 (all lj reduced units)\n")
@@ -1422,11 +1454,11 @@ def _write_dihedral_information(
14221454
data.write("#k, n, phi, weight\n")
14231455
for params, idx in sorted_dihedral_types.items():
14241456
data.write(
1425-
"{}\t{:.5f}\t{:d}\t{:.2f}\t{:.5f}\t# {}\t{}\t{}\t{}\n".format(
1457+
"{}\t{:.5f}\t{:d}\t{:d}\t{:.5f}\t# {}\t{}\t{}\t{}\n".format(
14261458
idx,
14271459
params[0],
14281460
params[1],
1429-
params[2],
1461+
int(params[2]),
14301462
params[3],
14311463
params[6],
14321464
params[7],

0 commit comments

Comments
 (0)