def test_liquid_density():

    model = StollWerthSurrogate(30.069 * unit.gram / unit.mole)  # C2H6

    (
        epsilon,
        sigma,
        bond_length,
        bond_length_star,
        quadrupole,
        quadrupole_star_sqr,
    ) = generate_parameters()

    temperatures = numpy.array([308.0])
    temperatures_star = temperatures / epsilon

    value = model.liquid_density(temperatures, epsilon, sigma, bond_length,
                                 quadrupole)
    assert numpy.isclose(value, 285.1592692)

    reduced_gradient_function = autograd.grad(model.liquid_density_star,
                                              (1, 2))
    gradient_function = autograd.grad(model.liquid_density, (1, 2, 3, 4))

    reduced_gradient = reduced_gradient_function(temperatures_star,
                                                 quadrupole_star_sqr,
                                                 bond_length_star)
    gradient = gradient_function(temperatures, epsilon, sigma, bond_length,
                                 quadrupole)

    assert len(reduced_gradient) == 2 and not numpy.allclose(
        reduced_gradient, 0.0)
    assert numpy.allclose(
        gradient,
        numpy.array([28.12601669, 2044.99241265, -10856.5686318, 0.01421091]))
def test_critical_temperature():

    model = StollWerthSurrogate(30.069 * unit.gram / unit.mole)  # C2H6

    (
        epsilon,
        sigma,
        bond_length,
        bond_length_star,
        quadrupole,
        quadrupole_star_sqr,
    ) = generate_parameters()

    value = model.critical_temperature(epsilon, sigma, bond_length, quadrupole)
    assert numpy.isclose(value, 310.99575)

    reduced_gradient_function = autograd.grad(model.critical_temperature_star,
                                              (0, 1))
    gradient_function = autograd.grad(model.critical_temperature, (0, 1, 2, 3))

    reduced_gradient = reduced_gradient_function(quadrupole_star_sqr,
                                                 bond_length_star)
    gradient = gradient_function(epsilon, sigma, bond_length, quadrupole)

    assert len(reduced_gradient) == 2 and not numpy.allclose(
        reduced_gradient, 0.0)
    assert numpy.allclose(
        gradient,
        numpy.array([3.17342591, 452.59372786, -1140.53645031, 0.00153665]))
def test_surface_tension():

    model = StollWerthSurrogate(30.069 * unit.gram / unit.mole)  # C2H6

    (
        epsilon,
        sigma,
        bond_length,
        bond_length_star,
        quadrupole,
        quadrupole_star_sqr,
    ) = generate_parameters()

    temperatures = numpy.array([308.0])
    temperatures_star = temperatures / epsilon

    value = model.surface_tension(temperatures, epsilon, sigma, bond_length,
                                  quadrupole)
    assert numpy.isclose(value, 0.00017652)

    reduced_gradient_function = autograd.grad(model.surface_tension_star,
                                              (1, 2))
    gradient_function = autograd.grad(model.surface_tension, (1, 2, 3, 4))

    reduced_gradient = reduced_gradient_function(temperatures_star,
                                                 quadrupole_star_sqr,
                                                 bond_length_star)
    gradient = gradient_function(temperatures, epsilon, sigma, bond_length,
                                 quadrupole)

    assert len(reduced_gradient) == 2 and not numpy.allclose(
        reduced_gradient, 0.0)
    assert numpy.allclose(
        gradient,
        numpy.array([0.00023103, 0.03215253, -0.08337817, 9.44823625e-07]))
예제 #4
0
def build_model(model_name, data_set, property_types):

    # Build the likelihood operator.
    surrogate_model = StollWerthSurrogate(data_set.molecular_weight)
    log_likelihood = StollWerthOp(data_set, property_types, surrogate_model)

    # Define the potentially 'fixed' model constants.
    bond_length = data_set.bond_length.to(unit.nanometer).magnitude
    quadrupole = 0.0

    # Build the model
    with pymc3.Model() as model:

        epsilon = pymc3.Bound(pymc3.Exponential, 0.0)("epsilon",
                                                      lam=1.0 / 400.0)
        sigma = pymc3.Bound(pymc3.Exponential, 0.0)("sigma", lam=1.0 / 5.0)

        if model_name == "AUA" or model_name == "AUA+Q":
            bond_length = pymc3.Bound(pymc3.Exponential, 0.0)("bond_length",
                                                              lam=1.0 / 3.0)
        if model_name == "AUA+Q":
            quadrupole = pymc3.Bound(pymc3.Exponential, 0.0)("quadrupole",
                                                             lam=1.0)

        theta = tt.as_tensor_variable(
            [epsilon, sigma, bond_length, quadrupole])

        pymc3.DensityDist(
            "likelihood",
            lambda v: log_likelihood(v),
            observed={"v": theta},
        )

    return model
