atomlite.Database¶
- class atomlite.Database(database, molecule_table='molecules')[source]¶
A molecular SQLite database.
- Parameters:
molecule_table (LiteralString) – The name of the table which stores the molecules.
Attributes
An open database connection.
Methods
Add molecular entries to the database.
Get a boolean property of a molecule.
Get molecular entries from the database.
Get a molecular entry from the database.
Get a float property of a molecule.
Get an integer property of a molecule.
Get the property of a molecule.
Get a DataFrame of the properties in the database.
Get property entries from the database.
Get a property entry from the database.
Get a string property of a molecule.
Check if a molecular entry is present in the database.
Check if a property entry is present in the database.
Get the number of molecular entries in the database.
Get the number of property entries in the database.
Remove molecular entries from the database.
Remove a property from a molecule.
Set a boolean property of a molecule.
Set a float property of a molecule.
Set an integer property of a molecule.
Set the property of a molecule.
Set a string property of a molecule.
Update molecular entries in the database.
Update property entries in the database.
- get_bool_property(key, path)[source]¶
Get a boolean property of a molecule.
- get_entries(keys=None)[source]¶
Get molecular entries from the database.
Tip
The molecules returned from the database are in JSON format, you may need to convert them to something more usable, for example,
rdkit
molecules withjson_to_rdkit()
.- Parameters:
keys (str | list[str] | None) – The keys of the molecules to retrieve from the database. If
None
, all entries will be returned.- Yields:
A molecular entry matching keys.
- Return type:
See also
get_entry()
: For retrieving a single entry.
- get_entry(key)[source]¶
Get a molecular entry from the database.
Tip
The molecules returned from the database are in JSON format, you may need to convert them to something more usable, for example,
rdkit
molecules withjson_to_rdkit()
.- Parameters:
key (str) – The key of the molecule to retrieve from the database.
- Returns:
The molecular entry matching key or
None
if key is not present in the database.- Return type:
Entry | None
See also
get_entries()
: For retrieving multiple entries.
- get_float_property(key, path)[source]¶
Get a float property of a molecule.
- get_int_property(key, path)[source]¶
Get an integer property of a molecule.
- get_property(key, path)[source]¶
Get the property of a molecule.
Note
If path does not lead to a property which exists,
None
will be returned. This means that the same value is returned for a missing value as well as an exisiting value set toNone
. If you need to distinguish between missing andNone
values you can use a different value to represent missing data, for example the string"MISSING"
.- Parameters:
- Returns:
The property.
None
will be returned if key is not present in the database or path leads to a non-existent property.- Return type:
Json
- get_property_df(properties, *, allow_missing=False)[source]¶
Get a DataFrame of the properties in the database.
- Parameters:
- Returns:
A DataFrame of the property entries in the database.
- Return type:
DataFrame
- get_property_entries(keys=None)[source]¶
Get property entries from the database.
- Parameters:
keys (str | list[str] | None) – The keys of the molecules to whose properties need to be retrieved from the database. If
None
all entries will be returned.- Yields:
A property entry matching keys.
- Return type:
See also
get_property_entry()
: For retrieving a single entry.
- get_property_entry(key)[source]¶
Get a property entry from the database.
- Parameters:
key (str) – The key of the molecule to retrieve from the database.
- Returns:
The property entry matching key or
None
if key is not present in the database.- Return type:
PropertyEntry | None
See also
get_property_entries()
: For retrieving multiple entries.
- get_str_property(key, path)[source]¶
Get a string property of a molecule.
- num_entries()[source]¶
Get the number of molecular entries in the database.
Note
This number includes both the commited and uncommited entries.
- Return type:
- num_property_entries()[source]¶
Get the number of property entries in the database.
Note
This number includes both the commited and uncommited entries.
- Return type:
- set_bool_property(key, path, property, *, commit=True)[source]¶
Set a boolean property of a molecule.
- Parameters:
key (str) – The key of the molecule.
path (str) –
A path to the property of the molecule. Valid paths are described here. You can also view various code examples in our docs.
property (bool) – The desired value of the property.
commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- set_float_property(key, path, property, *, commit=True)[source]¶
Set a float property of a molecule.
- Parameters:
key (str) – The key of the molecule.
path (str) –
A path to the property of the molecule. Valid paths are described here. You can also view various code examples in our docs.
property (float) – The desired value of the property.
commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- set_int_property(key, path, property, *, commit=True)[source]¶
Set an integer property of a molecule.
- Parameters:
key (str) – The key of the molecule.
path (str) –
A path to the property of the molecule. Valid paths are described here. You can also view various code examples in our docs.
property (int) – The desired value of the property.
commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- set_property(key, path, property, *, commit=True)[source]¶
Set the property of a molecule.
- Parameters:
key (str) – The key of the molecule.
path (str) –
A path to the property of the molecule. Valid paths are described here. You can also view various code examples in our docs.
property (float | str | bool | None) – The desired value of the property.
commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- set_str_property(key, path, property, *, commit=True)[source]¶
Set a string property of a molecule.
- Parameters:
key (str) – The key of the molecule.
path (str) –
A path to the property of the molecule. Valid paths are described here. You can also view various code examples in our docs.
property (str) – The desired value of the property.
commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- update_entries(entries, *, merge_properties=True, upsert=True, commit=True)[source]¶
Update molecular entries in the database.
- Parameters:
entries (Entry | list[Entry]) – The molecule entries to update in the database.
merge_properties (bool) – If
True
, the molecular properties will be merged rather than replaced. Properties present in both the update and the database will be overwritten.upsert (bool) – If
True
, entries will be added to the database if missing.commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- update_properties(entries, *, merge_properties=True, commit=True)[source]¶
Update property entries in the database.
- Parameters:
entries (PropertyEntry | list[PropertyEntry]) – The entries to update in the database.
merge_properties (bool) – If
True
, the molecular properties will be merged rather than replaced. Properties present in both the update and the database will be overwritten.commit (bool) – If
True
changes will be automatically commited to the database file.
- Return type:
None
- connection: Connection¶
An open database connection.
Can be used to run SQL commands against the database.