コード例 #1
0
def test_thermoml_mole_constraints():
    """A collection of tests to ensure that the Mole fraction constraint is
    implemented correctly alongside solvent constraints."""

    # Mole fraction
    data_set = ThermoMLDataSet.from_file(get_data_filename('test/properties/mole.xml'))

    assert data_set is not None
    assert len(data_set.properties) > 0

    # Mole fraction + Solvent: Mass fraction
    data_set = ThermoMLDataSet.from_file(get_data_filename('test/properties/mole_mass.xml'))

    assert data_set is not None
    assert len(data_set.properties) > 0

    # Mole fraction + Solvent: Mole fraction
    data_set = ThermoMLDataSet.from_file(get_data_filename('test/properties/mole_mole.xml'))

    assert data_set is not None
    assert len(data_set.properties) > 0

    # Mole fraction + Solvent: Molality
    data_set = ThermoMLDataSet.from_file(get_data_filename('test/properties/mole_molality.xml'))

    assert data_set is not None
    assert len(data_set.properties) > 0
コード例 #2
0
def test_from_url():

    data_set = ThermoMLDataSet.from_url('https://trc.nist.gov/journals/jct/2005v37/i04/j.jct.2004.09.022.xml')
    assert data_set is not None

    assert len(data_set.properties) > 0

    data_set = ThermoMLDataSet.from_url('https://trc.nist.gov/journals/jct/2005v37/i04/j.jct.2004.09.022.xmld')
    assert data_set is None
コード例 #3
0
def test_thermoml_from_url():
    """A test to ensure that ThermoML archive files can be loaded from a url."""

    data_set = ThermoMLDataSet.from_url('https://trc.nist.gov/journals/jct/2005v37/i04/j.jct.2004.09.022.xml')
    assert data_set is not None

    assert len(data_set.properties) > 0

    data_set = ThermoMLDataSet.from_url('https://trc.nist.gov/journals/jct/2005v37/i04/j.jct.2004.09.022.xmld')
    assert data_set is None
コード例 #4
0
def test_from_files():

    data_set = ThermoMLDataSet.from_file(get_data_filename('properties/j.jct.2004.09.014.xml'),
                                         get_data_filename('properties/j.jct.2004.09.022.xml'),
                                         get_data_filename('properties/j.jct.2007.09.004.xml'))
    assert data_set is not None

    assert len(data_set.properties) > 0

    data_set = ThermoMLDataSet.from_file('properties/j.jct.2004.09.014.xmld')
    assert data_set is None
コード例 #5
0
def test_serialization():
    """A test to ensure that data sets are JSON serializable."""

    data_set = ThermoMLDataSet.from_file(get_data_filename('properties/single_density.xml'))
    data_set_json = data_set.json()

    parsed_data_set = ThermoMLDataSet.parse_json(data_set_json)
    assert data_set.number_of_properties == parsed_data_set.number_of_properties

    parsed_data_set_json = parsed_data_set.json()
    assert parsed_data_set_json == data_set_json
コード例 #6
0
def test_thermoml_from_files():
    """A test to ensure that ThermoML archive files can be loaded from local sources."""

    data_set = ThermoMLDataSet.from_file(get_data_filename('properties/single_density.xml'),
                                         get_data_filename('properties/single_dielectric.xml'),
                                         get_data_filename('properties/single_enthalpy_mixing.xml'))

    assert data_set is not None
    assert len(data_set.properties) == 3

    data_set = ThermoMLDataSet.from_file('dummy_filename')
    assert data_set is None
コード例 #7
0
def test_from_doi():

    data_set = ThermoMLDataSet.from_doi('10.1016/j.jct.2016.10.001')
    assert data_set is not None

    assert len(data_set.properties) > 0

    for mixture_tag in data_set.properties:

        for physical_property in data_set.properties[mixture_tag]:

            physical_property_json = physical_property.json()
            print(physical_property_json)

            physical_property_recreated = PhysicalProperty.parse_json(physical_property_json)
            print(physical_property_recreated)

    data_set = ThermoMLDataSet.from_doi('10.1016/j.jct.2016.12.009')
    assert data_set is None

    data_set = ThermoMLDataSet.from_doi('10.1016/j.jct.2016.12.009x')
    assert data_set is None
