import numpy as np
import pytest
import unyt as u
from unyt.testing import assert_allclose_units

from gmso import Topology
from gmso.external.convert_parmed import from_parmed
from gmso.formats.gro import read_gro, write_gro
from gmso.tests.base_test import BaseTest
from gmso.utils.io import get_fn, has_parmed, import_

if has_parmed:
    pmd = import_("parmed")


@pytest.mark.skipif(not has_parmed, reason="ParmEd is not installed")
class TestGro(BaseTest):
    def test_read_gro(self):
        top = Topology.load(get_fn("acn.gro"))

        assert top.name == "ACN"
        assert top.n_sites == 6
        assert_allclose_units(
            top.box.lengths, 4 * np.ones(3) * u.nm, rtol=1e-5, atol=1e-8
        )

        top = Topology.load(get_fn("350-waters.gro"))

        assert top.name == "Generic title"
        assert top.n_sites == 1050
        assert_allclose_units(
            top.box.lengths, 2.20866 * np.ones(3) * u.nm, rtol=1e-5, atol=1e-8
        )

    def test_wrong_n_atoms(self):
        with pytest.raises(ValueError):
            Topology.load(get_fn("too_few_atoms.gro"))
        with pytest.raises(ValueError):
            Topology.load(get_fn("too_many_atoms.gro"))

    def test_write_gro(self):
        top = from_parmed(pmd.load_file(get_fn("ethane.gro"), structure=True))
        top.save("out.gro")

    def test_write_gro_non_orthogonal(self):
        top = from_parmed(pmd.load_file(get_fn("ethane.gro"), structure=True))
        top.box.angles = u.degree * [90, 90, 120]
        top.save("out.gro")

d07f57f2ec2154a4c4f353381e200fe84b9f40f2
<mask token>


