From 697f02228427ff5c2c91b46235346de69780080e Mon Sep 17 00:00:00 2001 From: Christoph Wehmeyer Date: Fri, 17 Feb 2017 16:51:58 +0100 Subject: [PATCH 1/2] [util] add pbc capability to get_umbrella_bias() --- CHANGELOG | 4 ++++ ext/util/_util.c | 13 ++++++++++--- ext/util/_util.h | 3 ++- ext/util/util.pyx | 11 +++++++++-- test/test_util.py | 3 ++- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 85fbe7e..ba6de8a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -108,4 +108,8 @@ Version 0.2.3 (Beta): - Fixes: self-consistency check in cset - Removes several misleading warnings +Version 0.2.4 (Beta): + + - Allow periodicity when computing umbrella sampling bias energies + Upcoming: diff --git a/ext/util/_util.c b/ext/util/_util.c index b27615d..49f4956 100644 --- a/ext/util/_util.c +++ b/ext/util/_util.c @@ -1,7 +1,7 @@ /* * This file is part of thermotools. * -* Copyright 2015, 2016 Computational Molecular Biology Group, Freie Universitaet Berlin (GER) +* Copyright 2015-2017 Computational Molecular Biology Group, Freie Universitaet Berlin (GER) * * thermotools is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -19,6 +19,12 @@ #include "_util.h" +inline double wrap(double x, const double width, const double inverse_width) { + if(width > 0.0) { + return x - nearbyint(x * inverse_width) * width; + } else return x; +} + /*************************************************************************************************** * sorting ***************************************************************************************************/ @@ -162,6 +168,7 @@ extern int _get_therm_state_break_points(int *T_x, int seq_length, int *break_po extern void _get_umbrella_bias( double *traj, double *umbrella_centers, double *force_constants, + double *width, double *inverse_width, int nsamples, int nthermo, int ndim, double *bias) { int i, j, s, k; @@ -184,8 +191,8 @@ extern void _get_umbrella_bias( if(0.0 == fc) continue; isum += fc - * (traj[sdim + i] - umbrella_centers[kdim + i]) - * (traj[sdim + j] - umbrella_centers[kdim + j]); + * wrap(traj[sdim + i] - umbrella_centers[kdim + i], width[i], inverse_width[i]) + * wrap(traj[sdim + j] - umbrella_centers[kdim + j], width[j], inverse_width[j]); } sum += isum; } diff --git a/ext/util/_util.h b/ext/util/_util.h index 28d3197..bf599bb 100644 --- a/ext/util/_util.h +++ b/ext/util/_util.h @@ -1,7 +1,7 @@ /* * This file is part of thermotools. * -* Copyright 2015, 2016 Computational Molecular Biology Group, Freie Universitaet Berlin (GER) +* Copyright 2015-2017 Computational Molecular Biology Group, Freie Universitaet Berlin (GER) * * thermotools is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -77,6 +77,7 @@ extern int _get_therm_state_break_points(int *T_x, int seq_length, int *break_po extern void _get_umbrella_bias( double *traj, double *umbrella_centers, double *force_constants, + double *width, double *inverse_width, int nsamples, int nthermo, int ndim, double *bias); /*************************************************************************************************** diff --git a/ext/util/util.pyx b/ext/util/util.pyx index 4ea4a0f..bc4f9e5 100644 --- a/ext/util/util.pyx +++ b/ext/util/util.pyx @@ -1,6 +1,6 @@ # This file is part of thermotools. # -# Copyright 2015, 2016 Computational Molecular Biology Group, Freie Universitaet Berlin (GER) +# Copyright 2015-2017 Computational Molecular Biology Group, Freie Universitaet Berlin (GER) # # thermotools is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by @@ -54,6 +54,7 @@ cdef extern from "_util.h": # bias calculation tools void _get_umbrella_bias( double *traj, double *umbrella_centers, double *force_constants, + double *width, double *inverse_width, int nsamples, int nthermo, int ndim, double *bias) # transition matrix renormalization void _renormalize_transition_matrix(double *p, int n_conf_states, double *scratch_M) @@ -380,7 +381,8 @@ def _overlap_post_hoc_RE( def get_umbrella_bias( _np.ndarray[double, ndim=2, mode="c"] traj not None, _np.ndarray[double, ndim=2, mode="c"] umbrella_centers not None, - _np.ndarray[double, ndim=3, mode="c"] force_constants not None): + _np.ndarray[double, ndim=3, mode="c"] force_constants not None, + _np.ndarray[double, ndim=1, mode="c"] width not None): r""" Restrict full list of samples to a subset and relabel configurational state indices. @@ -402,10 +404,15 @@ def get_umbrella_bias( nthermo = umbrella_centers.shape[0] ndim = traj.shape[1] bias = _np.zeros(shape=(nsamples, nthermo), dtype=_np.float64) + inverse_width = _np.zeros(shape=(ndim,), dtype=_np.float64) + idx = _np.where(width > 0.0)[0] + inverse_width[idx] = 1.0 / width[idx] _get_umbrella_bias( _np.PyArray_DATA(traj), _np.PyArray_DATA(umbrella_centers), _np.PyArray_DATA(force_constants), + _np.PyArray_DATA(width), + _np.PyArray_DATA(inverse_width), nsamples, nthermo, ndim, diff --git a/test/test_util.py b/test/test_util.py index 3a108f2..2a87784 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -201,7 +201,8 @@ def test_get_umbrella_bias_binary(): umbrella_centers[1, :] = 1.0 force_constants = np.array([ np.zeros(shape=(ndim, ndim), dtype=np.float64), np.eye(ndim, dtype=np.float64)]) - bias = util.get_umbrella_bias(traj, umbrella_centers, force_constants) + width = np.zeros(shape=(ndim,), dtype=np.float64) + bias = util.get_umbrella_bias(traj, umbrella_centers, force_constants, width) ref = np.vstack(( np.zeros(shape=(nsamples)), 0.5 * ndim * np.linspace(-1.0, 1.0, nsamples)**2)).T.astype(np.float64) From 2f3066ec7ac025f1399e24fd2859212e20d54ea6 Mon Sep 17 00:00:00 2001 From: "Martin K. Scherer" Date: Fri, 17 Feb 2017 17:52:23 +0100 Subject: [PATCH 2/2] fix test execution --- conda-recipe/meta.yaml | 3 +++ conda-recipe/run_test.py | 31 +------------------------------ 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index d488c4d..cc9b4cc 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -21,6 +21,9 @@ requirements: - msmtools >=1.1.3 test: + source_files: + - test/*.py + - .coveragerc requires: - nose - coverage ==4 diff --git a/conda-recipe/run_test.py b/conda-recipe/run_test.py index 53f641c..014b3dd 100644 --- a/conda-recipe/run_test.py +++ b/conda-recipe/run_test.py @@ -5,30 +5,9 @@ import shutil import re -src_dir = os.getenv('SRC_DIR') - -def coverage_report(): - fn = '.coverage' - assert os.path.exists(fn) - build_dir = os.getenv('TRAVIS_BUILD_DIR') - dest = os.path.join(build_dir, fn) - print( "copying coverage report to", dest) - shutil.copy(fn, dest) - assert os.path.exists(dest) - - # fix paths in .coverage file - with open(dest, 'r') as fh: - data = fh.read() - match= '"/home/travis/miniconda/envs/_test/lib/python.+?/site-packages/.+?/(thermotools/.+?)"' - repl = '"%s/\\1"' % build_dir - data = re.sub(match, repl, data) - os.unlink(dest) - with open(dest, 'w+') as fh: - fh.write(data) - nose_run = [ "nosetests", - os.path.join(src_dir, "test"), + "test", "-vv", "--with-coverage", "--cover-inclusive", @@ -36,14 +15,6 @@ def coverage_report(): "--with-doctest", "--doctest-options=+NORMALIZE_WHITESPACE,+ELLIPSIS"] -shutil.copyfile( - os.path.join(src_dir, ".coveragerc"), - os.path.join(os.getcwd(), ".coveragerc")) - res = subprocess.call(nose_run) -# move .coverage file to git clone on Travis CI -if os.getenv('TRAVIS', False): - coverage_report() - sys.exit(res)