示例#1
0
    def create_cif_data(cls):
        with tempfile.NamedTemporaryFile() as f:
            filename = f.name
            f.write(cls.valid_sample_cif_str)
            f.flush()
            a = CifData(file=filename,
                        source={
                            'version': '1234',
                            'db_name': 'COD',
                            'id': '0000001'
                        })
            a.store()

            g_ne = Group(name='non_empty_group')
            g_ne.store()
            g_ne.add_nodes(a)

            g_e = Group(name='empty_group')
            g_e.store()

        return {
            TestVerdiDataListable.NODE_ID_STR: a.id,
            TestVerdiDataListable.NON_EMPTY_GROUP_ID_STR: g_ne.id,
            TestVerdiDataListable.EMPTY_GROUP_ID_STR: g_e.id
        }
    def store_structure(self, name, description=None):
        structure_ase = self.get_ase(self.tmp_folder + '/' + name)
        if structure_ase is None:
            return

        # determine data source
        if name.endswith('.cif'):
            source_format = 'CIF'
        else:
            source_format = 'ASE'

        # perform conversion
        if self.data_format.value == 'CifData':
            if source_format == 'CIF':
                from aiida.orm.data.cif import CifData
                structure_node = CifData(file=self.tmp_folder + '/' + name,
                                         scan_type='flex',
                                         parse_policy='lazy')
            else:
                from aiida.orm.data.cif import CifData
                structure_node = CifData()
                structure_node.set_ase(structure_ase)
        else:
            # Target format is StructureData
            from aiida.orm.data.structure import StructureData
            structure_node = StructureData(ase=structure_ase)

            #TODO: Figure out whether this is still necessary for StructureData
            # ensure that tags got correctly translated into kinds
            for t1, k in zip(structure_ase.get_tags(),
                             structure_node.get_site_kindnames()):
                t2 = int(k[-1]) if k[-1].isnumeric() else 0
                assert t1 == t2
        if description is None:
            structure_node.description = self.get_description(
                structure_ase, name)
        else:
            structure_node.description = description
        structure_node.label = ".".join(name.split('.')[:-1])
        structure_node.store()
        self.structure_node = structure_node
        print("Stored in AiiDA: " + repr(structure_node))
示例#3
0
    def get_cif_node(self, store=False):
        """

        Creates a CIF node, that can be used in AiiDA workflow.

        :return: :py:class:`aiida.orm.data.cif.CifData` object
        """
        from aiida.common.utils import md5_file
        from aiida.orm.data.cif import CifData
        import tempfile

        cifnode = None

        with tempfile.NamedTemporaryFile() as f:
            f.write(self.cif)
            f.flush()
            cifnode = CifData(file=f.name, source=self.source)

        # Maintaining backwards-compatibility. Parameter 'store' should
        # be removed in the future, as the new node can be stored later.
        if store:
            cifnode.store()

        return cifnode
示例#4
0
    def create_cif_data(cls, cmd_to_nodeid_map, cmd_to_nodeid_map_for_groups,
                        cmd_to_nodeid_map_for_nuser, group, new_user):

        from aiida.orm.data.cif import CifData
        from aiida.cmdline.commands.data import _Cif
        import tempfile

        # Create the CIF data nodes
        with tempfile.NamedTemporaryFile() as f:
            f.write('''
                 data_9012064
                 _space_group_IT_number           166
                 _symmetry_space_group_name_H-M   'R -3 m :H'
                 _cell_angle_alpha                90
                 _cell_angle_beta                 90
                 _cell_angle_gamma                120
                 _cell_length_a                   4.395
                 _cell_length_b                   4.395
                 _cell_length_c                   30.440
                 _cod_database_code               9012064
                 loop_
                 _atom_site_label
                 _atom_site_fract_x
                 _atom_site_fract_y
                 _atom_site_fract_z
                 _atom_site_U_iso_or_equiv
                 Bi 0.00000 0.00000 0.40046 0.02330
                 Te1 0.00000 0.00000 0.00000 0.01748
                 Te2 0.00000 0.00000 0.79030 0.01912
             ''')
            f.flush()
            c1 = CifData(file=f.name)
            c1.store()
            c2 = CifData(file=f.name)
            c2.store()

            # Keep track of the created objects
            cmd_to_nodeid_map[_Cif] = [c1.id, c2.id]

            # Add the second CIF data to the group
            group.add_nodes([c2])
            # Keep track of the id of the node that you added to the group
            cmd_to_nodeid_map_for_groups[_Cif] = c2.id

            # Create a Cif node belonging to another user
            c3 = CifData(file=f.name)
            c3.dbnode.user = new_user._dbuser
            c3.store()

            # Put it is to the right map
            cmd_to_nodeid_map_for_nuser[_Cif] = [c3.id]
