Пример #1
0
def get_siblings_json(nre, formula, return_search=False):
    """
    use to get a sibling json
    return_search : return directly the search
    :return: json tree of a sibling
    """
    es_host = settings.ELASTICSEARCH
    es = Elasticsearch(hosts=[es_host])
    truncated_nre = truncate(nre, NRE_PRECISION)
    if truncated_nre < 0:
        upper_band_nre = truncated_nre + (-10**TME_PRECISION)
    else:
        upper_band_nre = truncated_nre + (10**TME_PRECISION)
    q = Q('bool', must=[Q('match', data__molecule__formula=formula)])
    q2 = Q('bool',
           data__results__nuclear_repulsion_energy_from_xyz=Range(
               gte=truncated_nre, lt=upper_band_nre))

    s = Search(index='quchempedia_index').using(es).query(q).query(q2)
    response = s.execute()
    result = []
    if return_search:
        return response
    else:
        for hit in response:
            try:
                try:
                    basis_set_name = hit.data.comp_details.general.basis_set_name
                except:
                    basis_set_name = "Null"

                try:
                    solvent = hit.data.comp_details.general.solvent
                except Exception as error:
                    solvent = "GAS"

                result.append({
                    "id_log":
                    hit.meta.id,
                    "job":
                    _get_job_type(hit),
                    "charge":
                    hit.data.molecule.charge,
                    "multiplicity":
                    hit.data.molecule.multiplicity,
                    "solvent":
                    solvent,
                    "ending_energy":
                    hit.data.results.wavefunction.total_molecular_energy,
                    "software":
                    hit.data.comp_details.general.package,
                    "basis_set_name":
                    basis_set_name,
                    "functionnal":
                    hit.data.comp_details.general.functional
                })
            except Exception as error:
                print(error)
        return result
Пример #2
0
def test_range_serializes_properly():
    class D(document.Document):
        lr = field.LongRange()

    d = D(lr=Range(lt=42))
    assert 40 in d.lr
    assert 47 not in d.lr
    assert {"lr": {"lt": 42}} == d.to_dict()

    d = D(lr={"lt": 42})
    assert {"lr": {"lt": 42}} == d.to_dict()
def test_range_raises_value_error_on_wrong_params(args, kwargs):
    with pytest.raises(ValueError):
        Range(*args, **kwargs)
def test_range_not_contains(kwargs, item):
    assert item not in Range(**kwargs)
        (({},), {"lt": 42}),
        ((), {"not_lt": 42}),
        ((object(),), {}),
        ((), {"lt": 1, "lte": 1}),
        ((), {"gt": 1, "gte": 1}),
    ],
)
def test_range_raises_value_error_on_wrong_params(args, kwargs):
    with pytest.raises(ValueError):
        Range(*args, **kwargs)


@pytest.mark.parametrize(
    "range,lower,inclusive",
    [
        (Range(gt=1), 1, False),
        (Range(gte=1), 1, True),
        (Range(), None, False),
        (Range(lt=42), None, False),
    ],
)
def test_range_lower(range, lower, inclusive):
    assert (lower, inclusive) == range.lower


@pytest.mark.parametrize(
    "range,upper,inclusive",
    [
        (Range(lt=1), 1, False),
        (Range(lte=1), 1, True),
        (Range(), None, False),