Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 3
0
def test_density():
    """Test the density calculation with a few water boxes"""

    req_density = 1.0
    mw = 18.02  # Density of water

    for n_waters in [1, 2, 3, 5, 7, 127]:
        length = (((mw * n_waters / (6.022E23 * req_density)) / 1E6)**(1 / 3) *
                  1E10)

        system = System(box_size=[length, length, length])
        system.add_molecules(h2o, n=n_waters)

        assert np.abs(system.density - req_density) < 1E-3
Exemplo n.º 4
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()
Exemplo n.º 5
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
Exemplo n.º 6
0
def test_print_gro_file():

    water_box = System(box_size=[10, 10, 10])
    water_box.add_molecules(molecule=get_solvent('h2o'), n=10)

    for molecule in water_box.molecules:
        molecule.set_mm_atom_types()

    config = Configuration(system=water_box)
    config.wrap()
    config.print_gro_file(system=water_box)

    assert os.path.exists('input.gro')
    os.remove('input.gro')
Exemplo n.º 7
0
def test_grid_positions():

    n_molecules = 10
    density = 0.786  # g cm-3
    mw = 3 * 1.01 + 2 * 12.01 + 14.01
    length = ((mw * n_molecules / (6.022E23 * density)) / 1E6)**(1 / 3) * 1E10

    system = System(box_size=[length, length, length])
    system.add_molecules(Molecule(os.path.join(here, 'data', 'mecn.xyz')),
                         n=n_molecules)

    config = system.grid(min_dist_threshold=1.7)
    config.save(filename='test_random.xyz')

    assert os.path.exists('test_random.xyz')

    os.remove('test_random.xyz')
Exemplo n.º 8
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')
Exemplo n.º 9
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')
Exemplo n.º 10
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
Exemplo n.º 11
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()
Exemplo n.º 12
0
def test_n_mols():

    system = System(box_size=[5, 5, 5])
    system.add_molecules(methane, n=1)
    system.add_molecules(h2o, n=1)
    assert system.n_unique_molecules == 2

    system.add_molecules(h2o, n=5)
    assert system.n_unique_molecules == 2
Exemplo n.º 13
0
def test_system():

    system = System(box_size=[5, 5, 5])
    # No molecules yet in the system
    assert len(system) == 0

    system += h2o

    assert len(system) == 1

    system.add_molecules(h2o, 10)
    assert len(system) == 11

    two_waters = [h2o, h2o]
    system += two_waters
    assert len(system) == 13
    assert system.n_unique_molecules == 1

    assert str(system) == 'H2O_13' or str(system) == 'OH2_13'

    # Should be able to print an xyz file of the configuration
    system.configuration().save(filename='test.xyz')
    assert os.path.exists('test.xyz')
    os.remove('test.xyz')
Exemplo n.º 14
0
from gaptrain.systems import System
from gaptrain.molecules import Molecule
from gaptrain.solvents import get_solvent
import gaptrain as gt
import numpy as np
import pytest
import ase
import os

here = os.path.abspath(os.path.dirname(__file__))
h2o = Molecule(os.path.join(here, 'data', 'h2o.xyz'))


side_length = 7.0
system = System(box_size=[side_length, side_length, side_length])
system.add_molecules(h2o, n=3)


def test_print_exyz():

    configs = ConfigurationSet(name='test')

    for _ in range(5):
        configs += system.random()

    configs.save()
    assert os.path.exists('test.xyz')
    os.remove('test.xyz')

    # If the energy and forces are set for all the configurations an exyz
    # should be able to be printed