From bf54842ef011aa6a11946a93ff44cf3455992a4c Mon Sep 17 00:00:00 2001 From: dominiquesydow Date: Fri, 10 Sep 2021 10:24:07 +0200 Subject: [PATCH 01/13] Create new branch From 47db0419f49873d32f0b5c8cea254ed6958a6c23 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:28:25 +0200 Subject: [PATCH 02/13] Add BaseAligner._safety_checks() without implementation --- opencadd/structure/superposition/engines/base.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opencadd/structure/superposition/engines/base.py b/opencadd/structure/superposition/engines/base.py index c3dc70e9..b4ae9ea6 100644 --- a/opencadd/structure/superposition/engines/base.py +++ b/opencadd/structure/superposition/engines/base.py @@ -32,3 +32,6 @@ def calculate(self, structures, *args, **kwargs): def _calculate(self, structures, *args, **kwargs): raise NotImplementedError("Reimplement in your subclass") + + def _safety_checks(self): + raise NotImplementedError("Reimplement in your subclass") From ba05f400fbc7c34a25d9ded7b50f549630594b3e Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:29:04 +0200 Subject: [PATCH 03/13] Add TheseusAligner._safety_checks + call in _calculate --- .../structure/superposition/engines/theseus.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/opencadd/structure/superposition/engines/theseus.py b/opencadd/structure/superposition/engines/theseus.py index 2ffa0808..cafb205a 100644 --- a/opencadd/structure/superposition/engines/theseus.py +++ b/opencadd/structure/superposition/engines/theseus.py @@ -21,6 +21,7 @@ import os import subprocess import logging +from distutils.spawn import find_executable import numpy as np @@ -55,6 +56,20 @@ def __init__(self, alignment_max_iterations: int = 32, statistics_only: bool = F self._alignment_file_biotite = "theseus_biotite.aln" self._alignment_executable = "muscle" self._theseus_transformation_file = "theseus_transf.txt" + + def _safety_checks(self): + """ + Check if `theseus` is installed (executable found?). + + Raises + ------ + OSError + Raises error if executable `theseus` cannot be found. + """ + + theseus = find_executable("theseus") + if theseus is None: + raise OSError("theseus cannot be located. Is it installed?") def _calculate(self, structures, *args, **kwargs) -> dict: """ @@ -106,6 +121,8 @@ def _calculate(self, structures, *args, **kwargs) -> dict: ``total_rounds``: total rounds """ + self._safety_checks() + with enter_temp_directory(remove=True) as (cwd, tmpdir): _logger.debug("All files are located in: %s", tmpdir) From 9b93a844f23dca6dc85634fa54a414802a053f98 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:29:12 +0200 Subject: [PATCH 04/13] Add MMLignerAligner._safety_checks + call in _calculate --- .../structure/superposition/engines/mmligner.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/opencadd/structure/superposition/engines/mmligner.py b/opencadd/structure/superposition/engines/mmligner.py index f2525eea..b4809913 100644 --- a/opencadd/structure/superposition/engines/mmligner.py +++ b/opencadd/structure/superposition/engines/mmligner.py @@ -25,6 +25,7 @@ import sys import subprocess import logging +from distutils.spawn import find_executable import numpy as np import biotite.sequence.io.fasta as fasta @@ -56,6 +57,20 @@ def __init__(self, executable=None, protein_selector="protein"): _logger.warning( "Current MMLigner wrappers produces accurate RMSD values but slightly shifted structures!" ) + + def _safety_checks(self): + """ + Check if `mmligner` is installed (executable found?). + + Raises + ------ + OSError + Raises error if executable `mmligner` cannot be found. + """ + + theseus = find_executable("mmligner") + if theseus is None: + raise OSError("theseus cannot be located. Is it installed?") def _calculate(self, structures, *args, **kwargs): """ @@ -84,6 +99,8 @@ def _calculate(self, structures, *args, **kwargs): - ``quarternion`` (array-like): 4x4 quarternion matrix """ + self._safety_checks() + with enter_temp_directory() as (cwd, tmpdir): # Needed because of the need of a copy of the structures. sys.setrecursionlimit(100000) From 9d3e4ea0d58ec00540f4817c15a4d9d74f0f1b94 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:48:50 +0200 Subject: [PATCH 05/13] Satisfy black --- opencadd/structure/superposition/engines/base.py | 2 +- opencadd/structure/superposition/engines/mmligner.py | 4 ++-- opencadd/structure/superposition/engines/theseus.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/opencadd/structure/superposition/engines/base.py b/opencadd/structure/superposition/engines/base.py index b4ae9ea6..49083960 100644 --- a/opencadd/structure/superposition/engines/base.py +++ b/opencadd/structure/superposition/engines/base.py @@ -32,6 +32,6 @@ def calculate(self, structures, *args, **kwargs): def _calculate(self, structures, *args, **kwargs): raise NotImplementedError("Reimplement in your subclass") - + def _safety_checks(self): raise NotImplementedError("Reimplement in your subclass") diff --git a/opencadd/structure/superposition/engines/mmligner.py b/opencadd/structure/superposition/engines/mmligner.py index b4809913..52584921 100644 --- a/opencadd/structure/superposition/engines/mmligner.py +++ b/opencadd/structure/superposition/engines/mmligner.py @@ -57,7 +57,7 @@ def __init__(self, executable=None, protein_selector="protein"): _logger.warning( "Current MMLigner wrappers produces accurate RMSD values but slightly shifted structures!" ) - + def _safety_checks(self): """ Check if `mmligner` is installed (executable found?). @@ -67,7 +67,7 @@ def _safety_checks(self): OSError Raises error if executable `mmligner` cannot be found. """ - + theseus = find_executable("mmligner") if theseus is None: raise OSError("theseus cannot be located. Is it installed?") diff --git a/opencadd/structure/superposition/engines/theseus.py b/opencadd/structure/superposition/engines/theseus.py index cafb205a..a159fff1 100644 --- a/opencadd/structure/superposition/engines/theseus.py +++ b/opencadd/structure/superposition/engines/theseus.py @@ -56,7 +56,7 @@ def __init__(self, alignment_max_iterations: int = 32, statistics_only: bool = F self._alignment_file_biotite = "theseus_biotite.aln" self._alignment_executable = "muscle" self._theseus_transformation_file = "theseus_transf.txt" - + def _safety_checks(self): """ Check if `theseus` is installed (executable found?). @@ -66,7 +66,7 @@ def _safety_checks(self): OSError Raises error if executable `theseus` cannot be found. """ - + theseus = find_executable("theseus") if theseus is None: raise OSError("theseus cannot be located. Is it installed?") From cf17d61f63228ef6af684bc6b5dd59921b3c3a4a Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:52:48 +0200 Subject: [PATCH 06/13] Add Windows to CI --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fcfe9b0a..96201c0d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macOS-latest, ubuntu-latest] + os: [macOS-latest, ubuntu-latest, windows-latest] python-version: [3.7, 3.8] env: CI_OS: ${{ matrix.os }} From 4d9fc0af017252dc971fd976357c2ea90448e4f4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:57:33 +0200 Subject: [PATCH 07/13] Remove Windows from CI --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 96201c0d..fcfe9b0a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macOS-latest, ubuntu-latest, windows-latest] + os: [macOS-latest, ubuntu-latest] python-version: [3.7, 3.8] env: CI_OS: ${{ matrix.os }} From 136cbda0c37517d5d976dc8a59f7ffb5736a1563 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Sep 2021 12:59:13 +0200 Subject: [PATCH 08/13] Add comment --- opencadd/structure/superposition/engines/mmligner.py | 1 + opencadd/structure/superposition/engines/theseus.py | 1 + 2 files changed, 2 insertions(+) diff --git a/opencadd/structure/superposition/engines/mmligner.py b/opencadd/structure/superposition/engines/mmligner.py index 52584921..bafa23b2 100644 --- a/opencadd/structure/superposition/engines/mmligner.py +++ b/opencadd/structure/superposition/engines/mmligner.py @@ -71,6 +71,7 @@ def _safety_checks(self): theseus = find_executable("mmligner") if theseus is None: raise OSError("theseus cannot be located. Is it installed?") + # proceed normally def _calculate(self, structures, *args, **kwargs): """ diff --git a/opencadd/structure/superposition/engines/theseus.py b/opencadd/structure/superposition/engines/theseus.py index a159fff1..6814c5ed 100644 --- a/opencadd/structure/superposition/engines/theseus.py +++ b/opencadd/structure/superposition/engines/theseus.py @@ -70,6 +70,7 @@ def _safety_checks(self): theseus = find_executable("theseus") if theseus is None: raise OSError("theseus cannot be located. Is it installed?") + # proceed normally def _calculate(self, structures, *args, **kwargs) -> dict: """ From bcd355b83050ac8777f4181c4d0dd81090389e81 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Sep 2021 09:21:15 +0200 Subject: [PATCH 09/13] Add MDAnalysisAligner._safety_checks (passes) --- opencadd/structure/superposition/engines/mda.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/opencadd/structure/superposition/engines/mda.py b/opencadd/structure/superposition/engines/mda.py index 5e4d6106..c10721ee 100644 --- a/opencadd/structure/superposition/engines/mda.py +++ b/opencadd/structure/superposition/engines/mda.py @@ -94,6 +94,13 @@ def __init__( self.superposition_weights = superposition_weights self.superposition_delta_mass_tolerance = superposition_delta_mass_tolerance + def _safety_checks(self): + """ + Check for `mda` installation passes; added here only for consistency across the engines. + """ + + pass + def _calculate(self, structures, *args, **kwargs): """ @@ -109,6 +116,9 @@ def _calculate(self, structures, *args, **kwargs): rmsd metadata """ + + self._safety_checks() + if len(structures) > 2: raise NotImplementedError( "This method can only be used for two structures at the same time, for now" From d18ebddad1dc0ff321bcbaed4016dfa15692568f Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Sep 2021 09:21:37 +0200 Subject: [PATCH 10/13] Fix variable names in MMLignerAligner._safety_checks --- opencadd/structure/superposition/engines/mmligner.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/opencadd/structure/superposition/engines/mmligner.py b/opencadd/structure/superposition/engines/mmligner.py index bafa23b2..8eaa18d5 100644 --- a/opencadd/structure/superposition/engines/mmligner.py +++ b/opencadd/structure/superposition/engines/mmligner.py @@ -68,9 +68,9 @@ def _safety_checks(self): Raises error if executable `mmligner` cannot be found. """ - theseus = find_executable("mmligner") - if theseus is None: - raise OSError("theseus cannot be located. Is it installed?") + mmligner = find_executable("mmligner") + if mmligner is None: + raise OSError("mmligner cannot be located. Is it installed?") # proceed normally def _calculate(self, structures, *args, **kwargs): From d935ab25ceffb2791b7b1c256adc0e18e4021acf Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Sep 2021 09:35:56 +0200 Subject: [PATCH 11/13] Satisfy black --- opencadd/structure/superposition/engines/mda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opencadd/structure/superposition/engines/mda.py b/opencadd/structure/superposition/engines/mda.py index c10721ee..41e259a1 100644 --- a/opencadd/structure/superposition/engines/mda.py +++ b/opencadd/structure/superposition/engines/mda.py @@ -96,7 +96,7 @@ def __init__( def _safety_checks(self): """ - Check for `mda` installation passes; added here only for consistency across the engines. + Check for `mda` installation passes; added here only for consistency across the engines. """ pass From fe519cabce177d0caf21460853ec451c19d8f0cd Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Sep 2021 10:22:31 +0200 Subject: [PATCH 12/13] Move _safety_checks() to BaseAligner; extend assert with message --- opencadd/structure/superposition/engines/base.py | 6 +++++- opencadd/structure/superposition/engines/mda.py | 6 ------ opencadd/structure/superposition/engines/mmligner.py | 2 -- opencadd/structure/superposition/engines/theseus.py | 2 -- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/opencadd/structure/superposition/engines/base.py b/opencadd/structure/superposition/engines/base.py index 49083960..215cef72 100644 --- a/opencadd/structure/superposition/engines/base.py +++ b/opencadd/structure/superposition/engines/base.py @@ -27,7 +27,11 @@ def calculate(self, structures, *args, **kwargs): - ``metadata``: Contextual information provided by the method """ - assert len(structures) == 2 + self._safety_checks() + assert ( + len(structures) == 2, + "This method can only be used for two structures at the same time, for now" + ) return self._calculate(structures, *args, **kwargs) def _calculate(self, structures, *args, **kwargs): diff --git a/opencadd/structure/superposition/engines/mda.py b/opencadd/structure/superposition/engines/mda.py index 41e259a1..a89fa023 100644 --- a/opencadd/structure/superposition/engines/mda.py +++ b/opencadd/structure/superposition/engines/mda.py @@ -117,12 +117,6 @@ def _calculate(self, structures, *args, **kwargs): metadata """ - self._safety_checks() - - if len(structures) > 2: - raise NotImplementedError( - "This method can only be used for two structures at the same time, for now" - ) ref_universe, mob_universe = structures # Get matching atoms diff --git a/opencadd/structure/superposition/engines/mmligner.py b/opencadd/structure/superposition/engines/mmligner.py index 8eaa18d5..114b334e 100644 --- a/opencadd/structure/superposition/engines/mmligner.py +++ b/opencadd/structure/superposition/engines/mmligner.py @@ -100,8 +100,6 @@ def _calculate(self, structures, *args, **kwargs): - ``quarternion`` (array-like): 4x4 quarternion matrix """ - self._safety_checks() - with enter_temp_directory() as (cwd, tmpdir): # Needed because of the need of a copy of the structures. sys.setrecursionlimit(100000) diff --git a/opencadd/structure/superposition/engines/theseus.py b/opencadd/structure/superposition/engines/theseus.py index 6814c5ed..07c5759c 100644 --- a/opencadd/structure/superposition/engines/theseus.py +++ b/opencadd/structure/superposition/engines/theseus.py @@ -122,8 +122,6 @@ def _calculate(self, structures, *args, **kwargs) -> dict: ``total_rounds``: total rounds """ - self._safety_checks() - with enter_temp_directory(remove=True) as (cwd, tmpdir): _logger.debug("All files are located in: %s", tmpdir) From 91e786928a27e558be85399f1d33f6d10389dd62 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 13 Sep 2021 10:23:05 +0200 Subject: [PATCH 13/13] Satify black --- opencadd/structure/superposition/engines/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opencadd/structure/superposition/engines/base.py b/opencadd/structure/superposition/engines/base.py index 215cef72..1aefd196 100644 --- a/opencadd/structure/superposition/engines/base.py +++ b/opencadd/structure/superposition/engines/base.py @@ -29,8 +29,8 @@ def calculate(self, structures, *args, **kwargs): """ self._safety_checks() assert ( - len(structures) == 2, - "This method can only be used for two structures at the same time, for now" + len(structures) == 2, + "This method can only be used for two structures at the same time, for now", ) return self._calculate(structures, *args, **kwargs)