예제 #1
0
def structure_from_ucell(name):
    """Returns a `Structure` from the name of entry in the database."""
    try:
        return Structure.from_abivars(ucell(name))
    except KeyError:
        raise KeyError("Cannot find key %s in:\n %s" %
                       (name, list(_UCELLS.keys())))
예제 #2
0
def find_all_pp(obj, xc, family, label_dict={},pp_path=pp_path):
    symbols = []
    if isinstance(obj, collections.Iterable) and (
            not isinstance(obj, str)) and isinstance(obj[0], str):
        symbols = obj
    elif isinstance(obj, str) and os.path.isfile(obj):
        structure = Structure.as_structure(obj)
        symbols = set(structure.symbol_set)
    elif isinstance(obj, Structure):
        symbols = obj.symbol_set
    elif isinstance(obj, Atoms):
        for elem in obj.get_chemical_symbols():
            if elem not in symbols:
                symbols.append(elem)
    else:
        raise ValueError(
            'obj should be one of these: list of chemical symbols| abipy structure file name| abipy structure| ase atoms.'
        )
    ppdict = OrderedDict()
    for elem in symbols:
        if elem not in ppdict:
            if elem in label_dict:
                label = label_dict
            else:
                label = ''
            ppdict[elem] = find_pp(elem, xc, family, label,pp_path=pp_path)
    return list(ppdict.values())
예제 #3
0
def to_abi_structure(obj, magmoms=False):
    ms = None
    if isinstance(obj, str) and os.path.isfile(obj):
        structure = Structure.as_structure(obj)
    elif isinstance(obj, Structure):
        structure = obj
    elif isinstance(obj, Atoms):
        structure = Structure.from_ase_atoms(obj)
        if magmoms:
            ms = obj.get_initial_magnetic_moments()
    else:
        raise ValueError(
            'obj should be one of these:  abipy structure file name| abipy structure| ase atoms.'
        )
    if magmoms:
        return structure, ms
    else:
        return structure
예제 #4
0
 def test_GWWork(self):
     """
     Testing the abstract class GWFWWork
     """
     struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
     struc.item = 'test'
     self.assertIsInstance(struc, AbiStructure)
     work = GWWork()
     work.set_status(struc)
     self.assertEqual(work.workdir, 'Si_test/work_0')
     self.assertEqual(work.grid, 0)
     self.assertFalse(work.all_done)
예제 #5
0
 def test_GWWork(self):
     """
     Testing the abstract class GWFWWork
     """
     struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
     struc.item = 'test'
     self.assertIsInstance(struc, AbiStructure)
     work = GWWork()
     work.set_status(struc)
     self.assertEqual(work.workdir, 'Si_test/work_0')
     self.assertEqual(work.grid, 0)
     self.assertFalse(work.all_done)
예제 #6
0
def to_abi_structure(obj,magmoms=False):
    ms=None
    if isinstance(obj, str) and os.path.isfile(obj):
        structure = Structure.as_structure(obj)
    elif isinstance(obj, Structure):
        structure = obj
    elif isinstance(obj, Atoms):
        #cell=obj.get_cell()
        #acell0=np.linalg.norm(cell[0])
        #acell1=np.linalg.norm(cell[1])
        #acell2=np.linalg.norm(cell[2])
        #cell0=cell[0]/acell0
        #cell1=cell[1]/acell1
        #cell2=cell[2]/acell2
        #acell=[acell0, acell1, acell2]
        #rprim=[cell0, cell1, cell2]
        #xred=obj.get_scaled_positions()
        #znucl=list(set(obj.get_atomic_numbers()))
        #ntypat=len(znucl)
        #typat=[]
        #for z in obj.get_atomic_numbers():
        #    for i,n in enumerate(znucl):
        #        if z==n:
        #            typat.append(i)
        #structure = Structure.from_abivars(acell=acell, rprim=rprim, typat=typat, xred=xred, ntypat=ntypat, znucl=znucl)
        structure = Structure.from_ase_atoms(obj)
        if magmoms:
            ms=obj.get_initial_magnetic_moments()
    else:
        raise ValueError(
            'obj should be one of these:  abipy structure file name| abipy structure| ase atoms.'
        )
    if magmoms:
        return structure,ms
    else:
        return structure
