-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add value iteration example. * Add NotImplemented base method. * Minor. * Implement get_entries for Molecule class. * Only yield molecule. * Implement get_entries for ConstructedMolecule class. * Handle KeyError in example. * Add tests. * Update examples. * Update constructed_molecule.py * Update molecule.py * Update constructed_molecule.py * Update molecule.py * Update value.py * Update test_get_entries.py * Update docs. * Fix tests. Minor. Co-authored-by: Lukas Turcani <lukasturcani93@gmail.com>
- Loading branch information
1 parent
77d063f
commit c2f95e4
Showing
7 changed files
with
285 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
tests/databases/constructed_molecule/mongo_db/test_get_all.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import stk | ||
import pymongo | ||
|
||
from tests.utilities import is_equivalent_constructed_molecule | ||
|
||
|
||
def test_get_all(): | ||
""" | ||
Test iteration over all molecules. | ||
""" | ||
|
||
database_name = '_test_get_entries_constructed_molecule' | ||
client = pymongo.MongoClient() | ||
client.drop_database(database_name) | ||
|
||
key_maker = stk.Inchi() | ||
jsonizer = stk.ConstructedMoleculeJsonizer( | ||
key_makers=(key_maker, ) | ||
) | ||
|
||
database = stk.ConstructedMoleculeMongoDb( | ||
mongo_client=client, | ||
database=database_name, | ||
jsonizer=jsonizer, | ||
put_lru_cache_size=0, | ||
get_lru_cache_size=0, | ||
) | ||
|
||
molecules = [ | ||
stk.ConstructedMolecule( | ||
topology_graph=stk.polymer.Linear( | ||
building_blocks=(stk.BuildingBlock( | ||
smiles='BrCCCBr', | ||
functional_groups=[stk.BromoFactory()]), | ||
), | ||
repeating_unit='A', | ||
num_repeating_units=3, | ||
), | ||
), | ||
stk.ConstructedMolecule( | ||
topology_graph=stk.polymer.Linear( | ||
building_blocks=( | ||
stk.BuildingBlock( | ||
smiles='BrCCBr', | ||
functional_groups=[stk.BromoFactory()] | ||
), | ||
stk.BuildingBlock( | ||
smiles='BrCNCBr', | ||
functional_groups=[stk.BromoFactory()] | ||
), | ||
), | ||
repeating_unit='AB', | ||
num_repeating_units=2, | ||
), | ||
), | ||
] | ||
molecules_by_key = { | ||
key_maker.get_key(molecule): molecule | ||
for molecule in molecules | ||
} | ||
|
||
for molecule in molecules: | ||
database.put(molecule) | ||
|
||
for i, retrieved in enumerate(database.get_all()): | ||
key = key_maker.get_key(retrieved) | ||
molecule = molecules_by_key[key] | ||
is_equivalent_constructed_molecule( | ||
molecule.with_canonical_atom_ordering(), | ||
retrieved.with_canonical_atom_ordering(), | ||
) | ||
|
||
# Check number of molecules. | ||
assert i+1 == len(molecules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import stk | ||
import pymongo | ||
|
||
from tests.utilities import is_equivalent_molecule | ||
|
||
|
||
def test_get_all(): | ||
""" | ||
Test iteration over all entries. | ||
""" | ||
|
||
database_name = '_test_get_entries_molecule' | ||
client = pymongo.MongoClient() | ||
client.drop_database(database_name) | ||
|
||
key_maker = stk.Inchi() | ||
jsonizer = stk.MoleculeJsonizer(key_makers=(key_maker, )) | ||
|
||
database = stk.MoleculeMongoDb( | ||
mongo_client=client, | ||
database=database_name, | ||
jsonizer=jsonizer, | ||
put_lru_cache_size=0, | ||
get_lru_cache_size=0, | ||
) | ||
|
||
molecules = ( | ||
stk.BuildingBlock('CCC').with_canonical_atom_ordering(), | ||
stk.BuildingBlock('BrCCCBr').with_canonical_atom_ordering(), | ||
stk.BuildingBlock('NCCN').with_canonical_atom_ordering(), | ||
) | ||
molecules_by_key = { | ||
key_maker.get_key(molecule): molecule | ||
for molecule in molecules | ||
} | ||
|
||
for molecule in molecules: | ||
database.put(molecule) | ||
|
||
for i, retrieved in enumerate(database.get_all()): | ||
key = key_maker.get_key(retrieved) | ||
molecule = molecules_by_key[key] | ||
is_equivalent_molecule( | ||
molecule1=molecule.with_canonical_atom_ordering(), | ||
molecule2=retrieved.with_canonical_atom_ordering(), | ||
) | ||
|
||
# Check number of molecules. | ||
assert i+1 == len(molecules) |