def test_saturation_pressure():

    model = StollWerthSurrogate(30.069 * unit.gram / unit.mole)  # C2H6

    (
        epsilon,
        sigma,
        bond_length,
        bond_length_star,
        quadrupole,
        quadrupole_star_sqr,
    ) = generate_parameters()

    temperatures = numpy.array([308.0])
    temperatures_star = temperatures / epsilon

    value = model.saturation_pressure(temperatures, epsilon, sigma,
                                      bond_length, quadrupole)
    assert numpy.isclose(value, 5027.57796073)

    reduced_gradient_function = autograd.grad(model.saturation_pressure_star,
                                              (1, 2))
    gradient_function = autograd.grad(model.saturation_pressure, (1, 2, 3, 4))

    reduced_gradient = reduced_gradient_function(temperatures_star,
                                                 quadrupole_star_sqr,
                                                 bond_length_star)
    gradient = gradient_function(temperatures, epsilon, sigma, bond_length,
                                 quadrupole)

    assert len(reduced_gradient) == 2 and not numpy.allclose(
        reduced_gradient, 0.0)
    assert numpy.allclose(
        gradient,
        numpy.array(
            [-234.84756081, -68931.5713522, 73156.01894348, -0.11010289]),
    )
예제 #6
0
def _get_two_center_model():

    data_set = NISTDataSet("C2H2")
    property_types = [*data_set.data_types]

    priors = {
        "epsilon": ("exponential", [0.0, random() * 400.0]),
        "sigma": ("exponential", [0.0, random() * 5.0]),
        "L": ("exponential", [0.0, random() * 3.0]),
        "Q": ("exponential", [0.0, random() * 1.0]),
    }
    fixed = {}

    model = TwoCenterLJModel(
        "AUA+Q",
        priors,
        fixed,
        data_set,
        property_types,
        StollWerthSurrogate(data_set.molecular_weight),
    )

    return model
def test_evaluate():

    model = StollWerthSurrogate(30.069 * unit.gram / unit.mole)  # C2H6
    epsilon, sigma, bond_length, _, quadrupole, _ = generate_parameters()

    parameters = numpy.array([epsilon, sigma, bond_length, quadrupole])
    temperatures = numpy.array([298.0, 300.0, 308.0])

    gradient_function = autograd.jacobian(model.evaluate, 1)

    density_gradients = gradient_function(NISTDataType.LiquidDensity,
                                          parameters, temperatures)
    pressure_gradients = gradient_function(NISTDataType.SaturationPressure,
                                           parameters, temperatures)
    tension_gradients = gradient_function(NISTDataType.SurfaceTension,
                                          parameters, temperatures)

    assert (density_gradients.shape == pressure_gradients.shape ==
            tension_gradients.shape)

    assert not numpy.allclose(density_gradients, 0.0)
    assert not numpy.allclose(pressure_gradients, 0.0)
    assert not numpy.allclose(tension_gradients, 0.0)
예제 #8
0
def get_model(model_name, data_set, property_types, simulation_params):

    priors = {
        "epsilon": simulation_params["priors"]["epsilon"],
        "sigma": simulation_params["priors"]["sigma"],
    }
    fixed = {}

    if model_name == "AUA":

        priors["L"] = simulation_params["priors"]["L"]
        fixed["Q"] = 0.0

    elif model_name == "AUA+Q":

        priors["L"] = simulation_params["priors"]["L"]
        priors["Q"] = simulation_params["priors"]["Q"]

    elif model_name == "UA":

        fixed["L"] = data_set.bond_length.to(unit.nanometer).magnitude
        fixed["Q"] = 0.0

    else:

        raise NotImplementedError()

    model = TwoCenterLJModel(
        model_name,
        priors,
        fixed,
        data_set,
        property_types,
        StollWerthSurrogate(data_set.molecular_weight),
    )

    return model
def test_critical_density():

    model = StollWerthSurrogate(30.069 * unit.gram / unit.mole)  # C2H6

    (
        epsilon,
        sigma,
        bond_length,
        bond_length_star,
        quadrupole,
        quadrupole_star_sqr,
    ) = generate_parameters()

    reduced_gradient_function = autograd.grad(model.critical_density_star,
                                              (0, 1))
    gradient_function = autograd.grad(model.critical_density, (0, 1, 2, 3))

    reduced_gradient = reduced_gradient_function(quadrupole_star_sqr,
                                                 bond_length_star)
    gradient = gradient_function(epsilon, sigma, bond_length, quadrupole)

    assert len(reduced_gradient) == 2 and not numpy.allclose(
        reduced_gradient, 0.0)
    assert len(gradient) == 4 and not numpy.allclose(gradient, 0.0)