예제 #7
0
    def test_expand(self):
        """
        Testing helper function to extend the convergence grid
        """
        self.maxDiff = None
        spec = get_spec('GW')
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        print('wdir', wdir)

        os.chdir(wdir)
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_ABINIT_PS = None

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir

        tests = SingleAbinitGWWork(struc, spec).convs
        tests_out = {'nscf_nbands': {'test_range': (40,),
                                     'control': 'gap', 'method': 'set_bands', 'level': 'nscf'},
                     'ecut': {'test_range': (50, 48, 46, 44),
                              'control': 'e_ks_max', 'method': 'direct', 'level': 'scf'},
                     'ecuteps': {'test_range': (4, 8, 12, 16, 20),
                                 'control': 'gap', 'method': 'direct', 'level': 'sigma'}}
        self.assertEqual(expand(tests, 1), tests_out)
        spec.data['code'] = 'VASP'

        if "VASP_PSP_DIR" in os.environ:
            spec.update_code_interface()
            tests = GWG0W0VaspInputSet(struc, spec).convs
            tests_out = {'ENCUTGW': {'test_range': (200, 400, 600, 800), 'control': 'gap', 'method': 'incar_settings'}}
            self.assertEqual(expand(tests, 1), tests_out)

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #8
0
    def test_VaspGWFWWorkFlow(self):
        """
        Testing the concrete VaspGWFWWorkFlow class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'
        self.assertIsInstance(struc, AbiStructure)
        work = VaspGWFWWorkFlow()

        self.assertEqual(len(work.work_list), 0)
        self.assertEqual(len(work.connections), 0)
        self.assertEqual(work.fw_id, 1)
        self.assertEqual(work.prep_id, 1)
        self.assertEqual(len(work.wf), 0)

        if False:
            for job in ['prep', 'G0W0', 'GW0', 'scGW0']:
                parameters = dict()
                parameters['spec'] = dict()
                parameters['spec']['converge'] = True
                parameters['job'] = job
                work.add_work(parameters=parameters)
예제 #9
0
    def test_VaspGWFWWorkFlow(self):
        """
        Testing the concrete VaspGWFWWorkFlow class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'
        self.assertIsInstance(struc, AbiStructure)
        work = VaspGWFWWorkFlow()

        self.assertEqual(len(work.work_list), 0)
        self.assertEqual(len(work.connections), 0)
        self.assertEqual(work.fw_id, 1)
        self.assertEqual(work.prep_id, 1)
        self.assertEqual(len(work.wf), 0)

        if False:
            for job in ['prep', 'G0W0', 'GW0', 'scGW0']:
                parameters = dict()
                parameters['spec'] = dict()
                parameters['spec']['converge'] = True
                parameters['job'] = job
                work.add_work(parameters=parameters)
예제 #10
0
    def test_expand(self):
        """
        Testing helper function to extend the convergence grid
        """
        self.maxDiff = None
        spec = get_spec('GW')
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        print('wdir', wdir)

        os.chdir(wdir)
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'simple_scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        temp_ABINIT_PS_EXT = os.environ.get('ABINIT_PS_EXT', None)
        temp_ABINIT_PS = os.environ.get('ABINIT_PS', None)

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir

        tests = SingleAbinitGWWork(struc, spec).convs
        tests_out = {'nscf_nbands': {'test_range': (25,),
                                     'control': 'gap', 'method': 'set_bands', 'level': 'nscf'},
                     'ecut': {'test_range': (50, 48, 46, 44),
                              'control': 'e_ks_max', 'method': 'direct', 'level': 'scf'},
                     'ecuteps': {'test_range': (4, 6, 8, 10, 12),
                                 'control': 'gap', 'method': 'direct', 'level': 'sigma'}}
        self.assertEqual(expand(tests, 1), tests_out)
        spec.data['code'] = 'VASP'

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #11
0
파일: ucells.py 프로젝트: akakcolin/abipy
def structure_from_ucell(name):
    """Returns a `Structure` from the name of entry in the database."""
    try:
        return Structure.from_abivars(ucell(name))
    except KeyError:
        raise KeyError("Cannot find key %s in:\n %s" % (name, _UCELLS.keys()))
