From 65cbc33b571791d30c4333bb2061fcf4141f40f1 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 15 Sep 2021 19:55:48 +0200 Subject: [PATCH 1/5] KLIFS: Move back KLIFS_CLIENT/KLIFS_API_DEFINITIONS from utils to remote --- opencadd/databases/klifs/local.py | 3 ++- opencadd/databases/klifs/remote.py | 3 +++ opencadd/databases/klifs/session.py | 2 +- opencadd/databases/klifs/utils.py | 3 --- opencadd/tests/databases/test_sync_klifs_and_opencadd.py | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/opencadd/databases/klifs/local.py b/opencadd/databases/klifs/local.py index 99739bb1..00d87eef 100644 --- a/opencadd/databases/klifs/local.py +++ b/opencadd/databases/klifs/local.py @@ -23,7 +23,8 @@ FIELDS, POCKET_KLIFS_REGIONS, ) -from .utils import KLIFS_CLIENT, PATH_DATA, metadata_to_filepath, filepath_to_metadata +from .utils import PATH_DATA, metadata_to_filepath, filepath_to_metadata +from .remote import KLIFS_CLIENT from .exceptions import KlifsPocketIncompleteError, KlifsPocketUnequalSequenceStructure from opencadd.io import DataFrame, Rdkit diff --git a/opencadd/databases/klifs/remote.py b/opencadd/databases/klifs/remote.py index 13561736..e8428c58 100644 --- a/opencadd/databases/klifs/remote.py +++ b/opencadd/databases/klifs/remote.py @@ -26,6 +26,9 @@ _logger = logging.getLogger(__name__) +KLIFS_API_DEFINITIONS = "https://dev.klifs.net/swagger_v2/swagger.json" +KLIFS_CLIENT = SwaggerClient.from_url(KLIFS_API_DEFINITIONS, config={"validate_responses": False}) + class SerializableSwaggerClient(SwaggerClient): # Since they are using __attributes to mangle the namespace diff --git a/opencadd/databases/klifs/session.py b/opencadd/databases/klifs/session.py index b37e92c0..2b1f547f 100644 --- a/opencadd/databases/klifs/session.py +++ b/opencadd/databases/klifs/session.py @@ -10,7 +10,7 @@ from . import remote from . import local -from .utils import KLIFS_CLIENT +from .remote import KLIFS_CLIENT class Session: diff --git a/opencadd/databases/klifs/utils.py b/opencadd/databases/klifs/utils.py index 7474c36d..8e1f4aba 100644 --- a/opencadd/databases/klifs/utils.py +++ b/opencadd/databases/klifs/utils.py @@ -13,9 +13,6 @@ _logger = logging.getLogger(__name__) -KLIFS_API_DEFINITIONS = "https://dev.klifs.net/swagger_v2/swagger.json" -KLIFS_CLIENT = SwaggerClient.from_url(KLIFS_API_DEFINITIONS, config={"validate_responses": False}) - PATH_DATA = Path(__file__).parent / ".." / ".." / "data" diff --git a/opencadd/tests/databases/test_sync_klifs_and_opencadd.py b/opencadd/tests/databases/test_sync_klifs_and_opencadd.py index 10c79380..ec359b58 100644 --- a/opencadd/tests/databases/test_sync_klifs_and_opencadd.py +++ b/opencadd/tests/databases/test_sync_klifs_and_opencadd.py @@ -3,7 +3,7 @@ If errors are raised, it is time to update opencadd. """ -from opencadd.databases.klifs.utils import KLIFS_CLIENT +from opencadd.databases.klifs.remote import KLIFS_CLIENT from opencadd.databases.klifs.schema import FIELDS From 3bd7878932e12f65111c2d339c07beea5c0f5e54 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 15 Sep 2021 20:09:29 +0200 Subject: [PATCH 2/5] Satisfy pylint --- opencadd/databases/klifs/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/opencadd/databases/klifs/utils.py b/opencadd/databases/klifs/utils.py index 8e1f4aba..35c6d4e0 100644 --- a/opencadd/databases/klifs/utils.py +++ b/opencadd/databases/klifs/utils.py @@ -9,8 +9,6 @@ from pathlib import Path import re -from bravado.client import SwaggerClient - _logger = logging.getLogger(__name__) PATH_DATA = Path(__file__).parent / ".." / ".." / "data" From 24037d94240b902ad9bb2490019619a5abe4cf6c Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 16 Sep 2021 08:56:55 +0200 Subject: [PATCH 3/5] KLIFS: Add parallelization test for remote session --- .../test_klifs_remote_parallelization.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 opencadd/tests/databases/test_klifs_remote_parallelization.py diff --git a/opencadd/tests/databases/test_klifs_remote_parallelization.py b/opencadd/tests/databases/test_klifs_remote_parallelization.py new file mode 100644 index 00000000..7211ac5c --- /dev/null +++ b/opencadd/tests/databases/test_klifs_remote_parallelization.py @@ -0,0 +1,35 @@ +""" +Tests for opencadd.databases.klifs.remote parallelization! +""" + +from itertools import repeat +from multiprocessing import Pool + +import pytest + +from opencadd.databases.klifs import setup_remote + +# Set local session +REMOTE = setup_remote() + +@pytest.mark.parametrize( + "klifs_session, structure_klifs_ids, n_cores", + [(REMOTE, [111, 113], 2)], +) +def test_remote_parallelization(klifs_session, structure_klifs_ids, n_cores): + + pool = Pool(processes=n_cores) + + pool.starmap( + _parallelize_klifs_session, zip(structure_klifs_ids, repeat(klifs_session)) + ) + pool.close() + pool.join() + +def _parallelize_klifs_session(structure_klifs_id, klifs_session): + """ + Dummy function that simulates a function that takes the KLIFS session as input; + shall be used in our test where we want to pass a single klifs_session to multiple functions + that are called in a parallelized process. + """ + return klifs_session.structures.by_structure_klifs_id(structure_klifs_id) \ No newline at end of file From d5770243ce1cf5a6b2b937f41994f6f846b13a46 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 16 Sep 2021 08:57:18 +0200 Subject: [PATCH 4/5] KLIFS: Fix SwaggerClient > SerializableSwaggerClient --- opencadd/databases/klifs/remote.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/opencadd/databases/klifs/remote.py b/opencadd/databases/klifs/remote.py index e8428c58..c3dbacac 100644 --- a/opencadd/databases/klifs/remote.py +++ b/opencadd/databases/klifs/remote.py @@ -26,9 +26,6 @@ _logger = logging.getLogger(__name__) -KLIFS_API_DEFINITIONS = "https://dev.klifs.net/swagger_v2/swagger.json" -KLIFS_CLIENT = SwaggerClient.from_url(KLIFS_API_DEFINITIONS, config={"validate_responses": False}) - class SerializableSwaggerClient(SwaggerClient): # Since they are using __attributes to mangle the namespace @@ -47,6 +44,12 @@ def __getstate__(self, *args): } +KLIFS_API_DEFINITIONS = "https://dev.klifs.net/swagger_v2/swagger.json" +KLIFS_CLIENT = SerializableSwaggerClient.from_url( + KLIFS_API_DEFINITIONS, config={"validate_responses": False} +) + + class RemoteInitializer: """ Base class used to define __init__ for all remote classes. From 11526c8134094ddc56dd921928f976c735a227aa Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 16 Sep 2021 09:04:29 +0200 Subject: [PATCH 5/5] Satisfy pytest --- .../databases/test_klifs_remote_parallelization.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/opencadd/tests/databases/test_klifs_remote_parallelization.py b/opencadd/tests/databases/test_klifs_remote_parallelization.py index 7211ac5c..479d779f 100644 --- a/opencadd/tests/databases/test_klifs_remote_parallelization.py +++ b/opencadd/tests/databases/test_klifs_remote_parallelization.py @@ -12,6 +12,7 @@ # Set local session REMOTE = setup_remote() + @pytest.mark.parametrize( "klifs_session, structure_klifs_ids, n_cores", [(REMOTE, [111, 113], 2)], @@ -19,17 +20,16 @@ def test_remote_parallelization(klifs_session, structure_klifs_ids, n_cores): pool = Pool(processes=n_cores) - - pool.starmap( - _parallelize_klifs_session, zip(structure_klifs_ids, repeat(klifs_session)) - ) + + pool.starmap(_parallelize_klifs_session, zip(structure_klifs_ids, repeat(klifs_session))) pool.close() pool.join() + def _parallelize_klifs_session(structure_klifs_id, klifs_session): """ Dummy function that simulates a function that takes the KLIFS session as input; - shall be used in our test where we want to pass a single klifs_session to multiple functions + shall be used in our test where we want to pass a single klifs_session to multiple functions that are called in a parallelized process. """ - return klifs_session.structures.by_structure_klifs_id(structure_klifs_id) \ No newline at end of file + return klifs_session.structures.by_structure_klifs_id(structure_klifs_id)