コード例 #1
0
ファイル: common.py プロジェクト: quanshengwu/aiida-vasp
    def structure(cls):
        larray = np.array([[0, .5, .5], [.5, 0, .5], [.5, .5, 0]])
        alat = 6.058
        structure = DataFactory('structure')(cell=larray * alat)
        structure.append_atom(position=[0, 0, 0], symbols='In')
        structure.append_atom(position=[.25, .25, .25], symbols='As')

        return structure
コード例 #2
0
    def structure():
        """Create a StructureData object which can be used in tests"""
        larray = np.array([[0, .5, .5], [.5, 0, .5], [.5, .5, 0]])
        alat = 6.058
        structure = DataFactory('structure')(cell=larray * alat)
        structure.append_atom(position=[0, 0, 0], symbols='In')
        structure.append_atom(position=[.25, .25, .25], symbols='As')

        return structure
コード例 #3
0
def vasp_structure(request, aiida_env):
    """Fixture: StructureData or CifData"""
    from aiida_vasp.backendtests.common import subpath
    from aiida.orm import DataFactory
    if request.param == 'cif':
        cif_path = subpath('data', 'EntryWithCollCode43360.cif')
        structure = DataFactory('cif').get_or_create(cif_path)[0]
    elif request.param == 'str':
        larray = numpy.array([[0, .5, .5], [.5, 0, .5], [.5, .5, 0]])
        alat = 6.058
        structure = DataFactory('structure')(cell=larray * alat)
        structure.append_atom(position=[0, 0, 0], symbols='In')
        structure.append_atom(position=[.25, .25, .25], symbols='As')
        structure.append_atom(position=[.25, .33, .34], symbols='As')
        structure.append_atom(position=[.5, .5, .5], symbols='In', name='In_d')
        structure.append_atom(position=[.7896, .6234, .5],
                              symbols='In',
                              name='In_d')
        structure.append_atom(position=[.75, .75, .75], symbols='As')
    return structure
コード例 #4
0
    def test_simple(self):
        import numpy as np
        from aiida.orm import DataFactory
        s = DataFactory('structure')(cell=[[4, 0, 0], [0, 4, 0], [0, 0, 6]])
        s.append_atom(symbols='Ba', position=[0, 0, 0])
        s.append_atom(symbols='Ti', position=[2, 2, 3])
        s.append_atom(symbols='O', position=[2, 2, 0])
        s.append_atom(symbols='O', position=[2, 0, 3])
        s.append_atom(symbols='O', position=[0, 2, 3])

        retdict = get_explicit_k_path(s,
                                      with_time_reversal=True,
                                      reference_distance=0.025,
                                      recipe='hpkot',
                                      threshold=1.e-7)

        self.assertTrue(retdict['has_inversion_symmetry'])
        self.assertFalse(retdict['augmented_path'])
        self.assertAlmostEqual(retdict['volume_original_wrt_prim'], 1.0)
        self.assertEqual(retdict['segments'], [(0, 31), (30, 61), (60, 104),
                                               (103, 123), (122, 153),
                                               (152, 183), (182, 226),
                                               (226, 246), (246, 266)])
        ret_s = retdict['primitive_structure']
        ret_k = retdict['explicit_kpoints']
        self.assertEqual(ret_k.labels, [(0, 'GAMMA'), (30, 'X'), (60, 'M'),
                                        (103, 'GAMMA'), (122, 'Z'), (152, 'R'),
                                        (182, 'A'), (225, 'Z'), (226, 'X'),
                                        (245, 'R'), (246, 'M'), (265, 'A')])
        kpts = ret_k.get_kpoints(cartesian=False)
        highsympoints_relcoords = [kpts[idx] for idx, label in ret_k.labels]
        self.assertAlmostEqual(
            np.sum(
                np.abs(
                    np.array([
                        [0., 0., 0.],  # Gamma
                        [0., 0.5, 0.],  # X
                        [0.5, 0.5, 0.],  # M
                        [0., 0., 0.],  # Gamma
                        [0., 0., 0.5],  # Z
                        [0., 0.5, 0.5],  # R
                        [0.5, 0.5, 0.5],  # A
                        [0., 0., 0.5],  # Z
                        [0., 0.5, 0.],  # X
                        [0., 0.5, 0.5],  # R
                        [0.5, 0.5, 0.],  # M
                        [0.5, 0.5, 0.5],  # A
                    ]) - np.array(highsympoints_relcoords))),
            0.)

        # The primitive structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(s.cell) - np.array(ret_s.cell))), 0.)
        self.assertEqual([_.kind_name for _ in s.sites],
                         [_.kind_name for _ in ret_s.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in s.sites]) -
                    np.array([_.position for _ in ret_s.sites]))), 0.)
