File size: 1,422 Bytes
a3f3d91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
    @file
    @author Simon Mitternacht
    @copyright [MIT License](md_license.html)

    @brief Short program that illustrates how to use the most basic
    functionality of the API

    The program does basic error handling, printing an unspecific
    error message if anything fails, in addition to the library
    errors.
 */

#include <stdlib.h>
#include <stdio.h>
#include "freesasa.h"

//! \{
int main(int argc, char **argv) {
    freesasa_structure *structure = NULL;
    freesasa_result *result = NULL;
    const freesasa_classifier *classifier = &freesasa_default_classifier;
    freesasa_nodearea area;

    /* Read structure from stdin */
    structure = freesasa_structure_from_pdb(stdin, classifier, 0);

    /* Calculate SASA using structure */
    if (structure) {
        result = freesasa_calc_structure(structure, NULL);
    }

    /* Calculate area of classes (Polar/Apolar/..) */
    if (result) {
        area = freesasa_result_classes(structure, result);
    } else {
        /* If there was an error at any step, we will end up here */
        printf("Error calculating SASA\n");
    }
    
    /* Print results */
    printf("Total  : %f A2\n", area.total);
    printf("Apolar : %f A2\n", area.apolar);
    printf("Polar  : %f A2\n", area.polar);

    /* Free allocated resources */
    freesasa_result_free(result);
    freesasa_structure_free(structure);

    return EXIT_SUCCESS;
}
//! \}