File: TestCompoundTransforms.cpp

package info (click to toggle)
molmodel 3.1.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,384 kB
  • sloc: cpp: 39,830; perl: 526; ansic: 107; makefile: 41
file content (134 lines) | stat: -rw-r--r-- 4,557 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "SimTKmolmodel.h"
#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;
using namespace SimTK;

void testBaseAtomTransform() 
{
    Compound compound;

    Vec3 baseTransform(17, 0, 0);
    compound.setBaseAtom( QuadrivalentAtom("A", Element::getBySymbol("C")), baseTransform );

    // test initial default location
    Vec3 atomLocation = compound.calcDefaultAtomLocationInGroundFrame("A");
    Vec3 errorVec( baseTransform - atomLocation );
    SimTK_ASSERT_ALWAYS(dot(errorVec, errorVec) < 0.1, "setBaseAtom() transform not applied correctly in default location");
    SimTK_ASSERT_ALWAYS(dot(atomLocation, atomLocation) > 0.1, "setBaseAtom() transform not applied correctly in default location");

    // test dynamic location
    CompoundSystem system;
    SimbodyMatterSubsystem matter(system);
    Amber99ForceSubsystem amber99(system);
    compound.setAtomBiotype("A", "Alanine", " CA ");

    system.adoptCompound(compound);
    system.modelCompounds();
    State state = system.realizeTopology();
    system.realize(state, Stage::Position);
    atomLocation = compound.calcAtomLocationInGroundFrame( state, Compound::AtomIndex(0) );
    errorVec = baseTransform - atomLocation;
    SimTK_ASSERT_ALWAYS(dot(errorVec, errorVec) < 0.1, "setBaseAtom() transform not applied correctly in dynamic location");
}

void testAdoptCompoundTransform()
{
    Compound compound;

    compound.setBaseAtom( QuadrivalentAtom("A", Element::getBySymbol("C")) );

    Vec3 atomLocation = compound.calcDefaultAtomLocationInGroundFrame("A");
    assert(dot(atomLocation, atomLocation) < 0.1);

    CompoundSystem system;
    SimbodyMatterSubsystem matter(system);
    Amber99ForceSubsystem amber99(system);
    compound.setAtomBiotype("A", "Alanine", " CA ");

    Vec3 adoptTransform(0, -6.8, 0);
    assert(dot(adoptTransform, adoptTransform) > 0.1);

    system.adoptCompound(compound, adoptTransform);

    // adoptCompound(Transform) should affect default configuration too!!!
    atomLocation = compound.calcDefaultAtomLocationInGroundFrame("A");
    Vec3 errorVec = atomLocation - adoptTransform;
    SimTK_ASSERT_ALWAYS(dot(atomLocation, atomLocation) > 0.1, "adoptCompound() transform not applied correctly in default location");
    SimTK_ASSERT_ALWAYS(dot(errorVec, errorVec) < 0.1, "adoptCompound() transform not applied correctly in default location");

    // test dynamic location
    system.modelCompounds();
    State state = system.realizeTopology();
    system.realize(state, Stage::Position);
    atomLocation = compound.calcAtomLocationInGroundFrame( state, Compound::AtomIndex(0) );
    errorVec= adoptTransform - atomLocation;
    SimTK_ASSERT_ALWAYS(dot(errorVec, errorVec) < 0.1, "adoptCompound() transform not applied correctly in dynamic location");
}

void testMatchTopLevelTransform()
{
    Compound compound;

    compound.setBaseAtom( QuadrivalentAtom("A", Element::getBySymbol("C")) );

    Vec3 atomLocation = compound.calcDefaultAtomLocationInGroundFrame("A");
    assert(dot(atomLocation, atomLocation) < 0.1);

    CompoundSystem system;
    SimbodyMatterSubsystem matter(system);
    Amber99ForceSubsystem amber99(system);
    compound.setAtomBiotype("A", "Alanine", " CA ");

    Vec3 adoptTransform(0, 0, 3.14159);
    assert(dot(adoptTransform, adoptTransform) > 0.1);

    system.adoptCompound(compound, adoptTransform);

    Vec3 atomTarget(1.7, -3.6, 0.002);
    Compound::AtomTargetLocations atomTargetLocations;
    atomTargetLocations[Compound::AtomIndex(0)] = atomTarget;

    // test getTransformAndResidual()
    Transform transform1 = compound.getTransformAndResidual(atomTargetLocations).transform;
    Vec3 errorVec = transform1 * adoptTransform - atomTarget;
    SimTK_ASSERT_ALWAYS( dot(errorVec, errorVec) < 0.1, "getTransformAndResidual() got wrong answer");

    // test matchDefaultTopLevelTransform()
    compound.matchDefaultTopLevelTransform(atomTargetLocations);
    errorVec = atomTarget - compound.calcDefaultAtomLocationInGroundFrame("A");
    SimTK_ASSERT_ALWAYS( dot(errorVec, errorVec) < 0.1, "matchDefaultTopLevelTransform got wrong answer" );
}


int main() 
{
try {
    testBaseAtomTransform();
    testAdoptCompoundTransform();
    testMatchTopLevelTransform();

    cout << "PASSED" << endl;
    return 0;
}

catch (const std::exception& e)
{
    cerr << "EXCEPTION THROWN: " << e.what() << endl;

    cerr << "FAILED" << endl;
    return 1;
}

catch (...)
{
    cerr << "UNKNOWN EXCEPTION THROWN" << endl;

    cerr << "FAILED" << endl;
    return 1;
}

}