Create and modify a database#
All functionality to create and modify a database structure is combined in the
Factory class.
Create a new DB#
from duckatoms import Factory
factory = Factory('<path_to_db_file>/<db_name>.duckdb')
factory.create()
This generates a database with the minimal required properties to add atomic structures.
Modify an existing DB#
Use the
Factoryclass instance from the database creation or instantiate aFactoryclass with the path to an existing database file.
factory = Factory('<path_to_db_file>/<db_name>.duckdb')
Inspect what properties (aka columns) your database contains with:
factory.show_db_structure()
Add properties to your structures or atoms table like coordination number or mace descriptor with:
# add coordination number
factory.add_property(table_name='atoms', property_name='o_coordination_number', property_dtype='INTEGER')
# add mace descriptor
factory.add_property(table_name='atoms', property_name='mace_descriptor', property_dtype='DOUBLE[128]')
To find the right datatype from Python to DuckDB take a look here.
To remove properties from the atoms table:
factory.remove_property(table_name='atoms', property_name='o_coordination_number')
Keep in mind that deleting a property also deletes all its saved values.
Note: Properties from the structures table can’t be removed. This is due to the fact that DuckDB does not allow the removal of columns from a table whose primary key is referenced in another table as a foreign key. To keep the data integrity, the structure_id is referenced as a foreign key in the atoms table. If you really want to remove a column, you unfortunately have to create a new database.