Beispiel #1
0
def ensure_otfg_family(family_name):
    """Add common OTFG families if they do not exist"""

    from aiida.common import NotExistent
    from aiida_castep.data.otfg import upload_otfg_family

    # Ensure family name is a str
    if isinstance(family_name, orm.Str):
        family_name = family_name.value

    try:
        OTFGGroup.objects.get(label=family_name)
    except NotExistent:
        description = f"CASTEP built-in on-the-fly generated pseudos libraray '{family_name}'"
        upload_otfg_family([family_name], family_name, description, stop_if_existing=True)
Beispiel #2
0
def test_set_up_family_from_nodes(clear_database_before_test, otfg, otfg_nodes,
                                  otfgdata):

    entry, uploaded = otfg.upload_otfg_family(otfg_nodes[:1],
                                              "Test",
                                              "Test",
                                              stop_if_existing=True)

    groups = otfgdata.get_otfg_groups()
    assert len(groups) == 1
    assert len(groups[0].nodes) == 1

    with pytest.raises(ValidationError):
        entry, uploaded = otfg.upload_otfg_family(otfg_nodes,
                                                  "Test",
                                                  "Test",
                                                  stop_if_existing=True)

    entry, uploaded = otfg.upload_otfg_family(otfg_nodes,
                                              "Test",
                                              "Test",
                                              stop_if_existing=False)
    groups = otfgdata.get_otfg_groups()
    assert len(groups) == 1
    assert len(groups[0].nodes) == 3

    Ce = otfgdata()
    Ce.set_string("Ce BLA")

    entry, uploaded = otfg.upload_otfg_family(otfg_nodes + [Ce],
                                              "Test",
                                              "Test",
                                              stop_if_existing=False)

    group = otfgdata.get_otfg_group("Test")

    uuid_in_the_group = [node.uuid for node in group.nodes]
    for o in otfg_nodes + [Ce]:
        assert o.uuid in uuid_in_the_group
Beispiel #3
0
def test_usp_upload_family(clear_database_before_test, usp_folder):
    """
    Test uploading the usp family
    """
    from aiida_castep.data.usp import upload_usp_family
    from aiida_castep.data.otfg import upload_otfg_family, OTFGGroup
    upload_usp_family(str(usp_folder), "Test", "Test")

    new = usp_folder / "O_00.usp"
    new.write_text("asdfgghhd")
    # This will raise an exception as the same file is being uploaded
    with pytest.raises(ValueError):
        upload_usp_family(str(usp_folder),
                          "Test",
                          "Test",
                          stop_if_existing=True)
    # This should be OK
    upload_usp_family(str(usp_folder), "Test", "Test", stop_if_existing=False)

    # Should be able to mix-in Usp and OTFG entries
    upload_otfg_family(['C18'], "Test", "Test")

    nodes = list(OTFGGroup.get(label='Test').nodes)
    upload_otfg_family(nodes, "Test2", "Test", stop_if_existing=False)
Beispiel #4
0
def test_set_up_family_from_string(clear_database_before_test, otfg_nodes,
                                   otfgdata):

    text_entries = [n.entry for n in otfg_nodes]
    entry, uploaded = upload_otfg_family(text_entries[:1], "Test", "Test")
    assert (entry, uploaded) == (1, 1)

    # Creating duplicated family - should fail
    with pytest.raises(ValidationError):
        entry, uploaded = upload_otfg_family(text_entries, "Test", "Test")

    entry, uploaded = upload_otfg_family(text_entries,
                                         "Test",
                                         "Test",
                                         stop_if_existing=False)

    assert (entry, uploaded) == (3, 2)

    # Check if they are indeed stored
    groups = otfgdata.get_otfg_groups()
    retrieved_entries = [node.entry for node in groups[0].nodes]

    for txt in text_entries:
        assert txt in retrieved_entries
Beispiel #5
0
 def _create(otfgs, group_name):
     from aiida_castep.data.otfg import upload_otfg_family
     upload_otfg_family(otfgs, group_name, 'TEST', stop_if_existing=False)
Beispiel #6
0
 def upload_otfg_family(self, entries, name, desc='test', **kwargs):
     """Return a factory for upload OTFGS"""
     from aiida_castep.data.otfg import upload_otfg_family
     upload_otfg_family(entries, name, desc, **kwargs)