Esempio n. 1
0
def get_abinit_variables():
    """Returns the database with the description of the ABINIT variables."""
    global __VARS_DATABASE

    if __VARS_DATABASE is None: 
        pickle_file = os.path.join(os.getenv("HOME"), ".abinit", "abipy", "abinit_vars.pickle")
        
        if os.path.exists(pickle_file): 
            #print("Reading from pickle")
            with open(pickle_file, "rb") as fh:
                __VARS_DATABASE = pickle.load(fh)

        else:
            # Make dir and file if not present.
            if not os.path.exists(os.path.dirname(pickle_file)):
                os.makedirs(os.path.dirname(pickle_file))

            #print("Reading database from YAML file and generating pickle version. It may take a while...")
            from abipy import data as abidata
            yaml_file = abidata.var_file('abinit_vars.yml')
            with open(yaml_file, "rt") as fh:
                var_list = yaml.load(fh)

            # Build ordered dict with variables in alphabetical order.
            var_list = sorted(var_list, key=lambda v: v.varname)
            __VARS_DATABASE = VariableDatabase([(v.varname, v) for v in var_list])

            # Save object to pickle file so that can we can reload it from pickle instead of yaml (slower)
            with open(pickle_file, "wb") as fh:
                pickle.dump(__VARS_DATABASE, fh)

    return __VARS_DATABASE
Esempio n. 2
0
def get_abinit_variables():
    """Returns the database with the description of the ABINIT variables."""
    global __VARS_DATABASE

    if __VARS_DATABASE is None:
        pickle_file = os.path.join(os.getenv("HOME"), ".abinit", "abipy",
                                   "abinit_vars.pickle")

        if os.path.exists(pickle_file):
            #print("Reading from pickle")
            with open(pickle_file, "rb") as fh:
                __VARS_DATABASE = pickle.load(fh)

        else:
            # Make directory and file if not present.
            if not os.path.exists(os.path.dirname(pickle_file)):
                os.makedirs(os.path.dirname(pickle_file))

            #print("Reading database from YAML file and generating pickle version. It may take a while...")
            from abipy import data as abidata
            yaml_file = abidata.var_file('abinit_vars.yml')
            with open(yaml_file, "rt") as fh:
                var_list = yaml.load(fh)

            # Build ordered dict with variables in alphabetical order.
            var_list = sorted(var_list, key=lambda v: v.varname)
            __VARS_DATABASE = VariableDatabase([(v.varname, v)
                                                for v in var_list])

            # Save object to pickle file so that can we can reload it from pickle instead of yaml (slower)
            with open(pickle_file, "wb") as fh:
                pickle.dump(__VARS_DATABASE, fh)

    return __VARS_DATABASE
Esempio n. 3
0
def is_abivar(s):
    """True if s is an ABINIT variable."""
    global ABI_VARNAMES
    if ABI_VARNAMES is None:
        from abipy import data as abidata
        with open(abidata.var_file("abinit_vars.json")) as fh:
            ABI_VARNAMES = json.load(fh)

    return s in ABI_VARNAMES
Esempio n. 4
0
def _get_anaddb_varnames():
    global _anaddb_varnames
    if _anaddb_varnames is not None:
        return _anaddb_varnames

    from abipy import data as abidata
    with open(abidata.var_file("anaddb_vars.json")) as fh:
        _anaddb_varnames = set(json.load(fh))
        return _anaddb_varnames
Esempio n. 5
0
def is_abivar(s):
    """True if s is an ABINIT variable."""
    global ABI_VARNAMES
    if ABI_VARNAMES is None:
        from abipy import data as abidata
        with open(abidata.var_file("abinit_vars.json")) as fh:
            ABI_VARNAMES = set(json.load(fh))

    return s in ABI_VARNAMES
Esempio n. 6
0
def _get_anaddb_varnames():
    global _anaddb_varnames
    if _anaddb_varnames is not None:
        return _anaddb_varnames

    from abipy import data as abidata
    with open(abidata.var_file("anaddb_vars.json")) as fh:
        _anaddb_varnames = set(json.load(fh))
        return _anaddb_varnames
Esempio n. 7
0
def is_abivar(s):
    """True if s is an ABINIT variable."""
    global ABI_VARNAMES
    if ABI_VARNAMES is None:
        from abipy import data as abidata
        with open(abidata.var_file("abinit_vars.json"), "rt") as fh:
            ABI_VARNAMES = set(json.load(fh))
            # Add include statement
            # FIXME: These variables should be added to the database.
            ABI_VARNAMES.update(("include", "xyzfile"))

    return s in ABI_VARNAMES
Esempio n. 8
0
 def sections(self):
     """List of sections"""
     from abipy import data as abidata
     with open(abidata.var_file('sections.yml'), 'rt') as f:
         return yaml.load(f)
Esempio n. 9
0
 def characteristics(self):
     """List of characteristics."""
     from abipy import data as abidata
     with open(abidata.var_file('characteristics.yml'), 'rt') as f:
         return yaml.load(f)
Esempio n. 10
0
 def __init__(self):
     self.load_vars(abidata.var_file('abinit_vars.yml'))
Esempio n. 11
0
 def sections(self):
     """List of sections"""
     from abipy import data as abidata
     with open(abidata.var_file('sections.yml'), 'rt') as f:
         return yaml.load(f)
Esempio n. 12
0
 def characteristics(self):
     """List of characteristics."""
     from abipy import data as abidata
     with open(abidata.var_file('characteristics.yml'), 'rt') as f:
         return yaml.load(f)
Esempio n. 13
0
#!/usr/bin/env python

import yaml
import abipy.data as abidata

f = open(abidata.var_file('characteristics.yml'),'r')
list_chars=yaml.load(f);
f.close();

f = open(abidata.var_file('sections.yml'),'r')
list_sections=yaml.load(f);
f.close();

list_specials = [
('AUTO_FROM_PSP','Means that the value is read from the PSP file'),
('CUDA','True if CUDA is enabled (compilation)'),
('ETSF_IO','True if ETSF_IO is enabled (compilation)'),
('FFTW3','True if FFTW3 is enabled (compilation)'),
('MPI_IO','True if MPI_IO is enabled (compilation)'),
('NPROC','Number of processors used for Abinit'),
('PARALLEL','True if the code is compiled with MPI'),
('SEQUENTIAL','True if the code is compiled without MPI'),
]

class literal(str): pass

def literal_unicode_representer(dumper, data):
    return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|')

yaml.add_representer(literal, literal_unicode_representer)