Value Database

class ValueDatabase[source]

Bases: object

Abstract base class for storing of molecular property values.

Examples

Subclass Implementation

The source of any of the subclasses, listed in molecule_value_database, can serve as good examples.

Iterating Through Entries in the Database

The MoleculeDatabase.get_all() and ConstructedMoleculeDatabase.get_all() methods can be used to iterate through all of the database’s entries, which can then be used to access values in the ValueDatabase

import pymongo

client = pymongo.MongoClient()
molecule_db = stk.MoleculeMongoDb(client)

value_db = stk.ValueMongoDb(
    mongo_client=client,
    collection='atom_counts',
)

molecule = stk.BuildingBlock('BrBr')
molecule_db.put(molecule)
value_db.put(molecule, molecule.get_num_atoms())

for molecule in molecule_db.get_all():
    try:
        value = value_db.get(molecule)
        print(value)
    except KeyError:
        # In case molecule is not in value_db.
        pass
2

Methods

get(molecule)

Get the stored value for molecule.

put(molecule, value)

Put a value into the database.

get(molecule)[source]

Get the stored value for molecule.

Parameters

molecule (Molecule) – The molecule whose value is to be retrieved from the database.

Returns

The value associated with molecule.

Return type

object

Raises

KeyError – If molecule is not found in the database.

put(molecule, value)[source]

Put a value into the database.

Parameters
  • molecule (Molecule) – The molecule which is associated with the value.

  • value (object) – Some value associated with molecule.

Returns

None

Return type

NoneType