diff --git a/dynophores/cli.py b/dynophores/cli.py index a5ddbe1..7600dbf 100644 --- a/dynophores/cli.py +++ b/dynophores/cli.py @@ -238,7 +238,7 @@ def _update_paths_in_notebook(notebook_path, dyno_path, pdb_path, dcd_path=None) filedata = f.read() # Replace the target string - for (search_str, replace_str) in search_replace_tuples: + for search_str, replace_str in search_replace_tuples: filedata = filedata.replace(search_str, replace_str) # Write the file out again diff --git a/dynophores/core/chemicalfeaturecloud3d.py b/dynophores/core/chemicalfeaturecloud3d.py index db57438..995db07 100644 --- a/dynophores/core/chemicalfeaturecloud3d.py +++ b/dynophores/core/chemicalfeaturecloud3d.py @@ -20,7 +20,6 @@ class ChemicalFeatureCloud3D: """ def __init__(self, center, points, **kwargs): - self.center = center self.points = [ point diff --git a/dynophores/core/chemicalfeaturecloud3dpoint.py b/dynophores/core/chemicalfeaturecloud3dpoint.py index 4773009..4ff3a45 100644 --- a/dynophores/core/chemicalfeaturecloud3dpoint.py +++ b/dynophores/core/chemicalfeaturecloud3dpoint.py @@ -24,7 +24,6 @@ class ChemicalFeatureCloud3DPoint: """ def __init__(self, x, y, z, frame_ix, weight, **kwargs): - self.x = x self.y = y self.z = z diff --git a/dynophores/core/dynophore.py b/dynophores/core/dynophore.py index 536f7a4..c4c13d8 100644 --- a/dynophores/core/dynophore.py +++ b/dynophores/core/dynophore.py @@ -37,7 +37,6 @@ def __init__( superfeatures, **kwargs, ): - self.id = id self.ligand = ligand if isinstance(ligand, Ligand) else Ligand(**ligand) self.superfeatures = { @@ -66,7 +65,6 @@ def from_dir(cls, dynophore_path): dynophore_path = Path(dynophore_path) if dynophore_path.is_dir(): - # Set JSON path json_path = list(dynophore_path.glob("*.json")) if len(json_path) == 1: diff --git a/dynophores/core/envpartner.py b/dynophores/core/envpartner.py index 7a18956..a6d0faf 100644 --- a/dynophores/core/envpartner.py +++ b/dynophores/core/envpartner.py @@ -28,7 +28,6 @@ class EnvPartner: def __init__( self, id, residue_name, residue_number, chain, atom_numbers, occurrences, distances ): - if len(occurrences) != len(distances): raise ValueError("Occurrences and distances must be of same length.") diff --git a/dynophores/core/ligand.py b/dynophores/core/ligand.py index 9afd9e7..ab9d74f 100644 --- a/dynophores/core/ligand.py +++ b/dynophores/core/ligand.py @@ -30,7 +30,6 @@ def __init__( atom_serials, **kwargs, ): - self.name = name self.smiles = smiles self.mdl_mol_buffer = mdl_mol_buffer diff --git a/dynophores/core/superfeature.py b/dynophores/core/superfeature.py index af8766c..c2fc7a0 100644 --- a/dynophores/core/superfeature.py +++ b/dynophores/core/superfeature.py @@ -34,7 +34,6 @@ class SuperFeature: """ def __init__(self, id, feature_type, atom_numbers, occurrences, envpartners, color, cloud): - self.id = id self.feature_type = feature_type self.atom_numbers = atom_numbers @@ -185,7 +184,7 @@ def _count(self, property_envpartners_occurrences): ) envpartners_count = property_envpartners_occurrences.sum() - return superfeature_count.append(envpartners_count) + return pd.concat([superfeature_count, envpartners_count]) @property def frequency(self): @@ -279,7 +278,6 @@ def _data_collapsed(self): # For each unique residue ID, # we want to aggregate data for all environmental partners that belong to the same residue for residue_id in residue_ids: - # Get all environmental partner IDs that belong to this residue ids_to_be_collapsed = [_id for _id in ids if _id.startswith(residue_id)] diff --git a/dynophores/parsers.py b/dynophores/parsers.py index c744364..e7a876d 100644 --- a/dynophores/parsers.py +++ b/dynophores/parsers.py @@ -83,7 +83,6 @@ def _pml_to_dict(pml_path): feature_clouds = dynophore3d_xml.findall("featureCloud") for feature_cloud in feature_clouds: - # Superfeature ID superfeature_feature_name = feature_cloud.get("name") superfeature_atom_numbers = feature_cloud.get("involvedAtomSerials") diff --git a/dynophores/tests/conftest.py b/dynophores/tests/conftest.py index 1e7e823..18b8bae 100644 --- a/dynophores/tests/conftest.py +++ b/dynophores/tests/conftest.py @@ -15,40 +15,34 @@ @pytest.fixture(scope="module") def dynophore(): - dynophore = Dynophore.from_dir(PATH_TEST_DATA / "out") return dynophore @pytest.fixture(scope="module") def superfeature(dynophore): - superfeature = dynophore.superfeatures["H[4615,4623,4622,4613,4621,4614]"] return superfeature @pytest.fixture(scope="module") def chemicalfeaturecloud3d(superfeature): - cloud = superfeature.cloud return cloud @pytest.fixture(scope="module") def chemicalfeaturecloud3dpoint(superfeature): - point = next(iter(superfeature.cloud.points)) return point @pytest.fixture(scope="module") def envpartner(superfeature): - envpartner = superfeature.envpartners["ILE-10-A[169,171,172]"] return envpartner @pytest.fixture(scope="module") def ligand(dynophore): - return dynophore.ligand diff --git a/dynophores/tests/core/test_chemicalfeaturecloud3d.py b/dynophores/tests/core/test_chemicalfeaturecloud3d.py index 39ef472..9a638c0 100644 --- a/dynophores/tests/core/test_chemicalfeaturecloud3d.py +++ b/dynophores/tests/core/test_chemicalfeaturecloud3d.py @@ -22,7 +22,6 @@ class TestsChemicalFeatureCloud3D: """ def test_init(self): - dynophore_dict = parsers._json_pml_to_dict( PATH_TEST_DATA / "out/1KE7_dynophore.json", PATH_TEST_DATA / "out/1KE7_dynophore.pml", diff --git a/dynophores/tests/core/test_chemicalfeaturecloud3dpoint.py b/dynophores/tests/core/test_chemicalfeaturecloud3dpoint.py index db96edc..b20c4fa 100644 --- a/dynophores/tests/core/test_chemicalfeaturecloud3dpoint.py +++ b/dynophores/tests/core/test_chemicalfeaturecloud3dpoint.py @@ -22,7 +22,6 @@ class TestsChemicalFeatureCloud3DPoint: """ def test_init(self): - dynophore_dict = parsers._json_pml_to_dict( PATH_TEST_DATA / "out/1KE7_dynophore.json", PATH_TEST_DATA / "out/1KE7_dynophore.pml", diff --git a/dynophores/tests/core/test_dynophore.py b/dynophores/tests/core/test_dynophore.py index 3885e6c..3786bd0 100644 --- a/dynophores/tests/core/test_dynophore.py +++ b/dynophores/tests/core/test_dynophore.py @@ -25,7 +25,6 @@ class TestsDynophore: @pytest.mark.parametrize("id", ["dynophore_1KE7"]) def test_attributes(self, dynophore, id): - dynophore_dict = parsers._json_pml_to_dict( PATH_TEST_DATA / "out/1KE7_dynophore.json", PATH_TEST_DATA / "out/1KE7_dynophore.pml", @@ -48,12 +47,10 @@ def test_attributes(self, dynophore, id): @pytest.mark.parametrize("filepath", [PATH_TEST_DATA / "out"]) def test_from_dir(self, filepath): - dynophore = Dynophore.from_dir(filepath) assert isinstance(dynophore, Dynophore) def test_clouds_and_cloud_by_superfeature(self, dynophore): - # Property `cloud` assert isinstance(dynophore.clouds, dict) assert list(dynophore.clouds.keys()) == list(dynophore.superfeatures.keys()) @@ -88,7 +85,6 @@ def test_clouds_and_cloud_by_superfeature(self, dynophore): ], ) def test_superfeatures_occurrences(self, dynophore, column_names, counts_sum): - data = dynophore.superfeatures_occurrences assert data.columns.to_list() == column_names assert data.index.to_list() == list(range(0, dynophore.n_frames)) @@ -115,7 +111,6 @@ def test_superfeatures_occurrences(self, dynophore, column_names, counts_sum): def test_envpartners_occurrences_and_envpartners_occurrences_by_superfeature( self, dynophore, counts_sum_dict ): - # Test `envpartners_occurrences` assert sorted(list(dynophore.envpartners_occurrences.keys())) == sorted( list(counts_sum_dict.keys()) @@ -150,7 +145,6 @@ def test_envpartners_occurrences_and_envpartners_occurrences_by_superfeature( ], ) def test_envpartners_distances(self, dynophore, distances_sum_dict): - assert sorted(list(dynophore.envpartners_distances.keys())) == sorted( list(distances_sum_dict.keys()) ) @@ -161,12 +155,10 @@ def test_envpartners_distances(self, dynophore, distances_sum_dict): @pytest.mark.parametrize("n_superfeatures", [10]) def test_n_superfeatures(self, dynophore, n_superfeatures): - assert dynophore.n_superfeatures == n_superfeatures @pytest.mark.parametrize("n_frames", [1002]) def test_n_frames(self, dynophore, n_frames): - assert dynophore.n_frames == n_frames @pytest.mark.parametrize( @@ -218,7 +210,6 @@ def test_n_frames(self, dynophore, n_frames): def test_count_frequency( self, dynophore, count_sum, frequency_sum, superfeature_ids, envpartner_names ): - # TODO remove this when fixed in DynophoreApp json export envpartner_names = [i.replace("_", "-") for i in envpartner_names] @@ -240,7 +231,6 @@ def test_count_frequency( def test_raise_keyerror_if_invalid_superfeature_id( self, dynophore, valid_superfeature, superfeature_id ): - if valid_superfeature: assert dynophore._raise_keyerror_if_invalid_superfeature_id(superfeature_id) is None else: @@ -248,14 +238,12 @@ def test_raise_keyerror_if_invalid_superfeature_id( dynophore._raise_keyerror_if_invalid_superfeature_id(superfeature_id) def test_superfeatures_atom_serials(self, dynophore): - atom_serials = dynophore.superfeatures_atom_serials assert isinstance(atom_serials, dict) assert list(atom_serials) == list(dynophore.superfeatures) assert isinstance(next(iter(atom_serials.values()))[0], int) def test_superfeatures_colors(self, dynophore): - colors = dynophore.superfeatures_colors assert isinstance(colors, dict) assert list(colors) == list(dynophore.superfeatures) diff --git a/dynophores/tests/core/test_envpartner.py b/dynophores/tests/core/test_envpartner.py index 1cb5f3f..5ee3f2f 100644 --- a/dynophores/tests/core/test_envpartner.py +++ b/dynophores/tests/core/test_envpartner.py @@ -21,7 +21,6 @@ class TestsEnvPartner: """ def test_init(self): - dynophore_dict = parsers._json_pml_to_dict( PATH_TEST_DATA / "out/1KE7_dynophore.json", PATH_TEST_DATA / "out/1KE7_dynophore.pml", @@ -64,7 +63,6 @@ def test_init(self): ], ) def test_init_raises(self, envpartner_dict): - with pytest.raises(ValueError): EnvPartner(**envpartner_dict) diff --git a/dynophores/tests/core/test_ligand.py b/dynophores/tests/core/test_ligand.py index ef8a0b2..907412b 100644 --- a/dynophores/tests/core/test_ligand.py +++ b/dynophores/tests/core/test_ligand.py @@ -19,7 +19,6 @@ class TestsLigand: """ def test_init(self): - dynophore_dict = parsers._json_pml_to_dict( PATH_TEST_DATA / "out/1KE7_dynophore.json", PATH_TEST_DATA / "out/1KE7_dynophore.pml", diff --git a/dynophores/tests/core/test_superfeature.py b/dynophores/tests/core/test_superfeature.py index 69af1a0..518bbc4 100644 --- a/dynophores/tests/core/test_superfeature.py +++ b/dynophores/tests/core/test_superfeature.py @@ -24,7 +24,6 @@ class TestsSuperFeature: """ def test_init(self): - dynophore_dict = parsers._json_pml_to_dict( PATH_TEST_DATA / "out/1KE7_dynophore.json", PATH_TEST_DATA / "out/1KE7_dynophore.pml", diff --git a/dynophores/tests/test_cli.py b/dynophores/tests/test_cli.py index 3737141..fef577c 100644 --- a/dynophores/tests/test_cli.py +++ b/dynophores/tests/test_cli.py @@ -136,6 +136,5 @@ def test_update_paths_in_notebook_raises(notebook_path, dyno_path, pdb_path, dcd ], ) def test_open_notebook_raises(notebook): - with pytest.raises(RuntimeError): cli._open_notebook(notebook) diff --git a/dynophores/tests/viz/test_plot_static.py b/dynophores/tests/viz/test_plot_static.py index a5f22d6..5fb633d 100644 --- a/dynophores/tests/viz/test_plot_static.py +++ b/dynophores/tests/viz/test_plot_static.py @@ -23,7 +23,6 @@ ], ) def test_superfeatures_vs_envpartners(dynophore, superfeature_ids, annotate_heatmap): - fig, ax = plot.static.superfeatures_vs_envpartners( dynophore, superfeature_ids, annotate_heatmap ) @@ -34,7 +33,6 @@ def test_superfeatures_vs_envpartners(dynophore, superfeature_ids, annotate_heat @pytest.mark.parametrize("superfeature_ids", ["xxx"]) def test_superfeatures_vs_envpartners_raises(dynophore, superfeature_ids): - with pytest.raises(KeyError): plot.static.superfeatures_vs_envpartners(dynophore, superfeature_ids) @@ -58,7 +56,6 @@ def test_superfeatures_vs_envpartners_raises(dynophore, superfeature_ids): def test_superfeatures_occurrences( dynophore, superfeature_ids, color_by_feature_type, frames_range, frames_step_size ): - fig, ax = plot.static.superfeatures_occurrences( dynophore, superfeature_ids, color_by_feature_type, frames_range, frames_step_size ) @@ -69,7 +66,6 @@ def test_superfeatures_occurrences( @pytest.mark.parametrize("superfeature_ids", ["xxx"]) def test_superfeatures_occurrences_raises(dynophore, superfeature_ids): - with pytest.raises(KeyError): plot.static.superfeatures_occurrences(dynophore, superfeature_ids) @@ -105,7 +101,6 @@ def test_superfeatures_occurrences_raises(dynophore, superfeature_ids): def test_envpartners_occurrences( dynophore, superfeature_ids, frames_range, frames_step_size, occurrence_min, collapse_residues ): - fig, axes = plot.static.envpartners_occurrences( dynophore, superfeature_ids, @@ -125,7 +120,6 @@ def test_envpartners_occurrences( @pytest.mark.parametrize("superfeature_id", ["xxx", ["AR[4605,4607,4603,4606,4604]", "xxx"]]) def test_envpartners_occurrences_raises(dynophore, superfeature_id): - with pytest.raises(KeyError): plot.static.envpartners_occurrences(dynophore, superfeature_id) @@ -139,7 +133,6 @@ def test_envpartners_occurrences_raises(dynophore, superfeature_id): ], ) def test_envpartners_distances(dynophore, superfeature_ids, kind): - fig, axes = plot.static.envpartners_distances(dynophore, superfeature_ids, kind) assert isinstance(fig, matplotlib.figure.Figure) if isinstance(superfeature_ids, str): @@ -154,7 +147,6 @@ def test_envpartners_distances(dynophore, superfeature_ids, kind): "superfeature_id, kind", [("xxx", "line"), ("AR[4605,4607,4603,4606,4604]", "xxx")] ) def test_envpartner_distances_raises(dynophore, superfeature_id, kind): - with pytest.raises(KeyError): plot.static.envpartners_distances(dynophore, superfeature_id, kind) @@ -167,7 +159,6 @@ def test_envpartner_distances_raises(dynophore, superfeature_id, kind): ], ) def test_envpartners_all_in_one(dynophore, superfeature_id, frames_range, frames_step_size): - fig, axes = plot.static.envpartners_all_in_one( dynophore, superfeature_id, frames_range, frames_step_size ) @@ -179,6 +170,5 @@ def test_envpartners_all_in_one(dynophore, superfeature_id, frames_range, frames @pytest.mark.parametrize("superfeature_id", ["xxx"]) def test_envpartners_all_in_one_raises(dynophore, superfeature_id): - with pytest.raises(KeyError): plot.static.envpartners_all_in_one(dynophore, superfeature_id) diff --git a/dynophores/tests/viz/test_view2d_static.py b/dynophores/tests/viz/test_view2d_static.py index 0d221ca..a944698 100644 --- a/dynophores/tests/viz/test_view2d_static.py +++ b/dynophores/tests/viz/test_view2d_static.py @@ -29,12 +29,10 @@ def test_show(dynophore, show_superfeatures, show_pdb_serial_numbers): @pytest.mark.parametrize("show_pdb_serial_numbers", [False, True]) def test_view2d(self, ligand, show_pdb_serial_numbers): - mol = ligand.view2d(show_pdb_serial_numbers) assert isinstance(mol, Chem.rdchem.Mol) @pytest.mark.parametrize("show_pdb_serial_numbers", [False, True]) def test_view2d_superfeatures(self, ligand, show_pdb_serial_numbers): - img = ligand.view2d_superfeatures(show_pdb_serial_numbers) assert isinstance(img, Image) diff --git a/dynophores/tests/viz/test_view3d_interactive.py b/dynophores/tests/viz/test_view3d_interactive.py index a6dedad..43665e7 100644 --- a/dynophores/tests/viz/test_view3d_interactive.py +++ b/dynophores/tests/viz/test_view3d_interactive.py @@ -68,7 +68,6 @@ def test_show( def test_show_raises( dynophore, pdb_path, dcd_path, visualization_type, color_cloud_by_frame, frame_range ): - with pytest.raises(ValueError): view3d.show( dynophore, diff --git a/dynophores/viz/plot/static.py b/dynophores/viz/plot/static.py index 8bb54f0..85846f6 100644 --- a/dynophores/viz/plot/static.py +++ b/dynophores/viz/plot/static.py @@ -184,7 +184,6 @@ def envpartners_occurrences( ) for i, superfeature_id in enumerate(superfeature_ids): - if len(superfeature_ids) > 1: ax = axes[i] else: @@ -207,7 +206,6 @@ def envpartners_occurrences( ax.set_yticks([0]) ax.set_yticklabels([""]) else: - # Get frame indices with events events_dict = { envpartner_id: envpartner[envpartner == 1].index.to_list() @@ -285,7 +283,6 @@ def envpartners_distances( ) for i, superfeature_id in enumerate(superfeature_ids): - if len(superfeature_ids) > 1: ax = axes[i] else: @@ -311,14 +308,12 @@ def envpartners_distances( ax.set_yticks([0]) ax.set_yticklabels([""]) else: - # Add % to environmental partners data.columns = dynophore._envpartner_names_frequencies_strings( superfeature_id, data.columns.to_list() ) if kind == "line": - # Plot all distances as line plot data.plot(kind="line", ax=ax, linewidth=0.5) @@ -333,7 +328,6 @@ def envpartners_distances( ax.legend(labels=legend_labels, loc=6, bbox_to_anchor=(1, 0.5)) elif kind == "hist": - # TODO or use min/max in full dataset instead of per superfeature? value_floor = int(np.floor(data_interaction_frames.min().min())) value_ceil = int(np.ceil(data_interaction_frames.max().max())) @@ -508,7 +502,6 @@ def _prepare_envpartner_plotting_data( occurrence_min=0, collapse_residues=False, ): - """ Prepare envpartner data for plotting. diff --git a/dynophores/viz/view2d/static.py b/dynophores/viz/view2d/static.py index 0fbe663..3b88da3 100644 --- a/dynophores/viz/view2d/static.py +++ b/dynophores/viz/view2d/static.py @@ -134,7 +134,6 @@ def _get_superfeatures_drawing_data(mol, superfeatures_atom_serials, superfeatur mol_rings = mol.GetRingInfo().AtomRings() for superfeature_id, atom_serials in superfeatures_atom_serials.items(): - # Map PDB atom IDs to RDKit atom IDs rdkit_atom_idx = [ atom.GetIdx() @@ -151,7 +150,6 @@ def _get_superfeatures_drawing_data(mol, superfeatures_atom_serials, superfeatur rings.append((ring, color)) for atom_idx in rdkit_atom_idx: - # Highlight information for atoms highlight_atoms[atom_idx].append(color) highlight_radius[atom_idx] = 0.4 @@ -216,7 +214,7 @@ def _draw_superfeatures( ) d2d.ClearDrawing() conf = mol.GetConformer() - for (ring, color) in rings: + for ring, color in rings: positions = [] for atom_idx in ring: position = Geometry.Point2D(conf.GetAtomPosition(atom_idx))