Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tests to changes in databases #505

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions src/biotite/database/pubchem/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ class NameQuery(Query):
--------

>>> print(search(NameQuery("Alanine")))
[5950, 602, 71080]
[5950, 449619, 7311724, 155817681]
"""

def __init__(self, name):
self._name = name

def get_input_url_path(self):
return "compound/name"

Expand All @@ -107,7 +107,7 @@ class SmilesQuery(Query):
----------
smiles : str
The *SMILES* string.

Examples
--------

Expand All @@ -117,7 +117,7 @@ class SmilesQuery(Query):

def __init__(self, smiles):
self._smiles = smiles

def get_input_url_path(self):
return "compound/smiles"

Expand All @@ -134,7 +134,7 @@ class InchiQuery(Query):
----------
inchi : str
The *InChI* string.

Examples
--------

Expand All @@ -144,7 +144,7 @@ class InchiQuery(Query):

def __init__(self, inchi):
self._inchi = inchi

def get_input_url_path(self):
return "compound/inchi"

Expand All @@ -161,7 +161,7 @@ class InchiKeyQuery(Query):
----------
inchi_key : str
The *InChI* key.

Examples
--------

Expand All @@ -171,7 +171,7 @@ class InchiKeyQuery(Query):

def __init__(self, inchi_key):
self._inchi_key = inchi_key

def get_input_url_path(self):
return "compound/inchikey"

Expand Down Expand Up @@ -199,7 +199,7 @@ class FormulaQuery(Query):
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can be
considered unlimited.

Examples
--------

Expand All @@ -214,7 +214,7 @@ def __init__(self, formula, allow_other_elements=False, number=None):
self._formula = formula
self._allow_other_elements = allow_other_elements
self._number = number

@staticmethod
def from_atoms(atoms, allow_other_elements=False, number=None):
"""
Expand Down Expand Up @@ -247,7 +247,7 @@ def from_atoms(atoms, allow_other_elements=False, number=None):
for element in sorted_elements:
formula += _format_element(element, element_counter[element])
return FormulaQuery(formula, allow_other_elements, number)

def get_input_url_path(self):
# The 'fastformula' service seems not to accept the formula
# in the parameter section of the request
Expand Down Expand Up @@ -287,7 +287,7 @@ class StructureQuery(Query, metaclass=abc.ABCMeta):
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
Expand Down Expand Up @@ -351,7 +351,7 @@ def from_atoms(cls, atoms, *args, **kwargs):
sdf = "\r\n".join(mol_file.lines) + "\r\n$$$$\r\n",
**kwargs
)

def get_input_url_path(self):
input_string = f"compound/{self.search_type()}/{self._query_key}"
if self._query_key == "cid":
Expand Down Expand Up @@ -384,7 +384,7 @@ def get_files(self):
return {"sdf": self._query_val}
else:
return {}

@abc.abstractmethod
def search_type(self):
"""
Expand Down Expand Up @@ -434,7 +434,7 @@ class SuperOrSubstructureQuery(StructureQuery, metaclass=abc.ABCMeta):
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
Expand Down Expand Up @@ -463,7 +463,7 @@ class SuperOrSubstructureQuery(StructureQuery, metaclass=abc.ABCMeta):
stereo : {'ignore', 'exact', 'relative', 'nonconflicting'}, optional
How to handle stereo.
(Default: 'ignore')

Notes
-----
Optional parameter descriptions are taken from the *PubChem* REST
Expand All @@ -488,7 +488,7 @@ def __init__(self, **kwargs):
self._options[option] = value
del kwargs[option]
super().__init__(**kwargs)

def search_options(self):
return self._options

Expand All @@ -514,7 +514,7 @@ class SuperstructureQuery(SuperOrSubstructureQuery):
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
Expand Down Expand Up @@ -543,7 +543,7 @@ class SuperstructureQuery(SuperOrSubstructureQuery):
stereo : {'ignore', 'exact', 'relative', 'nonconflicting'}, optional
How to handle stereo.
(Default: 'ignore')

Notes
-----
Optional parameter descriptions are taken from the *PubChem* REST
Expand Down Expand Up @@ -587,7 +587,7 @@ class SubstructureQuery(SuperOrSubstructureQuery):
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
Expand Down Expand Up @@ -616,7 +616,7 @@ class SubstructureQuery(SuperOrSubstructureQuery):
stereo : {'ignore', 'exact', 'relative', 'nonconflicting'}, optional
How to handle stereo.
(Default: 'ignore')

Notes
-----
Optional parameter descriptions are taken from the *PubChem* REST
Expand Down Expand Up @@ -666,22 +666,22 @@ class SimilarityQuery(StructureQuery):
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.

Notes
-----
The conformation based similarity measure uses *shape-Tanimoto* and
*color-Tanimoto* scores :footcite:`Kim2018`.

References
----------

.. footbibliography::

Examples
Expand All @@ -700,11 +700,11 @@ def __init__(self, threshold=0.9, conformation_based=False, **kwargs):
self._threshold = threshold
self._conformation_based = conformation_based
super().__init__(**kwargs)

def search_type(self):
dim = "3d" if self._conformation_based else "2d"
return f"fastsimilarity_{dim}"

def search_options(self):
return {"threshold" : int(round(self._threshold * 100))}

Expand All @@ -730,14 +730,14 @@ class IdentityQuery(StructureQuery):
sdf : str, optional
A query structure as SDF formatted string.
Usually :meth:`from_atoms()` is used to create the SDF from an
:class:`AtomArray`.
:class:`AtomArray`.
cid : int, optional
The query structure given as CID.
number : int, optional
The maximum number of matches that this query may return.
By default, the *PubChem* default value is used, which can
be considered unlimited.

Examples
--------

Expand All @@ -753,28 +753,28 @@ class IdentityQuery(StructureQuery):
def __init__(self, identity_type="same_stereo_isotope", **kwargs):
self._identity_type = identity_type
super().__init__(**kwargs)

def search_type(self):
return "fastidentity"

def get_params(self):
# Use 'get_params()' instead of 'search_options()', since the
# parameter 'identity_type' in the REST API is *snake case*
# -> Conversion to *camel case* is undesirable
params = super().get_params()
params["identity_type"] = self._identity_type
return params




def search(query, throttle_threshold=0.5, return_throttle_status=False):
"""
Get all CIDs that meet the given query requirements,
via the PubChem REST API.

