An API for loading local files

This API can be used to ingest data from a local directory. To do so, the API scans a directory, finding files that match a specific naming pattern.

The basic configuration requires the following file structure:

  • root_directory
    • <properties.file>

    • directory[0]
      • <input.file>

    • directory[1]
      • <input.file>

Where ``

class madas.apis.local_data_API.API(root='.', file_reader=<madas.apis.local_data_API.FileReaderASE object>, property_reader=<madas.apis.local_data_API.CSVPropertyReader object>, logger=None)

API class to add materials from a local folder structure.

Requires the following data structure:

  • root_directory
    • <properties.file>

    • directory[0]
      • <input.file>

    • directory[1]
      • <input.file>

where the directory names correspond to the entries of the first column of the CSV file.

The name of individual files can be chosen on demand.

Keyword arguments

root: str

Root directory.

default: ‘.’

file_reader: FileReader

File reader object for reading input files.

default: FileReaderASE()

property_reader: FileReader

File reader object for reading properties file.

default: CSVPropertyReader()

logger: logging.Logger

Logger to write error and info messages.

Methods:

get_calculation(file_path: str, file_name: str, property_file_path: str, property_file_name: str, property_file_id: str, file_reader_kwargs: dict = {}, property_reader_kwargs: dict = {}) Material

Get calculation from a local file.

Arguments:

file_path: str

Path to the local file of the structure. Passed to FileReader.read() method of file reader.

file_name: str

Name of the local file of the structure. Passed to FileReader.read() method of file reader.

property_file_path: str

Path of the file containing the properties of the calculation. Passed to FileReader.read() method of property reader.

property_file_name: str

Name of the file containing the properties of the calculation. Passed to FileReader.read() method of property reader.

property_file_id: str

Id of the structure in the property file. If no string is provided, it will be converted to string.

Keyword arguments:

file_reader_kwargs: dict

Additional keyword arguments passed to the file reader object.

default: {}

property_reader_kwargs: dict

Additional keyword arguments passed to the property reader object.

default: {}

Returns:

material: Material

Material object with set material id, atomic structure and data properties.

Get calculations from a local file-structure.

Assumes that every struture is stored in a separate directory, which has a name corresponding to the id extracted from the properties file.

Arguments:

file_path: str

Path to the local file of the structure. Passed to FileReader.read() method of file reader.

file_name: str

Name of the local file of the structure. Passed to FileReader.read() method of file reader.

property_file_path: str

Path of the file containing the properties of the calculation. Passed to FileReader.read() method of property reader.

property_file_name: str

Name of the file containing the properties of the calculation. Passed to FileReader.read() method of property reader.

Keyword arguments:

file_reader_kwargs: dict

Additional keyword arguments passed to the file reader object.

default: {}

property_reader_kwargs: dict

Additional keyword arguments passed to the property reader object.

default: {}

Returns:

materials: List[Material]

List of Material objects with set material id, atomic structure and data properties.

get_property(*args, **kwargs)

Not implemented

class madas.apis.local_data_API.CSVPropertyReader(file_path: str = '.')

Read material properties from a CSV file and return as dictionary.

Assumes that the first column of CSV file contains a key. Example content:

id,property1,property2
0, 1.4, 2.3
1, 2, 2.5

Calling read() returns:

{"0" : {"property1" : 1.4, "property2" : 2.3},
"1" : {"property1" : 2, "property2" : 2.5}}

Keyword arguments:

file_path: str

Path to file to be read.

Methods:

read(file_name_csv: str, file_path_csv: str | None = None, **kwargs) dict

Read CSV data from file to dictionary.

Arguments:

file_name_csv: str

Name of CSV file to be read.

Keyword arguments:

file_path_csv: str

File path to file to be read.

default: None –> use self.file_path

Additional keyword arguments are ignored.

Returns:

data_dict: dict

Dictionary of properties. First column of csv data is used as dictionary keys.

class madas.apis.local_data_API.FileReader(file_path: str = '.')

Base class for file reader objects.

Keyword arguments:

file_path: str

Path to file to be read.

Methods:

set_file_path(file_path: str) None

Set the file path.

Arguments:

file_path: str

File path of file to be read.

class madas.apis.local_data_API.FileReaderASE(file_path: str = '.')

Wrapper class around the ASE IO module.

Loads geometry from a DFT input file to an ASE Atoms object.

Keyword arguments:

file_path: str

Path to file to be read.

Methods:

read(file_name: str, file_path: str | None = None, **kwargs) Atoms

Read geometry from DFT input file.

Arguments:

file_name: str

Name of file to be read. Format is guessed from extension.

Keyword arguments:

file_path: str

Path of file to be read. Sets the file_path attribute.

default: None –> use self.file_path

Additional keyword arguments are forwarded to ase.io.read.

Returns:

atoms: ase.Atoms

Atoms object with geometry read from file.