File: TestShortPdbLines.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 (61 lines) | stat: -rw-r--r-- 1,436 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
#include "SimTKmolmodel.h"
#include <iostream>
#include <string>
#include <stdexcept>

using namespace std;
using namespace SimTK;

void testCompletePdbLineShouldBeOK() 
{
    // Truncate at character 57; has coordinates but nothing after
    istringstream completeLine("ATOM    866  CA  LEU A 112      30.133  37.313  21.927  0.90 34.39           C  ");
    PdbStructure pdbStructure(completeLine, PdbStructure::InputType::PDB);

    const PdbAtom& atom = pdbStructure.getAtom(" CA ", PdbResidueId(112, ' '), "A");
    SimTK_TEST_EQ_TOL(atom.getOccupancy(), 0.90, 1e-7);
    SimTK_TEST_EQ_TOL(atom.getTemperatureFactor(),  34.39, 1e-7);
}

// Lack of coordinates should raise exception
void testMissingZCoordinateShouldRaiseException() 
{
    try {
        istringstream trunc("ATOM      1  N   ALA A   1     -52.630  -1.437");
        PdbStructure pdbStructure(trunc, PdbStructure::InputType::PDB);
    }
    catch (...) {
        return;
    }

    throw std::logic_error("Missing z-coordinate failed to raise an exception");
}

int main() 
{
try {
    testCompletePdbLineShouldBeOK();
    testMissingZCoordinateShouldRaiseException();

    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;
}

}