コード例 #5
0
    def test_simple(self):
        import numpy as np
        from aiida.orm import DataFactory
        s = DataFactory('structure')(cell=[[4, 0, 0], [0, 4, 0], [0, 0, 6]])
        s.append_atom(symbols='Ba', position=[0, 0, 0])
        s.append_atom(symbols='Ti', position=[2, 2, 3])
        s.append_atom(symbols='O', position=[2, 2, 0])
        s.append_atom(symbols='O', position=[2, 0, 3])
        s.append_atom(symbols='O', position=[0, 2, 3])

        retdict = get_path(s,
                           with_time_reversal=True,
                           reference_distance=0.025,
                           recipe='hpkot',
                           threshold=1.e-7)

        self.assertTrue(retdict['has_inversion_symmetry'])
        self.assertFalse(retdict['augmented_path'])
        self.assertAlmostEqual(retdict['volume_original_wrt_prim'], 1.0)
        self.assertAlmostEqual(retdict['volume_original_wrt_conv'], 1.0)
        self.assertEqual(retdict['bravais_lattice'], 'tP')
        self.assertEqual(retdict['bravais_lattice_extended'], 'tP1')
        self.assertEqual(retdict['path'], [('GAMMA', 'X'), ('X', 'M'),
                                           ('M', 'GAMMA'), ('GAMMA', 'Z'),
                                           ('Z', 'R'), ('R', 'A'), ('A', 'Z'),
                                           ('X', 'R'), ('M', 'A')])

        self.assertEqual(
            retdict['point_coords'], {
                'A': [0.5, 0.5, 0.5],
                'M': [0.5, 0.5, 0.0],
                'R': [0.0, 0.5, 0.5],
                'X': [0.0, 0.5, 0.0],
                'Z': [0.0, 0.0, 0.5],
                'GAMMA': [0.0, 0.0, 0.0]
            })

        self.assertAlmostEqual(
            np.sum(
                np.abs(
                    np.array(
                        retdict['inverse_primitive_transformation_matrix']) -
                    np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))), 0.)

        ret_prims = retdict['primitive_structure']
        ret_convs = retdict['conv_structure']
        # The primitive structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(s.cell) - np.array(ret_prims.cell))), 0.)
        self.assertEqual([_.kind_name for _ in s.sites],
                         [_.kind_name for _ in ret_prims.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in s.sites]) -
                    np.array([_.position for _ in ret_prims.sites]))), 0.)

        # Also the conventional structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(s.cell) - np.array(ret_convs.cell))), 0.)
        self.assertEqual([_.kind_name for _ in s.sites],
                         [_.kind_name for _ in ret_convs.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in s.sites]) -
                    np.array([_.position for _ in ret_convs.sites]))), 0.)
