asedb package
Submodules
asedb.abstract module
- class asedb.abstract.ArrayType(*args: Any, **kwargs: Any)[source]
Bases:
TypeDecoratorCustom type for saving/loading NumPy arrays.
- compare_values(x: Any, y: Any) bool[source]
Given two values, compare them for equality.
By default this calls upon
TypeEngine.compare_values()of the underlying “impl”, which in turn usually uses the Python equals operator==.This function is used by the ORM to compare an original-loaded value with an intercepted “changed” value, to determine if a net change has occurred.
- impl
alias of
LargeBinary
- class asedb.abstract.NamedArray(**kwargs: Any)[source]
Bases:
BaseBase table object for storing a NumPy array along with a name and some metadata.
- classmethod from_np_array(name: str, array: ndarray) T_Arr[source]
Construct an instance of the NamedArray model from a NumPy array.
- set_array(array: ndarray | Cell) None[source]
Update the blob representing a NumPy array. The array will be serialized to a binary blob using the NumPy save function.
Note: Arbitrary Python objects are not allowed, as Pickle serialization is disabled by default for security purposes. Change the asedb.abstract.ALLOW_PICKLE variable to True to allow pickle serialization.
asedb.atoms_model module
- class asedb.atoms_model.AtomsArray(**kwargs)[source]
Bases:
NamedArray
- class asedb.atoms_model.AtomsModel(**kwargs)[source]
Bases:
BaseThe primary class representing the SQLAlchemy model for an ASE Atoms object.
This class facilitates the storage and retrieval of atomic structures within a relational database, utilizing the SQLAlchemy ORM. It intends to seamlessly serialize and deserialize ASE Atoms objects, including their associated calculator results when available.
The main usage will be something like
atoms = ase.Atoms(...) model = AtomsModel.from_atoms(atoms) session.add(model) session.commit() # Load the model from the database loaded = session.query(AtomsModel).first().to_atoms()
The AtomsModel will also serialize a calculator object into a
Calculationif a calculator exists.- arrays: Mapped[list[AtomsArray]]
- calculation: Mapped[Calculation]
- classmethod from_atoms(atoms: Atoms, import_calculation: bool = True, project: None | str = None) AtomsModel[source]
Helper method to instantiate an AtomsModel instance from an ASE Atoms object.
- Parameters:
- Returns:
The newly instantiated AtomsModel.
- Return type:
- get_element_counts() dict[str, int][source]
Get the number of times a particular element occurs in the model.
- property has_calc: bool
Indicates whether the atoms object represented by the model has an associated calculator.
- set_atoms(atoms: Atoms, import_calculation: bool = True) None[source]
Read the current Atoms configurations, including the calculator, and save the state in the current AtomsModel instance.
If import_calculation is True, then the calculator object will also be serialized into a Calculation object, otherwise the calculator will be ignored.
- to_atoms() Atoms[source]
Export the SQL Alchemy object as an ASE Atoms object. If a corresponding
Calculationobject exists, a SinglePointCalculator will be attached to the constructed Atoms object.
- class asedb.atoms_model.CalcArray(**kwargs)[source]
Bases:
NamedArray
- class asedb.atoms_model.Calculation(**kwargs)[source]
Bases:
BaseRepresents the serialization of an ASE Calculator, encapsulating the results of computational chemistry calculations. This class stores various properties such as energy, free energy, magnetic moment, and the maximum force acting on atoms alongside arbitrary arrays of data like forces or stresses that are results of these calculations.
- fmax
The maximum force acting on any atom in the structure, derived from the forces array.
- Type:
float, optional
- arrays
A relationship to a collection of CalcArray instances that store arbitrary array results from the calculation.
The class provides methods to construct a Calculation instance from an ASE Calculator object, manage result arrays, and retrieve calculation results for re-creation of an ASE Calculator object for further analysis.
Example usage:
from ase.calculators.emt import EMT from ase.build import molecule from asedb import Calculation, AtomsModel atoms = molecule('H2O') atoms.calc = EMT() energy = atoms.get_potential_energy() model = AtomsModel.from_atoms(atoms) # The calc object now contains the calculation results and can be associated with an AtomsModel assert energy == model.calculation.energy
- add_array(name: str, array: ndarray) None[source]
Adds an array of calculation results to the Calculation object.
This method is used to store additional arrays of results, such as forces or stress tensors, that come from the calculation. If adding forces, the maximum force (fmax) is automatically updated.
- Parameters:
name (str) – The name of the array (e.g., “forces”, “stress”).
array (np.ndarray) – The numpy array containing the calculation results.
- drop_array(name: str) None[source]
Removes an array of calculation results from the Calculation object.
This method allows for the removal of specific arrays of results, useful for correcting or updating calculation data.
- Parameters:
name (str) – The name of the array to remove (e.g., “forces”, “stress”).
- Raises:
ValueError – If the specified array name does not exist within the Calculation object.
- classmethod from_calc(calc: Calculator) Calculation[source]
Constructs a Calculation instance from an ASE Calculator object, extracting relevant calculation results and arrays.
- Parameters:
calc (AseCalculator) – The ASE Calculator object from which to extract calculation results.
- Returns:
An instance of Calculation populated with results from the ASE Calculator.
- Return type:
This method automatically extracts properties like energy, free energy, and magnetic moment as floats, and results like forces, stress, and magnetic moments as arrays, storing them for later reconstruction.
asedb.initialization module
asedb.properties module
asedb.time_utils module
asedb.trajectory_model module
- class asedb.trajectory_model.Trajectory(**kwargs)[source]
Bases:
Base- add_atoms(atoms: Atoms) AtomsModel[source]
Add an Atoms object to the Trajectory. Returns the newly created AtomsModel instance, which belongs to the trajectory.
- atoms_list: Mapped[list[AtomsModel]]
asedb.utils module
asedb.version module
Module contents
- class asedb.AtomsModel(**kwargs)[source]
Bases:
BaseThe primary class representing the SQLAlchemy model for an ASE Atoms object.
This class facilitates the storage and retrieval of atomic structures within a relational database, utilizing the SQLAlchemy ORM. It intends to seamlessly serialize and deserialize ASE Atoms objects, including their associated calculator results when available.
The main usage will be something like
atoms = ase.Atoms(...) model = AtomsModel.from_atoms(atoms) session.add(model) session.commit() # Load the model from the database loaded = session.query(AtomsModel).first().to_atoms()
The AtomsModel will also serialize a calculator object into a
Calculationif a calculator exists.- arrays: Mapped[list[AtomsArray]]
- calculation: Mapped[Calculation]
- classmethod from_atoms(atoms: Atoms, import_calculation: bool = True, project: None | str = None) AtomsModel[source]
Helper method to instantiate an AtomsModel instance from an ASE Atoms object.
- Parameters:
- Returns:
The newly instantiated AtomsModel.
- Return type:
- get_element_counts() dict[str, int][source]
Get the number of times a particular element occurs in the model.
- property has_calc: bool
Indicates whether the atoms object represented by the model has an associated calculator.
- set_atoms(atoms: Atoms, import_calculation: bool = True) None[source]
Read the current Atoms configurations, including the calculator, and save the state in the current AtomsModel instance.
If import_calculation is True, then the calculator object will also be serialized into a Calculation object, otherwise the calculator will be ignored.
- to_atoms() Atoms[source]
Export the SQL Alchemy object as an ASE Atoms object. If a corresponding
Calculationobject exists, a SinglePointCalculator will be attached to the constructed Atoms object.
- class asedb.Calculation(**kwargs)[source]
Bases:
BaseRepresents the serialization of an ASE Calculator, encapsulating the results of computational chemistry calculations. This class stores various properties such as energy, free energy, magnetic moment, and the maximum force acting on atoms alongside arbitrary arrays of data like forces or stresses that are results of these calculations.
- fmax
The maximum force acting on any atom in the structure, derived from the forces array.
- Type:
float, optional
- arrays
A relationship to a collection of CalcArray instances that store arbitrary array results from the calculation.
The class provides methods to construct a Calculation instance from an ASE Calculator object, manage result arrays, and retrieve calculation results for re-creation of an ASE Calculator object for further analysis.
Example usage:
from ase.calculators.emt import EMT from ase.build import molecule from asedb import Calculation, AtomsModel atoms = molecule('H2O') atoms.calc = EMT() energy = atoms.get_potential_energy() model = AtomsModel.from_atoms(atoms) # The calc object now contains the calculation results and can be associated with an AtomsModel assert energy == model.calculation.energy
- add_array(name: str, array: ndarray) None[source]
Adds an array of calculation results to the Calculation object.
This method is used to store additional arrays of results, such as forces or stress tensors, that come from the calculation. If adding forces, the maximum force (fmax) is automatically updated.
- Parameters:
name (str) – The name of the array (e.g., “forces”, “stress”).
array (np.ndarray) – The numpy array containing the calculation results.
- drop_array(name: str) None[source]
Removes an array of calculation results from the Calculation object.
This method allows for the removal of specific arrays of results, useful for correcting or updating calculation data.
- Parameters:
name (str) – The name of the array to remove (e.g., “forces”, “stress”).
- Raises:
ValueError – If the specified array name does not exist within the Calculation object.
- classmethod from_calc(calc: Calculator) Calculation[source]
Constructs a Calculation instance from an ASE Calculator object, extracting relevant calculation results and arrays.
- Parameters:
calc (AseCalculator) – The ASE Calculator object from which to extract calculation results.
- Returns:
An instance of Calculation populated with results from the ASE Calculator.
- Return type:
This method automatically extracts properties like energy, free energy, and magnetic moment as floats, and results like forces, stress, and magnetic moments as arrays, storing them for later reconstruction.
- class asedb.Trajectory(**kwargs)[source]
Bases:
Base- add_atoms(atoms: Atoms) AtomsModel[source]
Add an Atoms object to the Trajectory. Returns the newly created AtomsModel instance, which belongs to the trajectory.
- atoms_list: Mapped[list[AtomsModel]]