예제 #1
0
 def _get_raw_pseudopotential_type(cls, calc, **kwargs):  # pylint: disable=unused-argument
     """Return the raw pseudopotential type."""
     from aiida.orm.nodes.data.upf import parse_upf
     types = {}
     for node in calc.get_incoming(node_class=UpfData).all_nodes():
         element = node.element
         parsed = parse_upf(node.get_file_abs_path())
         if parsed['version'] != '2':
             types[element] = None
             continue
         upf_type = None
         with open(node.filename) as handle:
             for line in handle:
                 match = cls._upf_type_v2_regexp.match(line.strip())
                 if match:
                     upf_type = match.group('upf_type')
                     break
         types[element] = upf_type
     return types
예제 #2
0
    def test_invalid_element_upf_v1(self):
        """Test parsers exception on invalid element name in UPF v1."""

        upf_filename = 'Ab.test_file_invalid_element_v1.UPF'
        # upf file header contents
        upf_contents = '\n'.join([
            '<PP_INFO>'
            'Human readable section is completely irrelevant for parsing!',
            '<PP_HEADER',
            'contents before element tag',
            'Ab                     Element',
            'contents following element tag',
            '>',
        ])
        path_to_upf = os.path.join(self.temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)
        # Check if parser raises the desired ParsingError
        with self.assertRaises(ParsingError):
            _ = parse_upf(path_to_upf, check_filename=True)
예제 #3
0
    def test_missing_element_upf_v2(self):
        """Test parsers exception on missing element name in UPF v2."""

        upf_filename = 'Ab.test_file_missing_element_v2.UPF'
        # upf file header contents
        upf_contents = '\n'.join([
            "<UPF version=\"2.0.1\">",
            'Human readable section is completely irrelevant for parsing!',
            '<PP_HEADER',
            'contents before element tag',
            'element should be here but is missing',
            'contents following element tag',
            '>',
        ])
        path_to_upf = os.path.join(self.temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)
        # Check if parser raises the desired ParsingError
        with self.assertRaises(ParsingError):
            _ = parse_upf(path_to_upf, check_filename=True)
예제 #4
0
    def test_check_filename(self):
        """Test built-in check for if file name matches element"""

        upf_filename = 'Al.test_file.UPF'
        # upf file header contents
        upf_contents = '\n'.join([
            "<UPF version=\"2.0.1\">",
            'Human readable section is completely irrelevant for parsing!',
            '<PP_HEADER',
            'contents before element tag',
            "element=\"Pt\"",
            'contents following element tag',
            '>',
        ])
        path_to_upf = os.path.join(self.temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)
        # Check if parser raises the desired ParsingError
        with self.assertRaises(ParsingError):
            _ = parse_upf(path_to_upf, check_filename=True)
예제 #5
0
    def test_upf_version_two(self):
        """Check if parsing for regular UPF file (version 2) succeeds."""

        upf_filename = 'Al.test_file_v2.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(self.temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)
        # try to parse version / element name from UPF file contents
        parsed_data = parse_upf(path_to_upf, check_filename=True)
        # check that parsed data matches the expected one
        self.assertEqual(parsed_data['version'], '2.0.1')
        self.assertEqual(parsed_data['element'], 'Al')
예제 #6
0
    def test_upf_version_one(self):
        """Check if parsing for regular UPF file (version 1) succeeds."""

        upf_filename = 'O.test_file_v1.UPF'
        # regular upf file version 1 header
        upf_contents = u'\n'.join([
            '<PP_INFO>'
            'Human readable section is completely irrelevant for parsing!',
            '<PP_HEADER',
            'contents before element tag',
            'O                     Element',
            'contents following element tag',
            '>',
        ])
        path_to_upf = os.path.join(self.temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)
        # try to parse version / element name from UPF file contents
        parsed_data = parse_upf(path_to_upf, check_filename=True)
        # check that parsed data matches the expected one
        self.assertEqual(parsed_data['version'], '1')
        self.assertEqual(parsed_data['element'], 'O')
예제 #7
0
    def test_additional_header_line(self):
        """Regression #2228: check if parsing succeeds if additional header line is present."""

        upf_filename = 'Pt.test_file.UPF'
        # minimal contents required for parsing including additional header
        # file
        upf_contents = '\n'.join([
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
            "<UPF version=\"2.0.1\">",
            'Human readable section is completely irrelevant for parsing!',
            '<PP_HEADER',
            'contents before element tag',
            "element=\"Pt\"",
            'contents following element tag',
            '>',
        ])
        path_to_upf = os.path.join(self.temp_dir, upf_filename)
        with open(path_to_upf, 'w') as upf_file:
            upf_file.write(upf_contents)
        # try to parse version / element name from UPF file contents
        parsed_data = parse_upf(path_to_upf, check_filename=True)
        # check that parsed data matches the expected one
        self.assertEqual(parsed_data['version'], '2.0.1')
        self.assertEqual(parsed_data['element'], 'Pt')