コード例 #6
0
class Vasp5CalcTest(AiidaTestCase):
    '''
    Test Case for
    py:class:`~aiida.orm.calculation.job.vasp.vasp5.Vasp5Calculation`
    '''
    def setUp(self):
        self.calc = CalculationFactory('vasp.vasp5')()
        Common.import_paw()

        larray = np.array([[0, .5, .5],
                           [.5, 0, .5],
                           [.5, .5, 0]])
        alat = 6.058
        self.structure = DataFactory('structure')(cell=larray*alat)
        self.structure.append_atom(position=[0, 0, 0], symbols='In')
        self.structure.append_atom(position=[.25, .25, .25], symbols='As')

        cifpath = realpath(join(dirname(__file__),
                                'data', 'EntryWithCollCode43360.cif'))
        self.cif = DataFactory('cif').get_or_create(cifpath)[0]

    def test_inputs(self):
        self.assertTrue(hasattr(self.calc, 'use_code'))
        self.assertTrue(hasattr(self.calc, 'use_settings'))
        self.assertTrue(hasattr(self.calc, 'use_structure'))
        self.assertTrue(hasattr(self.calc, 'use_paw'))
        self.assertTrue(hasattr(self.calc, 'use_kpoints'))
        self.assertTrue(hasattr(self.calc, 'use_charge_density'))
        self.assertTrue(hasattr(self.calc, 'use_wavefunctions'))

    def test_internal_params(self):
        self.assertTrue(self.calc.get_parser_name())

    def test_settings_property(self):
        self.calc.use_settings(self.calc.new_settings(dict={'A': 0}))
        self.assertEqual(self.calc._settings, {'a': 0})

    def test_write_incar(self):
        '''
        write out an INCAR tag to a tempfile and check wether
        it was written correctly
        '''
        inc = self.calc.new_settings(dict={'system': 'InAs'})
        dst = tempfile.mkstemp()[1]
        self.calc.use_settings(inc)
        self.calc.write_incar({}, dst)
        with open(dst, 'r') as incar:
            self.assertEqual(incar.read().strip(), 'SYSTEM = InAs')

    def test_write_potcar(self):
        '''
        concatenate two paws into a tmp POTCAR and check wether
        each is contained in the result
        '''
        self.calc.use_settings(self.calc.new_settings(dict={'System': 'Test'}))
        self.calc.use_structure(self.structure)
        self.calc.use_paw(
            self.calc.load_paw(family='TEST', symbol='In_d'), kind='In')
        self.calc.use_paw(
            self.calc.load_paw(family='TEST', symbol='As'), kind='As')
        dst = tempfile.mkstemp()[1]
        self.calc.write_potcar(self.calc.get_inputs_dict(), dst)
        with open(dst, 'r') as potcar:
            x = potcar.read()
            with open(self.calc.inp.paw_In.potcar, 'r') as paw_In:
                a = paw_In.read()
                self.assertIn(a, x)
            with open(self.calc.inp.paw_As.potcar, 'r') as paw_As:
                b = paw_As.read()
                self.assertIn(b, x)

    def test_write_poscar(self):
        '''
        feed a structure into calc and write it to a POSCAR temp file
        check for nonemptiness of the file
        '''
        self.calc.use_structure(self.structure)
        dst = tempfile.mkstemp()[1]
        self.calc.write_poscar({}, dst)
        with open(dst, 'r') as poscar:
            self.assertTrue(poscar.read())

    def test_write_poscar_cif(self):
        '''
        feed a cif file into calc and write it to a POSCAR temp file
        make sure the file is not empty
        '''
        self.calc.use_structure(self.cif)
        dst = tempfile.mkstemp()[1]
        self.calc.write_poscar({}, dst)
        with open(dst, 'r') as poscar:
            self.assertTrue(poscar.read())

    def test_write_kpoints(self):
        '''
        feed kpoints into calc and write to KPOINTS temp file
        verify the file is not empty
        '''
        kp = self.calc.new_kpoints()
        kp.set_kpoints_mesh([4, 4, 4])
        self.calc.use_kpoints(kp)
        self.calc.use_settings(self.calc.new_settings())
        dst = tempfile.mkstemp()[1]
        self.calc.write_kpoints(self.calc.get_inputs_dict(), dst)
        with open(dst, 'r') as kpoints:
            self.assertTrue(kpoints.read())

    def test_need_kp_false(self):
        self.calc.use_settings(
            self.calc.new_settings(dict={'kspacing': 0.5, 'kgamma': True}))
        self.assertFalse(self.calc._need_kp())

    def test_need_kp_true(self):
        self.calc.use_settings(self.calc.new_settings())
        self.assertTrue(self.calc._need_kp())

    def test_need_chgd_none(self):
        self.calc.use_settings(self.calc.new_settings())
        self.assertFalse(self.calc._need_chgd())

    def test_need_chgd_icharg(self):
        for i in [0, 2, 4, 10, 12]:
            self.calc.use_settings(
                self.calc.new_settings(dict={'icharg': i}))
            self.assertFalse(self.calc._need_chgd())
        for i in [1, 11]:
            self.calc.use_settings(
                self.calc.new_settings(dict={'icharg': i}))
            self.assertTrue(self.calc._need_chgd())

    def test_need_wfn_none(self):
        self.calc.use_settings(self.calc.new_settings())
        self.assertFalse(self.calc._need_wfn())
        self.calc.use_wavefunctions(self.calc.new_wavefunctions())
        self.assertTrue(self.calc._need_wfn())

    def test_need_wfn_istart(self):
        self.calc.use_settings(
            self.calc.new_settings(dict={'istart': 0}))
        self.assertFalse(self.calc._need_wfn())
        for i in [1, 2, 3]:
            self.calc.use_settings(
                self.calc.new_settings(dict={'istart': i}))
            self.assertTrue(self.calc._need_wfn(),
                            msg='_need_wfn not True for istart=%s' % i)

    def test_get_paw_linkname(self):
        self.assertEqual(self.calc._get_paw_linkname('In'), 'paw_In')

    def test_Paw(self):
        self.assertIs(self.calc.Paw, DataFactory('vasp.paw'))

    def test_load_paw(self):
        paw_A = self.calc.load_paw(family='TEST', symbol='As')
        paw_B = self.calc.Paw.load_paw(family='TEST', symbol='As')[0]
        self.assertEqual(paw_A.pk, paw_B.pk)

    def test_new_setting(self):
        self.assertIsInstance(self.calc.new_settings(),
                              DataFactory('parameter'))

    def test_new_structure(self):
        self.assertIsInstance(self.calc.new_structure(),
                              DataFactory('structure'))

    def test_new_kpoints(self):
        self.assertIsInstance(self.calc.new_kpoints(),
                              DataFactory('array.kpoints'))

    def test_new_charge_density(self):
        self.assertIsInstance(self.calc.new_charge_density(),
                              DataFactory('vasp.chargedensity'))

    def test_new_wavefunctions(self):
        self.assertIsInstance(self.calc.new_wavefunctions(),
                              DataFactory('vasp.wavefun'))
