示例#1
0
def test_random_distance():

    system = System(box_size=[10, 10, 10])
    methane = Molecule(os.path.join(here, 'data', 'methane.xyz'))
    system.add_molecules(methane, n=4)

    config = system.random(min_dist_threshold=1.5)

    for coord in config.coordinates():
        assert np.min(coord) > 0.0
        assert np.max(coord) < 10 - 1.5
示例#2
0
def test_perturbation():

    system = System(box_size=[7, 7, 7])
    system.add_molecules(h2o, n=5)
    config = system.random(min_dist_threshold=1.5, sigma=0.1, max_length=0.2)

    pcoords = config.coordinates()

    # Adding a displacement to each atom should still afford a reasonably
    # sensible structure (no short distances)
    dist_matrix = distance_matrix(pcoords, pcoords)
    dist_matrix += np.identity(len(pcoords))
    assert np.min(dist_matrix) > 0.6
示例#3
0
def test_autode_parallel_orca():

    if 'GT_ORCA' not in os.environ or not os.environ['GT_ORCA'] == 'True':
        return

    # Check that orca runs work
    water = System(box_size=[10, 10, 10])
    water.add_molecules(h2o, n=2)

    configs = Data()
    for _ in range(3):
        configs += water.random(with_intra=True)

    configs.parallel_orca()
示例#4
0
def test_autode_xtb():

    if 'GT_XTB' not in os.environ or not os.environ['GT_XTB'] == 'True':
        return

    # Check that orca and xtb runs work
    water = System(box_size=[10, 10, 10])
    water.add_molecules(h2o, n=5)

    config = water.random()
    config.run_xtb()

    assert config.energy is not None
    assert config.forces is not None
示例#5
0
def test_random_grid_positions():

    system = System(box_size=[10, 12, 14])
    methane = Molecule(os.path.join(here, 'data', 'methane.xyz'))
    system.add_molecules(methane, n=5)

    config = system.random(grid=True)
    config.save(filename='test_random.xyz')

    # Minimum pairwise distance should be ~ the C-H distance (1.109 Å)
    atoms = xyz_file_to_atoms('test_random.xyz')
    coords = np.array([atom.coord for atom in atoms])
    dist_matrix = distance_matrix(coords, coords)

    # Distance matrix has zeros along the diagonals so add the identity
    assert np.min(dist_matrix + 9 * np.identity(len(coords))) > 1.1

    os.remove('test_random.xyz')
示例#6
0
def test_histogram():

    water_dimer = System(box_size=[7, 7, 7])
    water_dimer.add_molecules(h2o, n=2)

    data = Data(name='test')
    data += water_dimer.random()

    # Can't histogram energies and forces with no energies
    with pytest.raises(NoEnergy):
        data.histogram(name='test')

    data[0].energy = 1
    data[0].forces = np.zeros(shape=(6, 3))

    data.histogram(name='test')
    assert os.path.exists('test.png')
    os.remove('test.png')
示例#7
0
def test_gap():

    water_dimer = System(box_size=[7, 7, 7])
    water_dimer.add_molecules(h2o, n=2)

    data = Data(name='test')
    for _ in range(2):
        data += water_dimer.random()

    assert len(data) == 2

    coords1 = data[0].coordinates()
    assert coords1.shape == (6, 3)

    coords2 = data[1].coordinates()

    # Coordinates should be somewhat different
    assert np.min(distance_matrix(coords1, coords2)) > 1E-3
示例#8
0
def test_with_charges():

    # Slightly modified ASE calculator to be compatible with the latest DFTB+
    calculator = DFTB()
    assert isinstance(calculator, Dftb)

    # Can't get the fermi level with no calculation run
    with pytest.raises(TypeError):
        calculator.read_fermi_levels()

    if 'GT_DFTB' not in os.environ or not os.environ['GT_DFTB'] == 'True':
        return

    # Check that charges work
    na_water = System(box_size=[10, 10, 10])
    na_water.add_molecules(Ion('Na', charge=1), n=1)
    na_water.add_molecules(h2o, n=5)

    assert na_water.charge() == 1

    config = na_water.random()
    config.run_dftb()