Skip to content

Commit

Permalink
Remove deprecated formats, update reader and writer backends (#1191)
Browse files Browse the repository at this point in the history
* remove hoomdxml

* remove protobuf

* remove hoomd3 force writers

* change backend for mol2 and xyz to gmso

* remove protobuf from dev environments

* add some TODO notes

* change behavior of xyz test

* comment out test for elements

* fix test based on expected behavior for xyz files, remove wrong n atoms tests, that is being tested for in GMSO test_xyz.py

* remove lammpsdata and tests

* remove duplicate benzene fixture that reads benzene from a mol2 file

* update benzene naming to fix failing rigid tests

* add hoomd_writer file that has GSD and snapshot writer

* fix typo

* add else statement

* move to_hoomdsnapshot to conversion, add method in Compound class. Delete old snapshot and gsd writers

* fix import

* remove hoomd writer file, add TODO flags to conversion

* add TODO notes, pass in overwrite to Topology.save(), comment out file formats that require typed systems

* remove tests for gsd, hoomd, cassandra and par writers, move tests for loading xys into test_compound

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add check for charges back in save method

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* add if statement before checking charge is neutral

* remove .top from unit test

* remove lammps and lammpsdata files from tests and support in conversion.py

* Don't use gmso mol2 backend

* remove gmso as backend for mol2 saver

* remove Hoomd V3 test from CI

* remove par writer and xyz reader/write

* pin gmso to latest ver in window env file

* add has_hoomd back to io.py, handle tests that use hoomd via gmso

* fix syntax

* remove unused import

* update doc strings with new links, correct file types and methods

* add saver mapping to compound.save doc strings

---------

Co-authored-by: CalCraven <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 26, 2024
1 parent c79a58e commit aabbab6
Show file tree
Hide file tree
Showing 25 changed files with 241 additions and 6,886 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ jobs:
- name: Test (OS -> ${{ matrix.os }} / Python -> ${{ matrix.python-version }})
run: python -m pytest -v --cov=mbuild --cov-report=xml --cov-append --cov-config=setup.cfg --color yes --pyargs mbuild

- name: Tests for HOOMD-blue (V3)
run: |
micromamba install -c conda-forge "hoomd>3"
python -m pytest -v --cov=mbuild --cov-report=xml --cov-append --cov-config=setup.cfg --color yes mbuild/tests/test_hoomd.py
if: runner.os == 'Linux'

- name: Upload Coverage Report
uses: codecov/codecov-action@v4
with:
Expand Down
3 changes: 1 addition & 2 deletions environment-dev-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- bump2version
- codecov
- ele
- gmso>=0.9.0
- gmso>=0.12.4
- foyer>=0.11.0
- garnett>=0.7.1
- gsd>=2.9
Expand All @@ -20,7 +20,6 @@ dependencies:
- parmed>=3.4.3
- pip
- pre-commit
- protobuf
- py3Dmol
- pycifrw
- pytest
Expand Down
1 change: 0 additions & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ dependencies:
- parmed>=3.4.3
- pip
- pre-commit
- protobuf
- py3Dmol
- pycifrw
- pytest
Expand Down
111 changes: 39 additions & 72 deletions mbuild/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,6 @@ def _visualize_py3dmol(
os.path.join(tmp_dir, "tmp.mol2"),
include_ports=show_ports,
overwrite=True,
parmed_kwargs={"infer_residues": False},
)

view = py3Dmol.view()
Expand Down Expand Up @@ -2979,15 +2978,9 @@ def save(
self,
filename,
include_ports=False,
forcefield_name=None,
forcefield_files=None,
forcefield_debug=False,
box=None,
overwrite=False,
residues=None,
combining_rule="lorentz",
foyer_kwargs=None,
parmed_kwargs=None,
**kwargs,
):
"""Save the Compound to a file.
Expand All @@ -2997,22 +2990,11 @@ def save(
filename : str
Filesystem path in which to save the trajectory. The extension or
prefix will be parsed and control the format. Supported extensions:
'hoomdxml', 'gsd', 'gro', 'top', 'lammps', 'lmp', 'mcf', 'pdb', 'xyz',
'json', 'mol2', 'sdf', 'psf'. See parmed/structure.py for more
information on savers.
'gsd', 'gro', 'top', 'mcf', 'pdb', 'xyz',
'json', 'mol2', 'sdf', 'psf'. See `mbuild.conversion.save()`
for more information about writer methods.
include_ports : bool, optional, default=False
Save ports contained within the compound.
forcefield_files : str, optional, default=None
Apply a forcefield to the output file using a forcefield provided
by the `foyer` package.
forcefield_name : str, optional, default=None
Apply a named forcefield to the output file using the `foyer`
package, e.g. 'oplsaa'. `Foyer forcefields
<https://github.com/mosdef-hub/foyer/tree/master/foyer/forcefields>`_
forcefield_debug : bool, optional, default=False
Choose verbosity level when applying a forcefield through `foyer`.
Specifically, when missing atom types in the forcefield xml file,
determine if the warning is condensed or verbose.
box : mb.Box, optional, default=self.boundingbox (with buffer)
Box information to be written to the output file. If 'None', a
bounding box is used with 0.25nm buffers at each face to avoid
Expand All @@ -3022,50 +3004,25 @@ def save(
residues : str of list of str
Labels of residues in the Compound. Residues are assigned by
checking against Compound.name.
combining_rule : str, optional, default='lorentz'
Specify the combining rule for nonbonded interactions. Only relevant
when the `foyer` package is used to apply a forcefield. Valid
options are 'lorentz' and 'geometric', specifying Lorentz-Berthelot
and geometric combining rules respectively.
foyer_kwargs : dict, optional, default=None
Keyword arguments to provide to `foyer.Forcefield.apply`.
Depending on the file extension these will be passed to either
`write_gsd`, `write_hoomdxml`, `write_lammpsdata`,
`write_mcf`, or `parmed.Structure.save`.
See `parmed structure documentation
<https://parmed.github.io/ParmEd/html/structobj/parmed.structure.Structure.html#parmed.structure.Structure.save>`_
parmed_kwargs : dict, optional, default=None
Keyword arguments to provide to :meth:`mbuild.Compound.to_parmed`
**kwargs
See `mbuild.conversion.save()`.
Depending on the file extension these will be passed to either
`write_gsd`, `write_hoomdxml`, `write_lammpsdata`, `write_mcf`, or
`parmed.Structure.save`.
Parmed or GMSO backend writers
See https://parmed.github.io/ParmEd/html/structobj/parmed.structure.
Structure.html#parmed.structure.Structure.save
Structure.html#parmed.structure.Structure.save and
https://github.com/mosdef-hub/gmso/tree/main/gmso/formats
Other Parameters
----------------
ref_distance : float, optional, default=1.0
Normalization factor used when saving to .gsd and .hoomdxml formats
Normalization factor used when saving to the .gsd format
for converting distance values to reduced units.
ref_energy : float, optional, default=1.0
Normalization factor used when saving to .gsd and .hoomdxml formats
Normalization factor used when saving to the .gsd format
for converting energy values to reduced units.
ref_mass : float, optional, default=1.0
Normalization factor used when saving to .gsd and .hoomdxml formats
Normalization factor used when saving to the .gsd format
for converting mass values to reduced units.
atom_style: str, default='full'
Defines the style of atoms to be saved in a LAMMPS data file. The
following atom styles are currently supported:
'full', 'atomic', 'charge', 'molecular'
See `LAMMPS atom style documentation
<https://lammps.sandia.gov/doc/atom_style.html>`_ for more
information.
unit_style: str, default='real'
Defines to unit style to be save in a LAMMPS data file. Defaults
to 'real' units. Current styles are supported: 'real', 'lj'. See
`LAMMPS unit style documentation_
<https://lammps.sandia.gov/doc/units.html>`_ for more information.
Notes
-----
Expand All @@ -3074,29 +3031,24 @@ def save(
* filename
* include_ports
The savers used for each supported file type are:
GMSO: .gro, .gsd, .data, .xyz, .mcf, .top
Parmed: .mol2, .pdb, .prmtop, .cif, .crd
PyBel: .sdf
See Also
--------
conversion.save : Main saver logic
formats.gsdwrite.write_gsd : Write to GSD format
formats.hoomdxml.write_hoomdxml : Write to Hoomd XML format
formats.xyzwriter.write_xyz : Write to XYZ format
formats.lammpsdata.write_lammpsdata : Write to LAMMPS data format
formats.cassandramcf.write_mcf : Write to Cassandra MCF format
formats.json_formats.compound_to_json : Write to a json file
mbuild.conversion.save : Main saver logic
mbuild.formats.cassandramcf.write_mcf : Write to Cassandra MCF format
mbuild.formats.json_formats.compound_to_json : Write to a json file
"""
conversion.save(
self,
filename,
include_ports,
forcefield_name,
forcefield_files,
forcefield_debug,
box,
overwrite,
residues,
combining_rule,
foyer_kwargs,
parmed_kwargs,
compound=self,
filename=filename,
include_ports=include_ports,
box=box,
overwrite=overwrite,
residues=residues,
**kwargs,
)

Expand Down Expand Up @@ -3246,6 +3198,21 @@ def to_gmso(self, **kwargs):
"""
return conversion.to_gmso(self, **kwargs)

def to_hoomdsnapshot(self, **kwargs):
"""Create a HOOMD-Blue snapshot from an mBuild Compound.
Parameters
----------
compound : mb.Compound
The mb.Compound to be converted.
Returns
-------
snapshot : gsd.hoomd.Frame
HOOMD-Blue compatible topology.
"""
return conversion.to_hoomdsnapshot(self, **kwargs)

# Interface to Trajectory for reading/writing .pdb and .mol2 files.
# -----------------------------------------------------------------
def from_trajectory(
Expand Down
Loading

0 comments on commit aabbab6

Please sign in to comment.