def test_by_ligand_expo_id(self, ligand_expo_ids):
        """
        Test class methods with Ligand Expo IDs as input.
        """

        # Ligands
        result_remote = REMOTE.ligands.by_ligand_expo_id(ligand_expo_ids)
        result_local = LOCAL.ligands.by_ligand_expo_id(ligand_expo_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("ligands"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("ligands"))

        # Structure
        result_remote = REMOTE.structures.by_ligand_expo_id(ligand_expo_ids)
        result_local = LOCAL.structures.by_ligand_expo_id(ligand_expo_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("structures"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("structures"))

        # Bioactivities
        result_remote = REMOTE.bioactivities.by_ligand_expo_id(ligand_expo_ids)
        with pytest.raises(NotImplementedError):
            LOCAL.bioactivities.by_ligand_expo_id(ligand_expo_ids)
        check_dataframe(
            result_remote,
            FIELDS.oc_name_to_type("bioactivities",
                                   {"ligand.expo_id (query)": "string"}),
        )
    def test_all_interactions(self):
        """
        Test request result for all kinases.
        """

        result_remote = REMOTE.interactions.all_interactions()
        result_local = LOCAL.interactions.all_interactions()

        check_dataframe(result_remote, FIELDS.oc_name_to_type("interactions"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("interactions"))
    def test_by_structure_pdb_id(self, structure_pdb_ids):
        """
        Test class methods with structure PDB IDs as input.
        """

        # Structure
        result_remote = REMOTE.structures.by_structure_pdb_id(
            structure_pdb_ids)
        result_local = LOCAL.structures.by_structure_pdb_id(structure_pdb_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("structures"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("structures"))
    def test_by_structure_klifs_id(self, structure_klifs_ids):
        """
        Test class methods with structure IDs as input.
        """

        # Structures
        result_remote = REMOTE.structures.by_structure_klifs_id(
            structure_klifs_ids)
        result_local = LOCAL.structures.by_structure_klifs_id(
            structure_klifs_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("structures"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("structures"))

        # Interactions
        result_remote = REMOTE.interactions.by_structure_klifs_id(
            structure_klifs_ids)
        result_local = LOCAL.interactions.by_structure_klifs_id(
            structure_klifs_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("interactions"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("interactions"))

        # Conformations
        result_remote = REMOTE.conformations.by_structure_klifs_id(
            structure_klifs_ids)
        # No local access available
        check_dataframe(result_remote,
                        FIELDS.oc_name_to_type("structure_conformations"))

        # Pockets and modified residues (takes only one structure ID as input!)
        if isinstance(structure_klifs_ids, int):
            structure_klifs_id = structure_klifs_ids

            # Pockets
            result_remote = REMOTE.pockets.by_structure_klifs_id(
                structure_klifs_ids)
            result_local_mol2 = LOCAL.pockets.by_structure_klifs_id(
                structure_klifs_ids, "mol2")
            result_local_pdb = LOCAL.pockets.by_structure_klifs_id(
                structure_klifs_ids, "pdb")

            check_dataframe(result_remote, FIELDS.oc_name_to_type("pockets"))
            check_dataframe(result_local_mol2,
                            FIELDS.oc_name_to_type("pockets"))
            check_dataframe(result_local_pdb,
                            FIELDS.oc_name_to_type("pockets"))

            assert all(result_local_mol2 == result_local_pdb)
            assert all(result_local_mol2 == result_remote)

            # Modified residues
            result_remote = REMOTE.modified_residues.by_structure_klifs_id(
                structure_klifs_id)
            # No local access available
            check_dataframe(
                result_remote,
                FIELDS.oc_name_to_type("structure_modified_residues"))
    def test_all_kinases(self, group, family, species, local_kinases):
        """
        Test request result for all kinases.
        """

        result_remote = REMOTE.kinases.all_kinases(group, family, species)
        result_local = LOCAL.kinases.all_kinases(group, family, species)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("kinases_all"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("kinases_all"))

        assert result_local["kinase.gene_name"].to_list() == local_kinases[0]
        assert result_local["species.klifs"].to_list() == local_kinases[1]
    def test_all_ligands(self):
        """
        Test request result for all ligands.
        """

        result_remote = REMOTE.ligands.all_ligands()
        result_local = LOCAL.ligands.all_ligands()

        check_dataframe(result_remote, FIELDS.oc_name_to_type("ligands"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("ligands"))

        assert result_local["ligand.expo_id"].to_list() == [
            "1N1", "QH1", "PRC", "-"
        ]
    def test_all_kinase_families(self, group, local_families):
        """
        Test request result for all kinase families.
        """

        result_remote = REMOTE.kinases.all_kinase_families(group)
        result_local = LOCAL.kinases.all_kinase_families(group)

        check_dataframe(result_remote,
                        FIELDS.oc_name_to_type("kinase_families"))
        check_dataframe(result_local,
                        FIELDS.oc_name_to_type("kinase_families"))

        assert result_local["kinase.family"].to_list() == local_families
    def test_all_kinases(self):
        """
        Check if opencadd is up-to-date with XXX model.
        """

        self._test_klifs_model(FIELDS.remote_to_oc_names("kinases_all"),
                               KLIFS_CLIENT.Information.get_kinase_names())
    def test_by_kinase_klifs_id(self, kinase_klifs_ids):
        """
        Test all class methods with kinase IDs as input.
        """

        # Kinases
        result_remote = REMOTE.kinases.by_kinase_klifs_id(kinase_klifs_ids)
        result_local = LOCAL.kinases.by_kinase_klifs_id(kinase_klifs_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("kinases"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("kinases"))

        # Ligands
        result_remote = REMOTE.ligands.by_kinase_klifs_id(kinase_klifs_ids)
        result_local = LOCAL.ligands.by_kinase_klifs_id(kinase_klifs_ids)
        check_dataframe(
            result_remote,
            FIELDS.oc_name_to_type("ligands",
                                   {"kinase.klifs_id (query)": "int32"}),
        )
        check_dataframe(
            result_local,
            FIELDS.oc_name_to_type("ligands",
                                   {"kinase.klifs_id (query)": "int32"}),
        )

        # Structures
        result_remote = REMOTE.structures.by_kinase_klifs_id(kinase_klifs_ids)
        result_local = LOCAL.structures.by_kinase_klifs_id(kinase_klifs_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("structures"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("structures"))

        # Bioactivities
        result_remote = REMOTE.bioactivities.by_kinase_klifs_id(
            kinase_klifs_ids)
        with pytest.raises(NotImplementedError):
            LOCAL.bioactivities.by_kinase_klifs_id(kinase_klifs_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("bioactivities"))

        # Interactions
        result_remote = REMOTE.interactions.by_kinase_klifs_id(
            kinase_klifs_ids)
        result_local = LOCAL.interactions.by_kinase_klifs_id(kinase_klifs_ids)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("interactions"))
        check_dataframe(
            result_local,
            FIELDS.oc_name_to_type("interactions",
                                   {"kinase.klifs_id (query)": "int32"}),
        )
    def test_ligands(self):
        """
        Check if opencadd is up-to-date with ligandDetails model.
        """

        self._test_klifs_model(
            FIELDS.remote_to_oc_names("ligands"),
            KLIFS_CLIENT.Ligands.get_ligands_list(kinase_ID=[1]),
        )
    def test_structures(self):
        """
        Check if opencadd is up-to-date with ligandDetails model.
        """

        self._test_klifs_model(
            FIELDS.remote_to_oc_names("structures"),
            KLIFS_CLIENT.Structures.get_structure_list(structure_ID=[1]),
        )
    def test_bioactivities(self):
        """
        Check if opencadd is up-to-date with ligandDetails model.
        """

        self._test_klifs_model(
            FIELDS.remote_to_oc_names("bioactivities"),
            KLIFS_CLIENT.Ligands.get_bioactivity_list_id(ligand_ID=2),
        )
    def test_interaction_types(self):
        """
        Check if opencadd is up-to-date with InteractionList model.
        """

        self._test_klifs_model(
            FIELDS.remote_to_oc_names("interaction_types"),
            KLIFS_CLIENT.Interactions.get_interactions_get_types(),
        )
    def test_all_drugs(self):
        """
        Test request result for all drugs.
        """

        result_remote = REMOTE.drugs.all_drugs()
        check_dataframe(result_remote, FIELDS.oc_name_to_type("drugs"))

        with pytest.raises(NotImplementedError):
            LOCAL.drugs.all_drugs()
    def test_all_structures(self):
        """
        Test request result for all structures.
        """

        result_remote = REMOTE.structures.all_structures()
        result_local = LOCAL.structures.all_structures()

        check_dataframe(result_remote, FIELDS.oc_name_to_type("structures"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("structures"))

        assert result_local["structure.klifs_id"].to_list() == [
            3482,
            12347,
            5728,
            5705,
            13623,
            1243,
        ]
    def test_pockets(self):
        """
        Check if opencadd is up-to-date with MatchList model.
        """

        self._test_klifs_model(
            FIELDS.remote_to_oc_names("pockets"),
            KLIFS_CLIENT.Interactions.get_interactions_match_residues(
                structure_ID=100),
        )
    def test_interaction_types(self):
        """
        Test request result for all interaction types.
        """

        result_remote = REMOTE.interactions.interaction_types
        check_dataframe(result_remote,
                        FIELDS.oc_name_to_type("interaction_types"))

        with pytest.raises(NotImplementedError):
            LOCAL.interactions.interaction_types()
    def test_all_conformations(self):
        """
        Test request result for all conformations.
        """

        result_remote = REMOTE.conformations.all_conformations()
        check_dataframe(result_remote,
                        FIELDS.oc_name_to_type("structure_conformations"))

        with pytest.raises(NotImplementedError):
            LOCAL.conformations.all_conformations()
    def test_modifications_by_structure_klifs_id(self, structure_klifs_id):
        """
        Extra test for modifications: Use structure that has modified residues in and outside the
        pocket (e.g. structure KLIFS ID 4126).
        """

        # Modified residues
        result_remote = REMOTE.modified_residues.by_structure_klifs_id(
            structure_klifs_id)
        # No local access available
        check_dataframe(result_remote,
                        FIELDS.oc_name_to_type("structure_modified_residues"))
    def test_all_bioactivities(self):
        """
        Test request result for all kinases.
        """

        # Usually this class method is used to get ALL bioactivities from ALL ligands
        # Since this query takes a few minutes, only the frist 3 ligands are used here for testing
        result_remote = REMOTE.bioactivities.all_bioactivities(_top_n=3)
        with pytest.raises(NotImplementedError):
            LOCAL.bioactivities.all_bioactivities()

        check_dataframe(result_remote, FIELDS.oc_name_to_type("bioactivities"))
    def test_all_kinase_groups(self):
        """
        Test request result for all kinase groups.
        """

        result_remote = REMOTE.kinases.all_kinase_groups()
        result_local = LOCAL.kinases.all_kinase_groups()

        check_dataframe(result_remote, FIELDS.oc_name_to_type("kinase_groups"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("kinase_groups"))

        assert sorted(result_remote["kinase.group"].to_list()) == [
            "AGC",
            "CAMK",
            "CK1",
            "CMGC",
            "Other",
            "STE",
            "TK",
            "TKL",
        ]
        assert sorted(result_local["kinase.group"].to_list()) == ["TK", "TKL"]
    def _test_to_dataframe(dataframe, n_atoms, centroid):
        """
        Test coordinates DataFrame that was loaded locally or remotely.
        """

        assert isinstance(dataframe, pd.DataFrame)
        column_names = list(FIELDS.oc_name_to_type("coordinates").keys())
        assert dataframe.columns.to_list() == column_names
        assert dataframe.shape[0] == n_atoms
        assert centroid[0] == pytest.approx(dataframe["atom.x"].mean(),
                                            abs=1.0e-6)
        assert centroid[1] == pytest.approx(dataframe["atom.y"].mean(),
                                            abs=1.0e-6)
        assert centroid[2] == pytest.approx(dataframe["atom.z"].mean(),
                                            abs=1.0e-6)
    def test_by_kinase_name(self, kinase_names, species):
        """
        Test class methods with kinase names as input.
        """

        # Kinases
        result_remote = REMOTE.kinases.by_kinase_name(kinase_names, species)
        result_local = LOCAL.kinases.by_kinase_name(kinase_names, species)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("kinases"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("kinases"))

        # Ligands
        result_remote = REMOTE.ligands.by_kinase_name(kinase_names)
        result_local = LOCAL.ligands.by_kinase_name(kinase_names)

        check_dataframe(
            result_remote,
            FIELDS.oc_name_to_type(
                "ligands",
                {
                    "kinase.klifs_id (query)": "int32",
                    "kinase.klifs_name (query)": "string",
                    "kinase.gene_name (query)": "string",
                    "species.klifs (query)": "string",
                },
            ),
        )
        check_dataframe(
            result_local,
            FIELDS.oc_name_to_type(
                "ligands",
                {
                    "kinase.klifs_name (query)": "string",
                    "kinase.gene_name (query)": "string",
                    "species.klifs (query)": "string",
                },
            ),
        )

        # Structures
        result_remote = REMOTE.structures.by_kinase_name(kinase_names)
        result_local = LOCAL.structures.by_kinase_name(kinase_names)

        check_dataframe(result_remote, FIELDS.oc_name_to_type("structures"))
        check_dataframe(result_local, FIELDS.oc_name_to_type("structures"))