@pytest.mark.skipif(not has_parmed, reason='ParmEd is not installed')
class TestGro(BaseTest):

    def test_read_gro(self):
        top = Topology.load(get_fn('acn.gro'))
        assert top.name == 'ACN'
        assert top.n_sites == 6
        assert_allclose_units(top.box.lengths, 4 * np.ones(3) * u.nm, rtol=
            1e-05, atol=1e-08)
        top = Topology.load(get_fn('350-waters.gro'))
        assert top.name == 'Generic title'
        assert top.n_sites == 1050
        assert_allclose_units(top.box.lengths, 2.20866 * np.ones(3) * u.nm,
            rtol=1e-05, atol=1e-08)

    def test_wrong_n_atoms(self):
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_few_atoms.gro'))
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_many_atoms.gro'))

    def test_write_gro(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.save('out.gro')
    <mask token>

<mask token>


@pytest.mark.skipif(not has_parmed, reason='ParmEd is not installed')
class TestGro(BaseTest):

    def test_read_gro(self):
        top = Topology.load(get_fn('acn.gro'))
        assert top.name == 'ACN'
        assert top.n_sites == 6
        assert_allclose_units(top.box.lengths, 4 * np.ones(3) * u.nm, rtol=
            1e-05, atol=1e-08)
        top = Topology.load(get_fn('350-waters.gro'))
        assert top.name == 'Generic title'
        assert top.n_sites == 1050
        assert_allclose_units(top.box.lengths, 2.20866 * np.ones(3) * u.nm,
            rtol=1e-05, atol=1e-08)

    def test_wrong_n_atoms(self):
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_few_atoms.gro'))
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_many_atoms.gro'))

    def test_write_gro(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.save('out.gro')

    def test_write_gro_non_orthogonal(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.box.angles = u.degree * [90, 90, 120]
        top.save('out.gro')

<mask token>
if has_parmed:
    pmd = import_('parmed')


@pytest.mark.skipif(not has_parmed, reason='ParmEd is not installed')
class TestGro(BaseTest):

    def test_read_gro(self):
        top = Topology.load(get_fn('acn.gro'))
        assert top.name == 'ACN'
        assert top.n_sites == 6
        assert_allclose_units(top.box.lengths, 4 * np.ones(3) * u.nm, rtol=
            1e-05, atol=1e-08)
        top = Topology.load(get_fn('350-waters.gro'))
        assert top.name == 'Generic title'
        assert top.n_sites == 1050
        assert_allclose_units(top.box.lengths, 2.20866 * np.ones(3) * u.nm,
            rtol=1e-05, atol=1e-08)

    def test_wrong_n_atoms(self):
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_few_atoms.gro'))
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_many_atoms.gro'))

    def test_write_gro(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.save('out.gro')

    def test_write_gro_non_orthogonal(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.box.angles = u.degree * [90, 90, 120]
        top.save('out.gro')

import numpy as np
import pytest
import unyt as u
from unyt.testing import assert_allclose_units
from gmso import Topology
from gmso.external.convert_parmed import from_parmed
from gmso.formats.gro import read_gro, write_gro
from gmso.tests.base_test import BaseTest
from gmso.utils.io import get_fn, has_parmed, import_
if has_parmed:
    pmd = import_('parmed')


@pytest.mark.skipif(not has_parmed, reason='ParmEd is not installed')
class TestGro(BaseTest):

    def test_read_gro(self):
        top = Topology.load(get_fn('acn.gro'))
        assert top.name == 'ACN'
        assert top.n_sites == 6
        assert_allclose_units(top.box.lengths, 4 * np.ones(3) * u.nm, rtol=
            1e-05, atol=1e-08)
        top = Topology.load(get_fn('350-waters.gro'))
        assert top.name == 'Generic title'
        assert top.n_sites == 1050
        assert_allclose_units(top.box.lengths, 2.20866 * np.ones(3) * u.nm,
            rtol=1e-05, atol=1e-08)

    def test_wrong_n_atoms(self):
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_few_atoms.gro'))
        with pytest.raises(ValueError):
            Topology.load(get_fn('too_many_atoms.gro'))

    def test_write_gro(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.save('out.gro')

    def test_write_gro_non_orthogonal(self):
        top = from_parmed(pmd.load_file(get_fn('ethane.gro'), structure=True))
        top.box.angles = u.degree * [90, 90, 120]
        top.save('out.gro')

import numpy as np
import pytest
import unyt as u
from unyt.testing import assert_allclose_units

from gmso import Topology
from gmso.external.convert_parmed import from_parmed
from gmso.formats.gro import read_gro, write_gro
from gmso.tests.base_test import BaseTest
from gmso.utils.io import get_fn, has_parmed, import_

if has_parmed:
    pmd = import_("parmed")


@pytest.mark.skipif(not has_parmed, reason="ParmEd is not installed")
class TestGro(BaseTest):
    def test_read_gro(self):
        top = Topology.load(get_fn("acn.gro"))

        assert top.name == "ACN"
        assert top.n_sites == 6
        assert_allclose_units(
            top.box.lengths, 4 * np.ones(3) * u.nm, rtol=1e-5, atol=1e-8
        )

        top = Topology.load(get_fn("350-waters.gro"))

        assert top.name == "Generic title"
        assert top.n_sites == 1050
        assert_allclose_units(
            top.box.lengths, 2.20866 * np.ones(3) * u.nm, rtol=1e-5, atol=1e-8
        )

    def test_wrong_n_atoms(self):
        with pytest.raises(ValueError):
            Topology.load(get_fn("too_few_atoms.gro"))
        with pytest.raises(ValueError):
            Topology.load(get_fn("too_many_atoms.gro"))

    def test_write_gro(self):
        top = from_parmed(pmd.load_file(get_fn("ethane.gro"), structure=True))
        top.save("out.gro")

    def test_write_gro_non_orthogonal(self):
        top = from_parmed(pmd.load_file(get_fn("ethane.gro"), structure=True))
        top.box.angles = u.degree * [90, 90, 120]
        top.save("out.gro")
