Пример #1
0
    def _get_spatial_features_dict(self, pocket_df):
        """
        Get spatial features (distances and moments).

        Parameters
        ----------
        pocket_df : kissim.io.PocketDataFrame
            DataFrame-based pocket object.

        Returns
        -------
        dict of list of float
            Per-subpocket feature values [and coordinates] (values) for distances and moments
            [and subpocket centers] (keys).
        """

        # Set up spatial features
        features = {}
        # Add subpockets features
        feature = SubpocketsFeature.from_pocket(pocket_df)
        features["distances"] = feature._distances
        features["moments"] = feature._moments
        features["subpocket_centers"] = feature._subpocket_centers

        return features
Пример #2
0
    def test_values(self, structure_klifs_id, klifs_session):
        """
        Test class property: values.
        """
        pocket = PocketDataFrame.from_structure_klifs_id(
            structure_klifs_id, klifs_session=klifs_session
        )
        feature = SubpocketsFeature.from_pocket(pocket)

        assert isinstance(feature.values, dict)
        assert feature.values == feature._moments
Пример #3
0
    def test_from_pocket(self, structure_klifs_id, klifs_session):
        """
        Test if SubpocketsFeature can be set from a Pocket object.
        Test object attribues.
        """
        pocket = PocketDataFrame.from_structure_klifs_id(
            structure_klifs_id, klifs_session=klifs_session
        )
        feature = SubpocketsFeature.from_pocket(pocket)
        assert isinstance(feature, SubpocketsFeature)

        # Test class attributes
        # Note: _distances and _moments are tested separately below
        assert feature.name == structure_klifs_id
        for residue_id, residue_ix in zip(feature._residue_ids, feature._residue_ixs):
            if residue_id is not None:
                assert isinstance(residue_id, int)
            assert isinstance(residue_ix, int)
Пример #4
0
 def test_calculate_distance_to_center(
     self, structure_klifs_id, klifs_session, residue_id, subpocket_center, distance
 ):
     """
     Test calculation of distances between a subpocket center and a pocket residues.
     """
     pocket = PocketDataFrame.from_structure_klifs_id(
         structure_klifs_id, klifs_session=klifs_session
     )
     feature = SubpocketsFeature.from_pocket(pocket)
     ca_atoms = pocket.ca_atoms
     distance_calculated = feature._calculate_distance_to_center(
         ca_atoms, residue_id, subpocket_center
     )
     if np.isnan(distance):
         assert np.isnan(distance_calculated)
     else:
         assert pytest.approx(distance_calculated, abs=1e-6) == distance
Пример #5
0
 def test_calculate_distances_to_center(
     self, structure_klifs_id, klifs_session, subpocket_center, mean_distance
 ):
     """
     Test calculation of distances between a subpocket center and all pocket residues.
     Test also the case that there is no subpocket center.
     """
     pocket = PocketDataFrame.from_structure_klifs_id(
         structure_klifs_id, klifs_session=klifs_session
     )
     feature = SubpocketsFeature.from_pocket(pocket)
     distances_calculated = feature._calculate_distances_to_center(pocket, subpocket_center)
     if subpocket_center is None:
         assert len(distances_calculated) == len(pocket._residue_ids)
         assert all(np.isnan(distances_calculated))
     else:
         mean_distance_calculated = np.nanmean(np.array(distances_calculated))
         assert pytest.approx(mean_distance_calculated, abs=1e-6) == mean_distance
Пример #6
0
    def test_calculate_distances_and_moments(
        self,
        structure_klifs_id,
        klifs_session,
        distances_mean,
        moments_mean,
        subpocket_centers_mean,
    ):
        """
        Test calculation of distances and moments for all subpockets.

        We are testing here the class attributes _distances and _moments, whose values are the
        return values from the class methods calculate_distance and calculate_moments.
        """

        pocket = PocketDataFrame.from_structure_klifs_id(
            structure_klifs_id, klifs_session=klifs_session
        )
        feature = SubpocketsFeature.from_pocket(pocket)

        # Test distances
        for _, distances in feature._distances.items():
            assert isinstance(distances, list)
        distances_mean_calculated = {
            name: np.nanmean(distances) for name, distances in feature._distances.items()
        }
        assert pytest.approx(distances_mean_calculated, abs=1e-6) == distances_mean

        # Test moments
        for _, moments in feature._moments.items():
            assert isinstance(moments, list)
        moments_mean_calculated = {
            name: np.nanmean(moments) for name, moments in feature._moments.items()
        }
        assert pytest.approx(moments_mean_calculated, abs=1e-6) == moments_mean

        # Test subpocket centers
        for _, subpocket_center in feature._subpocket_centers.items():
            assert isinstance(subpocket_center, list)
        subpocket_centers_mean_calculated = {
            name: (np.nanmean(coordinates) if coordinates is not None else None)
            for name, coordinates in feature._subpocket_centers.items()
        }
        assert pytest.approx(subpocket_centers_mean_calculated, abs=1e-6) == subpocket_centers_mean
Пример #7
0
    def test_details(self, structure_klifs_id, klifs_session):
        """
        Test class property: details.
        """
        pocket = PocketDataFrame.from_structure_klifs_id(
            structure_klifs_id, klifs_session=klifs_session
        )
        feature = SubpocketsFeature.from_pocket(pocket)

        assert isinstance(feature.details, dict)

        # Distances
        assert isinstance(feature.details["distances"], pd.DataFrame)
        assert feature.details["distances"].index.to_list() == feature._residue_ixs
        # Test first column name and dtypes (the other columns depend on the input subpocket names)
        assert feature.details["distances"].columns.to_list()[0] == "residue.id"
        assert feature.details["distances"].dtypes[0] == "Int32"

        # Moments
        assert isinstance(feature.details["moments"], pd.DataFrame)
        assert feature.details["moments"].index.to_list() == [1, 2, 3]