示例#1
0
    def setUp(self):
        from click.testing import CliRunner
        self.runner = CliRunner()

        # Set up basic ase supercell
        self.basic_lattice_size = 4.04
        self.basic_supercell_shape = [4, 4, 4]
        self.basic_matrix_element = 'Al'
        basic_ase = ase.build.bulk(self.basic_matrix_element,
                                   a=self.basic_lattice_size,
                                   cubic=True)
        self.basic_ase_supercell = basic_ase * np.array(
            self.basic_supercell_shape, dtype=int)
        self.basic_ase_small_supercell = basic_ase * np.array([2, 2, 2],
                                                              dtype=int)

        self.test_extras = {'foo': 'bar'}

        self.randomcell_elements = ['Al', 'Cu', 'Mg']
        self.randomcell_concentrations = [0.75, 0.15, 0.10]
        self.randomcell_lattices = [4.07, 3.68, -1]

        Group.objects.get_or_create(label=TEST_GROUP_NAME)

        from aiida.orm.nodes.data.upf import upload_upf_family
        upload_upf_family(TEST_UPF_DIRECTORY,
                          TEST_UPF_FAMILY,
                          group_description="")
示例#2
0
def upf_uploadfamily(folder, group_label, group_description, stop_if_existing):
    """
    Create a new UPF family from a folder of UPF files.

    Returns the numbers of files found and the number of nodes uploaded.

    Call without parameters to get some help.
    """
    from aiida.orm.nodes.data.upf import upload_upf_family
    files_found, files_uploaded = upload_upf_family(folder, group_label, group_description, stop_if_existing)
    echo.echo_success('UPF files found: {}. New files uploaded: {}'.format(files_found, files_uploaded))
示例#3
0
    def test_group_name_and_type_change(self, temp_dir):
        """ Group's name and type columns have changed
        Change for columns:
        “name”            --> “label”
        "type"            --> "type_string"
        Furthermore, type_strings have been updated to:
        ""                --> "user"
        "data.upf.family" --> "data.upf"
        "aiida.import"    --> "auto.import"
        "autogroup.run"   --> "auto.run"

        The new columns are called on group instances, and will fail if not present.
        A user created Group is validated to have the "user" value as a type_string.
        A UPF file is created and imported/uploaded as a UPF family,
        in order to create a Group with type_string="data.upf".
        Any import will create a Group with type_string "auto.import", which is checked.
        The type_string="auto.run" is not directly checked, but if the three checks
        above succeed, it is understood that "auto.run" is also correctly ex-/imported
        as the type_string content for the relevant Groups.
        """
        from aiida.orm.nodes.data.upf import upload_upf_family
        # To be saved
        groups_label = ['Users', 'UpfData']
        upf_filename = 'Al.test_file.UPF'
        # regular upf file version 2 header
        upf_contents = '\n'.join([
            "<UPF version=\"2.0.1\">",
            'Human readable section is completely irrelevant for parsing!',
            '<PP_HEADER',
            'contents before element tag',
            "element=\"Al\"",
            'contents following element tag',
            '>',
        ])
        path_to_upf = os.path.join(temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)

        # Create Groups
        node1 = orm.CalculationNode().store()
        node2 = orm.CalculationNode().store()
        node1.seal()
        node2.seal()
        group_user = orm.Group(label=groups_label[0]).store()
        group_user.add_nodes([node1, node2])

        upload_upf_family(temp_dir, groups_label[1], '')
        group_upf = orm.load_group(groups_label[1])

        # Save uuids and type
        groups_uuid = [str(g.uuid) for g in [group_user, group_upf]]
        groups_type_string = [g.type_string for g in [group_user, group_upf]]

        # Assert correct type strings exists prior to export
        self.assertListEqual(groups_type_string, ['core', 'core.upf'])

        # Export node
        filename = os.path.join(temp_dir, 'export.aiida')
        export([group_user, group_upf], filename=filename)

        # Clean the database and reimport
        self.clean_db()
        import_data(filename)

        # Retrieve Groups and make sure exactly 3 are retrieved (including the "import group")
        builder = orm.QueryBuilder()
        builder.append(orm.Group, project=['uuid'])
        imported_groups = builder.all()

        self.assertEqual(builder.count(), 3)

        # Check uuids are the same after import
        imported_groups_uuid = [str(g[0]) for g in imported_groups]

        # We do not know the "import group"'s uuid, so go through known uuids
        for group_uuid in groups_uuid:
            self.assertIn(group_uuid, imported_groups_uuid)

            # Pop known uuid from imported_groups_uuid, eventually leaving
            # only the "import group"
            imported_groups_uuid.remove(group_uuid)

            # Load group
            imported_group = orm.load_group(group_uuid)

            # Check whether types are correctly imported
            self.assertIn(imported_group.type_string, groups_type_string)

            # Assert labels are imported correctly
            self.assertIn(imported_group.label, groups_label)

        # Check type_string content of "import group"
        import_group = orm.load_group(imported_groups_uuid[0])
        self.assertEqual(import_group.type_string, 'core.import')