Create and modify a database

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#

  1. Use the Factory class instance from the database creation or instantiate a Factory class with the path to an existing database file.

factory = Factory('<path_to_db_file>/<db_name>.duckdb')
  1. Inspect what properties (aka columns) your database contains with:

factory.show_db_structure()
  1. 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.

  1. 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.