Skip to content

Commit

Permalink
Reorder lammps layered dihedrals, and accurately count duplicated dih…
Browse files Browse the repository at this point in the history
…edrals in the header n_dihedrals for dihedrals that are counted twice due to multiple layers of the dihedral
  • Loading branch information
CalCraven committed Jan 16, 2024
1 parent f0f3cb9 commit b6a91ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
6 changes: 2 additions & 4 deletions gmso/formats/lammpsdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
from gmso.utils.units import LAMMPS_UnitSystems, write_out_parameter_and_units


# TODO: impropers have to read multiple terms for each improper
# TODO: speed up this function to handle 500000 atoms
# TODO: make every parameter source identify styles
# TODO: Write in header of each potential type any conversions that happened
# TODO: write in file header the source of the xml
@saves_as(".lammps", ".lammpsdata", ".data")
Expand Down Expand Up @@ -725,10 +722,11 @@ def _validate_unit_compatibility(top, base_unyts):
def _write_header(out_file, top, atom_style, dihedral_parser):
"""Write Lammps file header."""
out_file.write(
"{} written by {} at {} using the GMSO LAMMPS Writer\n\n".format(
"{} written by {} at {} using the GMSO LAMMPS Writer\nUsing Forcefield {}\n\n".format(
os.environ.get("USER"),
top.name if top.name is not None else "",
str(datetime.datetime.now()),
top.get_forcefield().name,
)
)
out_file.write("{:d} atoms\n".format(top.n_sites))
Expand Down
1 change: 1 addition & 0 deletions gmso/tests/files/charmm.lammps
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
calcraven written by Topology at 2023-12-07 19:10:26.697824 using the GMSO LAMMPS Writer
Using Forcefield Topology_ForceField

9 atoms
8 bonds
Expand Down
14 changes: 10 additions & 4 deletions gmso/tests/test_lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ def compare_lammps_files(fn1, fn2, skip_linesList=[], offsets=None):
line_counter2 = 0
while True:
# check for offsets
if offsets:
if offsets[0][0][0] == line_counter1:
if offsets is not None:
if len(offsets[0]) == 0:
pass
elif offsets[0][0][0] == line_counter1:
line_counter1 += offsets[0][0][1]
offsets[0].pop(0)
if len(offsets[1]) == 0:
pass
elif offsets[1][0][0] == line_counter2:
line_counter2 += offsets[1][0][1]
offsets[1].pop(0)
Expand Down Expand Up @@ -294,6 +298,7 @@ def test_lammps_vs_parmed_by_mol(self, top, request):
"gmso.lammps",
"pmd.lammps",
skip_linesList=[0],
offsets=[[[1, 1], ["none", "none"]], [["none", "none"]]],
)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -325,6 +330,7 @@ def test_lammps_vs_parmed_by_styles(
"gmso.lammps",
"pmd.lammps",
skip_linesList=[0],
offsets=[[[0, 1]], [["none", "none"]]],
)

def test_lammps_default_conversions(
Expand All @@ -343,7 +349,7 @@ def test_lammps_default_conversions(
typed_ethane.save("opls.lammps")
with open("opls.lammps", "r") as f:
lines = f.readlines()
assert lines[38:41] == [
assert lines[39:42] == [
"Dihedral Coeffs #OPLSTorsionPotential\n",
"#\tk1 (kcal/mol)\tk2 (kcal/mol)\tk3 (kcal/mol)\tk4 (kcal/mol)\n",
"1\t0.000000\t-0.000000\t0.300000\t-0.000000\t# opls_140\topls_135\topls_135\topls_140\n",
Expand All @@ -361,7 +367,7 @@ def test_lammps_default_conversions(
"gmso.lammps",
"pmd.lammps",
skip_linesList=[0],
offsets=[[[16, 1], ["none", "none"]], [["none", "none"]]],
offsets=[[[0, 1], [17, 1]], []],
)
out_lammps = open("gmso.lammps", "r").readlines()
found_impropers = False
Expand Down

0 comments on commit b6a91ed

Please sign in to comment.