def setUp(self): self.pbe_db = df_database(XcFunc.from_name("PBE")) assert self.pbe_db.xc == "PBE" # Cached? assert df_database(XcFunc.from_abinit_ixc(11)) is self.pbe_db assert "WIEN2k" in self.pbe_db.codes assert "VASP" in self.pbe_db.codes spinat, spin_mode = self.pbe_db.spinat_spinmode_for_symbol("Si") assert spinat is None and spin_mode == "unpolarized" spinat, spin_mode = self.pbe_db.spinat_spinmode_for_symbol("Fe") assert spinat == 2 * [(0, 0, 2.3)] and spin_mode == "polarized" self.pw_db = df_database("PW") assert self.pw_db.xc == "PW" assert self.pw_db is not self.pbe_db assert "WIEN2k" in self.pw_db.codes # Accept PW_MOD as well. self.pwmod_db = df_database("PW_MOD") assert self.pwmod_db.xc == "PW_MOD" assert self.pwmod_db is not self.pw_db
class DojoInfo(AttrDict): """ Dictionary with metadata associated to the PseudoDojo table. """ # See https://github.com/Julian/jsonschema JSON_SCHEMA = { "$schema": "http://json-schema.org/schema#", "type": "object", "properties": { "pp_type": {"type": "string", "enum": ["NC", "PAW"]}, "xc_name": {"type": "string", "enum": XcFunc.aliases()}, "authors": {"type": "array"}, "description": {"type": "string"}, "references": {"type": "array"}, "dojo_dir": {"type": "string"}, #"generation_date": {"type": "string", "format": "date"}, #"tags": {"type": "array", "items": {"type": "string", "enum": ["accuracy", "efficiency"]}}, #"relativity": {"type": "string", "enum": ["non-relativistic", "scalar-relativistic", "relativistic"]} }, "required": ["pp_type", "xc_name", "authors", "description", "references", "dojo_dir", #"generation_date", "tags", "relativity" ], } def __init__(self, *args, **kwargs): super(DojoInfo, self).__init__(*args, **kwargs) self["xc"] = XcFunc.from_name(self["xc_name"]) def validate_json_schema(self): """Validate DojoInfo with validictory.""" from jsonschema import validate validate(self, self.JSON_SCHEMA) @classmethod def get_template_dict(cls): """Return a dictionary with the keys that must be filled by the user.""" return {k: str(v) for k, v in cls.JSON_SCHEMA["properties"].items()} @property def isnc(self): """True if norm-conserving pseudopotential.""" return self.pp_type == "NC" @property def ispaw(self): """True if PAW pseudopotential.""" return self.pp_type == "PAW"
def __init__(self, xc): """ Read data from CSV files and initialize the object. xc specifies the XC functionals used. """ self.xc = XcFunc.asxc(xc) if self.xc != "PBE": raise ValueError("Gbrv database supports only PBE pseudos") # Directory containing the GBRV tables in CSV format. datadir = os.path.abspath(os.path.dirname(__file__)) datadir = os.path.join(datadir, "data") # Build dictionary of tables. self.tables = tables = {} for stype in self.all_struct_types: filepath = os.path.join(datadir, stype + ".csv") tables[stype] = read_table_from_file(filepath)
def __init__(self, xc): """"xc specifies the XC functionals used.""" self.xc = XcFunc.asxc(xc) dirpath = os.path.abspath(os.path.dirname(__file__)) self.dirpath = os.path.join(dirpath, "data") self._data = {} for bname in self._FILES4XC[self.xc]: file_path = os.path.join(self.dirpath, bname) if os.path.isfile(file_path) and file_path.endswith(".txt"): code, ext = os.path.splitext(bname) code = code.split("-")[0] self._data[code] = read_data_from_filepath(file_path, self.xc) self._cif_paths = {} #loc = "CIFs" + "-" + str(self.xc) loc = self._CIFDIR4XC[self.xc] cif_dirpath = os.path.join(self.dirpath, loc) for bname in os.listdir(cif_dirpath): if bname.endswith(".cif"): symbol, ext = os.path.splitext(bname) self._cif_paths[symbol] = os.path.join(cif_dirpath, bname)
def __init__(self, *args, **kwargs): super(DojoInfo, self).__init__(*args, **kwargs) self["xc"] = XcFunc.from_name(self["xc_name"])
def test_xcfunc_api(self): """Testing XcFunc API.""" # Aliases should be unique assert len(XcFunc.aliases()) == len(set(XcFunc.aliases())) # LDA-Teter ixc_1 = XcFunc.from_abinit_ixc(1) print(ixc_1) assert ixc_1.type == "LDA" assert ixc_1.name == "LDA_XC_TETER93" assert ixc_1 == ixc_1 assert ixc_1 == "LDA_XC_TETER93" assert ixc_1 != "PBE" assert ixc_1.name not in XcFunc.aliases() assert ixc_1 == XcFunc.from_name(ixc_1.name) # LDA-PW (in aliases) ixc_7 = XcFunc.from_abinit_ixc(7) assert ixc_7.type == "LDA" assert ixc_7.name == "PW" assert ixc_7.name in XcFunc.aliases() assert ixc_7.name == XcFunc.from_name(ixc_7.name) assert ixc_7 != ixc_1 # GGA-PBE from ixc == 11 (in aliases) ixc_11 = XcFunc.from_abinit_ixc(11) assert ixc_11.type == "GGA" and ixc_11.name == "PBE" assert ixc_11.name in XcFunc.aliases() assert ixc_1 != ixc_11 # Test asxc assert XcFunc.asxc(ixc_11) is ixc_11 assert XcFunc.asxc("PBE") == ixc_11 d = {ixc_11: ixc_11.name} print(d) assert "PBE" in d assert ixc_11 in d # Test if object can be serialized with Pickle. self.serialize_with_pickle(ixc_11, test_eq=True) # Test if object supports MSONable # TODO # print("in test", type(ixc_11.x), type(ixc_11.c), type(ixc_11.xc)) # ixc_11.x.as_dict() # self.assertMSONable(ixc_11) # GGA-PBE from ixc given in abinit-libxc mode ixc_101130 = XcFunc.from_abinit_ixc(-101130) assert ixc_101130.type == "GGA" and ixc_101130.name == "PBE" assert ixc_101130 == ixc_11 # GGA-PBE built from name gga_pbe = XcFunc.from_name("PBE") assert gga_pbe.type == "GGA" and gga_pbe.name == "PBE" assert ixc_11 == gga_pbe # Use X from GGA and C from LDA! unknown_xc = XcFunc.from_name("GGA_X_PBE+ LDA_C_PW") assert unknown_xc not in XcFunc.aliases() assert unknown_xc.type == "GGA+LDA" assert unknown_xc.name == "GGA_X_PBE+LDA_C_PW" gga_pbe = XcFunc.from_type_name("GGA", "GGA_X_PBE+GGA_C_PBE") assert gga_pbe.type == "GGA" and gga_pbe.name == "PBE" assert str(gga_pbe) == "PBE"
def read_abinit_xcfunc(self): """ Read ixc from an Abinit file. Return :class:`XcFunc` object. """ ixc = int(self.read_value("ixc")) return XcFunc.from_abinit_ixc(ixc)
def test_gbrv(self): """Testing GBRV database...""" # Init the database. db = gbrv_database(xc="PBE") assert db.xc == "PBE" # Cached? assert gbrv_database(XcFunc.from_abinit_ixc(11)) is db # Test basic methods assert db.has_symbol("Si", stype="fcc") assert not db.has_symbol("Si", stype="rocksalt") assert "KMgF3" in db.all_symbols db.print_formulas() with self.assertRaises(ValueError): gbrv_database(xc="PW") # Get FCC entry for Silicon fcc_si = db.get_fcc_entry("Si") assert fcc_si.ae == 3.857 and fcc_si.gbrv_uspp == 3.853 assert fcc_si.struct_type == "fcc" and fcc_si.species == ["Si"] sfcc = fcc_si.build_structure() self.assert_almost_equal(sfcc.volume, fcc_si.ae**3 /4.) # Get BCC entry for H bcc_h = db.get_bcc_entry("H") assert bcc_h.ae == 1.806 and bcc_h.gbrv_paw == 1.807 assert bcc_h.struct_type == "bcc" and bcc_h.species == ["H"] sbcc = bcc_h.build_structure() self.assert_almost_equal(sbcc.volume, bcc_h.ae**3 /2.) # Hg is missing. missing = db.get_bcc_entry("Hg") assert missing.ae is None # Get Rocksalt entry for LiF lif = db.get_rocksalt_entry("LiF") assert lif.symbol == "LiF" and lif.struct_type == "rocksalt" assert lif.species == ["Li", "F"] assert lif.ae == 4.076 and lif.pslib == 4.081 struct = lif.build_structure() #print(struct.to_abivars()) # Get AB03 entry for SrLiF3 srlif3 = db.get_abo3_entry("SrLiF3") assert srlif3.symbol == "SrLiF3" and srlif3.struct_type == "ABO3" assert srlif3.ae == 3.884 and srlif3.gbrv_paw == 3.883 # TODO #srlif3.build_structure() # Get hH entry for SrLiF3 agalge = db.get_hH_entry("AgAlGe") assert agalge.symbol == "AgAlGe" and agalge.struct_type == "hH" assert agalge.ae == 6.224 and agalge.gbrv_paw == 6.218 # TODO #agalge.build_structure() assert len(db.entries_with_symbol("Si")) == 10 assert not db.entries_with_symbol("Lu") assert db.match_symbols(["Si", "Lu"]) is None assert db.match_symbols(["Si", "O"]).formula == "SiO" e = db.entries_with_symbols(["Sr", "Si", "O"]) assert e and len(e) == 1 and e[0].formula == "SrSiO3"
def __init__(self, xc): """xc is the exchange-correlation functional e.g. PBE, PW.""" self.xc = XcFunc.asxc(xc)
def test_xcfunc_api(self): """Testing XcFunc API.""" # Aliases should be unique assert len(XcFunc.aliases()) == len(set(XcFunc.aliases())) # LDA-Teter ixc_1 = XcFunc.from_abinit_ixc(1) print(ixc_1) assert ixc_1.type == "LDA" assert ixc_1.name == "LDA_XC_TETER93" assert ixc_1 == ixc_1 assert ixc_1 == "LDA_XC_TETER93" assert ixc_1 != "PBE" assert ixc_1.name not in XcFunc.aliases() assert ixc_1 == XcFunc.from_name(ixc_1.name) # LDA-PW (in aliases) ixc_7 = XcFunc.from_abinit_ixc(7) assert ixc_7.type == "LDA" assert ixc_7.name == "PW" assert ixc_7.name in XcFunc.aliases() assert ixc_7.name == XcFunc.from_name(ixc_7.name) assert ixc_7 != ixc_1 # GGA-PBE from ixc == 11 (in aliases) ixc_11 = XcFunc.from_abinit_ixc(11) assert ixc_11.type == "GGA" and ixc_11.name == "PBE" assert ixc_11.name in XcFunc.aliases() assert ixc_1 != ixc_11 # Test asxc assert XcFunc.asxc(ixc_11) is ixc_11 assert XcFunc.asxc("PBE") == ixc_11 d = {ixc_11: ixc_11.name} print(d) assert "PBE" in d assert ixc_11 in d # Test if object can be serialized with Pickle. self.serialize_with_pickle(ixc_11, test_eq=True) # Test if object supports MSONable # TODO #print("in test", type(ixc_11.x), type(ixc_11.c), type(ixc_11.xc)) #ixc_11.x.as_dict() #self.assertMSONable(ixc_11) # GGA-PBE from ixc given in abinit-libxc mode ixc_101130 = XcFunc.from_abinit_ixc(-101130) assert ixc_101130.type == "GGA" and ixc_101130.name == "PBE" assert ixc_101130 == ixc_11 # GGA-PBE built from name gga_pbe = XcFunc.from_name("PBE") assert gga_pbe.type == "GGA" and gga_pbe.name == "PBE" assert ixc_11 == gga_pbe # Use X from GGA and C from LDA! unknown_xc = XcFunc.from_name("GGA_X_PBE+ LDA_C_PW") assert unknown_xc not in XcFunc.aliases() assert unknown_xc.type == "GGA+LDA" assert unknown_xc.name == "GGA_X_PBE+LDA_C_PW"