Exemplo n.º 1
0
    def test_conversion(self):
        # Make an FCC cell.
        cell = Cell()
        cell.set_basis(lengths=[3.5, 3.6, 3.4], angles=[89, 90, 91])
        cell.add_atom(Atom([0, 0, 0], 0))
        cell.add_atom(Atom([0.5, 0.5, 0], 1))
        cell.add_atom(Atom([0.5, 0, 0.5], 1))
        cell.add_atom(Atom([0, 0.5, 0.5], 1))
        cell.set_type_name(0, "Al")
        cell.set_type_name(1, "Ni")

        # Convert it to string.
        vio = VASP5IO()
        temp = vio.convert_structure_to_string(cell)

        # Convert it back.
        new_cell = vio.parse_file(list_of_lines=temp)

        # Check to make sure everything is good.
        self.assertAlmostEqual(cell.volume(), new_cell.volume(), delta=1e-4)
        self.assertEqual(cell.n_types(), new_cell.n_types())
        np_tst.assert_array_almost_equal(cell.get_lattice_vectors()[1],
                                         new_cell.get_lattice_vectors()[1],
                                         decimal=4)
        new_temp = vio.convert_structure_to_string(new_cell)
        np_tst.assert_equal(temp, new_temp)
Exemplo n.º 2
0
 def test_parse_from_file(self):
     vio = VASP5IO()
     # this_file_path = os.path.dirname(__file__)
     # abs_path = os.path.join(this_file_path, "../../test-files/")
     abs_path = pkg_resources.resource_filename('chemml', os.path.join('datasets', 'data', 'magpie_python_test'))
     cell = vio.parse_file(file_name=os.path.join(abs_path, "393-Ta1.vasp"))
     self.assertAlmostEqual(556.549, cell.volume(), delta=1e-2)
     self.assertAlmostEqual(10.218, cell.get_lattice_vectors()[0][0],
                             delta=1e-2)
     self.assertEqual(30, cell.n_atoms())
     np_tst.assert_array_almost_equal([0.681, 0.818, 0.998],
                                      cell.get_atom(29).get_position(),
                                      decimal=2)
    def test_layered_compound(self):
        structure = VASP5IO.parse_file(file_name=os.path.join(self.abs_path, "16234-O2Si1.vasp"))
        # Run tessellation.
        result = VoronoiTessellationCalculator.compute(structure,
                                                       radical=False)

        # Test results.
        total_vol = 0.0
        for cell in result:
            total_vol += cell.get_volume()
            self.assertTrue(cell.geometry_is_valid())
        vol_error = (total_vol - structure.volume()) / structure.volume()
        self.assertAlmostEqual(0.0, vol_error, delta=1e-2)
    def test_B(self):
        structure = VASP5IO.parse_file(file_name=os.path.join(self.abs_path, "673-B1.vasp"))
        # Run tessellation.
        result = VoronoiTessellationCalculator.compute(structure,
                                                       radical=False)

        # Test results.
        total_vol = 0.0
        for cell in result:
            total_vol += cell.get_volume()
            self.assertTrue(cell.geometry_is_valid())
        self.assertAlmostEqual(structure.volume(), total_vol,
                                    delta=total_vol * 0.01)
    def test_ICSD_examples(self):
        example = ["3315-Ge2Os2Th1", "1001-N1Y1", "11375-C2N1",
            "12012-Ge2Ru2Tb1", "3778-Sr1Zn2", "4746-Cd1Cu4Er1"]
        for e in example:
            structure = VASP5IO.parse_file(file_name=os.path.join(self.abs_path,  e +".vasp"))
            # Run tessellation.
            result = VoronoiTessellationCalculator.compute(structure,
                                                           radical=False)

            # Test results.
            total_vol = 0.0
            for cell in result:
                total_vol += cell.get_volume()
                self.assertTrue(cell.geometry_is_valid())
            vol_error = (total_vol - structure.volume()) / structure.volume()
            self.assertAlmostEqual(0.0, vol_error, delta=1e-2)