コード例 #7
0
    def test_simple(self):
        import numpy as np
        from aiida.orm import DataFactory
        structure = DataFactory('structure')(
            cell=[[4, 0, 0], [0, 4, 0], [0, 0, 6]])
        structure.append_atom(symbols='Ba', position=[0, 0, 0])
        structure.append_atom(symbols='Ti', position=[2, 2, 3])
        structure.append_atom(symbols='O', position=[2, 2, 0])
        structure.append_atom(symbols='O', position=[2, 0, 3])
        structure.append_atom(symbols='O', position=[0, 2, 3])

        params = DataFactory('parameter')(dict={
            'with_time_reversal': True,
            'recipe': 'hpkot',
            'threshold': 1.e-7
        })

        return_value = get_path(structure, params)
        retdict = return_value['seekpath_parameters'].get_dict()

        self.assertTrue(retdict['has_inversion_symmetry'])
        self.assertFalse(retdict['augmented_path'])
        self.assertAlmostEqual(retdict['volume_original_wrt_prim'], 1.0)
        self.assertAlmostEqual(retdict['volume_original_wrt_conv'], 1.0)
        self.assertEqual(retdict['bravais_lattice'], 'tP')
        self.assertEqual(retdict['bravais_lattice_extended'], 'tP1')
        self.assertEqual(
            to_list_of_lists(retdict['path']),
            [['GAMMA', 'X'], ['X', 'M'], ['M', 'GAMMA'], ['GAMMA', 'Z'],
             ['Z', 'R'], ['R', 'A'], ['A', 'Z'], ['X', 'R'], ['M', 'A']])

        self.assertEqual(
            retdict['point_coords'], {
                'A': [0.5, 0.5, 0.5],
                'M': [0.5, 0.5, 0.0],
                'R': [0.0, 0.5, 0.5],
                'X': [0.0, 0.5, 0.0],
                'Z': [0.0, 0.0, 0.5],
                'GAMMA': [0.0, 0.0, 0.0]
            })

        self.assertAlmostEqual(
            np.sum(
                np.abs(
                    np.array(
                        retdict['inverse_primitive_transformation_matrix']) -
                    np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))), 0.)

        ret_prims = return_value['primitive_structure']
        ret_convs = return_value['conv_structure']
        # The primitive structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(structure.cell) -
                          np.array(ret_prims.cell))), 0.)
        self.assertEqual([_.kind_name for _ in structure.sites],
                         [_.kind_name for _ in ret_prims.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in structure.sites]) -
                    np.array([_.position for _ in ret_prims.sites]))), 0.)

        # Also the conventional structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(structure.cell) -
                          np.array(ret_convs.cell))), 0.)
        self.assertEqual([_.kind_name for _ in structure.sites],
                         [_.kind_name for _ in ret_convs.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in structure.sites]) -
                    np.array([_.position for _ in ret_convs.sites]))), 0.)