示例#5
0
    def test_cif_structure_roundtrip(self):
        from aiida.tools.dbexporters.tcod import export_cif, export_values
        from aiida.orm import Code
        from aiida.orm import JobCalculation
        from aiida.orm.data.cif import CifData
        from aiida.orm.data.parameter import ParameterData
        from aiida.orm.data.upf import UpfData
        from aiida.orm.data.folder import FolderData
        from aiida.common.folders import SandboxFolder
        from aiida.common.datastructures import calc_states
        import tempfile

        with tempfile.NamedTemporaryFile() as f:
            f.write('''
                data_test
                _cell_length_a    10
                _cell_length_b    10
                _cell_length_c    10
                _cell_angle_alpha 90
                _cell_angle_beta  90
                _cell_angle_gamma 90
                loop_
                _atom_site_label
                _atom_site_fract_x
                _atom_site_fract_y
                _atom_site_fract_z
                C 0 0 0
                O 0.5 0.5 0.5
            ''')
            f.flush()
            a = CifData(file=f.name)

        c = a._get_aiida_structure()
        c.store()
        pd = ParameterData()

        code = Code(local_executable='test.sh')
        with tempfile.NamedTemporaryFile() as f:
            f.write("#/bin/bash\n\necho test run\n")
            f.flush()
            code.add_path(f.name, 'test.sh')

        code.store()

        calc = JobCalculation(computer=self.computer)
        calc.set_resources({'num_machines': 1, 'num_mpiprocs_per_machine': 1})
        calc.add_link_from(code, "code")
        calc.set_environment_variables({
            'PATH': '/dev/null',
            'USER': '******'
        })

        with tempfile.NamedTemporaryFile(prefix="Fe") as f:
            f.write("<UPF version=\"2.0.1\">\nelement=\"Fe\"\n")
            f.flush()
            upf = UpfData(file=f.name)
            upf.store()
            calc.add_link_from(upf, "upf")

        with tempfile.NamedTemporaryFile() as f:
            f.write("data_test")
            f.flush()
            cif = CifData(file=f.name)
            cif.store()
            calc.add_link_from(cif, "cif")

        calc.store()
        calc._set_state(calc_states.SUBMITTING)
        with SandboxFolder() as f:
            calc._store_raw_input_folder(f.abspath)

        fd = FolderData()
        with open(
                fd._get_folder_pathsubfolder.get_abs_path(
                    calc._SCHED_OUTPUT_FILE), 'w') as f:
            f.write("standard output")
            f.flush()

        with open(
                fd._get_folder_pathsubfolder.get_abs_path(
                    calc._SCHED_ERROR_FILE), 'w') as f:
            f.write("standard error")
            f.flush()

        fd.store()
        fd.add_link_from(calc, calc._get_linkname_retrieved(), LinkType.CREATE)

        pd.add_link_from(calc, "calc", LinkType.CREATE)
        pd.store()

        with self.assertRaises(ValueError):
            export_cif(c, parameters=pd)

        c.add_link_from(calc, "calc", LinkType.CREATE)
        export_cif(c, parameters=pd)

        values = export_values(c, parameters=pd)
        values = values['0']

        self.assertEquals(values['_tcod_computation_environment'],
                          ['PATH=/dev/null\nUSER=unknown'])
        self.assertEquals(values['_tcod_computation_command'],
                          ['cd 1; ./_aiidasubmit.sh'])