# 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
            coordinates = unit_cell.to_cartesian(fractional)
            dm = molecules_distance_matrix(coordinates, unit_cell.matrix,
                                           unit_cell.reciprocal)
            for i in range(N):
                for j in range(i,N):
                    delta = coordinates[j]-coordinates[i]
                    delta = unit_cell.shortest_vector(delta)
                    distance = np.linalg.norm(delta)
                    self.assertAlmostEqual(dm[i,j], distance)

    def test_read_only(self):
        numbers = [8, 1]
        coordinates = [
            [0, 1, 2],
            [-2, 3, 1],
        ]
        mol = Molecule(numbers, coordinates)
        #try:
        #    mol.coordinates[0,1] = 5.0
        #    self.fail("Should have raised an error")
        #except (ValueError, RuntimeError), e:
        #    pass
        assert isinstance(mol.coordinates[0,0], float)

        coordinates = np.array(coordinates)
        mol = Molecule(numbers, coordinates)
        coordinates[0,1] = 5.0
        self.assertAlmostEqual(mol.coordinates[0,1], 1.0)

    def test_mass(self):

# 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

            coordinates = unit_cell.to_cartesian(fractional)
            dm = molecules_distance_matrix(coordinates, unit_cell.matrix,
                                           unit_cell.reciprocal)
            for i in range(N):
                for j in range(i,N):
                    delta = coordinates[j]-coordinates[i]
                    delta = unit_cell.shortest_vector(delta)
                    distance = np.linalg.norm(delta)
                    self.assertAlmostEqual(dm[i,j], distance)

    def test_read_only(self):
        numbers = [8, 1]
        coordinates = [
            [0, 1, 2],
            [-2, 3, 1],
        ]
        mol = Molecule(numbers, coordinates)
        #try:
        #    mol.coordinates[0,1] = 5.0
        #    self.fail("Should have raised an error")
        #except (ValueError, RuntimeError), e:
        #    pass
        assert isinstance(mol.coordinates[0,0], float)

        coordinates = np.array(coordinates)
        mol = Molecule(numbers, coordinates)
        coordinates[0,1] = 5.0
        self.assertAlmostEqual(mol.coordinates[0,1], 1.0)

    def test_mass(self):

        molecule = Molecule.from_file(pkg_resources.resource_filename("molmod", "data/test/water.xyz"))