File: TestShortPdbLines.cpp

package info (click to toggle)
molmodel 3.0~svn842-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 24,616 kB
  • sloc: cpp: 40,500; perl: 526; ansic: 317; makefile: 50
file content (73 lines) | stat: -rw-r--r-- 2,027 bytes parent folder | download
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
#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);

    const PdbAtom& atom = pdbStructure.getAtom(" CA ", PdbResidueId(112, ' '), "A");
    SimTK_ASSERT_ALWAYS(atom.getOccupancy() == 0.90, "Atom occupancy incorrectly parsed");
    SimTK_ASSERT_ALWAYS(atom.getTemperatureFactor() == 34.39, "Atom temperature factor inorrectly parsed");
}

void testCoordinatesButNoOccupancyShouldBeOK() 
{
    // Truncate at character 57; has coordinates but nothing after
    istringstream trunc57("ATOM      1  N   ALA A   1     -52.630  -1.437  23.003");
    PdbStructure pdbStructure(trunc57);

    const PdbAtom& atom = pdbStructure.getAtom(" N  ", PdbResidueId(1, ' '), "A");
    SimTK_ASSERT_ALWAYS(atom.getOccupancy() == 1.00, "Atom occupancy incorrectly parsed");
    SimTK_ASSERT_ALWAYS(atom.getTemperatureFactor() == 0.00, "Atom temperature factor inorrectly parsed");
}

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

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

int main() 
{
try {
    testCompletePdbLineShouldBeOK();
    testCoordinatesButNoOccupancyShouldBeOK();
    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;
}

}