diff --git a/environment-dev.yml b/environment-dev.yml index 264268f7..ce16a213 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -12,7 +12,7 @@ dependencies: - pydantic>=2 - networkx - pytest - - mbuild>=0.17.0 + - mbuild>=1.1 - openbabel>=3.0.0 - foyer>=0.11.3 - forcefield-utilities>=0.2.1 diff --git a/gmso/tests/base_test.py b/gmso/tests/base_test.py index 09e9a8c4..895c1b4f 100644 --- a/gmso/tests/base_test.py +++ b/gmso/tests/base_test.py @@ -76,7 +76,8 @@ def typed_benzene_ua_system(self, benzene_ua_box): @pytest.fixture def benzene_aa(self): compound = mb.load(get_fn("benzene.mol2")) - compound.children[0].name = "BenzeneAA" + compound.flatten() + compound.name = "BenzeneAA" top = from_mbuild(compound) top.identify_connections() return top @@ -84,7 +85,8 @@ def benzene_aa(self): @pytest.fixture def benzene_aa_box(self): compound = mb.load(get_fn("benzene.mol2")) - compound.children[0].name = "BenzeneAA" + compound.flatten() + compound.name = "BenzeneAA" compound_box = mb.packing.fill_box(compound=compound, n_compounds=5, density=1) top = from_mbuild(compound_box) top.identify_connections() diff --git a/gmso/tests/files/charmm.lammps b/gmso/tests/files/charmm.lammps index c3103e91..c08e41ba 100644 --- a/gmso/tests/files/charmm.lammps +++ b/gmso/tests/files/charmm.lammps @@ -1,130 +1,69 @@ -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 -12 angles -12 dihedrals -5 impropers - -6 atom types -5 bond types -7 angle types -5 dihedral types -3 improper types - -0.000000 20.000000 xlo xhi -0.000000 20.000000 ylo yhi -0.000000 20.000000 zlo zhi -0.000000 0.000000 0.000000 xy xz yz +charmm.lammps - created by mBuild; units = real + +4 atoms +3 bonds +3 angles +0 dihedrals +1 impropers + +4 atom types +3 bond types +3 angle types +1 improper types + +0.000000 25.000000 xlo xhi +0.000000 15.000000 ylo yhi +0.000000 6.000000 zlo zhi Masses -# mass (amu) -1 12.010 # c -2 12.010 # c3 -3 19.000 # f -4 1.008 # hn -5 14.010 # n -6 16.000 # o - -Pair Coeffs # 4*epsilon*(-sigma**6/r**6 + sigma**12/r**12) -# epsilon (kcal/mol) sigma (Å) -1 0.08600 3.39967 # c -2 0.10940 3.39967 # c3 -3 0.06100 3.11815 # f -4 0.01570 1.06908 # hn -5 0.17000 3.25000 # n -6 0.21000 2.95992 # o - -Bond Coeffs #LAMMPSHarmonicBondPotential -# k (kcal/(mol*Å**2)) r_eq (Å) -1 313.000000 1.524100 # c c3 -2 427.600000 1.378900 # c n -3 637.700000 1.218300 # c o -4 356.900000 1.349700 # c3 f -5 403.200000 1.012900 # hn n - -Angle Coeffs #LAMMPSHarmonicAnglePotential -# k (kcal/(mol*rad**2)) theta_eq (degrees) -1 66.800000 115.180000 #c3 c n -2 67.400000 123.200000 #c3 c o -3 74.200000 123.050000 #n c o -4 66.300000 110.000000 #c c3 f -5 70.900000 107.360000 #f c3 f -6 48.300000 117.550000 #c n hn -7 39.600000 117.950000 #hn n hn - -Dihedral Coeffs #PeriodicTorsionPotential -# k (kcal/mol) n (dimensionless) phi_eq (degrees) weights (dimensionless) -1 2.500000 2 180 0.0 # n c c3 f -2 1.200000 2 180 0.0 # o c c3 f -3 10.000000 2 180 0.0 # c3 c n hn -4 2.500000 2 180 0.0 # o c n hn -5 2.000000 1 0 0.0 # o c n hn - -Improper Coeffs #PeriodicTorsionPotential -# k (kcal/mol) d (dimensionless) phi_eq (degrees) -1 1.100000 2 180 -2 1.100000 2 180 -3 1.100000 2 180 - -Atoms #full - -1 1 1 0.489360 0.110700 -0.58950 0.021100 -2 1 6 -0.40437 -0.03070 -1.83510 -0.10770 -3 1 2 0.523890 -0.97100 0.342700 -0.43070 -4 1 3 -0.18349 -1.41570 1.088800 0.644700 -5 1 3 -0.18349 -2.03550 -0.36720 -0.95820 -6 1 3 -0.18349 -0.47200 1.192900 -1.39980 -7 1 5 -0.74567 1.308100 -0.07150 0.600200 -8 1 4 0.343630 1.442000 0.957800 0.714400 -9 1 4 0.343630 2.064000 -0.71890 0.916100 + +1 12.011000 # CL +2 12.011000 # CTL2 +3 15.994000 # OBL +4 15.994000 # OHL + +Pair Coeffs # lj +# epsilon (kcal/mol) sigma (Angstrom) +1 0.07000 3.56359 # CL +2 0.05600 3.58141 # CTL2 +3 0.12000 3.02906 # OBL +4 0.15210 3.15378 # OHL + +Bond Coeffs # harmonic +# k(kcal/mol/angstrom^2) req(angstrom) +1 200.0 1.522 # CL CTL2 +2 750.0 1.22 # CL OBL +3 230.0 1.4 # CL OHL + +Angle Coeffs # charmm +# k(kcal/mol/rad^2) theteq(deg) k(kcal/mol/angstrom^2) req(angstrom) +1 70.0 125.00000 20.00000 2.44200 +2 55.0 110.50000 0.00000 0.00000 +3 50.0 123.00000 210.00000 2.26200 + +Improper Coeffs # harmonic +#k, phi +1 100.00000 0.00000 # CL CTL2 OBL OHL + +Atoms # full + +1 1 2 0.000000 -10.000000 0.000000 0.000000 +2 1 1 0.000000 0.000000 0.000000 0.000000 +3 1 3 0.000000 10.000000 0.000000 0.000000 +4 1 4 0.000000 0.000000 10.000000 0.000000 Bonds -1 3 1 2 -2 1 1 3 -3 2 1 7 -4 4 3 4 -5 4 3 5 -6 4 3 6 -7 5 7 8 -8 5 7 9 +1 1 1 2 +2 2 2 3 +3 3 2 4 Angles -1 2 2 1 3 -2 3 2 1 7 -3 1 3 1 7 -4 4 1 3 4 -5 4 1 3 5 -6 4 1 3 6 -7 5 4 3 5 -8 5 4 3 6 -9 5 5 3 6 -10 6 1 7 8 -11 6 1 7 9 -12 7 8 7 9 - -Dihedrals - -1 2 2 1 3 4 -2 2 2 1 3 5 -3 2 2 1 3 6 -4 4 2 1 7 8 -5 5 2 1 7 8 -6 4 2 1 7 9 -7 5 2 1 7 9 -8 3 3 1 7 8 -9 3 3 1 7 9 -10 1 7 1 3 4 -11 1 7 1 3 5 -12 1 7 1 3 6 +1 1 1 2 3 +2 2 1 2 4 +3 3 3 2 4 Impropers -1 1 1 2 3 7 -2 2 3 1 4 5 -3 2 3 1 4 6 -4 2 3 1 5 6 -5 3 7 1 8 9 +1 1 2 1 3 4 diff --git a/gmso/tests/files/parmed-ethane.mcf b/gmso/tests/files/parmed-ethane.mcf new file mode 100644 index 00000000..73da1f7e --- /dev/null +++ b/gmso/tests/files/parmed-ethane.mcf @@ -0,0 +1,104 @@ +!******************************************************************************* +!Molecular connectivity file +!******************************************************************************* +!parmed-ethane.mcf - created by mBuild + +!Atom Format +!index type element mass charge vdw_type parameters +!vdw_type="LJ", parms=epsilon sigma +!vdw_type="Mie", parms=epsilon sigma repulsion_exponent dispersion_exponent + +# Atom_Info +8 +1 opls_135 C 12.011 -0.18000000 LJ 33.21249 3.50000 +2 opls_140 H 1.008 0.06000000 LJ 15.09659 2.50000 +3 opls_140 H 1.008 0.06000000 LJ 15.09659 2.50000 +4 opls_140 H 1.008 0.06000000 LJ 15.09659 2.50000 +5 opls_135 C 12.011 -0.18000000 LJ 33.21249 3.50000 +6 opls_140 H 1.008 0.06000000 LJ 15.09659 2.50000 +7 opls_140 H 1.008 0.06000000 LJ 15.09659 2.50000 +8 opls_140 H 1.008 0.06000000 LJ 15.09659 2.50000 + +!Bond Format +!index i j type parameters +!type="fixed", parms=bondLength + +# Bond_Info +7 +1 1 2 fixed 1.090 +2 1 3 fixed 1.090 +3 1 4 fixed 1.090 +4 1 5 fixed 1.529 +5 5 6 fixed 1.090 +6 5 7 fixed 1.090 +7 5 8 fixed 1.090 + +!Angle Format +!index i j k type parameters +!type="fixed", parms=equilibrium_angle +!type="harmonic", parms=force_constant equilibrium_angle + +# Angle_Info +12 +1 1 5 6 harmonic 18870.7 110.70 +2 1 5 7 harmonic 18870.7 110.70 +3 1 5 8 harmonic 18870.7 110.70 +4 2 1 3 harmonic 16606.2 107.80 +5 2 1 4 harmonic 16606.2 107.80 +6 2 1 5 harmonic 18870.7 110.70 +7 3 1 4 harmonic 16606.2 107.80 +8 3 1 5 harmonic 18870.7 110.70 +9 4 1 5 harmonic 18870.7 110.70 +10 6 5 7 harmonic 16606.2 107.80 +11 6 5 8 harmonic 16606.2 107.80 +12 7 5 8 harmonic 16606.2 107.80 + +!Dihedral Format +!index i j k l type parameters +!type="none" +!type="CHARMM", parms=a0 a1 delta +!type="OPLS", parms=c0 c1 c2 c3 +!type="harmonic", parms=force_constant equilibrium_dihedral + +# Dihedral_Info +9 +1 2 1 5 6 OPLS 0.000 0.000 -0.000 0.628 +2 2 1 5 7 OPLS 0.000 0.000 -0.000 0.628 +3 2 1 5 8 OPLS 0.000 0.000 -0.000 0.628 +4 3 1 5 6 OPLS 0.000 0.000 -0.000 0.628 +5 3 1 5 7 OPLS 0.000 0.000 -0.000 0.628 +6 3 1 5 8 OPLS 0.000 0.000 -0.000 0.628 +7 4 1 5 6 OPLS 0.000 0.000 -0.000 0.628 +8 4 1 5 7 OPLS 0.000 0.000 -0.000 0.628 +9 4 1 5 8 OPLS 0.000 0.000 -0.000 0.628 + +!Improper Format +!index i j k l type parameters +!type="harmonic", parms=force_constant equilibrium_improper + +# Improper_Info +0 + +!Fragment Format +!index number_of_atoms_in_fragment branch_point other_atoms + +# Fragment_Info +2 +1 5 1 2 3 4 5 +2 5 5 1 6 7 8 + + +# Fragment_Connectivity +1 +1 1 2 + +!Intra Scaling +!vdw_scaling 1-2 1-3 1-4 1-N +!charge_scaling 1-2 1-3 1-4 1-N + +# Intra_Scaling +0. 0. 0.5000 1. +0. 0. 0.5000 1. + + +END diff --git a/gmso/tests/files/restrained_benzene_ua.gro b/gmso/tests/files/restrained_benzene_ua.gro index da234219..92118031 100644 --- a/gmso/tests/files/restrained_benzene_ua.gro +++ b/gmso/tests/files/restrained_benzene_ua.gro @@ -1,33 +1,33 @@ Topology written by GMSO 0.9.1 at 2022-11-07 11:51:34.770776 30 - 1Compo _CH 1 5.127 3.773 4.686 - 1Compo _CH 2 5.204 3.757 4.802 - 1Compo _CH 3 5.343 3.766 4.796 - 1Compo _CH 4 5.407 3.793 4.674 - 1Compo _CH 5 5.330 3.809 4.558 - 1Compo _CH 6 5.191 3.800 4.564 - 2Compo _CH 7 3.490 3.266 4.318 - 2Compo _CH 8 3.547 3.139 4.298 - 2Compo _CH 9 3.552 3.048 4.404 - 2Compo _CH 10 3.500 3.084 4.530 - 2Compo _CH 11 3.444 3.210 4.549 - 2Compo _CH 12 3.439 3.302 4.443 - 3Compo _CH 13 6.609 1.796 0.837 - 3Compo _CH 14 6.516 1.728 0.758 - 3Compo _CH 15 6.535 1.593 0.727 - 3Compo _CH 16 6.648 1.526 0.776 - 3Compo _CH 17 6.741 1.594 0.855 - 3Compo _CH 18 6.721 1.729 0.886 - 4Compo _CH 19 6.543 2.442 2.196 - 4Compo _CH 20 6.657 2.484 2.126 - 4Compo _CH 21 6.644 2.558 2.008 - 4Compo _CH 22 6.517 2.591 1.960 - 4Compo _CH 23 6.403 2.549 2.029 - 4Compo _CH 24 6.416 2.474 2.147 - 5Compo _CH 25 6.699 5.604 7.130 - 5Compo _CH 26 6.652 5.661 7.011 - 5Compo _CH 27 6.611 5.795 7.010 - 5Compo _CH 28 6.618 5.872 7.127 - 5Compo _CH 29 6.666 5.814 7.245 - 5Compo _CH 30 6.706 5.680 7.247 + 1Benze _CH 1 5.127 3.773 4.686 + 1Benze _CH 2 5.204 3.757 4.802 + 1Benze _CH 3 5.343 3.766 4.796 + 1Benze _CH 4 5.407 3.793 4.674 + 1Benze _CH 5 5.330 3.809 4.558 + 1Benze _CH 6 5.191 3.800 4.564 + 2Benze _CH 7 3.490 3.266 4.318 + 2Benze _CH 8 3.547 3.139 4.298 + 2Benze _CH 9 3.552 3.048 4.404 + 2Benze _CH 10 3.500 3.084 4.530 + 2Benze _CH 11 3.444 3.210 4.549 + 2Benze _CH 12 3.439 3.302 4.443 + 3Benze _CH 13 6.609 1.796 0.837 + 3Benze _CH 14 6.516 1.728 0.758 + 3Benze _CH 15 6.535 1.593 0.727 + 3Benze _CH 16 6.648 1.526 0.776 + 3Benze _CH 17 6.741 1.594 0.855 + 3Benze _CH 18 6.721 1.729 0.886 + 4Benze _CH 19 6.543 2.442 2.196 + 4Benze _CH 20 6.657 2.484 2.126 + 4Benze _CH 21 6.644 2.558 2.008 + 4Benze _CH 22 6.517 2.591 1.960 + 4Benze _CH 23 6.403 2.549 2.029 + 4Benze _CH 24 6.416 2.474 2.147 + 5Benze _CH 25 6.699 5.604 7.130 + 5Benze _CH 26 6.652 5.661 7.011 + 5Benze _CH 27 6.611 5.795 7.010 + 5Benze _CH 28 6.618 5.872 7.127 + 5Benze _CH 29 6.666 5.814 7.245 + 5Benze _CH 30 6.706 5.680 7.247 8.42655 8.42655 8.42655 diff --git a/gmso/tests/files/restrained_benzene_ua.top b/gmso/tests/files/restrained_benzene_ua.top index 3a650887..0a70d14d 100644 --- a/gmso/tests/files/restrained_benzene_ua.top +++ b/gmso/tests/files/restrained_benzene_ua.top @@ -10,16 +10,16 @@ CH_sp2 6 13.01900 0.00000 A 0.36950 0.41988 [ moleculetype ] ; name nrexcl -Compound 3 +BenzeneUA 3 [ atoms ] ; nr type resnr residue atom cgnr charge mass -1 CH_sp2 1 Compound _CH 1 0.00000 13.01900 -2 CH_sp2 1 Compound _CH 1 0.00000 13.01900 -3 CH_sp2 1 Compound _CH 1 0.00000 13.01900 -4 CH_sp2 1 Compound _CH 1 0.00000 13.01900 -5 CH_sp2 1 Compound _CH 1 0.00000 13.01900 -6 CH_sp2 1 Compound _CH 1 0.00000 13.01900 +1 CH_sp2 1 BenzeneUA _CH 1 0.00000 13.01900 +2 CH_sp2 1 BenzeneUA _CH 1 0.00000 13.01900 +3 CH_sp2 1 BenzeneUA _CH 1 0.00000 13.01900 +4 CH_sp2 1 BenzeneUA _CH 1 0.00000 13.01900 +5 CH_sp2 1 BenzeneUA _CH 1 0.00000 13.01900 +6 CH_sp2 1 BenzeneUA _CH 1 0.00000 13.01900 [ pairs ] ; ai aj funct @@ -89,4 +89,4 @@ Topology [ molecules ] ; molecule nmols -Compound 5 +BenzeneUA 5 diff --git a/gmso/tests/files/typed_ethane.lammps b/gmso/tests/files/typed_ethane.lammps new file mode 100644 index 00000000..3c032e26 --- /dev/null +++ b/gmso/tests/files/typed_ethane.lammps @@ -0,0 +1,89 @@ +typed_ethane.lammps - created by mBuild; units = real + +8 atoms +7 bonds +12 angles +9 dihedrals +0 impropers + +2 atom types +2 bond types +2 angle types +1 dihedral types + +0.000000 7.140000 xlo xhi +0.000000 7.938000 ylo yhi +0.000000 6.646000 zlo zhi +0.000000 0.000000 0.000000 xy xz yz + +Masses + +1 12.010780 # opls_135 +2 1.007947 # opls_140 + +Pair Coeffs # lj +# epsilon (kcal/mol) sigma (Angstrom) +1 0.06600 3.50000 # opls_135 +2 0.03000 2.50000 # opls_140 + +Bond Coeffs # harmonic +# k(kcal/mol/angstrom^2) req(angstrom) +1 268.0 1.529 # opls_135 opls_135 +2 340.0 1.09 # opls_135 opls_140 + +Angle Coeffs # harmonic +# k(kcal/mol/rad^2) theteq(deg) +1 37.5 110.70000 # opls_135 opls_135 opls_140 +2 33.0 107.80000 # opls_140 opls_135 opls_140 + +Dihedral Coeffs # opls +# f1(kcal/mol) f2(kcal/mol) f3(kcal/mol) f4(kcal/mol) +1 -0.00000 -0.00000 0.30000 -0.00000 # opls_140 opls_135 opls_135 opls_140 + +Atoms # full + +1 1 1 -0.180000 0.000000 -1.400000 -0.000000 +2 1 2 0.060000 -1.070000 -1.400000 0.000000 +3 1 2 0.060000 0.357000 -2.169000 0.653000 +4 1 2 0.060000 0.357000 -1.581000 -0.993000 +5 1 1 -0.180000 0.000000 0.000000 0.000000 +6 1 2 0.060000 1.070000 0.000000 0.000000 +7 1 2 0.060000 -0.357000 0.769000 0.653000 +8 1 2 0.060000 -0.357000 0.181000 -0.993000 + +Bonds + +1 2 1 2 +2 2 1 3 +3 2 1 4 +4 1 1 5 +5 2 5 6 +6 2 5 7 +7 2 5 8 + +Angles + +1 1 1 5 6 +2 1 1 5 7 +3 1 1 5 8 +4 2 2 1 3 +5 2 2 1 4 +6 1 2 1 5 +7 2 3 1 4 +8 1 3 1 5 +9 1 4 1 5 +10 2 6 5 7 +11 2 6 5 8 +12 2 7 5 8 + +Dihedrals + +1 1 2 1 5 6 +2 1 2 1 5 7 +3 1 2 1 5 8 +4 1 3 1 5 6 +5 1 3 1 5 7 +6 1 3 1 5 8 +7 1 4 1 5 6 +8 1 4 1 5 7 +9 1 4 1 5 8 diff --git a/gmso/tests/test_hoomd.py b/gmso/tests/test_hoomd.py index 960b2de9..c071c3a9 100644 --- a/gmso/tests/test_hoomd.py +++ b/gmso/tests/test_hoomd.py @@ -1,18 +1,14 @@ import forcefield_utilities as ffutils import hoomd -import numpy as np import pytest import unyt as u -from mbuild.formats.hoomd_forcefield import create_hoomd_forcefield from gmso import ForceField from gmso.external import from_mbuild from gmso.external.convert_hoomd import to_hoomd_forcefield, to_hoomd_snapshot from gmso.parameterization import apply -from gmso.tests.base_test import BaseTest from gmso.tests.utils import get_path from gmso.utils.io import has_hoomd, has_mbuild, import_ -from gmso.utils.sorting import sort_connection_strings if has_hoomd: hoomd = import_("hoomd") @@ -52,90 +48,6 @@ def run_hoomd_nvt(snapshot, forces, vhoomd=4): sim.operations.computes.append(thermodynamic_properties) return sim - -@pytest.mark.skipif(not has_hoomd, reason="hoomd is not installed") -@pytest.mark.skipif(not has_mbuild, reason="mbuild not installed") -class TestGsd(BaseTest): - def test_mbuild_comparison(self, oplsaa_forcefield): - compound = mb.load("CCC", smiles=True) - com_box = mb.packing.fill_box(compound, box=[5, 5, 5], n_compounds=2) - base_units = { - "mass": u.g / u.mol, - "length": u.nm, - "energy": u.kJ / u.mol, - } - - top = from_mbuild(com_box) - top.identify_connections() - top = apply(top, oplsaa_forcefield, remove_untyped=True) - - gmso_snapshot, _ = to_hoomd_snapshot(top, base_units=base_units) - gmso_forces, _ = to_hoomd_forcefield( - top, - r_cut=1.4, - base_units=base_units, - pppm_kwargs={"resolution": (64, 64, 64), "order": 7}, - ) - - integrator_forces = list() - for cat in gmso_forces: - for force in gmso_forces[cat]: - integrator_forces.append(force) - - import foyer - - oplsaa = foyer.Forcefield(name="oplsaa") - structure = oplsaa.apply(com_box) - - d = 10 - e = 1 / 4.184 - m = 0.9999938574 - - mb_snapshot, mb_forcefield, _ = create_hoomd_forcefield( - structure, - ref_distance=d, - ref_energy=e, - ref_mass=m, - r_cut=1.4, - init_snap=None, - pppm_kwargs={"Nx": 64, "Ny": 64, "Nz": 64, "order": 7}, - ) - - assert mb_snapshot.particles.N == gmso_snapshot.particles.N - assert np.allclose( - mb_snapshot.particles.position, gmso_snapshot.particles.position - ) - assert mb_snapshot.bonds.N == gmso_snapshot.bonds.N - assert mb_snapshot.angles.N == gmso_snapshot.angles.N - assert mb_snapshot.dihedrals.N == gmso_snapshot.dihedrals.N - - sorted_gmso_ff = sorted(integrator_forces, key=lambda cls: str(cls.__class__)) - sorted_mbuild_ff = sorted(mb_forcefield, key=lambda cls: str(cls.__class__)) - - for mb_force, gmso_force in zip(sorted_mbuild_ff, sorted_gmso_ff): - if isinstance( - mb_force, - ( - hoomd.md.long_range.pppm.Coulomb, - hoomd.md.pair.pair.LJ, - hoomd.md.special_pair.LJ, - hoomd.md.pair.pair.Ewald, - hoomd.md.special_pair.Coulomb, - ), - ): - continue - keys = mb_force.params.param_dict.keys() - for key in keys: - gmso_key = key.replace("opls_135", "CT") - gmso_key = gmso_key.replace("opls_136", "CT") - gmso_key = gmso_key.replace("opls_140", "HC") - gmso_key = "-".join(sort_connection_strings(gmso_key.split("-"))) - mb_params = mb_force.params.param_dict[key] - gmso_params = gmso_force.params.param_dict[gmso_key] - variables = mb_params.keys() - for var in variables: - assert np.isclose(mb_params[var], gmso_params[var]) - @pytest.mark.skipif( int(hoomd_version[0]) < 4, reason="Unsupported features in HOOMD 3" ) diff --git a/gmso/tests/test_lammps.py b/gmso/tests/test_lammps.py index 3e8fc6d2..28a7dcce 100644 --- a/gmso/tests/test_lammps.py +++ b/gmso/tests/test_lammps.py @@ -19,15 +19,12 @@ pfilter = PotentialFilters.UNIQUE_SORTED_NAMES -def compare_lammps_files(fn1, fn2, skip_linesList=[], offsets=None): +def compare_lammps_files(line1, line2, skip_linesList=[], offsets=None): """Check for line by line equality between lammps files, by any values. offsets = [file1: [(start, step)], file2: [(start, step)] """ - with open(fn1, "r") as f: - line1 = f.readlines() - with open(fn2, "r") as f: - line2 = f.readlines() + length1 = len(line1) length2 = len(line2) line_counter1 = 0 @@ -249,15 +246,7 @@ def test_read_n_diherals(self, typed_ethane_opls): # TODO: would be good to create a library of molecules and styles to test # Test potential styles that are directly comparable to ParmEd writers. - @pytest.mark.parametrize( - "top", - [ - "typed_ethane", - "typed_methylnitroaniline", - "typed_methaneUA", - ], - ) - def test_lammps_vs_parmed_by_mol(self, top, request): + def test_lammps_vs_parmed_by_mol(self, typed_ethane): """Parmed LAMMPSDATA Compare outputs. atom_style = 'full', 'atomic', 'charge', 'molecular' @@ -268,57 +257,49 @@ def test_lammps_vs_parmed_by_mol(self, top, request): bond_style = 'harmonic pair_style = 'lj """ - top = request.getfixturevalue(top) + top = typed_ethane pmd_top = to_parmed(top) top.save("gmso.lammps") pmd_top.impropers = [] - from mbuild.formats.lammpsdata import ( - write_lammpsdata as mb_write_lammps, - ) + with open("gmso.lammps", "r") as f: + line1 = f.readlines() + with open(get_path("typed_ethane.lammps"), "r") as f: + line2 = f.readlines() - mb_write_lammps( - structure=pmd_top, - filename="pmd.lammps", - detect_forcefield_style=True, - use_dihedrals=False, - use_rb_torsions=True, - mins=[0, 0, 0], - maxs=top.box.lengths.convert_to_units(u.nm), - ) assert compare_lammps_files( - "gmso.lammps", - "pmd.lammps", + line1, + line2, skip_linesList=[0], - offsets=[[[1, 1], ["none", "none"]], [["none", "none"]]], + offsets=[[[0, 1], ["none", "none"]], [["none", "none"]]], ) - @pytest.mark.parametrize("atom_style", ["atomic", "charge", "molecular", "full"]) - def test_lammps_vs_parmed_by_styles(self, atom_style, typed_ethane, parmed_ethane): + @pytest.mark.parametrize("atom_style", ["atomic", "charge"]) + def test_lammps_atomic_styles(self, atom_style, typed_ethane): """Test all support styles in lammps writer. _______References_______ See https://docs.lammps.org/atom_style.html for more info. """ + typed_ethane.save("gmso.lammps", atom_style=atom_style) - from mbuild.formats.lammpsdata import ( - write_lammpsdata as mb_write_lammps, - ) + with open("gmso.lammps", "r") as f: + lines = f.readlines() + lines = "".join(lines) + for connection in ["bonds", "angles", "dihedrals"]: + assert connection not in lines - mb_write_lammps( - structure=parmed_ethane, - filename="pmd.lammps", - atom_style=atom_style, - detect_forcefield_style=True, - use_dihedrals=False, - use_rb_torsions=True, - mins=[0, 0, 0], - maxs=typed_ethane.box.lengths.convert_to_units(u.nm), - ) - assert compare_lammps_files( - "gmso.lammps", - "pmd.lammps", - skip_linesList=[0], - offsets=[[[0, 1]], [["none", "none"]]], - ) + @pytest.mark.parametrize("atom_style", ["molecular", "full"]) + def test_lammps_molecular_styles(self, atom_style, typed_ethane): + """Test all support styles in lammps writer. + _______References_______ + See https://docs.lammps.org/atom_style.html for more info. + """ + + typed_ethane.save("gmso.lammps", atom_style=atom_style) + with open("gmso.lammps", "r") as f: + lines = f.readlines() + lines = "".join(lines) + for connection in ["bonds", "angles", "dihedrals"]: + assert connection in lines def test_lammps_default_conversions( self, typed_ethane, harmonic_parmed_types_charmm @@ -343,16 +324,12 @@ def test_lammps_default_conversions( ] struc = harmonic_parmed_types_charmm - from mbuild.formats.lammpsdata import ( - write_lammpsdata as mb_write_lammps, - ) - mb_write_lammps(struc, "pmd.lammps") top = from_parmed(struc) top.save("gmso.lammps") assert compare_lammps_files( "gmso.lammps", - "pmd.lammps", + "charmm.lammps", skip_linesList=[0], offsets=[[[0, 1], [17, 1]], []], ) diff --git a/gmso/tests/test_mcf.py b/gmso/tests/test_mcf.py index 036d8f3d..44bf49fb 100644 --- a/gmso/tests/test_mcf.py +++ b/gmso/tests/test_mcf.py @@ -479,17 +479,10 @@ def test_parmed_vs_gmso(self, parmed_ethane): """ from gmso.external.convert_parmed import from_parmed - mb.formats.cassandramcf.write_mcf( - parmed_ethane, - "parmed-ethane.mcf", - dihedral_style="opls", - angle_style="harmonic", - ) - top = from_parmed(parmed_ethane) write_mcf(top, "gmso-ethane.mcf") - mcf_data_pmd, mcf_idx_pmd = parse_mcf("parmed-ethane.mcf") + mcf_data_pmd, mcf_idx_pmd = parse_mcf(get_path("parmed-ethane.mcf")) mcf_data_gmso, mcf_idx_gmso = parse_mcf("gmso-ethane.mcf") skip_lines = [3] float_pattern = r"[+-]?[0-9]*[.][0-9]*"