예제 #12
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingelAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        #wdir = '.'
        shutil.copyfile(abidata.cif_file("si.cif"),
                        os.path.join(wdir, 'si.cif'))
        shutil.copyfile(
            abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(
            os.path.join(abidata.dirpath, 'managers',
                         'shell_manager_nompi.yml'),
            os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(
            os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'),
            os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_ABINIT_PS = None

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir
        self.assertIsInstance(struc, AbiStructure)
        spec = get_spec('GW')
        spec.data['kp_grid_dens'] = 100
        spec.data['kp_in'] = -100
        with open(os.path.join(wdir, 'extra_abivars'), 'w') as f:
            f.write('{"ecut": 8, "ecutsigx": 8}')

        work = SingleAbinitGWWork(struc, spec)
        self.assertEqual(len(work.CONVS), 3)

        conv_strings = ['method', 'control', 'level']
        for test in work.CONVS:
            self.assertIsInstance(work.CONVS[test]['test_range'], tuple)
            for item in conv_strings:
                self.assertIsInstance(work.CONVS[test][item], unicode)
        self.assertEqual(work.work_dir, 'Si_test')
        self.assertEqual(len(work.pseudo_table), 1)
        self.assertEqual(work.bands_fac, 1)

        self.assertEqual(work.get_electrons(struc), 8)
        self.assertEqual(work.get_bands(struc), 6)
        self.assertGreater(work.get_bands(struc),
                           work.get_electrons(struc) / 2,
                           'More electrons than bands, very bad.')

        flow = work.create()
        print(work.work_dir)
        print(flow.workdir)
        print(flow[0].workdir)
        self.assertIsInstance(flow, Flow)
        self.assertEqual(len(flow), 1)  # one work
        self.assertEqual(len(flow[0]), 4)  # with 4 tasks
        # self.assertEqual(flow.workdir, 'Si')

        self.assertEqual(flow.build_and_pickle_dump(), 0)
        # some more tests
        flow.rmtree()

        spec = get_spec('GW')
        spec.data['converge'] = True
        struc.item = 'converge'
        work = SingleAbinitGWWork(struc, spec)
        flow = work.create()
        self.assertEqual(len(flow[0]), 45)
        self.assertEqual(flow[0][0].__class__, ScfTask)
        self.assertEqual(flow[0][1].__class__, ScfTask)
        self.assertEqual(flow[0][2].__class__, ScfTask)
        self.assertEqual(flow[0][3].__class__, ScfTask)
        self.assertEqual(flow[0][4].__class__, NscfTask)
        self.assertEqual(flow[0][5].__class__, ScrTask)
        self.assertEqual(flow[0][6].__class__, SigmaTask)

        ecuts = [
            dict(task.input.as_dict()['abi_args'])['ecut'] for task in flow[0]
        ]
        print('ecuts:', ecuts)
        # it is essential that the first four are diffent, this is for the convergence study of ecut, and that
        # after that is stays the same
        self.assertEqual(ecuts, [
            50, 48, 46, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
            44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
            44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44
        ])

        nbands = [
            dict(task.input.as_dict()['abi_args'])['nband'] for task in flow[0]
        ]
        print('nbands:', nbands)
        # the firs 4 should be 'low' these are self consistent
        # the fifth should be the maximum of what follows
        # the 6th and on should always be pairs that are the same, they are combinations of scr and sigma tasks
        self.assertEqual(nbands, [
            26, 26, 26, 26, 180, 30, 30, 60, 60, 120, 120, 180, 180, 30, 30,
            60, 60, 120, 120, 180, 180, 30, 30, 60, 60, 120, 120, 180, 180, 30,
            30, 60, 60, 120, 120, 180, 180, 30, 30, 60, 60, 120, 120, 180, 180
        ])

        ecuteps = [
            dict(task.input.as_dict()['abi_args']).get('ecuteps', None)
            for task in flow[0]
        ]
        print('ecuteps:', ecuteps)
        self.assertEqual(ecuteps, [
            None, None, None, None, None, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8,
            8, 8, 8, 8, 12, 12, 12, 12, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16,
            16, 16, 20, 20, 20, 20, 20, 20, 20, 20
        ])

        inplens = [len(task.input.as_dict()['abi_args']) for task in flow[0]]
        print(inplens)
        self.assertEqual(inplens, [
            17, 17, 17, 17, 18, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30,
            27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30, 27,
            30, 27, 30, 27, 30, 27, 30, 27, 30, 27, 30
        ])

        ngkpts = [
            dict(task.input.as_dict()['abi_args'])['ngkpt'] for task in flow[0]
        ]

        for ngkpt in ngkpts:
            self.assertEqual(ngkpt, [2, 2, 2])

        self.assertEqual(flow.build_and_pickle_dump(), 0)

        # some more tests
        flow.rmtree()

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #13
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingelAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        #wdir = '.'
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager_nompi.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_ABINIT_PS = None

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir
        self.assertIsInstance(struc, AbiStructure)
        spec = get_spec('GW')
        spec.data['kp_grid_dens'] = 100
        spec.data['kp_in'] = -100
        with open(os.path.join(wdir, 'extra_abivars'), 'w') as f:
            f.write('{"ecut": 8, "ecutsigx": 8}')

        work = SingleAbinitGWWork(struc, spec)
        self.assertEqual(len(work.CONVS), 3)

        conv_strings = ['method', 'control', 'level']
        for test in work.CONVS:
            self.assertIsInstance(work.CONVS[test]['test_range'], tuple)
            for item in conv_strings:
                self.assertIsInstance(work.CONVS[test][item], unicode)
        self.assertEqual(work.work_dir, 'Si_test')
        self.assertEqual(len(work.pseudo_table), 1)
        self.assertEqual(work.bands_fac, 1)

        self.assertEqual(work.get_electrons(struc), 8)
        self.assertEqual(work.get_bands(struc), 6)
        self.assertGreater(work.get_bands(struc), work.get_electrons(struc) / 2, 'More electrons than bands, very bad.')

        flow = work.create()
        print(work.work_dir)
        print(flow.workdir)
        print(flow[0].workdir)
        self.assertIsInstance(flow, Flow)
        self.assertEqual(len(flow), 1)      # one work
        self.assertEqual(len(flow[0]), 4)   # with 4 tasks
        # self.assertEqual(flow.workdir, 'Si')

        self.assertEqual(flow.build_and_pickle_dump(), 0)
        # some more tests
        flow.rmtree()

        spec = get_spec('GW')
        spec.data['converge'] = True
        struc.item = 'converge'
        work = SingleAbinitGWWork(struc, spec)
        flow = work.create()
        self.assertEqual(len(flow[0]), 45)
        self.assertEqual(flow.build_and_pickle_dump(), 0)
        # some more tests
        flow.rmtree()

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #14
0
    def test_expand(self):
        """
        Testing helper function to extend the convergence grid
        """
        self.maxDiff = None
        spec = get_spec('GW')
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = tempfile.mkdtemp()
        print('wdir', wdir)

        os.chdir(wdir)
        shutil.copyfile(abidata.cif_file("si.cif"),
                        os.path.join(wdir, 'si.cif'))
        shutil.copyfile(
            abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(
            os.path.join(abidata.dirpath, 'managers', 'shell_manager.yml'),
            os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(
            os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'),
            os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_ABINIT_PS = None

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir

        tests = SingleAbinitGWWork(struc, spec).convs
        tests_out = {
            'nscf_nbands': {
                'test_range': (40, ),
                'control': 'gap',
                'method': 'set_bands',
                'level': 'nscf'
            },
            'ecut': {
                'test_range': (50, 48, 46, 44),
                'control': 'e_ks_max',
                'method': 'direct',
                'level': 'scf'
            },
            'ecuteps': {
                'test_range': (4, 8, 12, 16, 20),
                'control': 'gap',
                'method': 'direct',
                'level': 'sigma'
            }
        }
        self.assertEqual(expand(tests, 1), tests_out)
        spec.data['code'] = 'VASP'

        if "VASP_PSP_DIR" in os.environ:
            spec.update_code_interface()
            tests = GWG0W0VaspInputSet(struc, spec).convs
            tests_out = {
                'ENCUTGW': {
                    'test_range': (200, 400, 600, 800),
                    'control': 'gap',
                    'method': 'incar_settings'
                }
            }
            self.assertEqual(expand(tests, 1), tests_out)

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #15
0
#!/usr/bin/env python
from __future__ import division

import numpy as np

import abipy.data as data
from abipy.abilab import Structure, StructureModifier, AbiInput

structure = Structure.from_file(data.cif_file("si.cif"))

modifier = StructureModifier(structure)

# From 98% to 102% of the initial volume.
new_structures = modifier.scale_lattice(vol_ratios=np.arange(98, 104, 2) / 100.)

inp = AbiInput(pseudos=data.pseudos("14si.pspnc"), ndtset=len(new_structures))

for (idt, new_structure) in enumerate(new_structures):
    inp.set_structure(new_structure, dtset=idt+1)

print(inp)

# Supercell
inp = AbiInput(pseudos=data.pseudos("14si.pspnc"), ndtset=1)

new_structure = modifier.make_supercell(scaling_matrix=[1,2,3])
inp.set_structure(new_structure)

print(inp)

structure = Structure.from_abivars({
예제 #16
0
# This context manager is required to use the collection name selected in source_db
# By default mongoengine uses the name of the class (in this case RelaxResult) as
# name of the collection to query.
with source_db.switch_collection(RelaxResult) as RelaxResult:
    # download from the database the relaxed structure
    # This relies on mongoengine (http://mongoengine.org/) to interact with the database.
    # See the module abiflows.database.mongoengine.abinit_results for the objects used to store the results
    relaxed_results = RelaxResult.objects(mp_id=mp_id)

    # Assume that there is one and only one result matching the query. In real cases you might want to check this.
    # At this point is an instance of a RelaxResult object
    relaxed = relaxed_results[0]

    # load the relaxed Structure
    structure = Structure.from_dict(relaxed.abinit_output.structure)
    # use the same k-point sampling as the one of the relax
    kppa = relaxed.abinit_input.kppa
    ngkpt = relaxed.abinit_input.ngkpt

    # The AbinitInput object used for the relax is stored in the database.
    # We get it to use the same approximations used during the relaxation.
    relax_input = relaxed.abinit_input.last_input.to_mgobj()

    # We use the same k and q point grid
    qppa = kppa
    extra_abivars = dict(chkprim=1, nstep=100, chksymbreak=1)
    # as for the relax workflow, information stored in the database for the calculation. In particular information
    # about the source structure.
    initialization_info = dict(kppa=kppa, mp_id=mp_id,
                               relax_db=source_db.as_dict_no_credentials(), relax_id=relaxed.id,
예제 #17
0
    def test_SingleAbinitGWWork(self):
        """
        Testing the concrete SingelAbinitGWWork class
        """
        struc = AbiStructure.from_file(abidata.cif_file("si.cif"))
        struc.item = 'test'

        wdir = '.'
        shutil.copyfile(abidata.cif_file("si.cif"), os.path.join(wdir, 'si.cif'))
        shutil.copyfile(abidata.pseudo("14si.pspnc").path, os.path.join(wdir, 'Si.pspnc'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'shell_manager_nompi.yml'),
                        os.path.join(wdir, 'manager.yml'))
        shutil.copyfile(os.path.join(abidata.dirpath, 'managers', 'scheduler.yml'), os.path.join(wdir, 'scheduler.yml'))

        try:
            temp_ABINIT_PS_EXT = os.environ['ABINIT_PS_EXT']
            temp_ABINIT_PS = os.environ['ABINIT_PS']
        except KeyError:
            temp_ABINIT_PS_EXT = None
            temp_ABINIT_PS = None

        os.environ['ABINIT_PS_EXT'] = '.pspnc'
        os.environ['ABINIT_PS'] = wdir
        self.assertIsInstance(struc, AbiStructure)
        spec = get_spec('GW')
        spec.data['kp_grid_dens'] = 100
        spec.data['kp_in'] = -100
        with open('extra_abivars', 'w') as f:
            f.write('{"ecut": 8, "ecutsigx": 8}')

        work = SingleAbinitGWWork(struc, spec)
        self.assertEqual(len(work.CONVS), 3)

        conv_strings = ['method', 'control', 'level']
        for test in work.CONVS:
            self.assertIsInstance(work.CONVS[test]['test_range'], tuple)
            for item in conv_strings:
                self.assertIsInstance(work.CONVS[test][item], unicode)
        self.assertEqual(work.work_dir, 'Si_test')
        self.assertEqual(len(work.pseudo_table), 1)
        self.assertEqual(work.bands_fac, 1)

        self.assertEqual(work.get_electrons(struc), 8)
        self.assertEqual(work.get_bands(struc), 6)
        self.assertGreater(work.get_bands(struc), work.get_electrons(struc) / 2, 'More electrons than bands, very bad.')

        flow = work.create()
        print(work.work_dir)
        print(flow.workdir)
        print(flow[0].workdir)
        self.assertIsInstance(flow, Flow)
        self.assertEqual(len(flow), 1)      # one work
        self.assertEqual(len(flow[0]), 4)   # with 4 tasks
        # self.assertEqual(flow.workdir, 'Si')

        self.assertEqual(flow.build_and_pickle_dump(), 0)
        # some more tests
        flow.rmtree()

        spec = get_spec('GW')
        spec.data['converge'] = True
        struc.item = 'converge'
        work = SingleAbinitGWWork(struc, spec)
        flow = work.create()
        self.assertEqual(len(flow[0]), 45)
        self.assertEqual(flow.build_and_pickle_dump(), 0)
        # some more tests
        flow.rmtree()

        if temp_ABINIT_PS is not None:
            os.environ['ABINIT_PS_EXT'] = temp_ABINIT_PS_EXT
            os.environ['ABINIT_PS'] = temp_ABINIT_PS
예제 #18
0
파일: ucells.py 프로젝트: srirampr/abipy
def structure_from_ucell(name):
    """Returns a `Structure` from the name of entry in the database."""
    return Structure.from_abivars(ucell(name))