예제 #1
0
def _test_from_json(
    dejsonizer,
    json,
    molecule,
):
    """
    Test :meth:`.MoleculeDejsonizer.from_json`.

    Parameters
    ----------
    dejsonizer : :class:`.MoleculeDejsonizer`
        The dejsonizer to test.

    json : :class:`dict`
        The JSON to test.

    molecule : :class:`.Molecule`
        The correct dejsonized molecule.

    Returns
    -------
    None : :class:`NoneType`

    """

    result = dejsonizer.from_json(json)
    is_equivalent_molecule(result, molecule)
    assert np.all(
        np.equal(
            molecule.get_position_matrix(),
            result.get_position_matrix(),
        ))
예제 #2
0
def _test_get_all(
    database: stk.MoleculeDatabase,
    expected_molecules: dict[str, stk.BuildingBlock],
) -> None:
    """
    Test iteration over all entries.

    Parameters:

        database: A database to test.

        expected_molecules: The expected molecules to get from the
            databases using their smiles as the key.

    """

    smiles = stk.Smiles()
    for i, retrieved in enumerate(database.get_all()):
        expected = expected_molecules[smiles.get_key(retrieved)]
        is_equivalent_molecule(
            molecule1=expected.with_canonical_atom_ordering(),
            molecule2=retrieved.with_canonical_atom_ordering(),
        )

    assert i+1 == len(expected_molecules)
예제 #3
0
def _test_database(database, molecule, key):
    """
    Test a molecule or constructed molecule database.

    Parameters
    ----------
    database : :class:`.MoleculeCache`
        The database to test.

    molecule : :class:`.Molecule`
        The molecule to put and get from the `database`.

    key : :class:`object`
        The key used to retrieve `molecule` from the database.

    Returns
    -------
    None : :class:`NoneType`

    """

    database.put(molecule)
    retrieved = database.get(key)
    is_equivalent_molecule(
        molecule1=molecule.with_canonical_atom_ordering(),
        molecule2=retrieved.with_canonical_atom_ordering(),
    )
예제 #4
0
def is_equivalent_building_block(building_block1, building_block2):
    is_equivalent_molecule(building_block1, building_block2)
    are_equivalent_functional_groups(
        functional_groups1=building_block1.get_functional_groups(),
        functional_groups2=building_block2.get_functional_groups(),
    )
    for placer_id1, placer_id2 in it.zip_longest(
            building_block1.get_placer_ids(),
            building_block2.get_placer_ids(),
    ):
        assert placer_id1 == placer_id2

    for core_atom_id1, core_atom_id2 in it.zip_longest(
            building_block1.get_core_atom_ids(),
            building_block2.get_core_atom_ids(),
    ):
        assert core_atom_id1 == core_atom_id2
예제 #5
0
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)
예제 #6
0
파일: molecule.py 프로젝트: zaeemnajeeb/stk
def is_clone_molecule(molecule1, molecule2):
    assert molecule1 is not molecule2
    is_equivalent_molecule(molecule1, molecule2)