# 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 unittest
import numpy as np
import pkg_resources
from molmod.test.test_unit_cells import get_random_uc
from molmod import *
        from molmod.ext import molecules_distance_matrix
          "SID_40363571.sdf", "SID_31646548.sdf", "SID_31646545.sdf",
          "SID_41893278.sdf", "SID_41893280.sdf", "SID_54258192.sdf",
          "SID_55488598.sdf",
        ]
        for fn in fns:
            molecule = self.load_molecule(fn)
            if allow_multi or len(molecule.graph.independent_vertices) == 1:
                yield molecule

    def test_guess_geometry(self):
        for input_mol in self.iter_molecules(allow_multi=False):
            output_mol = guess_geometry(input_mol.graph)
            output_mol.title = input_mol.title
            #output_mol.write_to_file("guess_%s.xyz" % input_mol.title)

    def test_tune_geometry(self):
        for input_mol in self.iter_molecules(allow_multi=False):
            output_mol = tune_geometry(input_mol.graph, input_mol)
            output_mol.title = input_mol.title
            #output_mol.write_to_file("tune_%s.xyz" % input_mol.title)

    def get_random_ff(self):
        N = 6

        mask = np.zeros((N,N), bool)
        for i in range(N):
            for j in range(i):
                mask[i,j] = True

        while True:

# 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_toyff.py
import unittest
import numpy as np
import pkg_resources
from molmod.test.test_unit_cells import get_random_uc
from molmod import *
        from molmod.ext import molecules_distance_matrix

          "SID_40363571.sdf", "SID_31646548.sdf", "SID_31646545.sdf",
          "SID_41893278.sdf", "SID_41893280.sdf", "SID_54258192.sdf",
          "SID_55488598.sdf",
        ]
        for fn in fns:
            molecule = self.load_molecule(fn)
            if allow_multi or len(molecule.graph.independent_vertices) == 1:
                yield molecule

    def test_guess_geometry(self):
        for input_mol in self.iter_molecules(allow_multi=False):
            output_mol = guess_geometry(input_mol.graph)
            output_mol.title = input_mol.title
            #output_mol.write_to_file("guess_%s.xyz" % input_mol.title)

    def test_tune_geometry(self):
        for input_mol in self.iter_molecules(allow_multi=False):
            output_mol = tune_geometry(input_mol.graph, input_mol)
            output_mol.title = input_mol.title
            #output_mol.write_to_file("tune_%s.xyz" % input_mol.title)

    def get_random_ff(self):
        N = 6

        mask = np.zeros((N,N), bool)
        for i in range(N):
            for j in range(i):
                mask[i,j] = True

        while True:

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