# Path: molmod/test/test_unit_cells.py
# def get_random_uc(scale=2, num_active=3, min_spacing=0.1):
#     while True:
#         active = np.random.randint(0, 2, 3).astype(bool)
#         if active.sum() == num_active:
#             break
#     while True:
#         try:
#             result = UnitCell(np.random.uniform(-scale, scale, (3, 3)), active)
#             if not active.any() or result.spacings[active].min() >= min_spacing:
#                 return result
#         except ValueError:
#             pass


import numpy as np
import pkg_resources
        import copy
from molmod.test.common import *
from molmod.test.test_unit_cells import get_random_uc
from molmod import *
            from molmod.ext import molecules_distance_matrix
# MolMod is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>
#
# --






__all__ = ["MoleculeTestCase"]


class MoleculeTestCase(BaseTestCase):
    def test_distance_matrix(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/tpa.xyz"))
        dm = 0
        for i in 0,1,2:
            dm += np.subtract.outer(molecule.coordinates[:,i],molecule.coordinates[:,i])**2
        dm = np.sqrt(dm)
        assert (abs(molecule.distance_matrix - dm) < 1e-5).all(), "Wrong distance matrix"

    def test_distance_matrix_periodic(self):
        for i in range(1000):
            N = 6

# Path: molmod/test/test_unit_cells.py
# def get_random_uc(scale=2, num_active=3, min_spacing=0.1):
#     while True:
#         active = np.random.randint(0, 2, 3).astype(bool)
#         if active.sum() == num_active:
#             break
#     while True:
#         try:
#             result = UnitCell(np.random.uniform(-scale, scale, (3, 3)), active)
#             if not active.any() or result.spacings[active].min() >= min_spacing:
#                 return result
#         except ValueError:
#             pass


# Path: molmod/test/test_molecules.py
import numpy as np
import pkg_resources
        import copy
from molmod.test.common import *
from molmod.test.test_unit_cells import get_random_uc
from molmod import *
            from molmod.ext import molecules_distance_matrix

# MolMod is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>
#
# --






__all__ = ["MoleculeTestCase"]


class MoleculeTestCase(BaseTestCase):
    def test_distance_matrix(self):
        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/tpa.xyz"))
        dm = 0
        for i in 0,1,2:
            dm += np.subtract.outer(molecule.coordinates[:,i],molecule.coordinates[:,i])**2
        dm = np.sqrt(dm)
        assert (abs(molecule.distance_matrix - dm) < 1e-5).all(), "Wrong distance matrix"

    def test_distance_matrix_periodic(self):
        for i in range(1000):
            N = 6

            unit_cell = get_random_uc(1.0, np.random.randint(0, 4))