예제 #1
0
def launch(dataset_path, group_name, group_description, parse_comments_path,
           parse_comments_structure):
    print("loading dataset: {} to group: {}".format(dataset_path, group_name))

    # Setup/Retrieve the Group
    g = Group.objects.get_or_create(name=group_name,
                                    description=group_description)[0]
    # Loop over structures in the dataset_path, storing the nodes then adding them to the group
    i = 0
    while True:
        try:
            ase_structure = ase.io.read(dataset_path, index=i, format="runner")
        except StopIteration:
            break
        # setup and store the ase structure as an aiida StructureData node
        aiida_structure = StructureData()
        aiida_structure.set_ase(ase_structure)
        aiida_structure_stored = aiida_structure.store()

        # add in the dataset_path line if possible
        if parse_comments_path:
            try:
                structure_path = ase_structure.comment.strip().split()[-1][3:]
                aiida_structure_stored.set_extra("structure_path",
                                                 structure_path)
            except AttributeError:
                print(
                    "could not set structure_path on {}".format(ase_structure))
                pass
        # Add in details of parent structure uuid
        if parse_comments_structure:
            try:
                parent_uuid = ase_structure.comment.strip().split()[-1]
                aiida_structure_stored.set_extra("parent_uuid", parent_uuid)
                add_parentstructure_extras(aiida_structure_stored, parent_uuid)
            except AttributeError:
                print("could not set parent_uuid on {}".format(ase_structure))
                pass

        # add in the chemical formula and number of atoms if possible
        try:
            aiida_structure_stored.set_extra("num_atoms", len(ase_structure))
            aiida_structure_stored.set_extra(
                "chem_formula", ase_structure.get_chemical_formula())
        except AttributeError:
            print("could not set either num_atoms or chemical_formula " \
                  " on {}".format(ase_structure))
            pass

        # add the structure to the group
        g.add_nodes(aiida_structure_stored)
        g.store()
        i += 1
예제 #2
0
def store_asestructure(ase_structure, extras, structure_group, dryrun):
    ase_structure = sort(ase_structure)
    ase_structure.set_tags(
        [0] *
        len(ase_structure))  #force AiiDA to use the same kind for each element

    # convert any instances of vacancy internal symbol use back to user symbol use
    for key in extras:
        if extras[key] == VACANCY_INTERNAL_SYMBOL:
            extras[key] = VACANCY_USER_SYMBOL

        if key == 'matrix_elements':
            extras[key] = [
                (lambda x: x
                 if x != VACANCY_INTERNAL_SYMBOL else VACANCY_USER_SYMBOL)(x)
                for x in extras[key]
            ]

    # delete all the vacancy sites prior to storage
    del ase_structure[[
        x.index for x in ase_structure if x.symbol == VACANCY_INTERNAL_SYMBOL
        or x.symbol == VACANCY_USER_SYMBOL
    ]]

    alreadyin_group = checkif_structure_alreadyin_group(
        ase_structure, structure_group)

    if alreadyin_group:
        print(("skiping structure, already stored in group: {}".format(
            ase_structure)))
        return

    if dryrun:
        print(("structure: {}".format(ase_structure)))
        print(("extras: {}".format(extras)))
    else:
        print(("storing structure: {}".format(ase_structure)))
        aiida_structure = StructureData()
        aiida_structure.set_ase(ase_structure)
        aiida_structure_stored = aiida_structure.store()
        for key in extras:
            aiida_structure_stored.set_extra(key, extras[key])

        aiida_structure_stored.set_extra("num_atoms", len(ase_structure))
        aiida_structure_stored.set_extra("chem_formula",
                                         ase_structure.get_chemical_formula())

        structure_group.add_nodes(aiida_structure_stored)
        print(("{} stored".format(aiida_structure_stored)))

    return
예제 #3
0
def cli(dataset_path, group_name, group_description, parse_comments_path,
        parse_comments_structure, dryrun):
    print("loading dataset: {} to group: {}".format(dataset_path, group_name))

    # Setup/Retrieve the Group
    structure_group = Group.objects.get_or_create(
        name=group_name, description=group_description)[0]
    # Loop over structures in the dataset_path, storing the nodes then adding them to the group
    i = 0
    while True:
        try:
            ase_structure = ase.io.read(dataset_path, index=i, format="runner")
        except StopIteration:
            break
        # setup and store the ase structure as an aiida StructureData node
        aiida_structure = StructureData()
        aiida_structure.set_ase(ase_structure)
        extras = {}

        # add in the dataset_path line if possible
        if parse_comments_path:
            try:
                structure_path = ase_structure.comment.strip().split()[-1][3:]
                extras['structure_path'] = str(structure_path)
            except AttributeError:
                print(
                    "could not set structure_path on {}".format(ase_structure))
                print(
                    "Can your version of ase parse comments for runner data?")
                pass
        # Add in details of parent structure uuid
        if parse_comments_structure:
            try:
                parent_uuid = ase_structure.comment.strip().split()[-1]
                aiida_structure.set_extra("parent_uuid", parent_uuid)
                add_parentstructure_extras(aiida_structure, parent_uuid)
            except AttributeError:
                print("could not set parent_uuid on {}".format(ase_structure))
                pass

        # add the structure to the group
        store_asestructure(ase_structure, extras, structure_group, dryrun)
        i += 1