コード例 #8
0
    def test_simple(self):
        import numpy as np
        from aiida.orm import DataFactory
        structure = DataFactory('structure')(
            cell=[[4, 0, 0], [0, 4, 0], [0, 0, 6]])
        structure.append_atom(symbols='Ba', position=[0, 0, 0])
        structure.append_atom(symbols='Ti', position=[2, 2, 3])
        structure.append_atom(symbols='O', position=[2, 2, 0])
        structure.append_atom(symbols='O', position=[2, 0, 3])
        structure.append_atom(symbols='O', position=[0, 2, 3])

        params = DataFactory('parameter')(dict={
            'with_time_reversal': True,
            'reference_distance': 0.025,
            'recipe': 'hpkot',
            'threshold': 1.e-7
        })

        return_value = get_explicit_k_path(structure, params)
        retdict = return_value['seekpath_parameters'].get_dict()

        self.assertTrue(retdict['has_inversion_symmetry'])
        self.assertFalse(retdict['augmented_path'])
        self.assertAlmostEqual(retdict['volume_original_wrt_prim'], 1.0)
        self.assertEqual(to_list_of_lists(retdict['explicit_segments']),
                         [[0, 31], [30, 61], [60, 104], [103, 123], [122, 153],
                          [152, 183], [182, 226], [226, 246], [246, 266]])

        ret_k = return_value['explicit_kpoints']
        self.assertEqual(to_list_of_lists(ret_k.labels),
                         [[0, 'GAMMA'], [30, 'X'], [60, 'M'], [103, 'GAMMA'],
                          [122, 'Z'], [152, 'R'], [182, 'A'], [225, 'Z'],
                          [226, 'X'], [245, 'R'], [246, 'M'], [265, 'A']])
        kpts = ret_k.get_kpoints(cartesian=False)
        highsympoints_relcoords = [kpts[idx] for idx, label in ret_k.labels]
        self.assertAlmostEqual(
            np.sum(
                np.abs(
                    np.array([
                        [0., 0., 0.],  # Gamma
                        [0., 0.5, 0.],  # X
                        [0.5, 0.5, 0.],  # M
                        [0., 0., 0.],  # Gamma
                        [0., 0., 0.5],  # Z
                        [0., 0.5, 0.5],  # R
                        [0.5, 0.5, 0.5],  # A
                        [0., 0., 0.5],  # Z
                        [0., 0.5, 0.],  # X
                        [0., 0.5, 0.5],  # R
                        [0.5, 0.5, 0.],  # M
                        [0.5, 0.5, 0.5],  # A
                    ]) - np.array(highsympoints_relcoords))),
            0.)

        ret_prims = return_value['primitive_structure']
        ret_convs = return_value['conv_structure']
        # The primitive structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(structure.cell) -
                          np.array(ret_prims.cell))), 0.)
        self.assertEqual([_.kind_name for _ in structure.sites],
                         [_.kind_name for _ in ret_prims.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in structure.sites]) -
                    np.array([_.position for _ in ret_prims.sites]))), 0.)

        # Also the conventional structure should be the same as the one I input
        self.assertAlmostEqual(
            np.sum(np.abs(np.array(structure.cell) -
                          np.array(ret_convs.cell))), 0.)
        self.assertEqual([_.kind_name for _ in structure.sites],
                         [_.kind_name for _ in ret_convs.sites])
        self.assertEqual(
            np.sum(
                np.abs(
                    np.array([_.position for _ in structure.sites]) -
                    np.array([_.position for _ in ret_convs.sites]))), 0.)