This function requires an internet connection.

Parameters
----------
query : Query
Expand All @@ -787,7 +787,7 @@ def search(query, throttle_threshold=0.5, return_throttle_status=False):
If ``None`` is given, the execution is never halted.
return_throttle_status : float, optional
If set to true, the :class:`ThrottleStatus` is also returned.

Returns
-------
ids : list of int
Expand All @@ -796,12 +796,12 @@ def search(query, throttle_threshold=0.5, return_throttle_status=False):
The :class:`ThrottleStatus` obtained from the server response.
This can be used for custom request throttling, for example.
Only returned, if `return_throttle_status` is set to true.

Examples
--------

>>> print(search(NameQuery("Alanine")))
[5950, 602, 71080]
[5950, 449619, 7311724, 155817681]
"""
# Use POST to be compatible with the larger payloads
# of structure searches
Expand Down
11 changes: 6 additions & 5 deletions tests/application/test_autodock.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ def test_docking(flexible):
flexible_mask = np.isin(receptor.res_id, (23, 88))
else:
flexible_mask = None

app = VinaApp(
ligand, receptor, struc.centroid(ref_ligand), [20, 20, 20],
flexible=flexible_mask
)
app.set_seed(0)
app.start()
app.join()

test_ligand_coord = app.get_ligand_coord()
test_receptor_coord = app.get_receptor_coord()
energies = app.get_energies()
Expand Down Expand Up @@ -80,13 +80,14 @@ def test_docking(flexible):
test_receptor_coord = test_receptor_coord[not_nan_mask]
# Check if it least one atom is preserved
assert test_receptor_coord.shape[1] > 0
# The flexible residues should have a maximum deviation of 1 Å
# The flexible residues should have a maximum deviation of 1.0 Å
# from the original conformation
# NOTE: Currently 1.0 Å is sufficient in local testing,
# but not in the CI (1.6 Å)
assert np.max(
struc.distance(test_receptor_coord, ref_receptor_coord)
) < 1.0
) < 1.7
else:
ref_receptor_coord = receptor.coord
for model_coord in test_receptor_coord:
assert np.array_equal(model_coord, ref_receptor_coord)

8 changes: 4 additions & 4 deletions tests/database/test_pubchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_fetch_structural_formula(as_structural_formula):
2244, as_structural_formula=as_structural_formula
))
atoms = mol_file.get_structure()

if as_structural_formula:
assert np.all(atoms.coord[:, 2] == 0)
else:
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_fetch_invalid():
@pytest.mark.parametrize(
"query, ref_ids",
[
(pubchem.NameQuery("Alanine"), [71080, 602, 5950]),
(pubchem.NameQuery("Alanine"), [155817681, 449619, 7311724, 5950]),
(pubchem.SmilesQuery("CCCC"), [7843]),
(pubchem.InchiQuery("InChI=1S/C4H10/c1-3-4-2/h3-4H2,1-2H3"), [7843]),
(pubchem.InchiKeyQuery("IJDNQMDRQITEOD-UHFFFAOYSA-N"), [7843]),
Expand Down Expand Up @@ -138,7 +138,7 @@ def test_search_super_and_substructure(cid, from_atoms, query_type):
NUMBER = 5

original_atoms = mol.MOLFile.read(pubchem.fetch(cid)).get_structure()

if from_atoms:
query = query_type.from_atoms(original_atoms, number=NUMBER)
else:
Expand All @@ -148,7 +148,7 @@ def test_search_super_and_substructure(cid, from_atoms, query_type):
# Expect number of returned CIDs to be limited by given max number
assert len(cids) == NUMBER
if query_type == pubchem.SubstructureQuery:
# Expect that the input itself is the top hit
# Expect that the input itself is the top hit
assert cid in cids

for result_cid in cids:
Expand Down
Loading
Loading