Skip to content

Commit

Permalink
Develop (#48)
Browse files Browse the repository at this point in the history
* Rework readme (#6)

* Renamed actions and added badges to readme

* Switched slash for dash

* Fix import structure (#10)

* Fixed import structure

* Removed pull_request target as push also seems to trigger on pull request?

* Fix visualization helpers (#13)

* Fixed bugs

* Added pull_request again as trigger for workflow

* Update build_deploy.yml

* Fix compressing core and installed pre-commit (#15)

* Pre-commit test

* Added local hook for zipping core

* Added .zip and .tar.gz autozips into core_archives folder

* Zip test

* tar.gz test

* Compressing works, only really ugly workaround for moving files

* Refered to the archives in the README

* Fix datasets (#17)

* Release v0.2a1 (#14)

* Rework readme (#6)

* Renamed actions and added badges to readme

* Switched slash for dash

* Fix import structure (#10)

* Fixed import structure

* Removed pull_request target as push also seems to trigger on pull request?

* Fix visualization helpers (#13)

* Fixed bugs

* Added pull_request again as trigger for workflow

* Deleted old log file and changed setup version

* Restructured dataset files and added package_data to setup.py, also changed max-line-length for black to 79

* New setup for loading datasets

* Added dataset inclusion

* Added archiving for datasets

* Test for matrix include (#18)

* Test for matrix include

* Added runOns variable

* Changed to a custom action

* Added inputFile

* Copied literal line

* Changed strategy order

* Check only ubuntu

* Extended matrix with all OS and extra CIBW_BUILD ENV flag

* Added default of only python 3.6 builds for 64-bit if push is not to master

* Added enter to README

* Release v0.2a2 (#20)

* Release v0.2a1 (#14)

* Rework readme (#6)

* Renamed actions and added badges to readme

* Switched slash for dash

* Fix import structure (#10)

* Fixed import structure

* Removed pull_request target as push also seems to trigger on pull request?

* Fix visualization helpers (#13)

* Fixed bugs

* Added pull_request again as trigger for workflow

* Deleted old log file and changed setup version

* Changed master trigger to release trigger

* Moved wildcard

* Moved wildcard of JMESPath

* Added dot

* Trying starts_with

* Switched arguments

* Excluded python 2.7 pypy

* New jmespath filter test

* Changed version number

* Add PyTest to repo and CI (#21)

* Added first pytest script for protein class and a script for performing local tests.

* Added pytest in CI

* Forgot -r for file

* Version of pytest with pytest at end of pipeline

* New pytest CI where pip installs local package

* Fixed tabs and added caching of python/pip environment

* Removed dot and added removal of build dirs to manage clean command

* Added cache ignores for env setup and ids for the caches

* Fixed cache IDs

* Renamed cache because GitHub does not allow for clearing caches...

* Moved python setup to be before cache loading

* Run that will install the dependencies

* Uncommented the cache-hit detection for installing dependencies

* Updated pre-commit version in hope that runner will create new cache

* Added more tests and added flake8 incompatability

* Other flake8 config try

* Reset to .flake8 file

* Downgrade of pre-commit to force dep. installation in CI

* Different pre-commit version

* Added depth_first tests

* Added depth_first_bnb tests

* Push to try and install all dependencies correctly

* Added back cache check for installing dependencies. New way of calling flake8, added class dependencies on tests

* Removed ls

* Core change test

* Core change test - new correctly

* Core archiving works

* Fixed pytest ordering and upgraded pandas version to trigger new cache

* Upgraded pandas

* Changed pandas version to 1.1.0

* Removed caching of CI and moved code to new PR

* Add CI caching for python environments (#23)

* Added first pytest script for protein class and a script for performing local tests.

* Added pytest in CI

* Forgot -r for file

* Version of pytest with pytest at end of pipeline

* New pytest CI where pip installs local package

* Fixed tabs and added caching of python/pip environment

* Removed dot and added removal of build dirs to manage clean command

* Added cache ignores for env setup and ids for the caches

* Fixed cache IDs

* Renamed cache because GitHub does not allow for clearing caches...

* Moved python setup to be before cache loading

* Run that will install the dependencies

* Uncommented the cache-hit detection for installing dependencies

* Updated pre-commit version in hope that runner will create new cache

* Added more tests and added flake8 incompatability

* Other flake8 config try

* Reset to .flake8 file

* Downgrade of pre-commit to force dep. installation in CI

* Different pre-commit version

* Added depth_first tests

* Added depth_first_bnb tests

* Push to try and install all dependencies correctly

* Added back cache check for installing dependencies. New way of calling flake8, added class dependencies on tests

* Removed ls

* Core change test

* Core change test - new correctly

* Core archiving works

* Fixed pytest ordering and upgraded pandas version to trigger new cache

* Upgraded pandas

* Changed pandas version to 1.1.0

* Dependency check

* new flake8 installation

* Flake8 action

* Added pip update flag

* Cleaned up the flake8 action usage

* Trying to install new deps

* Removed caching, only using dependencies during pytest

* Add documentation to project (#24)

* Ran the sphinx quickstart, ignored mypy on docs

* First version of docs

* Added installation instructions for python

* Finished installation page and added quickstart info (not done yet)

* Finished v1 of the quickstart guide

* Removed heterogeneous setup page and added todo for creating example

* Added manpages for the datasets and algorithms

* Added helpers and visualize documentation

* Added placeholders for the Protein properties

* Added methods of Protein to the documentation

* Small changes

* Reworked the README

* Added whitespace for enter

* Added github star and filler-logo

* Starting on logo

* Added logo

* Removed github fork banner

* Logo test

* Changed logo loading

* New test

* Trying image tag

* Trying image tag 2.0

* Trying image tag 2.0

* Trying relative link

* New size

* New logo test

* New logo try

* New logo

* Reworked logo

* Downgraded matplotlib to alllow CI pipeline

* Added edittable logo, fixed small rst things, fixed compression of cores

* Added some figures, added reference to license, added license

* Started on AminoAcid class (#28)

* Started on AminoAcid class

* Added comments in core, still bugs to sort out

* Fixed more bugs in the core when adding AminoAcid class

* Moved part of bind

* Integrated AminoAcid class and fixed Protein tests

* Mid way testing for new depth-first approach

* Added local check script and depth_first works for HPPH

* Fixed depth_first search new version

* Fixed depth_first_bnb algorithm using new system

* Fixed small core bugs, working on new logo

* Mid-way of changing bond_value  structure

* Cleaned up bugs from intermediate version. Bumped versions of requirements. Introduced max_weights string for keeping track of possible future scores. Merged bond_semetry model setup with the else model setup. Fixed bug with cur_len of protein always being 1. Fixed getting the weight of a amino bond

* Bumbed python version in github workflow for matplotlib version dependency

* Bumped workflow python version to 3.9 as numpy 1.23 requires so

* Removed h_idxs from prune function. Nothing has been tested

* Fixed Protein signature for pybind build

* Setup for debugging current protein issues

* Introduced core testing code

* Finished test script for amino acids

* Started on Protein core tests

* Fixed protein test compilation

* Fixed first couple protein generation checks

* Added more debug statements for core tests

* Fixed bugs with bond checks

* Fixed generation of weighted amino maps

* Finished all protein generation test

* Added debug options in script to run core tests with gdb

* Added removal of amino tests

* Updated some pytest asserts. Added pytest and core_test asserts for score updates

* Updated reference for black in pre-commit

* Try adding core build in github actions pipeline

* Fixed local algorithm core tests

* Fixed dfs_bnb

* Fixed pybind11 change to providing protein pointers

* Added special compilation case for MacOS

* Changed minimum Python version to 3.9 as 3.11 will release soon

* Changed always build to only build python 3.9 versions

* Changed CIwheel builds to be specific instead of exlcuding based

* Leaving documentation as is and adding issue for the future

* Added more licensing references

* Added config file for rtfd to set python version to 3.9

* Temp commit to switch branch

* Update core merge (#33)

* Started on AminoAcid class

* Added comments in core, still bugs to sort out

* Fixed more bugs in the core when adding AminoAcid class

* Moved part of bind

* Integrated AminoAcid class and fixed Protein tests

* Mid way testing for new depth-first approach

* Added local check script and depth_first works for HPPH

* Fixed depth_first search new version

* Fixed depth_first_bnb algorithm using new system

* Fixed small core bugs, working on new logo

* Mid-way of changing bond_value  structure

* Cleaned up bugs from intermediate version. Bumped versions of requirements. Introduced max_weights string for keeping track of possible future scores. Merged bond_semetry model setup with the else model setup. Fixed bug with cur_len of protein always being 1. Fixed getting the weight of a amino bond

* Bumbed python version in github workflow for matplotlib version dependency

* Bumped workflow python version to 3.9 as numpy 1.23 requires so

* Removed h_idxs from prune function. Nothing has been tested

* Fixed Protein signature for pybind build

* Setup for debugging current protein issues

* Introduced core testing code

* Finished test script for amino acids

* Started on Protein core tests

* Fixed protein test compilation

* Fixed first couple protein generation checks

* Added more debug statements for core tests

* Fixed bugs with bond checks

* Fixed generation of weighted amino maps

* Finished all protein generation test

* Added debug options in scriptn to run core tests with gdb

* Fixed the last_pos indexing error from place_amino. Changed the 'changed' variable to 'solutions_found'-like variable

* Solved typing issues

* Finished protein movement tests

* Added removal of amino tests

* Updated some pytest asserts. Added pytest and core_test asserts for score updates

* Updated reference for black in pre-commit

* Fixed score generation of core_test

* Fixed score update through removal

* Try adding core build in github actions pipeline

* Started on algorithm code

* Changed signature of depth_first to use pointers. Added testing code for 2d and 3d depth_first tests

* Fixed local algorithm core tests

* Fixed dfs_bnb

* Fixed pybind11 change to providing protein pointers

* Added dynamic_lookup for linking python in case of undefined symbols

* New way of setting -undefined flag

* Updated the way of passing -undefined setting for macos

* Added special compilation case for MacOS

* Saving Furo update for issue

* Changed minimum Python version to 3.9 as 3.11 will release soon

* Updated versions for wheel deployment

* Changed always build to only build python 3.9 versions

* Changed CIwheel builds to be specific instead of exlcuding based

* Leaving documentation as is and adding issue for the future

* Added more licensing references

* Added config file for rtfd to set python version to 3.9

* Removed commented code

* Merge visualization updates (#41) (#42)

* Develop merge into master to sync commits. (#41)

* Rework readme (#6)

* Renamed actions and added badges to readme

* Switched slash for dash

* Fix import structure (#10)

* Fixed import structure

* Removed pull_request target as push also seems to trigger on pull request?

* Fix visualization helpers (#13)

* Fixed bugs

* Added pull_request again as trigger for workflow

* Update build_deploy.yml

* Fix compressing core and installed pre-commit (#15)

* Pre-commit test

* Added local hook for zipping core

* Added .zip and .tar.gz autozips into core_archives folder

* Zip test

* tar.gz test

* Compressing works, only really ugly workaround for moving files

* Refered to the archives in the README

* Fix datasets (#17)

* Release v0.2a1 (#14)

* Rework readme (#6)

* Renamed actions and added badges to readme

* Switched slash for dash

* Fix import structure (#10)

* Fixed import structure

* Removed pull_request target as push also seems to trigger on pull request?

* Fix visualization helpers (#13)

* Fixed bugs

* Added pull_request again as trigger for workflow

* Deleted old log file and changed setup version

* Restructured dataset files and added package_data to setup.py, also changed max-line-length for black to 79

* New setup for loading datasets

* Added dataset inclusion

* Added archiving for datasets

* Test for matrix include (#18)

* Test for matrix include

* Added runOns variable

* Changed to a custom action

* Added inputFile

* Copied literal line

* Changed strategy order

* Check only ubuntu

* Extended matrix with all OS and extra CIBW_BUILD ENV flag

* Added default of only python 3.6 builds for 64-bit if push is not to master

* Added enter to README

* Release v0.2a2 (#20)

* Release v0.2a1 (#14)

* Rework readme (#6)

* Renamed actions and added badges to readme

* Switched slash for dash

* Fix import structure (#10)

* Fixed import structure

* Removed pull_request target as push also seems to trigger on pull request?

* Fix visualization helpers (#13)

* Fixed bugs

* Added pull_request again as trigger for workflow

* Deleted old log file and changed setup version

* Changed master trigger to release trigger

* Moved wildcard

* Moved wildcard of JMESPath

* Added dot

* Trying starts_with

* Switched arguments

* Excluded python 2.7 pypy

* New jmespath filter test

* Changed version number

* Add PyTest to repo and CI (#21)

* Added first pytest script for protein class and a script for performing local tests.

* Added pytest in CI

* Forgot -r for file

* Version of pytest with pytest at end of pipeline

* New pytest CI where pip installs local package

* Fixed tabs and added caching of python/pip environment

* Removed dot and added removal of build dirs to manage clean command

* Added cache ignores for env setup and ids for the caches

* Fixed cache IDs

* Renamed cache because GitHub does not allow for clearing caches...

* Moved python setup to be before cache loading

* Run that will install the dependencies

* Uncommented the cache-hit detection for installing dependencies

* Updated pre-commit version in hope that runner will create new cache

* Added more tests and added flake8 incompatability

* Other flake8 config try

* Reset to .flake8 file

* Downgrade of pre-commit to force dep. installation in CI

* Different pre-commit version

* Added depth_first tests

* Added depth_first_bnb tests

* Push to try and install all dependencies correctly

* Added back cache check for installing dependencies. New way of calling flake8, added class dependencies on tests

* Removed ls

* Core change test

* Core change test - new correctly

* Core archiving works

* Fixed pytest ordering and upgraded pandas version to trigger new cache

* Upgraded pandas

* Changed pandas version to 1.1.0

* Removed caching of CI and moved code to new PR

* Add CI caching for python environments (#23)

* Added first pytest script for protein class and a script for performing local tests.

* Added pytest in CI

* Forgot -r for file

* Version of pytest with pytest at end of pipeline

* New pytest CI where pip installs local package

* Fixed tabs and added caching of python/pip environment

* Removed dot and added removal of build dirs to manage clean command

* Added cache ignores for env setup and ids for the caches

* Fixed cache IDs

* Renamed cache because GitHub does not allow for clearing caches...

* Moved python setup to be before cache loading

* Run that will install the dependencies

* Uncommented the cache-hit detection for installing dependencies

* Updated pre-commit version in hope that runner will create new cache

* Added more tests and added flake8 incompatability

* Other flake8 config try

* Reset to .flake8 file

* Downgrade of pre-commit to force dep. installation in CI

* Different pre-commit version

* Added depth_first tests

* Added depth_first_bnb tests

* Push to try and install all dependencies correctly

* Added back cache check for installing dependencies. New way of calling flake8, added class dependencies on tests

* Removed ls

* Core change test

* Core change test - new correctly

* Core archiving works

* Fixed pytest ordering and upgraded pandas version to trigger new cache

* Upgraded pandas

* Changed pandas version to 1.1.0

* Dependency check

* new flake8 installation

* Flake8 action

* Added pip update flag

* Cleaned up the flake8 action usage

* Trying to install new deps

* Removed caching, only using dependencies during pytest

* Add documentation to project (#24)

* Ran the sphinx quickstart, ignored mypy on docs

* First version of docs

* Added installation instructions for python

* Finished installation page and added quickstart info (not done yet)

* Finished v1 of the quickstart guide

* Removed heterogeneous setup page and added todo for creating example

* Added manpages for the datasets and algorithms

* Added helpers and visualize documentation

* Added placeholders for the Protein properties

* Added methods of Protein to the documentation

* Small changes

* Reworked the README

* Added whitespace for enter

* Added github star and filler-logo

* Starting on logo

* Added logo

* Removed github fork banner

* Logo test

* Changed logo loading

* New test

* Trying image tag

* Trying image tag 2.0

* Trying image tag 2.0

* Trying relative link

* New size

* New logo test

* New logo try

* New logo

* Reworked logo

* Downgraded matplotlib to alllow CI pipeline

* Added edittable logo, fixed small rst things, fixed compression of cores

* Added some figures, added reference to license, added license

* Started on AminoAcid class (#28)

* Started on AminoAcid class

* Added comments in core, still bugs to sort out

* Fixed more bugs in the core when adding AminoAcid class

* Moved part of bind

* Integrated AminoAcid class and fixed Protein tests

* Mid way testing for new depth-first approach

* Added local check script and depth_first works for HPPH

* Fixed depth_first search new version

* Fixed depth_first_bnb algorithm using new system

* Fixed small core bugs, working on new logo

* Mid-way of changing bond_value  structure

* Cleaned up bugs from intermediate version. Bumped versions of requirements. Introduced max_weights string for keeping track of possible future scores. Merged bond_semetry model setup with the else model setup. Fixed bug with cur_len of protein always being 1. Fixed getting the weight of a amino bond

* Bumbed python version in github workflow for matplotlib version dependency

* Bumped workflow python version to 3.9 as numpy 1.23 requires so

* Removed h_idxs from prune function. Nothing has been tested

* Fixed Protein signature for pybind build

* Setup for debugging current protein issues

* Introduced core testing code

* Finished test script for amino acids

* Started on Protein core tests

* Fixed protein test compilation

* Fixed first couple protein generation checks

* Added more debug statements for core tests

* Fixed bugs with bond checks

* Fixed generation of weighted amino maps

* Finished all protein generation test

* Added debug options in script to run core tests with gdb

* Added removal of amino tests

* Updated some pytest asserts. Added pytest and core_test asserts for score updates

* Updated reference for black in pre-commit

* Try adding core build in github actions pipeline

* Fixed local algorithm core tests

* Fixed dfs_bnb

* Fixed pybind11 change to providing protein pointers

* Added special compilation case for MacOS

* Changed minimum Python version to 3.9 as 3.11 will release soon

* Changed always build to only build python 3.9 versions

* Changed CIwheel builds to be specific instead of exlcuding based

* Leaving documentation as is and adding issue for the future

* Added more licensing references

* Added config file for rtfd to set python version to 3.9

* Temp commit to switch branch

* Update core merge (#33)

* Started on AminoAcid class

* Added comments in core, still bugs to sort out

* Fixed more bugs in the core when adding AminoAcid class

* Moved part of bind

* Integrated AminoAcid class and fixed Protein tests

* Mid way testing for new depth-first approach

* Added local check script and depth_first works for HPPH

* Fixed depth_first search new version

* Fixed depth_first_bnb algorithm using new system

* Fixed small core bugs, working on new logo

* Mid-way of changing bond_value  structure

* Cleaned up bugs from intermediate version. Bumped versions of requirements. Introduced max_weights string for keeping track of possible future scores. Merged bond_semetry model setup with the else model setup. Fixed bug with cur_len of protein always being 1. Fixed getting the weight of a amino bond

* Bumbed python version in github workflow for matplotlib version dependency

* Bumped workflow python version to 3.9 as numpy 1.23 requires so

* Removed h_idxs from prune function. Nothing has been tested

* Fixed Protein signature for pybind build

* Setup for debugging current protein issues

* Introduced core testing code

* Finished test script for amino acids

* Started on Protein core tests

* Fixed protein test compilation

* Fixed first couple protein generation checks

* Added more debug statements for core tests

* Fixed bugs with bond checks

* Fixed generation of weighted amino maps

* Finished all protein generation test

* Added debug options in scriptn to run core tests with gdb

* Fixed the last_pos indexing error from place_amino. Changed the 'changed' variable to 'solutions_found'-like variable

* Solved typing issues

* Finished protein movement tests

* Added removal of amino tests

* Updated some pytest asserts. Added pytest and core_test asserts for score updates

* Updated reference for black in pre-commit

* Fixed score generation of core_test

* Fixed score update through removal

* Try adding core build in github actions pipeline

* Started on algorithm code

* Changed signature of depth_first to use pointers. Added testing code for 2d and 3d depth_first tests

* Fixed local algorithm core tests

* Fixed dfs_bnb

* Fixed pybind11 change to providing protein pointers

* Added dynamic_lookup for linking python in case of undefined symbols

* New way of setting -undefined flag

* Updated the way of passing -undefined setting for macos

* Added special compilation case for MacOS

* Saving Furo update for issue

* Changed minimum Python version to 3.9 as 3.11 will release soon

* Updated versions for wheel deployment

* Changed always build to only build python 3.9 versions

* Changed CIwheel builds to be specific instead of exlcuding based

* Leaving documentation as is and adding issue for the future

* Added more licensing references

* Added config file for rtfd to set python version to 3.9

* Removed commented code

* Splitted visualization function to allow for multiple styles

* Fixed function for plotting proteins

* Fixed bug where no bonds would form

* Fixed paper style

* V1 paper style plots

* Fixed first paper visualization. Added visualization to test set

* Ran pre-commit

* Increased version to make new visualizations available

* Add beam (#47)

* V1 (untested) of a beam_search function

* Compiles and runs, does not work

* In mids of debug

* Small changes

* Changed wrong author usage in toml. Fixing copy issues with proteins and amino acids

* Fixed copy operators for Protein and AminoAcid

* Fixed bug in assignment and copy operators. New try for testing beam, which is also semi fixed

* Fixed beam_search bugs

* Added a more specific heuristic function for beam search and removed unnescessary branching in reach_prune

* Solved bug in beam_search and add protein length to print

* Finished beam search tests

* Extended AminoAcid with << and = operator overloads

* Added ptests for beam search and naive prune

* Fixed typo for beam search class

* Trying other pytest approach for mac

* Trying run-on conditional from matrix

* Removed file specifier for pytest

* Added Windows runner check to linux

* Enabled windows runner again

* ALso removed big beam width

* Removing dir slash in setuptools for windows buil

* Removed windows due to Pybind11 bug
  • Loading branch information
okkevaneck authored Feb 6, 2023
1 parent c45b12a commit b9f0ddb
Show file tree
Hide file tree
Showing 19 changed files with 536 additions and 22 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ jobs:
- name: Build and install
run: pip install --verbose .

# Exclude beam_width specification for macOS as it has different results.
- name: Test with pytest
run: pytest
run: |
if [ "$RUNNER_OS" == "Linux" || "$RUNNER_OS" == "Windows" ]; then
pytest
elif [ "$RUNNER_OS" == "macOS" ]; then
pytest -k 'not TestBeamSearch'; \
pytest -k '_no_bw or _bw_m1'
fi
shell: bash

build_wheels:
name: Build wheels
Expand Down
Binary file modified archives/prospr_core.tar.gz
Binary file not shown.
Binary file modified archives/prospr_core.zip
Binary file not shown.
Binary file modified archives/prospr_data.tar.gz
Binary file not shown.
Binary file modified archives/prospr_data.zip
Binary file not shown.
11 changes: 9 additions & 2 deletions prospr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from prospr_core import AminoAcid, Protein, depth_first, depth_first_bnb
from prospr_core import (
AminoAcid,
Protein,
depth_first,
depth_first_bnb,
beam_search,
)
from .datasets import load_vanEck250, load_vanEck1000, load_vanEck_hratio
from .visualize import plot_protein

__version__ = "0.2a29"
__version__ = "0.2a30"

__all__ = [
"__version__",
"AminoAcid",
"Protein",
"depth_first",
"depth_first_bnb",
"beam_search",
"load_vanEck250",
"load_vanEck1000",
"load_vanEck_hratio",
Expand Down
6 changes: 6 additions & 0 deletions prospr/core/core_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace py = pybind11;
#include "src/protein.cpp"
#include "src/depth_first.cpp"
#include "src/depth_first_bnb.cpp"
#include "src/beam_search.cpp"


PYBIND11_MODULE(prospr_core, m) {
Expand Down Expand Up @@ -87,4 +88,9 @@ PYBIND11_MODULE(prospr_core, m) {
m.def("depth_first_bnb", depth_first_bnb,
"Finds the optimal conformation via depth-first branch-and-bound search",
py::arg("protein"), py::arg("prune_func")="");

/* Beam search function definition. */
m.def("beam_search", beam_search,
"Finds the optimal conformation via beam search",
py::arg("protein"), py::arg("beam_width")=-1);
}
27 changes: 27 additions & 0 deletions prospr/core/src/amino_acid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
*/

#include "amino_acid.hpp"
#include <iostream>


/* Copy constructor. */
AminoAcid::AminoAcid(const AminoAcid &other) {
this->type = other.type;
this->index = other.index;
this->prev_move = other.prev_move;
this->next_move = other.next_move;
}

/* Construct a new AminoAcid. */
AminoAcid::AminoAcid(char type, int index, int prev_move, int next_move) {
this->type = type;
Expand All @@ -16,6 +25,16 @@ AminoAcid::AminoAcid(char type, int index, int prev_move, int next_move) {
this->next_move = next_move;
}

/* Overload assignment operator for copy-assignments. */
AminoAcid& AminoAcid::operator=(const AminoAcid& other) {
this->type = other.type;
this->index = other.index;
this->prev_move = other.prev_move;
this->next_move = other.next_move;

return *this;
}

/* Returns the AminoAcid's type. */
char AminoAcid::get_type() {
return type;
Expand Down Expand Up @@ -45,3 +64,11 @@ void AminoAcid::set_prev_move(int move) {
void AminoAcid::set_next_move(int move) {
next_move = move;
}

/* Overload << operator for printing AminoAcids. */
std::ostream &operator<<(std::ostream &os, AminoAcid& amino_acid) {
std::cout << "<AminoAcid '" << amino_acid.get_type() << "' idx=" \
<< amino_acid.get_index() << " moves=[" << amino_acid.get_prev_move() \
<< "," << amino_acid.get_next_move() << "]>" << std::flush;
return os;
}
11 changes: 11 additions & 0 deletions prospr/core/src/amino_acid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
#ifndef AMINO_ACID_H
#define AMINO_ACID_H

#include <string>


class AminoAcid {
public:
/* Copy constructor. */
AminoAcid(const AminoAcid &other);

/* Construct a new AminoAcid. */
AminoAcid(char type, int index, int prev_move=0, int next_move=0);

/* Overload assignment operator for copy-assignments. */
AminoAcid& operator=(const AminoAcid &other);

/* Returns the AminoAcid's type. */
char get_type();

Expand All @@ -39,4 +47,7 @@ class AminoAcid {
int next_move;
};

/* Overload << operator for printing AminoAcids. */
std::ostream &operator<<(std::ostream &os, AminoAcid& amino_acid);

#endif
189 changes: 189 additions & 0 deletions prospr/core/src/beam_search.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/* File: beam_search.h
* Description: Source file for a beam search function.
* License: This file is licensed under the GNU LGPL V3 license by
* Okke van Eck (2020 - 2023). See the LICENSE file for the
* specifics.
*/

#include "beam_search.hpp"
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
#include <math.h>
#include <numeric>
#include <cstring>


/* Type for storing info on bondable amino acids. */
struct BondInfo {
int max_length;
int no_neighbors;
std::vector<int> max_weights;
size_t num_idxs;
std::vector<int> h_idxs;
std::vector<std::vector<int>> bond_dists;
};

/* Type for ordering proteins in a priority queue. */
struct PrioProtein {
Protein protein;
int score;
};

/* Overload > operator for Conformation in the priority queue.
* Bigger indicates more potential for leading towards the minimum energy
* conformation.
*/
bool operator>(const PrioProtein& lhs,
const PrioProtein& rhs) {
return lhs.score > rhs.score;
}

/* Overload << operator for printing PrioProteins. */
std::ostream &operator<<(std::ostream &os, PrioProtein& prot) {
std::cout << "<" << prot.score << ", [";

for (int i: prot.protein.hash_fold()) {
std::cout << i << " ";
}

std::cout << "]>";
return os;
}

/* Compute how amino acids can possibly form bonds. */
BondInfo _comp_bondable_aminos(Protein* protein) {
/* Fetch protein specific information. */
int max_length = protein->get_sequence().length();
int no_neighbors = (int)pow(2, (protein->get_dim() - 1));
std::vector<int> max_weights = protein->get_max_weights();
std::vector<int> h_idxs = {};
std::vector<std::vector<int>> bond_dists = {};

/* Create vector with distances between aminos that can create bonds. */
std::vector<int> cur_dists = {};

for (int i = 0; i < max_length; i++) {
/* Only include indexes that can create bonds. */
if (max_weights[i] != 0) {
/* Create vector with distances to previous bondable aminos. */
for (int idx : h_idxs) {
if (i - idx >= 3 && (i - idx) % 2 == 1) {
cur_dists.push_back(i - idx);
}
}

/* Add distance vector to set and clear for next iterations. */
bond_dists.push_back(cur_dists);
cur_dists.clear();

/* Add current index for next iterations. */
h_idxs.push_back(i);
}
}

/* Store info on possible bonds in BondInfo struct and return. */
BondInfo binfo = {max_length, no_neighbors, max_weights, h_idxs.size(),
h_idxs, bond_dists};
return binfo;
}

/* Compute heuristic score for protein to use in priority queue. */
int comp_score(Protein* protein, BondInfo* binfo) {
/* Compute to be placed aminos possibly making bonds. */
int future_aminos = 0;
for (auto h_idx : binfo->h_idxs) {
if (h_idx >= protein->get_cur_len()) {
future_aminos++;
}
}

/* Compute branch score with the to be placed amino acids. */
int branch_score = 0;
for (size_t i = binfo->num_idxs - future_aminos; i < binfo->num_idxs; i++) {
/* Check if bondable amino is last of protein. */
if (binfo->h_idxs[i] == binfo->max_length - 1) {
/* The last amino being bondable can create an additional bond. */
branch_score += binfo->max_weights[binfo->h_idxs[i]] *
std::min((size_t)binfo->no_neighbors + 1,
binfo->bond_dists[i].size());
} else {
branch_score += binfo->max_weights[binfo->h_idxs[i]] *
std::min((size_t)binfo->no_neighbors,
binfo->bond_dists[i].size());
}
}

return protein->get_score() + branch_score;
}

/* A beam search function for finding a minimum energy conformation. */
Protein* beam_search(Protein* protein, int beam_width) {
int max_length = protein->get_sequence().length();
int dim = protein->get_dim();

/* The first two amino acids are fixed to prevent y-axis symmetry. */
if (max_length > 1)
protein->place_amino(-1);
if (max_length <= 2)
return protein;

/* Create vector for current proteins, and a priority queue to filter. */
std::vector<PrioProtein> beam = {};
std::priority_queue<PrioProtein,
std::vector<PrioProtein>,
std::greater<PrioProtein>> cur_proteins = {};

/* Create vector with all moves. */
std::vector<int> all_moves(dim * 2 + 1);
std::iota(all_moves.begin(), all_moves.end(), -dim);
all_moves.erase(all_moves.begin() + dim);

/* Compute future bondable connections for heuristic scoring. */
BondInfo binfo = _comp_bondable_aminos(protein);

/* Loop over proteins in beam until proteins are fully folded. */
PrioProtein cur_prioprot = {*protein, comp_score(protein, &binfo)};
beam.push_back(cur_prioprot);
Protein cur_protein, cur_expansion;
int num_elements;

while (beam[0].protein.get_cur_len() != max_length) {
/* Expand all proteins in the beam and add to priority queue. */
for (PrioProtein prio_prot : beam) {
cur_protein = prio_prot.protein;

for (int m : all_moves) {
if (cur_protein.is_valid(m)) {
cur_expansion = cur_protein;
cur_expansion.place_amino(m);
cur_prioprot = {cur_expansion,
comp_score(&cur_expansion, &binfo)};
cur_proteins.push(cur_prioprot);
}
}
}

/* Interpret beam_width of -1 as all elements. */
if (beam_width == -1) {
num_elements = cur_proteins.size();
} else {
num_elements = std::min(cur_proteins.size(), (size_t)beam_width);
}

/* Update beam with highest ranked proteins and clear priority queue. */
beam.clear();
for (int i = 0; i < num_elements; i++) {
beam.push_back(cur_proteins.top());
cur_proteins.pop();
}
cur_proteins = std::priority_queue<PrioProtein,
std::vector<PrioProtein>,
std::greater<PrioProtein>>();
}

/* First protein in priority queue will have highest score. */
*protein = beam[0].protein;
return protein;
}
17 changes: 17 additions & 0 deletions prospr/core/src/beam_search.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* File: beam_search.h
* Description: Header file for a beam search function.
* License: This file is licensed under the GNU LGPL V3 license by
* Okke van Eck (2020 - 2023). See the LICENSE file for the
* specifics.
*/

#ifndef BEAM_SEARCH_H
#define BEAM_SEARCH_H

#include "protein.hpp"


/* A beam search function for finding a minimum energy conformation. */
Protein* beam_search(Protein* protein, int beam_width=-1);

#endif
14 changes: 5 additions & 9 deletions prospr/core/src/depth_first_bnb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,19 @@ bool reach_prune(Protein* protein, int move, int best_score,
}
}

/* Check score improvement if branch cannot add any bonds. */
if (future_aminos == 0) {
protein->remove_amino();
return cur_score >= best_score;
}

/* Compute branch score with the to be placed amino acids. */
int branch_score = 0;
for (int i = p_vars->num_idxs - future_aminos; i < p_vars->num_idxs; i++) {
/* Check if bondable amino is last of protein. */
if (p_vars->h_idxs[i] == p_vars->max_length - 1) {
/* The last amino being bondable can create an additional bond. */
branch_score += p_vars->max_weights[p_vars->h_idxs[i]] *
std::min((size_t)p_vars->no_neighbors + 1, p_vars->bond_dists[i].size());
std::min((size_t)p_vars->no_neighbors + 1,
p_vars->bond_dists[i].size());
} else {
branch_score += p_vars->max_weights[p_vars->h_idxs[i]] *
std::min((size_t)p_vars->no_neighbors, p_vars->bond_dists[i].size());
std::min((size_t)p_vars->no_neighbors,
p_vars->bond_dists[i].size());
}
}

Expand Down Expand Up @@ -130,7 +126,7 @@ Protein* depth_first_bnb(Protein* protein, std::string prune_func) {
}
}

/* Add distance vector to set and clear for next iterations. */
/* Add distance vector to set and clear for next iterations. */
p_vars.bond_dists.push_back(cur_dists);
cur_dists.clear();

Expand Down
Loading

0 comments on commit b9f0ddb

Please sign in to comment.