コード例 #8
0
def test_thermoml_from_doi():
    """A test to ensure that ThermoML archive files can be loaded from a doi."""

    data_set = ThermoMLDataSet.from_doi('10.1016/j.jct.2016.10.001')
    assert data_set is not None

    assert len(data_set.properties) > 0

    for mixture_tag in data_set.properties:

        for physical_property in data_set.properties[mixture_tag]:

            physical_property_json = physical_property.json()
            print(physical_property_json)

            physical_property_recreated = PhysicalProperty.parse_json(physical_property_json)
            print(physical_property_recreated)

    data_set = ThermoMLDataSet.from_doi('10.1016/j.jct.2016.12.009')
    assert data_set is None

    data_set = ThermoMLDataSet.from_doi('10.1016/j.jct.2016.12.009x')
    assert data_set is None
コード例 #9
0
def compute_estimate_async():
    """Submit calculations to a running server instance"""
    from openforcefield.typing.engines import smirnoff

    setup_timestamp_logging()

    # Load in the data set of interest.
    data_set = ThermoMLDataSet.from_file(get_data_filename('properties/single_dielectric.xml'))
    # Load in the force field to use.
    force_field = smirnoff.ForceField(get_data_filename('forcefield/smirnoff99Frosst.offxml'))

    # new_property_0 = copy.deepcopy(data_set.properties['COCCO{1.0}'][0])
    # new_property_0.thermodynamic_state.temperature -= 2.0 * unit.kelvin
    # new_property_0.id = str(uuid4())
    #
    # data_set.properties['COCCO{1.0}'].append(new_property_0)
    #
    # new_property_1 = copy.deepcopy(data_set.properties['COCCO{1.0}'][0])
    # new_property_1.thermodynamic_state.temperature += 2.0 * unit.kelvin
    # new_property_1.id = str(uuid4())
    #
    # data_set.properties['COCCO{1.0}'].append(new_property_1)

    # Modify the submission options
    submission_options = PropertyEstimatorOptions()

    workflow_options = PropertyWorkflowOptions(PropertyWorkflowOptions.ConvergenceMode.RelativeUncertainty,
                                               relative_uncertainty_fraction=100000)

    submission_options.workflow_options = {
        'Density': workflow_options,
        'Dielectric': workflow_options,
        'EnthalpyOfMixing': workflow_options
    }
    # submission_options.allowed_calculation_layers = ['SimulationLayer']
    submission_options.allowed_calculation_layers = ['ReweightingLayer']

    # Create the client object.
    property_estimator = client.PropertyEstimatorClient()
    # Submit the request to a running server.
    request = property_estimator.request_estimate(data_set, force_field, submission_options)

    logging.info('Request info: {}'.format(str(request)))

    # Wait for the results.
    result = request.results(synchronous=True)

    logging.info('The server has returned a response: {}'.format(result.json()))
コード例 #10
0
def compute_estimate_sync():
    """Submit calculations to a running server instance"""
    from openforcefield.typing.engines import smirnoff

    setup_timestamp_logging()

    # Load in the data set of interest.
    data_set = ThermoMLDataSet.from_file(get_data_filename('properties/single_density.xml'))
    # Load in the force field to use.
    force_field = smirnoff.ForceField(get_data_filename('forcefield/smirnoff99Frosst.offxml'))

    # Create the client object.
    property_estimator = client.PropertyEstimatorClient()
    # Submit the request to a running server, and wait for the results.
    result = property_estimator.request_estimate(data_set, force_field)

    logging.info('The server has returned a response: {}'.format(result))
コード例 #11
0
def parse_all_jct_files():

    logging.basicConfig(filename='data_sets.log', filemode='w', level=logging.INFO)

    data_path = get_data_filename('properties/JCT')

    thermoml_files = []

    for file_path in listdir(data_path):

        full_path = join(data_path, file_path)

        if not isfile(full_path):
            continue

        thermoml_files.append(full_path)

    data_set = ThermoMLDataSet.from_file(*thermoml_files)

    from propertyestimator.properties.density import Density
    from propertyestimator.properties.dielectric import DielectricConstant
    from propertyestimator.properties.enthalpy import EnthalpyOfMixing

    properties_by_type = {Density.__name__: [], DielectricConstant.__name__: [],
                          EnthalpyOfMixing.__name__: []}

    for substance_key in data_set.properties:

        for data_property in data_set.properties[substance_key]:

            if type(data_property).__name__ not in properties_by_type:
                continue

            properties_by_type[type(data_property).__name__].append(data_property.source.reference)

    for type_key in properties_by_type:

        with open('{}.dat'.format(type_key), 'w') as file:

            for doi in properties_by_type[type_key]:
                file.write('{}\n'.format(doi))