示例#1
0
def test_load():

    xyz_path = os.path.join(here, 'data', 'configs.xyz')

    configs = ConfigurationSet()
    configs.load(xyz_path)

    assert len(configs) == 2

    # Should default to uncharged singlet
    for config in configs:
        assert config.box is not None
        assert config.charge == 0
        assert config.mult == 1

    zn_aq = System(gt.Ion('Zn', charge=2), box_size=[12, 12, 12])
    zn_aq.add_solvent('h2o', n=52)

    configs = ConfigurationSet()
    configs.load(xyz_path, system=zn_aq)
    for config in configs:
        assert config.box is not None
        assert config.charge == 2
        assert config.mult == 1

    configs = ConfigurationSet()
    configs.load(xyz_path, charge=2)
    for config in configs:
        assert config.box is not None
        assert config.charge == 2
        assert config.mult == 1

    with open('tmp.xyz', 'w') as test_xyz:
        print('1\n', file=test_xyz)

    # Should fail to load with no atoms in the xyz file
    configs = ConfigurationSet()
    with pytest.raises(LoadingFailed):
        configs.load(filename='tmp.xyz')

    os.remove('tmp.xyz')
示例#2
0
from gaptrain.loss import RMSE
from gaptrain.configurations import ConfigurationSet
from gaptrain.systems import System
import numpy as np

system = System(box_size=[10, 10, 10])
system.add_solvent('h2o', n=3)


def test_rmse():

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

    configs[0].energy = 1
    configs[1].energy = 2

    true_configs = configs.copy()
    true_configs[0].energy = 1.1
    true_configs[1].energy = 1.8

    rmse = RMSE(configs, true_configs)

    expected = np.sqrt(((1 - 1.1)**2 + (2 - 1.8)**2) / 2.0)
    assert np.abs(rmse.energy - expected) < 1E-6