File: test_bounding_restraint.cpp

package info (click to toggle)
gromacs 2026~rc-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 274,216 kB
  • sloc: xml: 3,831,143; cpp: 686,111; ansic: 75,300; python: 21,171; sh: 3,553; perl: 2,246; yacc: 644; fortran: 397; lisp: 265; makefile: 174; lex: 125; awk: 68; csh: 39
file content (74 lines) | stat: -rw-r--r-- 2,332 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Created by Eric Irrgang on 3/24/18.
//

#include <iostream>
#include <vector>

#include <gtest/gtest.h>

#include "ensemblepotential.h"
#include "testingconfiguration.h"

namespace
{

using ::gmx::Vector;

std::ostream& operator<<(std::ostream& stream, const gmx::Vector& vec)
{
    stream << "(" << vec[0] << "," << vec[1] << "," << vec[2] << ")";
    return stream;
}

const auto filename = plugin::testing::sample_tprfilename;

TEST(EnsembleBoundingPotentialPlugin, ForceCalc)
{
    const Vector zerovec{ 0, 0, 0 };
    // define some unit vectors
    const Vector e1{ real(1), real(0), real(0) };
    const Vector e2{ real(0), real(1), real(0) };
    const Vector e3{ real(0), real(0), real(1) };

    const real R0{ 1.0 };
    const real k{ 1.0 };

    // store temporary values long enough for inspection
    Vector force{};

    // Get a dummy EnsembleResources. We aren't testing that here.
    auto dummyFunc = [](const plugin::Matrix<double>&, plugin::Matrix<double>*) { return; };
    auto resource  = std::make_shared<plugin::Resources>(dummyFunc);

    // Define a reference distribution with a triangular peak at the 1.0 bin.
    const std::vector<double> experimental{ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1 };


    plugin::EnsemblePotential restraint{
        10,           // nbins
        1.0,          // binWidth
        5.0,          // minDist
        5.0,          // maxDist
        experimental, // experimental reference histogram
        1,            // nSamples
        0.001,        // samplePeriod
        1,            // nWindows
        100.,         // k
        1.0           // sigma
    };

    auto calculateForce = [&restraint](const Vector& a, const Vector& b, double t) {
        return restraint.calculate(a, b, t).force;
    };

    // Atoms should be driven towards each other when above maxDist and and away under minDist.
    force = calculateForce(e1, static_cast<real>(3) * e1, 0.001);
    ASSERT_LT(force[0], 0.) << " where force is (" << force[0] << ", " << force[1] << ", "
                            << force[2] << ")\n";
    force = calculateForce(e1, static_cast<real>(7) * e1, 0.001);
    ASSERT_GT(force[0], 0.) << " where force is (" << force[0] << ", " << force[1] << ", "
                            << force[2] << ")\n";
}

} // end anonymous namespace