diff --git a/.gitignore b/.gitignore index f7168f5c..5c9b157d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,7 @@ *.gcno .vscode *.gcda -*/Files.cmake +Files.cmake db/ *_run* *out @@ -25,7 +25,7 @@ doc/auto_examples examples/CMakeLists.txt .history doc/IMP.bff.docset - +CMakeModules/ test/CMakeLists.txt src/CMakeLists.txt pyext/CMakeLists.txt diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 42fcbcf5..00000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "tools"] - path = tools - url = https://gitlab.peulen.xyz/build/tools - branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index 70196680..d1768e60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") - # compatability with older systems + # compatibility with older systems SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mmacosx-version-min=10.13") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.13") SET(CMAKE_LFLAGS "${CMAKE_LFLAGS} -mmacosx-version-min=10.13") @@ -75,5 +75,3 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) else() INCLUDE(ModuleBuild.cmake) endif() - -INCLUDE(Setup.cmake) diff --git a/bin/imp_bff b/bin/imp_bff index 07f647d4..4fa38bcd 100755 --- a/bin/imp_bff +++ b/bin/imp_bff @@ -229,7 +229,7 @@ def rmsd( -r ~/science/Papers/00_in_preparation/Bayesian_Fluorescence_Toolkit/Test_case_candiates/01_Antibody/targets/nodes1_045.pdb \ -k structure - With provided column for RMSD reference calcualtion + With provided column for RMSD reference calculation structure rmsd \ -f /home/tpeulen/science/Papers/00_in_preparation/Bayesian_Fluorescence_Toolkit/Test_case_candiates/01_Antibody/targets/experiments/eTCSPC/ucfret/02_structure_search/local_scaling/species_sampling.sort.ol4 \ @@ -343,7 +343,7 @@ def auto_model(input_file, output_path=None, settings=None, fret_efficiency=None output_path = pathlib.Path(input_file).parent.absolute() input_file = pathlib.Path(input_file).absolute() - print("OUPTUT DIRECTORIES") + print("OUTPUT DIRECTORIES") print("===============================") OUT_PREANALYSIS = output_path / 'init' OUT_PREANALYSIS.mkdir(exist_ok=True) diff --git a/dependencies.py b/dependencies.py index 68076d1b..ad169e22 100644 --- a/dependencies.py +++ b/dependencies.py @@ -1,3 +1,3 @@ required_modules = 'container:core:em:atom' -required_dependencies = 'IMP.em' -optional_dependencies = '' +required_dependencies = 'NumPy' +optional_dependencies = 'AVX' diff --git a/Setup.cmake b/dependency/AVX.cmake similarity index 77% rename from Setup.cmake rename to dependency/AVX.cmake index 6fd19291..40482082 100644 --- a/Setup.cmake +++ b/dependency/AVX.cmake @@ -4,12 +4,12 @@ option(WITH_AVX "Enable AVX support" OFF) if (WITH_AVX AND NOT APPLE AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") - set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/dependency) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) include(simd) if (${AVX_FOUND}) message("BUILD WITH SIMD") - add_definitions(-DWITH_AVX) + file(WRITE "${CMAKE_BINARY_DIR}/build_info/AVX" "ok=True") if (MSVC) # https://devblogs.microsoft.com/cppblog/simd-extension-to-c-openmp-in-visual-studio/ @@ -19,10 +19,10 @@ if (WITH_AVX AND NOT APPLE AND CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx -mfma") endif (MSVC) else (${AVX_FOUND}) - unset(WITH_AVX) + file(WRITE "${CMAKE_BINARY_DIR}/build_info/AVX" "ok=False") endif (${AVX_FOUND}) else () # AVX only on x86_64 and not on Apple message("BUILD WITHOUT SIMD") - unset(WITH_AVX) -endif() \ No newline at end of file + file(WRITE "${CMAKE_BINARY_DIR}/build_info/AVX" "ok=False") +endif() diff --git a/dependency/AVX.description b/dependency/AVX.description new file mode 100644 index 00000000..792d6005 --- /dev/null +++ b/dependency/AVX.description @@ -0,0 +1 @@ +# diff --git a/doc/README.md b/doc/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/doc/conf.py b/doc/conf.py index a6eadcc7..3a2831dd 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # import os -import subprocess import sys import warnings import re @@ -14,7 +13,7 @@ # absolute, like shown here. sys.path.insert(0, os.path.abspath('sphinxext')) -import sphinx_gallery +import sphinx_gallery # noqa: E402 # -- General configuration --------------------------------------------------- root_doc = 'contents' @@ -76,7 +75,7 @@ copyright = ( f'2021 - {datetime.now().year}, IMP developers' ) -import IMP.bff +import IMP.bff # noqa: E402 version = IMP.bff.__version__ # List of patterns, relative to source directory, that match files and @@ -108,18 +107,18 @@ html_theme_path = sphinx_rtd_theme.get_html_theme_path() html_theme = 'sphinx_rtd_theme' else: - # Add any paths that contain custom themes here, relative to this directory. + # Add any paths that contain custom themes here, relative to this directory html_theme_path = ['themes'] html_theme = 'scikit-learn-modern' - # Theme options are theme-specific and customize the look and feel of a theme - # further. For a list of options available for each theme, see the - # documentation. + # Theme options are theme-specific and customize the look and feel + # of a theme further. For a list of options available for each theme, + # see the documentation. html_theme_options = {'google_analytics': True, 'mathjax_path': mathjax_path} # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. html_short_title = 'IMP.bff' @@ -164,9 +163,10 @@ # Finds the highlight with the latest version number latest_highlights = sorted(release_highlights_dir.glob("*.py"))[-1] latest_highlights = latest_highlights.with_suffix('').name -html_context["release_highlights"] = f"auto_examples/release_highlights/{latest_highlights}" +html_context["release_highlights"] = \ + f"auto_examples/release_highlights/{latest_highlights}" -# get version from higlight name assuming highlights have the form +# get version from highlight name assuming highlights have the form # plot_release_highlights_0_22_0 highlight_version = ".".join(latest_highlights.split("_")[-3:-1]) html_context["release_highlights_version"] = highlight_version @@ -192,7 +192,8 @@ # intersphinx configuration intersphinx_mapping = { - 'python': ('https://docs.python.org/{.major}'.format(sys.version_info), None), + 'python': ('https://docs.python.org/{.major}'.format(sys.version_info), + None), 'numpy': ('https://numpy.org/doc/stable', None), 'scipy': ('https://docs.scipy.org/doc/scipy/reference', None), 'matplotlib': ('https://matplotlib.org/', None), @@ -324,5 +325,3 @@ def setup(app): warnings.filterwarnings("ignore", category=UserWarning, message='Matplotlib is currently using agg, which is a' ' non-GUI backend, so cannot show the figure.') - - diff --git a/doc/install.ipynb b/doc/install.ipynb index 154a0eba..a5e3abf3 100644 --- a/doc/install.ipynb +++ b/doc/install.ipynb @@ -6,7 +6,7 @@ "metadata": {}, "source": [ "# Installation\n", - "`IMP.bff` is installed from prebuilt binaries using the [Conda](https://docs.conda.io) package manager. Conda is included as part of the Anaconda Python distribution, which you can download from https://docs.continuum.io/anaconda/install. Anaconda is a Python distribution specifically designed for scientific applications, with many of the most popular mathematical and scientific packages preinstalled. Alternatively, `IMP.bff` can be installed in a Miniconda distribuition (available from https://docs.conda.io/en/latest/miniconda.html). Miniconda includes only Python itself, plus the Conda package manager. Miniconda offers a much smaller initial download, with the ability to then install only the packages you want." + "`IMP.bff` is installed from prebuilt binaries using the [Conda](https://docs.conda.io) package manager. Conda is included as part of the Anaconda Python distribution, which you can download from https://docs.continuum.io/anaconda/install. Anaconda is a Python distribution specifically designed for scientific applications, with many of the most popular mathematical and scientific packages preinstalled. Alternatively, `IMP.bff` can be installed in a Miniconda distribution (available from https://docs.conda.io/en/latest/miniconda.html). Miniconda includes only Python itself, plus the Conda package manager. Miniconda offers a much smaller initial download, with the ability to then install only the packages you want." ] }, { diff --git a/doc/manual/decays/decay_forward_model.ipynb b/doc/manual/decays/decay_forward_model.ipynb index 359a9664..f2eedcfc 100644 --- a/doc/manual/decays/decay_forward_model.ipynb +++ b/doc/manual/decays/decay_forward_model.ipynb @@ -210,7 +210,7 @@ ")\n", "lifetime_settings = {\n", " 'lifetime_spectrum': lifetime_spectrum.flatten(),\n", - " 'abs_lifetime_spectrum': False, # True -> take abs of liftime spectrum\n", + " 'abs_lifetime_spectrum': False, # True -> take abs of lifetime spectrum\n", " 'use_amplitude_threshold': False, # True -> discriminate lifetimes below threshold\n", " 'amplitude_threshold': 0.0\n", "}\n", diff --git a/doc/manual/decays/decay_objective_function.ipynb b/doc/manual/decays/decay_objective_function.ipynb index 3b479858..520ec05a 100644 --- a/doc/manual/decays/decay_objective_function.ipynb +++ b/doc/manual/decays/decay_objective_function.ipynb @@ -154,7 +154,7 @@ " },\n", " \"lifetime_settings\": {\n", " 'lifetime_spectrum': [0.8, 4.0, 0.2, 2.0],\n", - " 'abs_lifetime_spectrum': False, # True -> take abs of liftime spectrum\n", + " 'abs_lifetime_spectrum': False, # True -> take abs of lifetime spectrum\n", " 'use_amplitude_threshold': False, # True -> discriminate lifetimes below threshold\n", " 'amplitude_threshold': 0.0\n", " },\n", diff --git a/doc/manual/imaging/flim_intro.rst b/doc/manual/imaging/flim_intro.rst index 7eb54037..30457946 100755 --- a/doc/manual/imaging/flim_intro.rst +++ b/doc/manual/imaging/flim_intro.rst @@ -204,7 +204,7 @@ time resolution by a factor of 2. Pixel averaged decays --------------------- Using selection masks the signal to noise of the fluorescence decays can be greatly -improved to allow for a detailed analyis. Here it is briefly outlined, how pixels +improved to allow for a detailed analysis. Here it is briefly outlined, how pixels are selected and fluorescence decays of these pixel sub-populations can be created. #.. plot:: ../examples/imaging/imaging_pixel_masks.py @@ -400,7 +400,6 @@ object with a ``TTTR`` object that contains the photon stream a set of ``CLSMFra .. code-block:: python - from __future__ import print_function import tttrlib import numpy as np import pylab as p diff --git a/doc/manual/input_output/tttr_operations.rst b/doc/manual/input_output/tttr_operations.rst index ec34e932..95cb081e 100755 --- a/doc/manual/input_output/tttr_operations.rst +++ b/doc/manual/input_output/tttr_operations.rst @@ -51,7 +51,7 @@ data that are offset by the last macro time record in the first set in addition the value specified by ``macro_time_offset``. The parameter ``macro_time_offset`` is set to zero by default. -By appending TTTR objects to each other data that is splitted into multiple files +By appending TTTR objects to each other data that is split into multiple files can be joined into a single TTTR object as follows @@ -77,7 +77,7 @@ can be joined into a single TTTR object as follows Selections ========== A defining feature of TTTR data is that subsets can be selected and defined for -more detailed analysis. This is for instance exploited in single-molecule experimetns +more detailed analysis. This is for instance exploited in single-molecule experiments There are different methods to access subsets of a TTTR object that are described in this section. @@ -130,7 +130,7 @@ fluorescence were (0, 8) and (1, 9) for the red detection window. The method 'get_selection_by_channel' provides an array that contains the indices of the events when a the channel equals the channel number of the provided arguments. To obtain the indices where the channel number. In the example below -the indices of the green (channel = 0 or channel = 8) and the indeces of the red +the indices of the green (channel = 0 or channel = 8) and the indices of the red (channel = 1 or channel = 9) are saved in the variables ``green_indices`` and ``red_indices``, respectively. @@ -185,4 +185,4 @@ experiments or to generate filters for advanced FCS analysis :cite:`laurence2004 TTTR ranges =========== -STOP \ No newline at end of file +STOP diff --git a/doc/manual/input_output/tttr_write.rst b/doc/manual/input_output/tttr_write.rst index ef9395d1..d8471bce 100755 --- a/doc/manual/input_output/tttr_write.rst +++ b/doc/manual/input_output/tttr_write.rst @@ -3,7 +3,7 @@ Writing TTTR-files ================== -TTTR objects can be writen to files using the method ``write`` of TTTR objects. +TTTR objects can be written to files using the method ``write`` of TTTR objects. .. code-block:: python @@ -74,9 +74,9 @@ writing to a file. data_ptu = tttrlib.TTTR(ptu_file) -When a TTTR file is writen to another format certain meta data need to be provided. +When a TTTR file is written to another format certain meta data need to be provided. The combination of tttr_container_type and tttr_record_type determines of the header -determines the ouput format of the TTTR writer method. +determines the output format of the TTTR writer method. For PTU files at least the instrument and the measurement mode (T2, T3) need to be provided. diff --git a/doc/manual/intensity/intensity_pda.ipynb b/doc/manual/intensity/intensity_pda.ipynb index 121f4442..09975215 100644 --- a/doc/manual/intensity/intensity_pda.ipynb +++ b/doc/manual/intensity/intensity_pda.ipynb @@ -188,7 +188,7 @@ " c_{12} \\frac{1}{\\sqrt{2\\pi \\sigma_{12}^2}} \\exp{\\left(-\\frac{(E-E_{12})^2}{2\\sigma_{12}^2}\\right)}\n", "$$\n", "\n", - "here, :math:`E_1` and :math:`E_2` corresond to the FRET efficiencies of the states :math:`S_1` and :math:`S_2`,\n", + "here, :math:`E_1` and :math:`E_2` correspond to the FRET efficiencies of the states :math:`S_1` and :math:`S_2`,\n", "respectively. The pre-factors are given by:\n", "\n", "$$\n", diff --git a/doc/manual/programming/programming_imp_decorator.ipynb b/doc/manual/programming/programming_imp_decorator.ipynb index 0ad8412c..6eb97804 100644 --- a/doc/manual/programming/programming_imp_decorator.ipynb +++ b/doc/manual/programming/programming_imp_decorator.ipynb @@ -15,7 +15,7 @@ "source": [ "# IMP Decorator\n", "\n", - "IMP particles can be decorated to add functionality. Here it is outlined how a the paramters of a fluorescence decay can be decorated to a particle. " + "IMP particles can be decorated to add functionality. Here it is outlined how a the parameters of a fluorescence decay can be decorated to a particle. " ] }, { @@ -132,7 +132,7 @@ "p = IMP.Particle(m)\n", "lifetime_settings = {\n", " 'lifetime_spectrum': [0.8, 4.0, 0.2, 2.0],\n", - " 'abs_lifetime_spectrum': False, # True -> take abs of liftime spectrum\n", + " 'abs_lifetime_spectrum': False, # True -> take abs of lifetime spectrum\n", " 'use_amplitude_threshold': False, # True -> discriminate lifetimes below threshold\n", " 'amplitude_threshold': 0.0\n", "}\n", diff --git a/doc/manual/single-molecule/decay.rst b/doc/manual/single-molecule/decay.rst index ed251f2f..3dd61e02 100755 --- a/doc/manual/single-molecule/decay.rst +++ b/doc/manual/single-molecule/decay.rst @@ -54,7 +54,7 @@ are accessible via a simplified object-based interface that reduces the number o lines of code that need to be written for analyzing fluorescence decay histograms. The code blocks that are used below to illustrate the tttrlib functionality are extracts from the tests located in the test folder of the tttrlib repository. The -test can be used as a more detailed refernce on how to use tttrlib. +test can be used as a more detailed reference on how to use tttrlib. Model functions can be computed using for instance the ``DecayFit23.modelf`` function of the ``tttrlib`` module. Here, the ``23`` represents a particular model @@ -117,7 +117,7 @@ interface handles the creation of auxiliary data structures such as ``tttrlib.MP In the example shown above, first a fit object of the type ``fit2x.DecayFit23`` is created. All necessary data except for the experimental data for a fit is passed to the fit object when it is created. To perform a fit on experimental data for -a set for a set of initial values, the fit object is called using the inital values +a set for a set of initial values, the fit object is called using the initial values and the data as parameters. diff --git a/doc/manual/single-molecule/single_molecule_experiment_simulation.ipynb b/doc/manual/single-molecule/single_molecule_experiment_simulation.ipynb index ed44d225..2c356b1b 100644 --- a/doc/manual/single-molecule/single_molecule_experiment_simulation.ipynb +++ b/doc/manual/single-molecule/single_molecule_experiment_simulation.ipynb @@ -61,7 +61,7 @@ "\n", "---\n", "\n", - "`QuEst` simulates the diffusion and interaction of dyes tethered to a protein to simulate dynmaic quenching by PET, [[ET]](https://pubs.acs.org/doi/full/10.1021/acs.jpcb.7b03441)). `QuEst` is available at https://github.com/fluorescence-tools/QuEst. The output of a `QuEst` simulation is a fluorescence decay curve of a dye along with the corresponding fluorescence quantum yield that can serve as an input for donor fluorescence properties in FRET experiment simulations. \n", + "`QuEst` simulates the diffusion and interaction of dyes tethered to a protein to simulate dynamic quenching by PET, [[ET]](https://pubs.acs.org/doi/full/10.1021/acs.jpcb.7b03441)). `QuEst` is available at https://github.com/fluorescence-tools/QuEst. The output of a `QuEst` simulation is a fluorescence decay curve of a dye along with the corresponding fluorescence quantum yield that can serve as an input for donor fluorescence properties in FRET experiment simulations. \n", "\n", "![Quest_gui](https://github.com/Fluorescence-Tools/quest/raw/master/doc/img/readme_screenshot_0.png?raw=true)\n", "\n", @@ -115,7 +115,7 @@ "\n", "---\n", "\n", - "The simulation software for confocal single molecule (FRET) experiment (`Burbulator`) was developed for Windows and that can be used on other platforms such as Linux and macOS using [Wine](https://www.winehq.org/). To obtain Burbulator download the data accompanying [[CO]](https://www.sciencedirect.com/science/article/pii/S0959440X1630197X) either with curl or using a webbrowser with the following [link](https://www.modelarchive.org/doi/10.5452/ma-a2hbq). Unfortunatelly, the `modelarchive` website will provide you with a file named wrongly as a `.cif`. Thus, you need to rename the file to correct file type `.tar.gz`. " + "The simulation software for confocal single molecule (FRET) experiment (`Burbulator`) was developed for Windows and that can be used on other platforms such as Linux and macOS using [Wine](https://www.winehq.org/). To obtain Burbulator download the data accompanying [[CO]](https://www.sciencedirect.com/science/article/pii/S0959440X1630197X) either with curl or using a webbrowser with the following [link](https://www.modelarchive.org/doi/10.5452/ma-a2hbq). Unfortunately, the `modelarchive` website will provide you with a file named wrongly as a `.cif`. Thus, you need to rename the file to correct file type `.tar.gz`. " ] }, { diff --git a/doc/related_projects.rst b/doc/related_projects.rst index 7df98120..224704b3 100644 --- a/doc/related_projects.rst +++ b/doc/related_projects.rst @@ -27,7 +27,7 @@ enhance the functionality of tttrlib estimators. **Fluorescence lifetime imaging** - `clsmview `_ A python program with - graphical user interface to vizualize and process confocal laser scanning data + graphical user interface to visualize and process confocal laser scanning data with tttrlib. **Model definition/optimization/sampling** diff --git a/examples/labels/plot_AVDecorator.py b/examples/labels/plot_AVDecorator.py index 3e0f23bc..9b188c15 100644 --- a/examples/labels/plot_AVDecorator.py +++ b/examples/labels/plot_AVDecorator.py @@ -70,7 +70,7 @@ # Access AV features # ------------------ # AV decorated particles use PathMaps to sample the accessible volume. -# Thus, features of the AV are accesses trough PathMap. The features can +# Thus, features of the AV are accessed through PathMap. The features can # be written to density maps (see: PathMapTile). PathMaps derive from # IMP EM density maps and sampled obstacles can be written to density files # using standard IMP methods. @@ -82,7 +82,7 @@ # %% # Features of a IMP.bff.PathMap are identified by the following constants pm_features = [ - IMP.bff.PM_TILE_PENALTY, # Penality of visiting a tile + IMP.bff.PM_TILE_PENALTY, # Penalty of visiting a tile IMP.bff.PM_TILE_COST, # Cost of a path to the tile IMP.bff.PM_TILE_DENSITY, # Density of tile IMP.bff.PM_TILE_COST_DENSITY, # Cost * Density of tile @@ -176,4 +176,6 @@ rda = np.linspace(rda_start, rda_stop, n_bins) p_rda = IMP.bff.av_distance_distribution(av1, av2, rda, n_samples=n_samples) plt.plot(rda, p_rda) -plt.show() +print("See plot.png for the distance distribution between two AVs") +plt.savefig('plot.png') +#plt.show() diff --git a/examples/labels/plot_AVNetworkRestraint.py b/examples/labels/plot_AVNetworkRestraint.py index ea6f7bb1..16f1f4f6 100644 --- a/examples/labels/plot_AVNetworkRestraint.py +++ b/examples/labels/plot_AVNetworkRestraint.py @@ -19,7 +19,6 @@ import numpy as np import pylab as plt -import RMF import IMP import IMP.rmf import IMP.atom @@ -76,4 +75,6 @@ plt.plot(x, x, "-") plt.xlabel("Model distance [Ang.]") plt.ylabel("Experimental distance [Ang.]") -plt.show() +print("See plot.png for experiment against model distance") +plt.savefig('plot.png') +#plt.show() diff --git a/examples/labels/plot_AVScreening.py b/examples/labels/plot_AVScreening.py index cbdc791b..de797f91 100644 --- a/examples/labels/plot_AVScreening.py +++ b/examples/labels/plot_AVScreening.py @@ -5,7 +5,6 @@ scoring structures in a trajectory. """ import json -import tqdm import pylab as plt import RMF @@ -14,6 +13,11 @@ import IMP.atom import IMP.bff +try: + from tqdm import tqdm +except ImportError: + def tqdm(x): return x + # %% # Load an RMF file and create a hierarchy print("Creating IMP Model") @@ -43,7 +47,7 @@ # Score each frame in the RMF file and plot score print("Scoring frames") scores = list() -for frame in tqdm.tqdm(f.get_root_frames()): +for frame in tqdm(f.get_root_frames()): IMP.rmf.load_frame(f, frame) v = fret_restraint.unprotected_evaluate(None) scores.append(v) @@ -53,5 +57,6 @@ plt.plot(scores, "o-") plt.xlabel("Frame") plt.ylabel("Score") -plt.show() - +print("See plot.png for score for each frame") +plt.savefig('plot.png') +#plt.show() diff --git a/examples/labels/plot_path_maps.py b/examples/labels/plot_path_maps.py index cf80e378..2acb09ba 100644 --- a/examples/labels/plot_path_maps.py +++ b/examples/labels/plot_path_maps.py @@ -92,7 +92,7 @@ path_map.find_path_dijkstra(start_idx, -1) # if the end_idx # %% # Now, we can backtrace the shortest path from every tile (voxel) to the -# start index. A path is a squence of tile/voxel ids. +# start index. A path is a sequence of tile/voxel ids. t = path_map.get_tiles() end_idx_1 = 829 path_1 = t[end_idx_1].backtrack_to_path() @@ -108,7 +108,8 @@ paths = [t[e].backtrack_to_path() for e in range(path_map.get_number_of_voxels())] path_length = [len(p) for p in paths] plt.hist(path_length, 27) -plt.show() +plt.savefig('plot1.png') +#plt.show() no_paths = [i for i, p in enumerate(paths) if len(p) <= 1] @@ -129,7 +130,8 @@ #%% # These features are returned as 3D arrays. plt.imshow(PM_TILE_COST_DENSITY[16]) -plt.show() +plt.savefig('plot2.png') +#plt.show() #%% # These features are returned as three dimensional arrays. @@ -137,4 +139,5 @@ axs[0].imshow(BFF_TILE_PENALTY[16]) axs[1].imshow(PM_TILE_COST[16]) axs[2].imshow(PM_TILE_COST_DENSITY[16]) -plt.show() +plt.savefig('plot3.png') +#plt.show() diff --git a/examples/labels/plot_search.py b/examples/labels/plot_search.py index bdc61de7..8869b9ea 100644 --- a/examples/labels/plot_search.py +++ b/examples/labels/plot_search.py @@ -122,4 +122,5 @@ def get_distances(path): axs[1].set_title('A-star') axs[0].legend() axs[1].legend() -plt.show() +plt.savefig('plot.png') +#plt.show() diff --git a/examples/release_highlights/plot_release_highlights_0_12_0.py b/examples/release_highlights/plot_release_highlights_0_12_0.py index a9a00440..d1bb0175 100644 --- a/examples/release_highlights/plot_release_highlights_0_12_0.py +++ b/examples/release_highlights/plot_release_highlights_0_12_0.py @@ -15,7 +15,6 @@ conda install -c tpeulen imp.bff """ -import numpy as np import pylab as plt import pathlib @@ -84,7 +83,8 @@ PM_TILE_COST_DENSITY = path_map.get_tile_values(IMP.bff.PM_TILE_COST_DENSITY, bounds) plt.imshow(PM_TILE_COST_DENSITY[16]) -plt.show() +plt.savefig('plot1.png') +#plt.show() #%% # These features are returned as three dimensional arrays. @@ -92,5 +92,6 @@ axs[0].imshow(BFF_TILE_PENALTY[16]) axs[1].imshow(PM_TILE_COST[16]) axs[2].imshow(PM_TILE_COST_DENSITY[16]) -plt.show() +plt.savefig('plot2.png') +#plt.show() diff --git a/examples/spectroscopy/plot_convolution_routines.py b/examples/spectroscopy/plot_convolution_routines.py index a0c9e3fe..4115c1dc 100644 --- a/examples/spectroscopy/plot_convolution_routines.py +++ b/examples/spectroscopy/plot_convolution_routines.py @@ -18,9 +18,14 @@ manufacture since 2012 are supported. """ -from __future__ import annotations import IMP.bff -import scipy.stats +import sys +try: + import scipy.stats +except ImportError: + print("To run this example, please first install the 'scipy'") + print("Python module.") + sys.exit(0) import time import numpy as np import pylab as p @@ -50,11 +55,15 @@ ex = time.perf_counter() - t_start times.append(ex) -t_start = time.perf_counter() -for _ in range(n_runs): - IMP.bff.decay_fconv_avx(fit=model, irf=irf, x=lifetime_spectrum, start=start, stop=stop, dt=dt) -ex = time.perf_counter() - t_start -times_avx.append(ex) +# If IMP.bff was built with AVX support, repeat the tests using AVX-accelerated +# code +if IMP.bff.IMP_BFF_HAS_AVX: + t_start = time.perf_counter() + for _ in range(n_runs): + IMP.bff.decay_fconv_avx(fit=model, irf=irf, x=lifetime_spectrum, + start=start, stop=stop, dt=dt) + ex = time.perf_counter() - t_start + times_avx.append(ex) t_start = time.perf_counter() # in seconds for _ in range(n_runs): @@ -62,14 +71,18 @@ ex = time.perf_counter() - t_start times.append(ex) -t_start = time.perf_counter() -for _ in range(n_runs): - IMP.bff.decay_fconv_per_avx(fit=model, irf=irf, x=lifetime_spectrum, period=period, start=start, stop=stop, dt=dt) -ex = time.perf_counter() - t_start -times_avx.append(ex) +if IMP.bff.IMP_BFF_HAS_AVX: + t_start = time.perf_counter() + for _ in range(n_runs): + IMP.bff.decay_fconv_per_avx(fit=model, irf=irf, x=lifetime_spectrum, + period=period, start=start, stop=stop, + dt=dt) + ex = time.perf_counter() - t_start + times_avx.append(ex) times = np.array(times) * 1000.0 / n_runs -times_avx = np.array(times_avx) * 1000.0 / n_runs +if IMP.bff.IMP_BFF_HAS_AVX: + times_avx = np.array(times_avx) * 1000.0 / n_runs # make plots @@ -84,17 +97,21 @@ IMP.bff.decay_fconv(fit=model, irf=irf, x=lifetime_spectrum, start=start, stop=stop, dt=dt) ax[0].semilogy(model, label="fconv") -model_avx = np.zeros_like(irf) -IMP.bff.decay_fconv_avx(fit=model_avx, irf=irf, x=lifetime_spectrum, start=start, stop=stop, dt=dt) -ax[0].semilogy(model, label="fconv_avx") +if IMP.bff.IMP_BFF_HAS_AVX: + model_avx = np.zeros_like(irf) + IMP.bff.decay_fconv_avx(fit=model_avx, irf=irf, x=lifetime_spectrum, + start=start, stop=stop, dt=dt) + ax[0].semilogy(model, label="fconv_avx") model = np.zeros_like(irf) IMP.bff.decay_fconv_per(fit=model, irf=irf, x=lifetime_spectrum, period=period, start=start, stop=stop, dt=dt) ax[0].semilogy(model, label="fconv_per") -model = np.zeros_like(irf) -IMP.bff.decay_fconv_per_avx(fit=model, irf=irf, x=lifetime_spectrum, period=period, start=start, stop=stop, dt=dt) -ax[0].semilogy(model, label="fconv_per_avx") +if IMP.bff.IMP_BFF_HAS_AVX: + model = np.zeros_like(irf) + IMP.bff.decay_fconv_per_avx(fit=model, irf=irf, x=lifetime_spectrum, + period=period, start=start, stop=stop, dt=dt) + ax[0].semilogy(model, label="fconv_per_avx") ax[0].legend() # Benchmark @@ -107,8 +124,10 @@ ax[1].set_xticklabels(names) width = 0.35 -ax[1].bar(ind, times_avx, width, color='y', label='AVX') -ax[1].bar(ind + width, times, width, color='r', label='default') +ax[1].bar(ind, times, width, color='r', label='default') +if IMP.bff.IMP_BFF_HAS_AVX: + ax[1].bar(ind + width, times_avx, width, color='y', label='AVX') ax[1].legend() -p.show() +p.savefig('plot.png') +#p.show() diff --git a/examples/spectroscopy/plot_k2_uncertainty.py b/examples/spectroscopy/plot_k2_uncertainty.py index 437544eb..ab266fbf 100644 --- a/examples/spectroscopy/plot_k2_uncertainty.py +++ b/examples/spectroscopy/plot_k2_uncertainty.py @@ -5,13 +5,19 @@ experimental steady state donor and acceptor anisotropies. """ +import sys import numpy as np -import numba as nb -import scipy.stats import pylab as plt -from matplotlib.ticker import (MultipleLocator, AutoMinorLocator) -import IMP.bff.spectroscopy.kappa2 +from matplotlib.ticker import MultipleLocator + +try: + import numba as nb +except ImportError: + print("To run this example, please first install the 'numba'") + print("Python module.") + sys.exit(0) + from IMP.bff.spectroscopy.kappa2 import s2delta, kappasq_all_delta @@ -161,7 +167,7 @@ def k2_call( k2_ax = k2_axis[1:] _, k2_sd = mean_sd(k2_ax, k2_pdf_wic) - # Use norm distirbution with width ovls + # Use norm distribution with width ovls # instead of delta function (numeric stability) ovls = (r_max - r_min) / (2 * n_axis) diff --git a/examples/spectroscopy/plot_pile_up.py b/examples/spectroscopy/plot_pile_up.py index 33376afa..0b0cbc47 100644 --- a/examples/spectroscopy/plot_pile_up.py +++ b/examples/spectroscopy/plot_pile_up.py @@ -8,7 +8,13 @@ """ import pylab as plt import numpy as np -import scipy.stats +import sys +try: + import scipy.stats +except ImportError: + print("To run this example, please first install the 'scipy'") + print("Python module.") + sys.exit(0) import IMP.bff n_channels = 128 diff --git a/examples/structure/.gitignore b/examples/structure/.gitignore new file mode 100644 index 00000000..b9d3909e --- /dev/null +++ b/examples/structure/.gitignore @@ -0,0 +1,4 @@ +mGBP2_mCh*.mrc +mGBP2_mCh*.txt +mGBP2_eGFP*.mrc +mGBP2_eGFP*.txt diff --git a/examples/structure/mGBP2_dimer_fp.py b/examples/structure/mGBP2_dimer_fp.py index d81d5c19..f96da68f 100644 --- a/examples/structure/mGBP2_dimer_fp.py +++ b/examples/structure/mGBP2_dimer_fp.py @@ -1,3 +1,4 @@ +## \example bff/structure/mGBP2_dimer_fp.py """ Guanylate binding proteins: Combining restraints ======================================== @@ -14,9 +15,7 @@ import IMP.core import IMP.atom -import RMF import IMP.rmf -import ihm.cross_linkers import IMP.pmi import IMP.pmi.io.crosslink @@ -32,11 +31,27 @@ import IMP.pmi.restraints.saxs import IMP.pmi.restraints.basic import IMP.pmi.restraints.stereochemistry +import sys +try: + import scipy +except ImportError: + print("To run this example, please first install the 'scipy'") + print("Python module.") + sys.exit(0) import IMP.bff import IMP.bff.tools import IMP.bff.restraints +IMP.setup_from_argv(sys.argv, + "Guanylate binding proteins: Combining restraints") +if IMP.get_check_level() >= IMP.USAGE_AND_INTERNAL: + print("This example is too slow to test in debug mode - run without") + print("internal tests enabled") + sys.exit(0) +if sys.maxsize <= 2**32: + print("This example uses too much memory to run well on a 32-bit system") + sys.exit(0) output_objects = list() root_dir = pathlib.Path(IMP.bff.get_example_path('structure')) / "GBP/" @@ -207,6 +222,9 @@ # Monte carlo sampling. For better results increase the number of frames num_frames = 100000 +if IMP.get_is_quick_test(): + num_frames = 10 + rex = IMP.pmi.macros.ReplicaExchange( mdl, simulated_annealing=False, diff --git a/examples/structure/t4l_pmi.py b/examples/structure/t4l_pmi.py index a7588560..08fea931 100644 --- a/examples/structure/t4l_pmi.py +++ b/examples/structure/t4l_pmi.py @@ -14,9 +14,14 @@ import IMP import IMP.core -import RMF import IMP.atom import IMP.bff +try: + import scipy +except ImportError: + print("To run this example, please first install the 'scipy'") + print("Python module.") + sys.exit(0) import IMP.bff.tools import IMP.bff.restraints diff --git a/include/AV.h b/include/AV.h index 92b580de..1dd3cdee 100644 --- a/include/AV.h +++ b/include/AV.h @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include @@ -49,7 +51,7 @@ typedef enum{ /// Container for experimental distance measurement -class IMPBFFEXPORT AVPairDistanceMeasurement{ +class IMPBFFEXPORT AVPairDistanceMeasurement : public Value { public: @@ -71,8 +73,10 @@ class IMPBFFEXPORT AVPairDistanceMeasurement{ */ double score_model(double model); + IMP_SHOWABLE_INLINE(AVPairDistanceMeasurement, + { out << "AVPairDistanceMeasurement"; }); }; - +IMP_VALUES(AVPairDistanceMeasurement, AVPairDistanceMeasurements); //! A decorator for a particle with accessible volume (AV). @@ -91,7 +95,7 @@ class IMPBFFEXPORT AV : public IMP::core::Gaussian { private: - IMP::bff::PathMap* av_map_ = nullptr; + Pointer av_map_; protected: @@ -435,4 +439,4 @@ IMPBFFEXPORT IMP::ParticleIndex search_labeling_site( IMPBFF_END_NAMESPACE -#endif /* IMPBFF_AV_H */ \ No newline at end of file +#endif /* IMPBFF_AV_H */ diff --git a/include/DecayConvolution.h b/include/DecayConvolution.h index 2c3c55a2..06b001f0 100644 --- a/include/DecayConvolution.h +++ b/include/DecayConvolution.h @@ -27,7 +27,7 @@ IMPBFF_BEGIN_NAMESPACE - +//! Compute convolved decay class DecayConvolution : public DecayModifier{ public: @@ -113,7 +113,7 @@ class DecayConvolution : public DecayModifier{ private: /// Input lifetime spectrum - DecayLifetimeHandler *lifetime_handler; + Pointer lifetime_handler; /// Background and shift corrected irf DecayCurve *corrected_irf = nullptr; @@ -349,6 +349,7 @@ class DecayConvolution : public DecayModifier{ }; +IMP_VALUES(DecayConvolution, DecayConvolutions); IMPBFF_END_NAMESPACE diff --git a/include/DecayLifetimeHandler.h b/include/DecayLifetimeHandler.h index 10b85ec7..ab8bf147 100644 --- a/include/DecayLifetimeHandler.h +++ b/include/DecayLifetimeHandler.h @@ -18,10 +18,18 @@ #include #include #include +#include +#include IMPBFF_BEGIN_NAMESPACE -class IMPBFFEXPORT DecayLifetimeHandler { +//! Store and handle lifetime spectra +/** This is responsible for storing and handling lifetime spectra. + A lifetime spectrum consists of a set of lifetimes and their corresponding + amplitudes. The class provides methods to set and retrieve the lifetime + spectrum, as well as to manipulate it. + */ +class IMPBFFEXPORT DecayLifetimeHandler : public Object { private: std::vector _lifetime_spectrum = std::vector(); //!< Lifetime spectrum / original std::vector lt_ = std::vector(); //!< Lifetime spectrum / for getter @@ -105,8 +113,10 @@ class IMPBFFEXPORT DecayLifetimeHandler { bool abs_lifetime_spectrum = false, double amplitude_threshold = std::numeric_limits::epsilon() ); + + IMP_OBJECT_METHODS(DecayLifetimeHandler); }; IMPBFF_END_NAMESPACE -#endif // IMPBFF_DECAYLIFETIMEHANDLER_H \ No newline at end of file +#endif // IMPBFF_DECAYLIFETIMEHANDLER_H diff --git a/include/DecayLinearization.h b/include/DecayLinearization.h index 7fca79ea..9484826d 100644 --- a/include/DecayLinearization.h +++ b/include/DecayLinearization.h @@ -72,6 +72,8 @@ class IMPBFFEXPORT DecayLinearization : public DecayModifier { int n_window = 5); }; +IMP_VALUES(DecayLinearization, DecayLinearizations); + IMPBFF_END_NAMESPACE -#endif // IMPBFF_DECAYLINEARIZATION_H \ No newline at end of file +#endif // IMPBFF_DECAYLINEARIZATION_H diff --git a/include/DecayModifier.h b/include/DecayModifier.h index 4fa3fb6f..ad0ef18a 100644 --- a/include/DecayModifier.h +++ b/include/DecayModifier.h @@ -100,6 +100,8 @@ class IMPBFFEXPORT DecayModifier : public DecayRange { } }; +IMP_VALUES(DecayModifier, DecayModifiers); + IMPBFF_END_NAMESPACE -#endif // IMPBFF_DECAYMODIFIER_H \ No newline at end of file +#endif // IMPBFF_DECAYMODIFIER_H diff --git a/include/DecayPattern.h b/include/DecayPattern.h index 2139c986..f49c91a0 100644 --- a/include/DecayPattern.h +++ b/include/DecayPattern.h @@ -93,6 +93,8 @@ class IMPBFFEXPORT DecayPattern: public DecayModifier{ ); }; +IMP_VALUES(DecayPattern, DecayPatterns); + IMPBFF_END_NAMESPACE -#endif //IMPBFF_DECAYPATTERN_H \ No newline at end of file +#endif //IMPBFF_DECAYPATTERN_H diff --git a/include/DecayPileup.h b/include/DecayPileup.h index b93f1393..bae8730f 100644 --- a/include/DecayPileup.h +++ b/include/DecayPileup.h @@ -19,6 +19,7 @@ #include #include #include /* add_pile_up_to_model */ +#include IMPBFF_BEGIN_NAMESPACE @@ -105,6 +106,8 @@ class IMPBFFEXPORT DecayPileup : public DecayModifier { ); }; +IMP_VALUES(DecayPileup, DecayPileups); + IMPBFF_END_NAMESPACE -#endif //IMPBFF_DECAYPILEUP_H \ No newline at end of file +#endif //IMPBFF_DECAYPILEUP_H diff --git a/include/DecayRange.h b/include/DecayRange.h index e3b5b87d..53df46c6 100644 --- a/include/DecayRange.h +++ b/include/DecayRange.h @@ -15,6 +15,9 @@ #include #include +#include +#include +#include #include IMPBFF_BEGIN_NAMESPACE @@ -27,7 +30,7 @@ IMPBFF_BEGIN_NAMESPACE * It allows setting and retrieving the start and stop indices of the range, * as well as setting the range using a vector of indices. */ -class IMPBFFEXPORT DecayRange { +class IMPBFFEXPORT DecayRange : public Value { private: size_t _start = 0; ///< Start index of the decay range size_t _stop = -1; ///< Stop index of the decay range @@ -90,8 +93,13 @@ class IMPBFFEXPORT DecayRange { * \brief Destructor */ virtual ~DecayRange() = default; + + IMP_SHOWABLE_INLINE(DecayRange, + { out << "DecayRange"; }); }; +IMP_VALUES(DecayRange, DecayRanges); + IMPBFF_END_NAMESPACE -#endif // IMPBFF_DECAYRANGE_H \ No newline at end of file +#endif // IMPBFF_DECAYRANGE_H diff --git a/include/DecayScale.h b/include/DecayScale.h index 76e28ec0..c0e58498 100644 --- a/include/DecayScale.h +++ b/include/DecayScale.h @@ -99,9 +99,11 @@ class IMPBFFEXPORT DecayScale : public DecayModifier { * Add a DecayCurve to be scaled by the DecayScale object. * \param decay The DecayCurve to be added. */ - void add(DecayCurve* decay); + void add(DecayCurve* decay) override; }; +IMP_VALUES(DecayScale, DecayScales); + IMPBFF_END_NAMESPACE -#endif // IMPBFF_DECAYSCALE_H \ No newline at end of file +#endif // IMPBFF_DECAYSCALE_H diff --git a/include/DecayScore.h b/include/DecayScore.h index 8cc41c04..9f0741ee 100644 --- a/include/DecayScore.h +++ b/include/DecayScore.h @@ -139,6 +139,8 @@ class IMPBFFEXPORT DecayScore : public DecayRange { }; +IMP_VALUES(DecayScore, DecayScores); + IMPBFF_END_NAMESPACE diff --git a/include/PathMap.h b/include/PathMap.h index 546ffd44..148f5d9f 100644 --- a/include/PathMap.h +++ b/include/PathMap.h @@ -41,6 +41,7 @@ IMPBFF_BEGIN_NAMESPACE class PathMapTile; +//! Class to search path on grids class IMPBFFEXPORT PathMap : public IMP::em::SampledDensityMap { friend class PathMapTile; diff --git a/include/PathMapHeader.h b/include/PathMapHeader.h index 0b639228..7d0424d9 100644 --- a/include/PathMapHeader.h +++ b/include/PathMapHeader.h @@ -21,7 +21,6 @@ #include #include -#include #include @@ -30,6 +29,7 @@ IMPBFF_BEGIN_NAMESPACE class PathMap; +//!* Header class for path search class PathMap class IMPBFFEXPORT PathMapHeader { friend class IMP::bff::PathMap; @@ -156,10 +156,9 @@ friend class IMP::bff::PathMap; //! Set origin on the PathMap (the corner of the grid) void set_origin(float x, float y, float z); + void show(std::ostream& out = std::cout) const; }; -IMP_OBJECTS(PathMapHeader, PathMapHeaders); - IMPBFF_END_NAMESPACE diff --git a/include/PathMapTile.h b/include/PathMapTile.h index 9ddb1d2d..338d750b 100644 --- a/include/PathMapTile.h +++ b/include/PathMapTile.h @@ -16,7 +16,6 @@ #include /* std::pair */ #include -#include #include IMPBFF_BEGIN_NAMESPACE @@ -47,6 +46,7 @@ typedef enum{ class PathMap; +//!* Tile used in path search by PathMap class IMPBFFEXPORT PathMapTile{ friend class PathMap; @@ -190,4 +190,4 @@ friend class PathMap; IMPBFF_END_NAMESPACE -#endif //IMPBFF_PATHMAPTILE_H \ No newline at end of file +#endif //IMPBFF_PATHMAPTILE_H diff --git a/include/PathMapTileEdge.h b/include/PathMapTileEdge.h index 48900f5b..376a8db1 100644 --- a/include/PathMapTileEdge.h +++ b/include/PathMapTileEdge.h @@ -10,19 +10,19 @@ #define IMPBFF_PATHMAPTILEEDGE_H #include +#include +#include +#include #include -#include -#include - IMPBFF_BEGIN_NAMESPACE class PathMap; class PathMapTile; -class PathMapTileEdge{ +class PathMapTileEdge : public Value { friend class PathMapTile; friend class PathMap; @@ -50,9 +50,13 @@ friend class PathMap; float edge_cost = std::numeric_limits::max() ) : tile_idx(edge_target), length(edge_cost){} + + IMP_SHOWABLE_INLINE(PathMapTileEdge, + { out << "PathMapTileEdge"; }); }; +IMP_VALUES(PathMapTileEdge, PathMapTileEdges); IMPBFF_END_NAMESPACE -#endif //IMPBFF_PATHMAPTILEEDGE_H \ No newline at end of file +#endif //IMPBFF_PATHMAPTILEEDGE_H diff --git a/include/internal/Histogram.h b/include/internal/Histogram.h index 06f04800..f8bb2cd6 100644 --- a/include/internal/Histogram.h +++ b/include/internal/Histogram.h @@ -379,7 +379,7 @@ void histogram1D( } -void bincount1D(int* data, int n_data, int* bins, int n_bins){ +inline void bincount1D(int* data, int n_data, int* bins, int n_bins){ for(int j=0; j < n_data; j++) { int v = data[j]; diff --git a/include/internal/PhotonStatistics.h b/include/internal/PhotonStatistics.h index c938a05f..9933fb4d 100644 --- a/include/internal/PhotonStatistics.h +++ b/include/internal/PhotonStatistics.h @@ -18,7 +18,6 @@ #include #include #include /* strcmp */ -#include "omp.h" IMPBFF_BEGIN_NAMESPACE diff --git a/include/internal/json.h b/include/internal/json.h index 777e5079..70171018 100644 --- a/include/internal/json.h +++ b/include/internal/json.h @@ -10886,7 +10886,8 @@ class binary_writer static CharType to_char_type(std::uint8_t x) noexcept { static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); - static_assert(std::is_pod::value, "CharType must be POD"); + static_assert(std::is_standard_layout::value && + std::is_trivial::value, "CharType must be POD"); CharType result; std::memcpy(&result, &x, sizeof(x)); return result; diff --git a/pyext/AV.i b/pyext/AV.i index b2fdaf3a..2606e6eb 100644 --- a/pyext/AV.i +++ b/pyext/AV.i @@ -1,4 +1,5 @@ IMP_SWIG_DECORATOR(IMP::bff, AV, AVs); +IMP_SWIG_VALUE(IMP::bff, AVPairDistanceMeasurement, AVPairDistanceMeasurements); IMP_SWIG_OBJECT(IMP::bff, AVNetworkRestraint, AVNetworkRestraints); %template(MapStringAVPairDistanceMeasurement) std::map; diff --git a/pyext/DecayConvolution.i b/pyext/DecayConvolution.i index 278b85f6..e3781f0a 100644 --- a/pyext/DecayConvolution.i +++ b/pyext/DecayConvolution.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayConvolution, DecayConvolutions); + %attribute(IMP::bff::DecayConvolution, IMP::bff::DecayCurve&, corrected_irf, get_corrected_irf); %attribute(IMP::bff::DecayConvolution, int, convolution_method, get_convolution_method, set_convolution_method); %attribute(IMP::bff::DecayConvolution, double, excitation_period, get_excitation_period, set_excitation_period); diff --git a/pyext/DecayLifetimeHandler.i b/pyext/DecayLifetimeHandler.i index c79e6f01..84ad80e6 100644 --- a/pyext/DecayLifetimeHandler.i +++ b/pyext/DecayLifetimeHandler.i @@ -1,3 +1,5 @@ +IMP_SWIG_OBJECT(IMP::bff, DecayLifetimeHandler, DecayLifetimeHandlers); + %attribute(IMP::bff::DecayLifetimeHandler, bool, abs_lifetime_spectrum, get_abs_lifetime_spectrum, set_abs_lifetime_spectrum); %attribute(IMP::bff::DecayLifetimeHandler, bool, use_amplitude_threshold, get_use_amplitude_threshold, set_use_amplitude_threshold); %attribute(IMP::bff::DecayLifetimeHandler, double, amplitude_threshold, get_amplitude_threshold, set_amplitude_threshold); diff --git a/pyext/DecayLinearization.i b/pyext/DecayLinearization.i index 60fbc5b6..6558bda2 100644 --- a/pyext/DecayLinearization.i +++ b/pyext/DecayLinearization.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayLinearization, DecayLinearizations); + //%attribute2(IMP::bff::DecayLinearization, IMP::bff::DecayCurve, linearization, get_linearization_table, set_linearization_table); -%include "IMP/bff/DecayLinearization.h" \ No newline at end of file +%include "IMP/bff/DecayLinearization.h" diff --git a/pyext/DecayModifier.i b/pyext/DecayModifier.i index 9472b3ed..a16d0633 100644 --- a/pyext/DecayModifier.i +++ b/pyext/DecayModifier.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayModifier, DecayModifiers); + %attribute(IMP::bff::DecayModifier, bool, active, is_active, set_active); %attribute_py(IMP::bff::DecayModifier, IMP::bff::DecayCurve*, data, get_data, set_data); %class_callable(IMP::bff::DecayModifier, add); diff --git a/pyext/DecayPattern.i b/pyext/DecayPattern.i index 906a6f3c..2a83b459 100644 --- a/pyext/DecayPattern.i +++ b/pyext/DecayPattern.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayPattern, DecayPatterns); + %attribute(IMP::bff::DecayPattern, IMP::bff::DecayCurve*,pattern, get_pattern, set_pattern); %attribute(IMP::bff::DecayPattern, double, pattern_fraction, get_pattern_fraction, set_pattern_fraction); %attribute(IMP::bff::DecayPattern, double, constant_offset, get_constant_offset, set_constant_offset); diff --git a/pyext/DecayPileup.i b/pyext/DecayPileup.i index 1c1eb821..fd16121d 100644 --- a/pyext/DecayPileup.i +++ b/pyext/DecayPileup.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayPileup, DecayPileups); + %attribute(IMP::bff::DecayPileup, double, instrument_dead_time, get_instrument_dead_time, set_instrument_dead_time); %attribute(IMP::bff::DecayPileup, double, repetition_rate, get_repetition_rate, set_repetition_rate); %attributestring(IMP::bff::DecayPileup, std::string, pile_up_model, get_pile_up_model, set_pile_up_model); diff --git a/pyext/DecayRange.i b/pyext/DecayRange.i index e8bb4066..af51f70a 100644 --- a/pyext/DecayRange.i +++ b/pyext/DecayRange.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayRange, DecayRanges); + %attribute(IMP::bff::DecayRange, int, start, get_start, set_start); %attribute(IMP::bff::DecayRange, int, stop, get_stop, set_stop); diff --git a/pyext/DecayScale.i b/pyext/DecayScale.i index d42df6fd..c9b50299 100644 --- a/pyext/DecayScale.i +++ b/pyext/DecayScale.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayScale, DecayScales); + %attribute(IMP::bff::DecayScale, double, number_of_photons, get_number_of_photons); %attribute(IMP::bff::DecayScale, double, constant_background, get_constant_background, set_constant_background); diff --git a/pyext/DecayScore.i b/pyext/DecayScore.i index c2ce5a78..19891eca 100644 --- a/pyext/DecayScore.i +++ b/pyext/DecayScore.i @@ -1,3 +1,5 @@ +IMP_SWIG_VALUE(IMP::bff, DecayScore, DecayScores); + %attributestring(IMP::bff::DecayScore, std::string, score_type, get_score_type, set_score_type); %attribute(IMP::bff::DecayScore, double, score, score); %attribute_py(IMP::bff::DecayScore, IMP::bff::DecayCurve, model, get_model, set_model); diff --git a/pyext/PathMap.i b/pyext/PathMap.i index e25d2cca..a5cc3c1d 100644 --- a/pyext/PathMap.i +++ b/pyext/PathMap.i @@ -1,4 +1,4 @@ -/* Make selected classes extensible in Python */ +IMP_SWIG_VALUE(IMP::bff, PathMapTileEdge, PathMapTileEdges); IMP_SWIG_OBJECT(IMP::bff, PathMap, PathMaps); // Use numpy.i for outputs of AV densities @@ -9,6 +9,27 @@ IMP_SWIG_OBJECT(IMP::bff, PathMap, PathMaps); ); %ignore IMP::bff::PathMap::get_xyz_density(); +/* Since PathMapHeaders are not values or Objects, we must ensure that whenever + pointers to them are returned to Python, the object that manages the header's + storage (usually a PathMap) must be kept alive so that the header is not + prematurely freed. See modules/em/pyext/swig.i-in for a similar workaround + for DensityHeader. */ +namespace IMP { + namespace bff { + %feature("shadow") PathMap::get_path_map_header() const %{ + def get_path_map_header(self): + h = _IMP_bff.DensityMap_get_path_map_header(self) + h._owner = self + return h + %} + %feature("shadow") PathMap::get_path_map_header_writable() %{ + def get_path_map_header_writable(self): + h = _IMP_bff.PathMap_get_path_map_header_writable(self) + h._owner = self + return h + %} + } +} %include "IMP/bff/PathMapHeader.h" %include "IMP/bff/PathMap.h" diff --git a/pyext/numpy.i b/pyext/numpy.i index 8084f341..68ced137 100644 --- a/pyext/numpy.i +++ b/pyext/numpy.i @@ -114,8 +114,8 @@ if (py_obj == NULL ) return "C NULL value"; if (py_obj == Py_None ) return "Python None" ; if (PyCallable_Check(py_obj)) return "callable" ; - if (PyString_Check( py_obj)) return "string" ; - if (PyInt_Check( py_obj)) return "int" ; + if (PyBytes_Check( py_obj)) return "string" ; + if (PyLong_Check( py_obj)) return "int" ; if (PyFloat_Check( py_obj)) return "float" ; if (PyDict_Check( py_obj)) return "dict" ; if (PyList_Check( py_obj)) return "list" ; @@ -1996,7 +1996,7 @@ %typemap(argout) (DATA_TYPE ARGOUT_ARRAY1[ANY]) { - $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum); + $result = SWIG_AppendOutput($result,(PyObject*)array$argnum); } /* Typemap suite for (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1) @@ -2007,7 +2007,7 @@ (PyObject* array = NULL) { npy_intp dims[1]; - if (!PyInt_Check($input)) + if (!PyLong_Check($input)) { const char* typestring = pytype_string($input); PyErr_Format(PyExc_TypeError, @@ -2024,7 +2024,7 @@ %typemap(argout) (DATA_TYPE* ARGOUT_ARRAY1, DIM_TYPE DIM1) { - $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum); + $result = SWIG_AppendOutput($result,(PyObject*)array$argnum); } /* Typemap suite for (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1) @@ -2035,7 +2035,7 @@ (PyObject* array = NULL) { npy_intp dims[1]; - if (!PyInt_Check($input)) + if (!PyLong_Check($input)) { const char* typestring = pytype_string($input); PyErr_Format(PyExc_TypeError, @@ -2052,7 +2052,7 @@ %typemap(argout) (DIM_TYPE DIM1, DATA_TYPE* ARGOUT_ARRAY1) { - $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum); + $result = SWIG_AppendOutput($result,(PyObject*)array$argnum); } /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) @@ -2070,7 +2070,7 @@ %typemap(argout) (DATA_TYPE ARGOUT_ARRAY2[ANY][ANY]) { - $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum); + $result = SWIG_AppendOutput($result,(PyObject*)array$argnum); } /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY]) @@ -2088,7 +2088,7 @@ %typemap(argout) (DATA_TYPE ARGOUT_ARRAY3[ANY][ANY][ANY]) { - $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum); + $result = SWIG_AppendOutput($result,(PyObject*)array$argnum); } /* Typemap suite for (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY]) @@ -2106,7 +2106,7 @@ %typemap(argout) (DATA_TYPE ARGOUT_ARRAY4[ANY][ANY][ANY][ANY]) { - $result = SWIG_Python_AppendOutput($result,(PyObject*)array$argnum); + $result = SWIG_AppendOutput($result,(PyObject*)array$argnum); } /*****************************/ @@ -2131,7 +2131,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEW_ARRAY1) @@ -2152,7 +2152,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) @@ -2174,7 +2174,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_ARRAY2) @@ -2196,7 +2196,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) @@ -2218,7 +2218,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEW_FARRAY2) @@ -2240,7 +2240,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2264,7 +2264,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, @@ -2288,7 +2288,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2312,7 +2312,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, @@ -2336,7 +2336,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2361,7 +2361,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, @@ -2386,7 +2386,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEW_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2411,7 +2411,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, @@ -2436,7 +2436,7 @@ PyArrayObject* array = (PyArrayObject*) obj; if (!array || !require_fortran(array)) SWIG_fail; - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /*************************************/ @@ -2474,7 +2474,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DATA_TYPE** ARGOUTVIEWM_ARRAY1) @@ -2508,7 +2508,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) @@ -2543,7 +2543,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_ARRAY2) @@ -2578,7 +2578,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY2, DIM_TYPE* DIM1, DIM_TYPE* DIM2) @@ -2613,7 +2613,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DATA_TYPE** ARGOUTVIEWM_FARRAY2) @@ -2648,7 +2648,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2685,7 +2685,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, @@ -2722,7 +2722,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY3, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2759,7 +2759,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, @@ -2796,7 +2796,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2834,7 +2834,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, @@ -2872,7 +2872,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2910,7 +2910,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, @@ -2948,7 +2948,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_ARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -2986,7 +2986,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, @@ -3024,7 +3024,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DATA_TYPE** ARGOUTVIEWM_FARRAY4, DIM_TYPE* DIM1, DIM_TYPE* DIM2, @@ -3062,7 +3062,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /* Typemap suite for (DIM_TYPE* DIM1, DIM_TYPE* DIM2, DIM_TYPE* DIM3, DIM_TYPE* DIM4, @@ -3100,7 +3100,7 @@ PyArray_SetBaseObject(array,cap); %#endif - $result = SWIG_Python_AppendOutput($result,obj); + $result = SWIG_AppendOutput($result,obj); } /**************************************/ diff --git a/pyext/src/__init__.py b/pyext/src/__init__.py index d8a24755..f9ee2fef 100644 --- a/pyext/src/__init__.py +++ b/pyext/src/__init__.py @@ -2,11 +2,9 @@ from __future__ import annotations import sys -import json -import pathlib -from . import restraints -from . import fret +from . import restraints # noqa: F401 +from . import fret # noqa: F401 # Take care of typing try: @@ -30,5 +28,3 @@ typing = None __version__ = "0.14.0" - - diff --git a/pyext/src/cli/__init__.py b/pyext/src/cli/__init__.py index 99e728f3..2a1b71b9 100644 --- a/pyext/src/cli/__init__.py +++ b/pyext/src/cli/__init__.py @@ -1 +1,5 @@ -from . flexfit import * +"""@namespace IMP.bff.cli + Tools for handling RMF files. +""" + +from . flexfit import * # noqa: F401, F403 diff --git a/pyext/src/cli/flexfit.py b/pyext/src/cli/flexfit.py index c84bdf43..daf94ef9 100644 --- a/pyext/src/cli/flexfit.py +++ b/pyext/src/cli/flexfit.py @@ -77,7 +77,6 @@ def __init__( IMP.rmf.save_frame(self._rh) def do_update(self, arg0): - #print(*[r.evaluate(False) for r in self.restraints], sep="\t") IMP.rmf.save_frame(self._rh) @@ -110,7 +109,8 @@ def __init__( def do_update(self, arg0): with open(self._restraint_filename, "a+") as fp: fp.write("%s\t" % self.frame) - fp.write("\t".join(["{:.3f}".format(r.evaluate(False)) for r in self.restraints])) + fp.write("\t".join(["{:.3f}".format(r.evaluate(False)) + for r in self.restraints])) fp.write("\t") if isinstance(self.output_objects, list): for obj in self.output_objects: @@ -122,6 +122,7 @@ def do_update(self, arg0): else: hiers = self._hier.get_children() for i, hier in enumerate(hiers): - out_fn = lead + "_state_" + str(i) + "_" + "{:04d}".format(self.frame) + ".pdb" + out_fn = (lead + "_state_" + str(i) + + "_" + "{:04d}".format(self.frame) + ".pdb") IMP.atom.write_pdb(hier, out=out_fn) self.frame += 1 diff --git a/pyext/src/restraints/AVNetworkRestraint.py b/pyext/src/restraints/AVNetworkRestraint.py index 1aea7657..0d9124a8 100644 --- a/pyext/src/restraints/AVNetworkRestraint.py +++ b/pyext/src/restraints/AVNetworkRestraint.py @@ -1,9 +1,6 @@ -"""@namespace IMP.bff -Restraints for handling distances between accessible volumes. +"""Restraints for handling distances between accessible volumes. """ -from __future__ import print_function - import pathlib import typing @@ -73,8 +70,8 @@ def add_used_dyes_to_rb(used_avs: typing.List[IMP.bff.AV]): for dk in used_avs: dye = used_avs[dk] p_dye = dye.get_particle() - # The coordinates of an AV are the mean AV the density map. Thus, the position of the - # AV changes when the AV is resampled. + # The coordinates of an AV are the mean AV the density map. + # Thus, the position of the AV changes when the AV is resampled. dye.resample() # dye_xyz = IMP.core.XYZ(p_dye) @@ -141,7 +138,7 @@ def __init__( m = hier.get_model() self.mdl: IMP.Model = m self.hier: IMP.atom.Hierarchy = hier - super(AVNetworkRestraintWrapper, self).__init__(m, label=label, weight=weight) + super().__init__(m, label=label, weight=weight) self.model_ps = [] self.model_ps += [k.get_particle() for k in IMP.atom.get_leaves(hier)] @@ -158,11 +155,14 @@ def __init__( else: raise FileNotFoundError("{}".format(fps_json_fn)) self.rs = IMP.RestraintSet(m, 'AVNetworkRestraint') - self.used_avs = dict([(v.get_name(), v) for v in self.av_network_restraint.get_used_avs()]) + self.used_avs = dict( + [(v.get_name(), v) + for v in self.av_network_restraint.get_used_avs()]) if not self.mean_position_restraint: self.rs.add_restraint(self.av_network_restraint) else: - self.used_distances = self.av_network_restraint.get_used_distances() + self.used_distances = \ + self.av_network_restraint.get_used_distances() self.add_used_dyes_to_rb(self.used_avs) for dk in self.used_distances: d_exp = self.used_distances[dk] diff --git a/pyext/src/restraints/__init__.py b/pyext/src/restraints/__init__.py index 9c5ae5cb..96231fb5 100644 --- a/pyext/src/restraints/__init__.py +++ b/pyext/src/restraints/__init__.py @@ -1 +1,5 @@ -from .AVNetworkRestraint import AVNetworkRestraintWrapper +"""@namespace IMP.bff.restraints + Restraints. +""" + +from .AVNetworkRestraint import AVNetworkRestraintWrapper # noqa: F401 diff --git a/pyext/src/restraints/xlink.py b/pyext/src/restraints/xlink.py index a8c45625..f97fa8ff 100644 --- a/pyext/src/restraints/xlink.py +++ b/pyext/src/restraints/xlink.py @@ -12,6 +12,14 @@ import numpy as np +def get_obstacles(*args, **keys): + raise NotImplementedError() + + +def get_path_length(*args, **keys): + raise NotImplementedError() + + class XLinkScore(typing.TypedDict): """ Attributes @@ -23,9 +31,9 @@ class XLinkScore(typing.TypedDict): cross-linker length total: np.ndarray - The sum of scores to all potential cross linking partners. The score is the - fraction of distances of all path that are shorter or equal to the - cross-linker length + The sum of scores to all potential cross linking partners. + The score is the fraction of distances of all path that are + shorter or equal to the cross-linker length """ individual: list @@ -60,7 +68,8 @@ def compute_scores(self, **kwargs) -> XLinkScore: linker_length = kwargs.get('linker_length', self.linker_length) linker_width = kwargs.get('linker_width', self.linker_width) radius = kwargs.get('radius', self.radius) - simulation_grid_spacing = kwargs.get('simulation_grid_spacing', self.simulation_grid_spacing) + simulation_grid_spacing = kwargs.get( + 'simulation_grid_spacing', self.simulation_grid_spacing) verbose = kwargs.get('verbose', self.verbose) min_points = kwargs.get('min_points', self.min_points) obstacles = self.obstacles @@ -72,8 +81,12 @@ def compute_scores(self, **kwargs) -> XLinkScore: protein_2 = xlink['protein_2'] residue_1 = xlink['residue_1'] residue_2 = xlink['residue_2'] - attachment_idx_1 = np.where((obstacles['res_id'] == residue_1) & (obstacles['protein_name'] == protein_1))[0] - attachment_idx_2 = np.where((obstacles['res_id'] == residue_2) & (obstacles['protein_name'] == protein_2))[0] + attachment_idx_1 = np.where( + (obstacles['res_id'] == residue_1) + & (obstacles['protein_name'] == protein_1))[0] + attachment_idx_2 = np.where( + (obstacles['res_id'] == residue_2) + & (obstacles['protein_name'] == protein_2))[0] x_links_scores = [] for idx_1 in attachment_idx_1: origin = obstacles['xyz'][idx_1] @@ -94,16 +107,20 @@ def compute_scores(self, **kwargs) -> XLinkScore: ) if len(np.array(av.points()).T) < min_points: if verbose: - print(protein_1, residue_1, "is not accessible") + print(protein_1, residue_1, + "is not accessible") x_links_scores.append(0.0) else: if verbose: - print("Eucledian distance < linker length.. Testing surface distance") + print("Eucledian distance < linker length.. " + "Testing surface distance") points = av.points() xyz = points[0:3] dist = points[3] - dist_eq = np.linalg.norm(xyz.T - target, axis=1) + dist - shorter = np.sum(dist_eq < (linker_length + radius)) + dist_eq = np.linalg.norm( + xyz.T - target, axis=1) + dist + shorter = np.sum( + dist_eq < (linker_length + radius)) score = shorter / len(dist_eq) x_links_scores.append(score) indiviudal_scores = np.array(x_links_scores) @@ -141,7 +158,7 @@ def __init__( label=label ) self.model = model - keys, formats = list(zip(*OBSTACLES_KEYS_FORMATS)) + keys, formats = list(zip(*OBSTACLES_KEYS_FORMATS)) # noqa: F821 obstacles = np.zeros(0, dtype={ 'names': keys, 'formats': formats @@ -152,7 +169,8 @@ def __init__( self.linker_length = xlink_settings['linker_length'] self.linker_width = xlink_settings['linker_width'] self.radius = xlink_settings['radius'] - self.simulation_grid_spacing = xlink_settings['simulation_grid_spacing'] + self.simulation_grid_spacing = \ + xlink_settings['simulation_grid_spacing'] self.min_points = xlink_settings['min_points'] self.verbose = verbose xlink_file = xlink_settings['xlink_file'] @@ -200,5 +218,3 @@ def __call__( def get_score(self) -> float: total_score = float(np.sum(self()['total'])) return total_score - - diff --git a/pyext/src/spectroscopy/__init__.py b/pyext/src/spectroscopy/__init__.py index c27a42b8..5b528f92 100644 --- a/pyext/src/spectroscopy/__init__.py +++ b/pyext/src/spectroscopy/__init__.py @@ -1 +1,5 @@ -from . decay import * +"""@namespace IMP.bff.spectroscopy + Handling of spectroscopy data. +""" + +from . decay import * # noqa: F401, F403 diff --git a/pyext/src/spectroscopy/decay.py b/pyext/src/spectroscopy/decay.py index 7e445044..a645f2be 100644 --- a/pyext/src/spectroscopy/decay.py +++ b/pyext/src/spectroscopy/decay.py @@ -88,7 +88,7 @@ class Decay(object): ] _attributes = { - #VERSION + # VERSION ##################### # TODO # 'version': ("", "get_version"), @@ -107,8 +107,10 @@ class Decay(object): # 'tttr_irf': ("_irf", None, "set_tttr"), # LIFETIME SPECTRUM ############################ - 'lifetime_spectrum': ("lifetime_handler", "get_lifetime_spectrum", "set_lifetime_spectrum"), - 'use_amplitude_threshold': ("lifetime_handler", "use_amplitude_threshold"), + 'lifetime_spectrum': ("lifetime_handler", "get_lifetime_spectrum", + "set_lifetime_spectrum"), + 'use_amplitude_threshold': ("lifetime_handler", + "use_amplitude_threshold"), 'abs_lifetime_spectrum': ("lifetime_handler", "abs_lifetime_spectrum"), 'amplitude_threshold': ("lifetime_handler", "amplitude_threshold"), # CONVOLUTION @@ -118,7 +120,8 @@ class Decay(object): 'convolution_method': ("decay_convolution", "convolution_method"), 'excitation_period': ("decay_convolution", "excitation_period"), 'irf_shift_channels': ("decay_convolution", "irf_shift_channels"), - 'irf_background_counts': ("decay_convolution", "irf_background_counts"), + 'irf_background_counts': ("decay_convolution", + "irf_background_counts"), # Scatter ############################ 'scatter_fraction': ("decay_scatter", "pattern_fraction"), @@ -174,7 +177,8 @@ def make_decay_curves( irf_histogram = np.zeros_like(data) if len(irf_histogram) > 0: irf_histogram[0] = 1.0 - decay = IMP.bff.DecayCurve(x=time_axis, y=data, acquisition_time=acquisition_time) + decay = IMP.bff.DecayCurve(x=time_axis, y=data, + acquisition_time=acquisition_time) irf = IMP.bff.DecayCurve(x=time_axis, y=irf_histogram) if data_noise is not None: decay.set_ey(data_noise) @@ -217,12 +221,14 @@ def __init__( model = IMP.bff.DecayCurve(data.x) lifetime_handler = IMP.bff.DecayLifetimeHandler(*lifetime_settings) - decay_convolution = IMP.bff.DecayConvolution(lifetime_handler, irf, *convolution_settings) + decay_convolution = IMP.bff.DecayConvolution( + lifetime_handler, irf, *convolution_settings) decay_scatter = IMP.bff.DecayPattern(*scatter_settings) decay_scatter.data = irf decay_background = IMP.bff.DecayPattern(*background_settings) decay_pileup = IMP.bff.DecayPileup(data, *pileup_settings) - decay_linearization = IMP.bff.DecayLinearization(*linearization_settings) + decay_linearization = IMP.bff.DecayLinearization( + *linearization_settings) decay_scale = IMP.bff.DecayScale(data, *scaling_settings) decay_score = IMP.bff.DecayScore(model, data, *score_settings) @@ -280,4 +286,3 @@ def set_score_range(self, start_stop): for dm in self._decay_modifier: dm.set_range(start_stop) self.decay_score.set_range(start_stop) - diff --git a/pyext/src/spectroscopy/kappa2.py b/pyext/src/spectroscopy/kappa2.py index 543de6ea..49c75e78 100644 --- a/pyext/src/spectroscopy/kappa2.py +++ b/pyext/src/spectroscopy/kappa2.py @@ -56,8 +56,10 @@ def kappasq_dwt( for i in range(n_samples): donor = donor_vec[i] acceptor = acceptor_vec[i] - # Assumption here: connecting vector R_DA is along the x-axis (R_DA=[1,0,0]) - delta = np.arccos(np.dot(donor, acceptor) / (np.linalg.norm(donor) * np.linalg.norm(acceptor))) + # Assumption here: connecting vector R_DA is along + # the x-axis (R_DA=[1,0,0]) + delta = np.arccos(np.dot(donor, acceptor) + / (np.linalg.norm(donor) * np.linalg.norm(acceptor))) beta1 = np.arccos(donor[0] / np.linalg.norm(donor)) beta2 = np.arccos(acceptor[0] / np.linalg.norm(acceptor)) @@ -83,8 +85,10 @@ def kappasq_dwt( beta2=beta2 ) ## - Ek2 = (1 - sD2) * (1 - sA2) / (1 + x) + sD2 * sA2 / (1 + 2 / 3. / k2_trapped_trapped * x) + sD2 * (1 - sA2) / ( - 1 + 2 / 3. / k2_trapped_free * x) + (1 - sD2) * sA2 / (1 + 2 / 3. / k2_free_trapped * x) + Ek2 = ((1 - sD2) * (1 - sA2) / (1 + x) + + sD2 * sA2 / (1 + 2 / 3. / k2_trapped_trapped * x) + + sD2 * (1 - sA2) / (1 + 2 / 3. / k2_trapped_free * x) + + (1 - sD2) * sA2 / (1 + 2 / 3. / k2_free_trapped * x)) k2 = 2 / 3. * x / (1 / Ek2 - 1) k2s[i] = k2 @@ -134,7 +138,6 @@ def kappasq_all_delta_new( return k2scale, k2hist, ks - @nb.jit(nopython=True) def kappasq_all_delta( delta: float, @@ -145,22 +148,23 @@ def kappasq_all_delta( k2_min: float = 0.0, k2_max: float = 4.0 ) -> typing.Tuple[np.ndarray, np.ndarray, np.ndarray]: - """Computes a orientation factor distribution for a wobbling in a cone model - using parameters that can be estimated by experimental anisotropies. + """Computes a orientation factor distribution for a wobbling in + a cone model using parameters that can be estimated by experimental + anisotropies. The function used second rank order parameter of the donor and acceptor and the angle delta between the symmetry axes of the dyes as input. These parameters can be estimated by the residual anisotropy the the dyes. The second rank order parameter of the donor and acceptor are estimated by the - dye's residual anisotropies. The angle between the symmetry axes is estimated - by the residual anisotropy of the FRET sensitized emission (see: - `chisurf.fluorescence.anisotropy.kappa2.s2delta`). + dye's residual anisotropies. The angle between the symmetry axes is + estimated by the residual anisotropy of the FRET sensitized emission + (see: `chisurf.fluorescence.anisotropy.kappa2.s2delta`). - This function computes a orientation factor distribution, :math:`p(/kappa^2)`, - for a wobbling in a cone model (WIC) for second rank structure factors of - the donor and acceptor, and an angle :math:`delta`. The angle - :math:`delta` is the angle between the symmetry axes of the dyes and can be - estimated using experimental residual anisotropies [1]_. + This function computes a orientation factor distribution, + :math:`p(/kappa^2)`, for a wobbling in a cone model (WIC) for second rank + structure factors of the donor and acceptor, and an angle :math:`delta`. + The angle :math:`delta` is the angle between the symmetry axes of the + dyes and can be estimated using experimental residual anisotropies [1]_. Parameters ---------- @@ -204,7 +208,8 @@ def kappasq_all_delta( ... step=2.0, ... n_bins=31 ... ) - >>> np.allclose(k2h, np.array([ 0. , 0. , 0. , 0. , + >>> np.allclose(k2h, np.array( + ... [ 0. , 0. , 0. , 0. , ... 3205.72877776, 1001.19048825, 611.44917432, 252.97166906, ... 0. , 0. , 0. , 0. , ... 0. , 0. , 0. , 0. , @@ -229,7 +234,8 @@ def kappasq_all_delta( """ # beta angles - beta1 = np.arange(0.001, np.pi / 2.0, step * np.pi / 180.0, dtype=np.float64) + beta1 = np.arange(0.001, np.pi / 2.0, step * np.pi / 180.0, + dtype=np.float64) phi = np.arange(0.001, 2.0 * np.pi, step * np.pi / 180.0, dtype=np.float64) n = beta1.shape[0] m = phi.shape[0] @@ -247,7 +253,8 @@ def kappasq_all_delta( n1 = np.array([-np.sin(beta1[i]), 0, np.cos(beta1[i])]) n2 = np.array([0, 1, 0]) for j in range(m): - d2 = (n1*np.cos(phi[j])+n2*np.sin(phi[j]))*np.sin(delta)+d1*np.cos(delta) + d2 = ((n1 * np.cos(phi[j]) + n2 * np.sin(phi[j])) + * np.sin(delta) + d1 * np.cos(delta)) beta2 = np.arccos(np.abs(d2.dot(rda_vec))) k2[i, j] = kappasq( delta=delta, @@ -270,12 +277,14 @@ def kappasq_all( k2_max: float = 4.0, n_samples: int = 10000 ) -> typing.Tuple[np.array, np.array, np.array]: - """Computes a orientation factor distribution for a wobbling in a cone model - using specific second rank structure factors of the donor and acceptor. + """Computes a orientation factor distribution for a wobbling in a + cone model using specific second rank structure factors of the donor + and acceptor. - This function computes a orientation factor distribution, :math:`p(/kappa^2)`, - for a wobbling in a cone model (WIC) for second rank structure factors of - the donor and acceptor estimated using experimental residual anisotropies [1]_. + This function computes a orientation factor distribution, + :math:`p(/kappa^2)`, for a wobbling in a cone model (WIC) for second rank + structure factors of the donor and acceptor estimated using experimental + residual anisotropies [1]_. Parameters ---------- @@ -320,7 +329,8 @@ def kappasq_all( 2.66666667, 2.8 , 2.93333333, 3.06666667, 3.2 , 3.33333333, 3.46666667, 3.6 , 3.73333333, 3.86666667, 4. ]) - >>> reference = np.array([0.0000e+00, 0.0000e+00, 0.0000e+00, 3.1920e+04, 4.3248e+04, + >>> reference = np.array( + ... [0.0000e+00, 0.0000e+00, 0.0000e+00, 3.1920e+04, 4.3248e+04, ... 1.4842e+04, 5.8930e+03, 2.5190e+03, 1.0840e+03, 3.9700e+02, ... 9.4000e+01, 3.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, ... 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, 0.0000e+00, @@ -347,7 +357,8 @@ def kappasq_all( d2 = np.random.random(3) n1 = np.linalg.norm(d1) n2 = np.linalg.norm(d2) - # Assumption here: connecting vector R_DA is along the x-axis (R_DA=[1,0,0]) + # Assumption here: connecting vector R_DA is along the + # x-axis (R_DA=[1,0,0]) delta = np.arccos(np.dot(d1, d2) / (n1 * n2)) beta1 = np.arccos(d1[0] / n1) beta2 = np.arccos(d2[0] / n2) @@ -370,7 +381,7 @@ def kappa_distance( a1: np.array, a2: np.array ) -> typing.Tuple[float, float]: - """Calculates the distance between the center of two dipoles and the + r"""Calculates the distance between the center of two dipoles and the orientation-factor kappa of the dipoles Calculates for the vectors d1 and d2 pointing to the donors and the vectors @@ -439,7 +450,7 @@ def kappa_distance( ... ) (0.8660254037844386, 1.0000000000000002) - """ + """ # noqa: E501 # coordinates of the dipole d11 = d1[0] d12 = d1[1] @@ -466,7 +477,7 @@ def kappa_distance( dM2 = d12 + dD21 * muD2 / 2.0 dM3 = d13 + dD21 * muD3 / 2.0 - ### Acceptor ### + # -- Acceptor -- # # cartesian coordinates of the acceptor a11 = a1[0] a12 = a1[1] @@ -507,11 +518,9 @@ def kappa_distance( nRDA3 = RDA3 / dRDA # Orientation factor kappa2 - kappa = muA1 * muD1 + \ - muA2 * muD2 + \ - muA3 * muD3 - \ - 3.0 * (muD1 * nRDA1 + muD2 * nRDA2 + muD3 * nRDA3) * \ - (muA1 * nRDA1 + muA2 * nRDA2 + muA3 * nRDA3) + kappa = (muA1 * muD1 + muA2 * muD2 + muA3 * muD3 + - 3.0 * (muD1 * nRDA1 + muD2 * nRDA2 + muD3 * nRDA3) + * (muA1 * nRDA1 + muA2 * nRDA2 + muA3 * nRDA3)) return dRDA, kappa @@ -529,8 +538,10 @@ def kappa( ------- >>> import numpy as np - >>> donor_dipole = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], dtype=np.float64) - >>> acceptor_dipole = np.array([[0.0, 0.5, 0.0], [0.0, 0.5, 1.0]], dtype=np.float64) + >>> donor_dipole = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], + ... dtype=np.float64) + >>> acceptor_dipole = np.array([[0.0, 0.5, 0.0], [0.0, 0.5, 1.0]], + ... dtype=np.float64) >>> kappa(donor_dipole, acceptor_dipole) (0.8660254037844386, 1.0000000000000002) """ @@ -546,7 +557,8 @@ def s2delta( r_inf_AD: float, r_0: float = 0.38 ) -> typing.Tuple[float, float]: - """Calculate s2delta from the residual anisotropies of the donor and acceptor + """Calculate s2delta from the residual anisotropies of the donor + and acceptor Parameters ---------- @@ -586,8 +598,9 @@ def s2delta( Notes ----- - The parameters `s2_donor` and `s2_acceptor`, which correspond to :math:`S^{(2)}_D` - and :math:`S^{(2)}_A` are calculated using the dye's residual anisotropy [1]_ + The parameters `s2_donor` and `s2_acceptor`, which correspond to + :math:`S^{(2)}_D` and :math:`S^{(2)}_A` are calculated using the dye's + residual anisotropy [1]_ ..math:: @@ -639,7 +652,7 @@ def calculate_kappa_distance( ) ks[i_frame] = k ds[i_frame] = d - except: + except: # noqa: E722 print("Frame ", i_frame, "skipped, calculation error") return ds, ks @@ -732,9 +745,9 @@ def p_isotropic_orientation_factor( Example ------- - >>> import scikit_fluorescence.modeling.kappa2 + >>> from scikit_fluorescence.modeling import kappa2 >>> k2 = np.linspace(0.1, 4, 32) - >>> p_k2 = scikit_fluorescence.modeling.kappa2.p_isotropic_orientation_factor(k2=k2) + >>> p_k2 = kappa2.p_isotropic_orientation_factor(k2=k2) >>> p_k2 array([0.17922824, 0.11927194, 0.09558154, 0.08202693, 0.07297372, 0.06637936, 0.06130055, 0.05723353, 0.04075886, 0.03302977, @@ -756,7 +769,8 @@ def p_isotropic_orientation_factor( if 0 <= k <= 1: r[i] = 0.5 / (s3 * k) * np.log(2 + s3) elif 1 <= k <= 2: - r[i] = 0.5 / (s3 * k) * np.log((2 + s3) / (k + np.sqrt(k**2 - 1.0))) + r[i] = 0.5 / (s3 * k) * np.log((2 + s3) + / (k + np.sqrt(k**2 - 1.0))) if normalize: r /= max(1.0, r.sum()) return r diff --git a/pyext/src/tools/__init__.py b/pyext/src/tools/__init__.py index 3961b942..51ab5871 100644 --- a/pyext/src/tools/__init__.py +++ b/pyext/src/tools/__init__.py @@ -1,3 +1,7 @@ +"""@namespace IMP.bff.tools + Utility functions. +""" + import IMP import IMP.core import IMP.atom @@ -37,7 +41,8 @@ def display_mean_av_positions( IMP.atom.Bonded.setup_particle(p_dye) if not IMP.atom.Bonded.get_is_setup(p_att): IMP.atom.Bonded.setup_particle(p_att) - if not IMP.atom.get_bond(IMP.atom.Bonded(p_dye), IMP.atom.Bonded(p_att)): + if not IMP.atom.get_bond(IMP.atom.Bonded(p_dye), + IMP.atom.Bonded(p_att)): IMP.atom.create_bond( IMP.atom.Bonded(p_dye), IMP.atom.Bonded(p_att), 1) @@ -131,15 +136,18 @@ def calc_distance_mean_fret(self): @property def fret_efficiency_mean(self): - return np.interp(self.dist_center_center, self._distances_, self._e_mean_) + return np.interp(self.dist_center_center, self._distances_, + self._e_mean_) @property def distance_mean(self): - return np.interp(self.dist_center_center, self._distances_, self._d_mean_) + return np.interp(self.dist_center_center, self._distances_, + self._d_mean_) @property def distance_mean_fret(self): - return np.interp(self.dist_center_center, self._distances_, self._d_mean_fret_) + return np.interp(self.dist_center_center, self._distances_, + self._d_mean_fret_) def __call__(self, value: float, distance_type: int): self.dist_center_center = value @@ -159,7 +167,8 @@ def __init__( ): self._forster_radius_ = forster_radius self._sigma_ = sigma - self._distances_ = np.linspace(*distance_range, n_distances, dtype=np.float64) + self._distances_ = np.linspace( + *distance_range, n_distances, dtype=np.float64) self._density_ = np.zeros_like(self._distances_) self._update_fret_efficiencies_(self._forster_radius_) self._update_lookup() @@ -172,7 +181,7 @@ def read_xlink_table(fn: str) -> typing.Dict[int, typing.Dict]: :return: """ # Read the xlink table - xlinks = {} # a dict of the xlinks, the keys are used to address the xlinks + xlinks = {} # dict of the xlinks, the keys are used to address the xlinks xlink_idx = 0 with open(fn, 'r') as fp: lines = fp.readlines() @@ -193,4 +202,3 @@ def read_xlink_table(fn: str) -> typing.Dict[int, typing.Dict]: except ValueError: pass return xlinks - diff --git a/src/AV.cpp b/src/AV.cpp index 17ab6396..69f59f6a 100644 --- a/src/AV.cpp +++ b/src/AV.cpp @@ -53,8 +53,8 @@ double av_distance( // Draw points using Inverse transform sampling auto el3getter = [](const IMP::algebra::Vector4D &p) { return p[3]; }; using points_type = std::vector; - auto m1 = av1.get_map(); - auto m2 = av2.get_map(); + Pointer m1 = av1.get_map(); + Pointer m2 = av2.get_map(); auto p1 = m1->get_xyz_density(); auto p2 = m2->get_xyz_density(); if(!p1.empty() && !p2.empty()){ @@ -103,13 +103,13 @@ double av_distance( IMP::bff::PathMap* AV::get_map() const{ // get_map needs to be const - if(av_map_ == nullptr){ + if(!av_map_) { // cast away const to init map ¯\_(ツ)_/¯ AV* ptr = (AV*)(this); ptr->init_path_map(); ptr->resample(); } - return av_map_; + return av_map_.get(); } IMP::algebra::Vector3D AV::get_mean_position(bool include_source) const{ @@ -272,7 +272,7 @@ IMP::ParticleIndex search_labeling_site( void get_xyz_density(); std::vector av_random_points(const AV& av, int n_samples){ - auto m = av.get_map(); + Pointer m = av.get_map(); auto d = m->get_xyz_density(); std::vector data; if(!d.empty()){ diff --git a/src/DecayLifetimeHandler.cpp b/src/DecayLifetimeHandler.cpp index 0806409d..0691b91e 100644 --- a/src/DecayLifetimeHandler.cpp +++ b/src/DecayLifetimeHandler.cpp @@ -57,7 +57,7 @@ DecayLifetimeHandler::DecayLifetimeHandler( bool use_amplitude_threshold, bool abs_lifetime_spectrum, double amplitude_threshold -){ +) : Object("DecayLifetimeHandler%1%") { set_use_amplitude_threshold(use_amplitude_threshold); set_abs_lifetime_spectrum(abs_lifetime_spectrum); set_amplitude_threshold(amplitude_threshold); diff --git a/src/DecayRoutines.cpp b/src/DecayRoutines.cpp index 3917c2b4..ae5cc88f 100644 --- a/src/DecayRoutines.cpp +++ b/src/DecayRoutines.cpp @@ -1,4 +1,5 @@ #include +#include IMPBFF_BEGIN_NAMESPACE @@ -82,7 +83,7 @@ void decay_fconv(double *fit, double *x, double *lamp, int numexp, int start, in // fast convolution AVX void decay_fconv_avx(double *fit, double *x, double *lamp, int numexp, int start, int stop, double dt) { -#ifdef WITH_AVX +#ifdef IMP_BFF_USE_AVX int start1 = std::max(1, start); // make sure that there are always multiple of 4 in the lifetimes @@ -148,7 +149,9 @@ void decay_fconv_avx(double *fit, double *x, double *lamp, int numexp, int start } } _mm_free(ex); _mm_free(p); free(l2); -#endif //WITH_AVX +#else + IMP_NOT_IMPLEMENTED; +#endif //IMP_BFF_USE_AVX } @@ -204,7 +207,7 @@ void decay_fconv_per(double *fit, double *x, double *lamp, int numexp, int start // fast convolution, high repetition rate, AVX void decay_fconv_per_avx(double *fit, double *x, double *lamp, int numexp, int start, int stop, int n_points, double period, double dt) { -#ifdef WITH_AVX +#ifdef IMP_BFF_USE_AVX #if IMPBFF_VERBOSE std::clog << "FCONV_PER_AVX" << std::endl; std::clog << "-- numexp: " << numexp << std::endl; @@ -325,8 +328,9 @@ void decay_fconv_per_avx(double *fit, double *x, double *lamp, int numexp, int s } } free(l2); _mm_free(p); _mm_free(ex); _mm_free(scale); _mm_free(tails); - -#endif //WITH_AVX +#else + IMP_NOT_IMPLEMENTED; +#endif //IMP_BFF_USE_AVX } @@ -339,7 +343,7 @@ void decay_fconv_per_cs(double *fit, double *x, double *lamp, int numexp, int st stop1, period_n = (int)ceil(period/dt-0.5); double fitcurr, expcurr, tail_a, deltathalf = dt*0.5; - for (i=0; i<=stop; i++) fit[i]=0; + for (i=0; i< stop; i++) fit[i]=0; stop1 = (period_n > n_points-1) ? n_points-1 : period_n; /* convolution */ @@ -357,7 +361,7 @@ void decay_fconv_per_cs(double *fit, double *x, double *lamp, int numexp, int st fit[i] += fitcurr*x[2*ne]; } fitcurr *= exp(-(period_n - stop1)*dt/x[2*ne+1]); - for (i=0; i<=stop; i++) { + for (i=0; i< stop; i++) { fitcurr *= expcurr; fit[i] += fitcurr*x[2*ne]*tail_a; } @@ -513,18 +517,17 @@ void decay_fconv_per_cs_time_axis( double period ){ double dt = time_axis[1] - time_axis[0]; -#ifdef WITH_AVX +#ifdef IMP_BFF_USE_AVX decay_fconv_per_avx( model, lifetime_spectrum, irf, (int) n_lifetime_spectrum / 2, convolution_start, convolution_stop, n_model, period, dt ); -#endif //WITH_AVX -#ifndef WITH_AVX +#else decay_fconv_per( model, lifetime_spectrum, irf, (int) n_lifetime_spectrum / 2, convolution_start, convolution_stop, n_model, period, dt ); -#endif //WITH_AVX +#endif //IMP_BFF_USE_AVX } @@ -538,7 +541,7 @@ void decay_fconv_cs_time_axis( int convolution_stop ){ double dt = time_axis[1] - time_axis[0]; -#ifdef WITH_AVX +#ifdef IMP_BFF_USE_AVX decay_fconv_avx( output, lifetime_spectrum, @@ -546,8 +549,7 @@ void decay_fconv_cs_time_axis( (int) n_lifetime_spectrum / 2, convolution_start, convolution_stop, dt ); -#endif //WITH_AVX -#ifndef WITH_AVX +#else decay_fconv( output, lifetime_spectrum, @@ -555,7 +557,7 @@ void decay_fconv_cs_time_axis( (int) n_lifetime_spectrum / 2, convolution_start, convolution_stop, dt ); -#endif //WITH_AVX +#endif //IMP_BFF_USE_AVX } IMPBFF_END_NAMESPACE diff --git a/src/DecayScale.cpp b/src/DecayScale.cpp index d6a55e84..4b3731b2 100644 --- a/src/DecayScale.cpp +++ b/src/DecayScale.cpp @@ -1,4 +1,5 @@ #include +#include IMPBFF_BEGIN_NAMESPACE @@ -80,4 +81,4 @@ void DecayScale::add(DecayCurve* decay){ } } -IMPBFF_END_NAMESPACE \ No newline at end of file +IMPBFF_END_NAMESPACE diff --git a/src/PathMap.cpp b/src/PathMap.cpp index 9ff7663f..e7dedf5a 100644 --- a/src/PathMap.cpp +++ b/src/PathMap.cpp @@ -73,7 +73,7 @@ void PathMap::find_path( heuristic = [&](long left, long right){ return 0.0; }; - } else if (heuristic_mode == 1) { // A* (euclidian) + } else if (heuristic_mode == 1) { // A* (euclidean) heuristic = [&](long left, long right){ auto dx = (x_loc_[left] - x_loc_[right]); auto dy = (y_loc_[left] - y_loc_[right]); @@ -149,7 +149,7 @@ void PathMap::update_tiles( if(reset_tile_edges){ edge_computed.resize(0); - edge_computed.resize(false, nvox); + edge_computed.resize(nvox, false); } normalized_ = false; diff --git a/src/PathMapHeader.cpp b/src/PathMapHeader.cpp index 0ec1cff5..c01d405e 100644 --- a/src/PathMapHeader.cpp +++ b/src/PathMapHeader.cpp @@ -84,5 +84,8 @@ void PathMapHeader::update_map_dimensions(int nx, int ny, int nz){ density_header_.compute_xyz_top(true); } +void PathMapHeader::show(std::ostream &out) const { + out << "PathMapHeader" << std::endl; +} IMPBFF_END_NAMESPACE diff --git a/src/PathMapTile.cpp b/src/PathMapTile.cpp index 7803891d..bcfb5c1b 100644 --- a/src/PathMapTile.cpp +++ b/src/PathMapTile.cpp @@ -7,6 +7,8 @@ * */ #include +#include +#include IMPBFF_BEGIN_NAMESPACE diff --git a/test/broken/test_bff_Session.py b/test/broken/test_bff_Session.py deleted file mode 100644 index fc5f0d4d..00000000 --- a/test/broken/test_bff_Session.py +++ /dev/null @@ -1,108 +0,0 @@ -import utils -import os -import unittest -import numpy as np - -TOPDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) -utils.set_search_paths(TOPDIR) - -import IMP.bff -from constants import * - - -class Tests(unittest.TestCase): - - def test_session_init(self): - n1 = IMP.bff.CnNode( - ports={ - 'portA': IMP.bff.CnPort(1), - 'portB': IMP.bff.CnPort(2), - 'portC': IMP.bff.CnPort(3) - }, - ) - n2 = IMP.bff.CnNode( - ports={ - 'inA': IMP.bff.CnPort(5), - 'inB': IMP.bff.CnPort(7), - 'outA': IMP.bff.CnPort(11, False, True), - 'outB': IMP.bff.CnPort(13, False, True) - } - ) - - s1 = IMP.bff.Session() - s1.add_node("nodeA", n1) - s1.add_node("nodeB", n2) - - nodes = { - "nodeA": n1, - "nodeB": n2 - } - s2 = IMP.bff.Session(nodes) - - na1 = s1.nodes['nodeA'] - na2 = s2.nodes['nodeA'] - na1.name = "new name" - - # the nodes are references - self.assertEqual(na1.name, na2.name) - - def test_read_session_template(self): - template_file = "examples/session_template.json" - - with open(template_file, 'r') as fp: - json_string = fp.read() - - s = IMP.bff.Session() - s.read_session_template(json_string) - - nodeA = s.nodes[list(s.nodes.keys())[0]] - nodeB = s.nodes[list(s.nodes.keys())[1]] - - # test reading of nodes - self.assertListEqual( - list(s.nodes.keys()), - ['nodeA', 'nodeB'] - ) - - # test reading of ports - self.assertListEqual( - nodeA.get_input_ports().keys(), - ['inA'] - ) - - # test reading of port values - self.assertListEqual( - list(np.hstack([d.value for d in nodeA.get_input_ports().values()])), - [1., 2., 3., 4., 5.] - ) - - # test evaluate - nodeA.evaluate() - - nodeA_inA = nodeA.get_port("inA") - nodeB_inA = nodeB.get_port("inA") - - # test links - self.assertListEqual( - list(nodeA_inA.value), - list(nodeB_inA.value) - ) - - v = list(np.hstack([d.value for d in nodeA.get_output_ports().values()])) - self.assertListEqual(v, [1., 2., 3., 4., 5.]) - - def test_create_node_template(self): - template_file = "examples/node_template.json" - json_string = "" - with open(template_file, 'r') as fp: - json_string = fp.read() - s = IMP.bff.Session() - s.read_session_template(json_string) - nodeA = s.create_node(json_string, "node_name") - - v = list(nodeA.get_output_port('outA').value) - self.assertListEqual(v, [1., 2., 4., 8., 16.]) - - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/test/constants.py b/test/constants.py deleted file mode 100644 index d9a83e09..00000000 --- a/test/constants.py +++ /dev/null @@ -1,18 +0,0 @@ -import IMP.bff as bff - - -DB_DICT = { - 'uri_string': "mongodb://localhost:27017", - 'db_string': "IMP_bff", - 'app_string': "bff", - 'collection_string': "test_collection" -} - - -def connects_to_db(): - mo = bff.CnMongoObject() - mo.connect_to_db(**DB_DICT) - return mo.is_connected_to_db - - -CONNECTS = connects_to_db() diff --git a/test/test_AVNetworkRestraint.py b/test/expensive_test_AVNetworkRestraint.py similarity index 96% rename from test/test_AVNetworkRestraint.py rename to test/expensive_test_AVNetworkRestraint.py index 67b555fa..cb2a633b 100644 --- a/test/test_AVNetworkRestraint.py +++ b/test/expensive_test_AVNetworkRestraint.py @@ -1,9 +1,5 @@ -from __future__ import division import unittest -import tempfile - -import math import json import numpy as np import numpy.testing @@ -13,6 +9,7 @@ import IMP.atom import IMP.em import IMP.bff +import IMP.test create_references = False @@ -49,7 +46,7 @@ def get_av( return av -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): """ Tests for the bff.AVNetworkRestraint class. """ @@ -102,3 +99,7 @@ def test_decorate_particle(self): experiment.append(d['distance']) np.testing.assert_almost_equal(model_ref, model, decimal=0) np.testing.assert_almost_equal(experiment_ref, experiment_ref, decimal=0) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_AccessibleVolume.py b/test/expensive_test_AccessibleVolume.py similarity index 94% rename from test/test_AccessibleVolume.py rename to test/expensive_test_AccessibleVolume.py index 46a5cb9b..4e2b56bb 100644 --- a/test/test_AccessibleVolume.py +++ b/test/expensive_test_AccessibleVolume.py @@ -1,4 +1,3 @@ -from __future__ import division import unittest import tempfile @@ -12,6 +11,7 @@ import IMP.atom import IMP.em import IMP.bff +import IMP.test create_references = False @@ -48,7 +48,7 @@ def get_av( return av -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): """ Tests for the bff.AV class. """ @@ -72,7 +72,9 @@ def test_decorate_particle(self): np.testing.assert_almost_equal(av.get_mean_position(), (-15.9244, 19.2183, 20.1207), decimal=3) np.testing.assert_almost_equal(av.get_radii(), (3.5, 0, 0), decimal=3) self.assertEqual(av.get_parameters_are_optimized(), False) - self.assertEqual(str(av.get_source()), '"Atom CB of residue 55"') + p = av.get_source() + self.assertIsInstance(p, IMP.Particle) + self.assertEqual(p.get_index(), source.get_index()) def test_AccessibleVolumeDecorator(self): """ @@ -98,7 +100,7 @@ def test_access_av_feature(self): IMP.em.write_map(av1_map, temp_file.name) pm_features = [ - IMP.bff.PM_TILE_PENALTY, # Penality of visiting a tile + IMP.bff.PM_TILE_PENALTY, # Penalty of visiting a tile IMP.bff.PM_TILE_COST, # Cost of a path to the tile IMP.bff.PM_TILE_DENSITY, # Density of tile IMP.bff.PM_TILE_COST_DENSITY, # Cost * Density of tile @@ -113,7 +115,8 @@ def test_access_av_feature(self): for feature in pm_features: with tempfile.NamedTemporaryFile(suffix=".mrc") as temp_file: fn = temp_file.name - fn_ref = "./references/av_reference_%s.mrc" % feature + fn_ref = self.get_input_file_name( + "av_reference_%s.mrc" % feature) if create_references: fn = fn_ref IMP.bff.write_path_map(av1_map, fn, feature, bounds) @@ -180,7 +183,7 @@ def test_av_av_distance(self): distance_type=t, n_samples=n_samples ) - self.assertAlmostEqual(v, ref, places=1) + self.assertAlmostEqual(v, ref, delta=0.08) # Test distance between AV and empty AV # create an AV in an inaccessible region @@ -218,3 +221,6 @@ def test_distance_distributions(self): ssdev = np.sum((p_rda_ref - p_rda)**2.) self.assertEqual(ssdev < 30000, True) + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/references/av_reference_0.mrc b/test/input/av_reference_0.mrc similarity index 100% rename from test/references/av_reference_0.mrc rename to test/input/av_reference_0.mrc diff --git a/test/references/av_reference_1.mrc b/test/input/av_reference_1.mrc similarity index 100% rename from test/references/av_reference_1.mrc rename to test/input/av_reference_1.mrc diff --git a/test/references/av_reference_2.mrc b/test/input/av_reference_2.mrc similarity index 100% rename from test/references/av_reference_2.mrc rename to test/input/av_reference_2.mrc diff --git a/test/references/av_reference_3.mrc b/test/input/av_reference_3.mrc similarity index 100% rename from test/references/av_reference_3.mrc rename to test/input/av_reference_3.mrc diff --git a/test/references/av_reference_4.mrc b/test/input/av_reference_4.mrc similarity index 100% rename from test/references/av_reference_4.mrc rename to test/input/av_reference_4.mrc diff --git a/test/references/av_reference_5.mrc b/test/input/av_reference_5.mrc similarity index 100% rename from test/references/av_reference_5.mrc rename to test/input/av_reference_5.mrc diff --git a/test/references/av_reference_6.mrc b/test/input/av_reference_6.mrc similarity index 100% rename from test/references/av_reference_6.mrc rename to test/input/av_reference_6.mrc diff --git a/test/references/av_reference_7.mrc b/test/input/av_reference_7.mrc similarity index 100% rename from test/references/av_reference_7.mrc rename to test/input/av_reference_7.mrc diff --git a/test/references/av_reference_8.mrc b/test/input/av_reference_8.mrc similarity index 100% rename from test/references/av_reference_8.mrc rename to test/input/av_reference_8.mrc diff --git a/test/standards_exceptions b/test/standards_exceptions new file mode 100644 index 00000000..332b809d --- /dev/null +++ b/test/standards_exceptions @@ -0,0 +1,105 @@ +show_exceptions=[ + 'VectorDouble', 'VectorFloat', 'VectorInt', 'VectorLong', + 'VectorPathMapTile', 'VectorPathMapTileEdge', 'VectorString', + 'MapStringAVPairDistanceMeasurement', 'DecayCurve', 'PairFloatFloat', + 'PathMapTile'] + +value_object_exceptions=[ + 'VectorDouble', 'VectorFloat', 'VectorInt', 'VectorLong', + 'VectorPathMapTile', 'VectorPathMapTileEdge', 'VectorString', + 'MapStringAVPairDistanceMeasurement', 'PathMapHeader', + 'DecayCurve', 'PairFloatFloat', 'PathMapTile'] + +function_name_exceptions=[ + 'AV.init_path_map', 'AV.normalize_rotation', + 'AV.pull_back_body_member_adjoints', 'AV.pull_back_member_adjoints', + 'AV.pull_back_members_adjoints', 'AV.resample', + 'AVNetworkRestraint.get_used_avs', 'AVPairDistanceMeasurement.get_json', + 'AVPairDistanceMeasurement.score_model', + 'DecayConvolution.compute_corrected_irf', 'DecayConvolution.get_irf', + 'DecayConvolution.resize', 'DecayConvolution.set_irf', 'DecayCurve.empty', + 'DecayCurve.get_json', 'DecayCurve.read_json', 'DecayCurve.resize', + 'DecayCurve.shift_array', 'DecayCurve.size', 'DecayCurve.sum', + 'DecayLinearization.resize', 'DecayModifier.resize', 'DecayPattern.resize', + 'DecayPileup.resize', 'DecayScale.resize', + 'MapStringAVPairDistanceMeasurement.asdict', + 'MapStringAVPairDistanceMeasurement.begin', + 'MapStringAVPairDistanceMeasurement.count', + 'MapStringAVPairDistanceMeasurement.empty', + 'MapStringAVPairDistanceMeasurement.end', + 'MapStringAVPairDistanceMeasurement.has_key', + 'MapStringAVPairDistanceMeasurement.items', + 'MapStringAVPairDistanceMeasurement.iterator', + 'MapStringAVPairDistanceMeasurement.iteritems', + 'MapStringAVPairDistanceMeasurement.iterkeys', + 'MapStringAVPairDistanceMeasurement.itervalues', + 'MapStringAVPairDistanceMeasurement.key_iterator', + 'MapStringAVPairDistanceMeasurement.keys', + 'MapStringAVPairDistanceMeasurement.lower_bound', + 'MapStringAVPairDistanceMeasurement.rbegin', + 'MapStringAVPairDistanceMeasurement.rend', + 'MapStringAVPairDistanceMeasurement.size', + 'MapStringAVPairDistanceMeasurement.upper_bound', + 'MapStringAVPairDistanceMeasurement.value_iterator', + 'MapStringAVPairDistanceMeasurement.values', + 'PathMap.calcRMS', 'PathMap.calc_all_voxel2loc', 'PathMap.copy_map', + 'PathMap.fill_sphere', 'PathMap.find_path_astar', + 'PathMap.find_path_dijkstra', 'PathMap.get_maximum_value_in_xy_plane', + 'PathMap.get_maximum_value_in_xz_plane', + 'PathMap.get_maximum_value_in_yz_plane', + 'PathMap.get_neighbor_idx_offsets', 'PathMap.is_normalized', + 'PathMap.is_part_of_volume', 'PathMap.is_xyz_ind_part_of_volume', + 'PathMap.lower_voxel_shift', 'PathMap.multiply', 'PathMap.pad', + 'PathMap.pad_margin', 'PathMap.pick_max', 'PathMap.project', + 'PathMap.resample', 'PathMap.resize', 'PathMap.same_dimensions', + 'PathMap.same_origin', 'PathMap.same_voxel_size', + 'PathMap.sample_obstacles', 'PathMap.std_normalize', + 'PathMap.upper_voxel_shift', 'PathMap.xyz_ind2voxel', + 'PathMapTile.backtrack_to_path', 'VectorDouble.append', + 'VectorDouble.assign', 'VectorDouble.back', 'VectorDouble.begin', + 'VectorDouble.capacity', 'VectorDouble.empty', 'VectorDouble.end', + 'VectorDouble.front', 'VectorDouble.insert', 'VectorDouble.iterator', + 'VectorDouble.rbegin', 'VectorDouble.rend', 'VectorDouble.resize', + 'VectorDouble.size', 'VectorFloat.append', 'VectorFloat.assign', + 'VectorFloat.back', 'VectorFloat.begin', 'VectorFloat.capacity', + 'VectorFloat.empty', 'VectorFloat.end', 'VectorFloat.front', + 'VectorFloat.insert', 'VectorFloat.iterator', 'VectorFloat.rbegin', + 'VectorFloat.rend', 'VectorFloat.resize', 'VectorFloat.size', + 'VectorInt.append', 'VectorInt.assign', 'VectorInt.back', + 'VectorInt.begin', 'VectorInt.capacity', 'VectorInt.empty', + 'VectorInt.end', 'VectorInt.front', 'VectorInt.insert', + 'VectorInt.iterator', 'VectorInt.rbegin', 'VectorInt.rend', + 'VectorInt.resize', 'VectorInt.size', 'VectorLong.append', + 'VectorLong.assign', 'VectorLong.back', 'VectorLong.begin', + 'VectorLong.capacity', 'VectorLong.empty', 'VectorLong.end', + 'VectorLong.front', 'VectorLong.insert', 'VectorLong.iterator', + 'VectorLong.rbegin', 'VectorLong.rend', 'VectorLong.resize', + 'VectorLong.size', 'VectorPathMapTile.append', 'VectorPathMapTile.assign', + 'VectorPathMapTile.back', 'VectorPathMapTile.begin', + 'VectorPathMapTile.capacity', 'VectorPathMapTile.empty', + 'VectorPathMapTile.end', 'VectorPathMapTile.front', + 'VectorPathMapTile.insert', 'VectorPathMapTile.iterator', + 'VectorPathMapTile.rbegin', 'VectorPathMapTile.rend', + 'VectorPathMapTile.resize', 'VectorPathMapTile.size', + 'VectorPathMapTileEdge.append', 'VectorPathMapTileEdge.assign', + 'VectorPathMapTileEdge.back', 'VectorPathMapTileEdge.begin', + 'VectorPathMapTileEdge.capacity', 'VectorPathMapTileEdge.empty', + 'VectorPathMapTileEdge.end', 'VectorPathMapTileEdge.front', + 'VectorPathMapTileEdge.insert', 'VectorPathMapTileEdge.iterator', + 'VectorPathMapTileEdge.rbegin', 'VectorPathMapTileEdge.rend', + 'VectorPathMapTileEdge.resize', 'VectorPathMapTileEdge.size', + 'VectorString.append', 'VectorString.assign', 'VectorString.back', + 'VectorString.begin', 'VectorString.capacity', 'VectorString.empty', + 'VectorString.end', 'VectorString.front', 'VectorString.insert', + 'VectorString.iterator', 'VectorString.rbegin', 'VectorString.rend', + 'VectorString.resize', 'VectorString.size', 'av_distance', + 'av_distance_distribution', 'av_random_distances', 'av_random_points', + 'decay_add_pile_up_to_model', 'decay_fconv', 'decay_fconv_avx', + 'decay_fconv_cs_time_axis', 'decay_fconv_per', 'decay_fconv_per_avx', + 'decay_fconv_per_cs', 'decay_fconv_per_cs_time_axis', 'decay_fconv_ref', + 'decay_rescale', 'decay_rescale_w', 'decay_rescale_w_bg', 'decay_sconv', + 'decay_shift_lamp', 'discriminate_small_amplitudes', 'mod_p', + 'search_labeling_site'] + +spelling_exceptions=['xz', 'yz', 'json', 'dijkstra', 'avs', 'idx', 'xy', + 'irf', 'astar', 'linearizations'] diff --git a/test/test_DecayConvolution.py b/test/test_DecayConvolution.py index 7dbcf1d5..4fa1f86b 100644 --- a/test/test_DecayConvolution.py +++ b/test/test_DecayConvolution.py @@ -1,10 +1,8 @@ -from __future__ import division import unittest -import platform - import numpy as np import numpy.testing import IMP.bff +import IMP.test x = np.linspace(0, 20, 32) irf_position = 2.0 @@ -23,41 +21,7 @@ def norm_pdf(x, mu, sigma): irf_y = norm_pdf(x, irf_position, irf_width) -class Tests(unittest.TestCase): - - def test_DecayConvolution_init(self): - irf = IMP.bff.DecayCurve(x, irf_y) - lh = IMP.bff.DecayLifetimeHandler([1, 4]) - settings = { - "lifetime_handler": lh, - "instrument_response_function": irf, - "convolution_method": IMP.bff.DecayConvolution.FAST, - "excitation_period": 100, - "irf_shift_channels": 0.0, - "irf_background_counts": 0.0, - "start": 0, "stop": -1, - "active": True - } - dc = IMP.bff.DecayConvolution(**settings) - decay = IMP.bff.DecayCurve(x) - dc.add(decay) - ref = np.array([1.19203776e-10, 1.59816046e-05, 2.61648339e-02, 4.63676222e-01, - 8.17250308e-01, 7.51713472e-01, 6.39828454e-01, 5.44522781e-01, - 4.63413367e-01, 3.94385610e-01, 3.35639884e-01, 2.85644631e-01, - 2.43096423e-01, 2.06885985e-01, 1.76069274e-01, 1.49842868e-01, - 1.27523017e-01, 1.08527821e-01, 9.23620548e-02, 7.86042610e-02, - 6.68957600e-02, 5.69312992e-02, 4.84510951e-02, 4.12340602e-02, - 3.50920390e-02, 2.98649029e-02, 2.54163750e-02, 2.16304778e-02, - 1.84085090e-02, 1.56664688e-02, 1.33328693e-02, 1.13468712e-02]) - np.testing.assert_allclose(decay.y, ref) - ref = np.array([ 0. , 0.64516129, 1.29032258, 1.93548387, 2.58064516, - 3.22580645, 3.87096774, 4.51612903, 5.16129032, 5.80645161, - 6.4516129 , 7.09677419, 7.74193548, 8.38709677, 9.03225806, - 9.67741935, 10.32258065, 10.96774194, 11.61290323, 12.25806452, - 12.90322581, 13.5483871 , 14.19354839, 14.83870968, 15.48387097, - 16.12903226, 16.77419355, 17.41935484, 18.06451613, 18.70967742, - 19.35483871, 20. ]) - np.testing.assert_allclose(decay.x, ref) +class Tests(IMP.test.TestCase): def test_DecayConvolution_init(self): irf = IMP.bff.DecayCurve(x, irf_y) @@ -86,15 +50,13 @@ def test_DecayConvolution_init(self): IMP.bff.DecayConvolution.FAST_PERIODIC, IMP.bff.DecayConvolution.FAST ] - conv_methods_fast = [ - IMP.bff.DecayConvolution.FAST_AVX, - IMP.bff.DecayConvolution.FAST_PERIODIC_AVX - ] - if "AMD64" in platform.machine(): - if platform.system() == "Linux": - conv_methods += conv_methods_fast - elif platform.system() == "Windows": - conv_methods += conv_methods_fast + # Only test AVX functionality if it was enabled + if IMP.bff.IMP_BFF_HAS_AVX: + conv_methods_fast = [ + IMP.bff.DecayConvolution.FAST_AVX, + IMP.bff.DecayConvolution.FAST_PERIODIC_AVX + ] + conv_methods += conv_methods_fast for i in conv_methods: settings["convolution_method"] = i dc = IMP.bff.DecayConvolution(**settings) @@ -186,3 +148,6 @@ def test_mean_lifetime(self): decay = IMP.bff.DecayCurve(x, y) self.assertAlmostEqual(dc.get_mean_lifetime(decay), 7.812499963266247) + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayCurve.py b/test/test_DecayCurve.py index 6e3b877c..767b2aaa 100644 --- a/test/test_DecayCurve.py +++ b/test/test_DecayCurve.py @@ -1,10 +1,10 @@ -from __future__ import division import unittest import numpy as np import numpy.testing import math import IMP.bff +import IMP.test def norm_pdf(x, mu, sigma): @@ -15,7 +15,7 @@ def norm_pdf(x, mu, sigma): return pdf -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_shift(self): time_axis = np.linspace(0, 12, 25) @@ -94,3 +94,7 @@ def test_decay_curve_resize(self): np.testing.assert_allclose(d.x, np.array([0. , 0.1, 0.2, 0.3, 0.4])) d.resize(6) np.testing.assert_allclose(d.x, np.array([0. , 0.1, 0.2, 0.3, 0.4, 0.5])) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayLifetimeHandler.py b/test/test_DecayLifetimeHandler.py index c77801a9..aed63c50 100644 --- a/test/test_DecayLifetimeHandler.py +++ b/test/test_DecayLifetimeHandler.py @@ -1,11 +1,11 @@ -from __future__ import division import unittest import numpy as np import IMP.bff +import IMP.test -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_DecayLifetimeHandler_init(self): lt = IMP.bff.DecayLifetimeHandler() @@ -65,3 +65,7 @@ def test_DecayLifetimeHandler_setter_getter(self): l = np.array([1., 4]) lt.lifetime_spectrum = l self.assertEqual(np.allclose(lt.lifetime_spectrum, l), True) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayLinearization.py b/test/test_DecayLinearization.py index f81f1e92..7cbb0257 100644 --- a/test/test_DecayLinearization.py +++ b/test/test_DecayLinearization.py @@ -1,12 +1,12 @@ -from __future__ import division import unittest import numpy as np import IMP.bff +import IMP.test -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_lin(self): dt = 0.0141 @@ -35,3 +35,7 @@ def test_lin(self): 1.00678725, 1.00884042, 0.9865171, 1.] np.testing.assert_array_almost_equal(ref_lin, lin.y[::256]) np.testing.assert_array_almost_equal(ref_mdl, model.y[::256]) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayPattern.py b/test/test_DecayPattern.py index 17e3a517..67d2f244 100644 --- a/test/test_DecayPattern.py +++ b/test/test_DecayPattern.py @@ -1,12 +1,12 @@ -from __future__ import division import unittest import numpy as np import numpy.testing import IMP.bff +import IMP.test -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_constant_background(self): x = np.arange(0, 4, dtype=np.float64) @@ -41,3 +41,7 @@ def test_pattern(self): bg.add(dc) r = y * (1-f) + bg_pattern * f * y.sum() / np.sum(bg_pattern) + offset np.testing.assert_allclose(r, dc.y) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayPileup.py b/test/test_DecayPileup.py index cef1ddc3..7d15303f 100644 --- a/test/test_DecayPileup.py +++ b/test/test_DecayPileup.py @@ -1,11 +1,11 @@ -from __future__ import division import unittest import numpy as np import IMP.bff +import IMP.test -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_pileup(self): x = np.arange(0, 16) @@ -64,3 +64,7 @@ def test_pileup_setter_getter(self): dp.resize(10) self.assertEqual(len(dp.data.y), 10) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayRoutines.py b/test/test_DecayRoutines.py index 63dcdfc2..6cee01bb 100644 --- a/test/test_DecayRoutines.py +++ b/test/test_DecayRoutines.py @@ -1,10 +1,8 @@ -from __future__ import division - import unittest import numpy as np -import platform import IMP.bff +import IMP.test def norm_pdf(x, mu, sigma): @@ -28,7 +26,7 @@ def model_irf( -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): data = np.array( [ @@ -146,7 +144,8 @@ def test_fconv(self): np.testing.assert_array_almost_equal(model_ref, model_fconv) - if "AMD64" in platform.machine(): + # Only test AVX functionality if it was enabled + if IMP.bff.IMP_BFF_HAS_AVX: model_fconv_avx = np.zeros_like(irf) IMP.bff.decay_fconv_avx( fit=model_fconv_avx, @@ -194,8 +193,8 @@ def test_fconv_per(self): ) np.testing.assert_array_almost_equal(model_fconv_per, ref) - # AVX won't be supported on Apple -> M1 - if "AMD64" in platform.machine(): + # Only test AVX functionality if it was enabled + if IMP.bff.IMP_BFF_HAS_AVX: model_fconv_avx = np.zeros_like(irf) IMP.bff.decay_fconv_per_avx( fit=model_fconv_avx, @@ -318,3 +317,6 @@ def test_lamp_shift(self): ) np.testing.assert_array_almost_equal(ref, irf_shift) + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayScale.py b/test/test_DecayScale.py index ad8c4726..6b2b349b 100644 --- a/test/test_DecayScale.py +++ b/test/test_DecayScale.py @@ -1,9 +1,9 @@ -from __future__ import division import unittest import numpy as np import numpy.testing import IMP.bff +import IMP.test x = np.arange(0, 16) y = np.ones_like(x) * 100 @@ -18,7 +18,7 @@ } -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_scale_init(self): ds = IMP.bff.DecayScale(**settings) @@ -88,3 +88,7 @@ def test_scale_scale_3(self): ds.add(model) np.testing.assert_allclose(model.y, ds.data.y - 100) np.testing.assert_almost_equal(ds.number_of_photons, 16000) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/test_DecayScore.py b/test/test_DecayScore.py index 63f6b166..f3b28523 100644 --- a/test/test_DecayScore.py +++ b/test/test_DecayScore.py @@ -1,8 +1,8 @@ -from __future__ import division import unittest import numpy as np import IMP.bff +import IMP.test np.random.seed(42) @@ -19,7 +19,7 @@ } -class Tests(unittest.TestCase): +class Tests(IMP.test.TestCase): def test_score_1(self): dc = IMP.bff.DecayScore(**score_settings) @@ -94,3 +94,7 @@ def test_setter_getter(self): # self.assertEqual(np.allclose(dc.data.y, a1), True) # self.assertEqual(np.allclose(dc.model.y, a2), True) + + +if __name__ == '__main__': + IMP.test.main() diff --git a/test/utils.py b/test/utils.py deleted file mode 100644 index 8f42309a..00000000 --- a/test/utils.py +++ /dev/null @@ -1,72 +0,0 @@ -import os -import sys -import tempfile -import contextlib -import shutil -import unittest - -# If we're using Python 2.6, add in more modern unittest convenience methods -if not hasattr(unittest.TestCase, 'assertIn'): - def assertIn(self, member, container, msg=None): - return self.assertTrue(member in container, - msg or '%s not found in %s' % (member, container)) - def assertNotIn(self, member, container, msg=None): - return self.assertTrue(member not in container, - msg or '%s unexpectedly found in %s' - % (member, container)) - def assertIsInstance(self, obj, cls, msg=None): - return self.assertTrue(isinstance(obj, cls), - msg or '%s is not an instance of %s' % (obj, cls)) - def assertLessEqual(self, a, b, msg=None): - return self.assertTrue(a <= b, - msg or '%s not less than or equal to %s' % (a, b)) - def assertGreaterEqual(self, a, b, msg=None): - return self.assertTrue(a >= b, - msg or '%s not greater than or equal to %s' % (a, b)) - unittest.TestCase.assertIn = assertIn - unittest.TestCase.assertNotIn = assertNotIn - unittest.TestCase.assertIsInstance = assertIsInstance - unittest.TestCase.assertLessEqual = assertLessEqual - unittest.TestCase.assertGreaterEqual = assertGreaterEqual - -def set_search_paths(topdir): - """Set search paths so that we can import Python modules""" - os.environ['PYTHONPATH'] = topdir + os.pathsep \ - + os.environ.get('PYTHONPATH', '') - sys.path.insert(0, topdir) - -def get_input_file_name(topdir, fname): - """Return full path to a test input file""" - return os.path.join(topdir, 'test', 'input', fname) - -@contextlib.contextmanager -def temporary_directory(dir=None): - _tmpdir = tempfile.mkdtemp(dir=dir) - yield _tmpdir - shutil.rmtree(_tmpdir, ignore_errors=True) - -if 'coverage' in sys.modules: - import atexit - # Collect coverage information from subprocesses - __site_tmpdir = tempfile.mkdtemp() - with open(os.path.join(__site_tmpdir, 'sitecustomize.py'), 'w') as fh: - fh.write(""" -import coverage -import atexit -import os - -_cov = coverage.coverage(branch=True, data_suffix=True, auto_data=True, - data_file=os.path.join('%s', '.coverage')) -_cov.start() - -def _coverage_cleanup(c): - c.stop() -atexit.register(_coverage_cleanup, _cov) -""" % os.getcwd()) - - os.environ['PYTHONPATH'] = __site_tmpdir + os.pathsep \ - + os.environ.get('PYTHONPATH', '') - - def __cleanup(d): - shutil.rmtree(d, ignore_errors=True) - atexit.register(__cleanup, __site_tmpdir) diff --git a/tools b/tools deleted file mode 160000 index 83ab85c3..00000000 --- a/tools +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 83ab85c301b06555cf27982b5f05e080a7e5742e