Database connection wrappers
The data that was added to a MaterialsDatabase needs to be stored on disk or in memory, depending on the application. To allow for maximal flexibility, MADAS provides a abstract class that can be used as a framework for different database implementations. Thus, if, e.g., a different database is required that stores only spectra, it can be quickly implemented using the Backend class and integrated with all other components of MADAS.
Each child of a Backend class should implement all methods listed below to ensure compatibility with the other components of MADAS.
- class madas.backend.backend_core.Backend(filename='materials_database.db', filepath='data', make_dirs=True, key_name='mid', log=None)
A database backend wrapper to unify file-based storage of materials data.
Keyword arguments:
- filename: str
Name of the data file
default: “materials_database.db”
- filepath: str
Path (location) of the file.
default: “data”
- make_dirs: bool
Create directory paths if it does not exist.
default: True
- key_name: str
Name of unique keys that are used to find (individual) entries in the database.
default: “mid”
- log: logging.Logger or None
Logger used displaying logs.
default: None
- property abs_path: str
Absolute path property, contains the absolute path of the backend file.
- add_many(*args, **kwargs) None
Add data to the database.
- add_single(*args, **kwargs) None
Add data to the database.
- get_length() int
Return the length of the database, i.e. the total number of entries.
- has_entry(entry_id) bool
Check if an entry with the given id is present in the database.
- property log: Logger | None
Logger property, returns the log.
- property metadata: dict
Metadata property, returns metadata attached to the backend.
- set_logger(logger: Logger) None
Set logger.
- update_many(*args, update_data: bool = False, **kwargs) None
Update several entries in the database.
- update_metadata(*args, **kwargs) None
Updata database metadata.
- update_single(*args, update_data: bool = False, **kwargs) None
Update a single entry in the database.
Built-in backends