Open source SASA calculations
|View on GitHub|
The API is found in the header freesasa.h and this is the only header installed by
make install. The other source-files and headers in the repository are for internal use, and are not present here, but are documented in the source itself. The file example.c contains a simple program that illustrates how to use the API to read a PDB file from
stdin and calculate and print the SASA.
To calculate the SASA of a structure, there are two main options:
The following explains how to use FreeSASA to calculate the SASA of a fictive PDB file (1abc.pdb). At each step one or more error checks should have been done, but these are ignored here for brevity. See the documentation of each function to see what errors can occur. Default parameters are used at every step, the section Customizing behavior explains how to configure the calculations.
The function freesasa_structure_from_pdb() reads the atom coordinates from a PDB file and assigns a radius to each atom. The second and third arguments can be changed to use a custom freesasa_classifier to define radii and to specify options for what to include in the PDB file, respectively.
We are commonly interested in the polar and apolar areas of a molecule, this can be calculated by freesasa_result_classify(). Again, passing a NULL freesasa_classifier uses the default. To get other classes of atoms we can either define our own classifier, or use freesasa_select_area() defined in the next section. The return type freesasa_strvp contains arrays of strings and values describing the different classes, as illustrated below.
Groups of atoms can be defined using freesasa_select_area(), which takes a selection definition uses a subset of the Pymol select syntax
If users wish to supply their own coordinates and radii, these are accepted as arrays of doubles passed to the function freesasa_calc_coord(). The coordinate-array should have size 3*n with coordinates in the order
The principle for error handling is that unpredictable errors should not cause a crash, but rather allow the user to exit gracefully or make another attempt. Therefore, errors due to user or system failures, such as faulty parameters, malformatted config-files, I/O errors or out of memory errors, are reported through return values, either FREESASA_FAIL or FREESASA_WARN, or by NULL pointers, depending on the context. See the documentation for the individual functions. If memory allocation fails as much memory as possible is released. To the extent that it's possible to emulate system failures like this, they have been verified to not cause aborts or seg-faults (see the tests/ directory) in any part of the code.
Errors that are attributable to programmers using the library, such as passing null pointers where not allowed, are checked by asserts.
It should be clear from the documentation when the other functions have side effects such as memory allocation and I/O, and thread-safety should generally not be an issue (to the extent that your C library has threadsafe I/O and dynamic memory allocation). The SASA calculation itself can be parallelized by passing a freesasa_parameters struct with freesasa_parameters.n_threads set to a value > 1 (default is 2) to freesasa_calc_structure() or freesasa_calc_coord(). This only gives a significant effect on performance for large proteins or at high precision, and because not all steps are parallelized it is usually not worth it to go beyond 2 threads.
The types freesasa_parameters and freesasa_classifier can be used to change the parameters of the calculations. Users who wish to use the defaults can pass NULL wherever pointers to these are requested.
Changing parameters is done by passing a freesasa_parameters object with the desired values. It can be initialized to default by
To allow the user to only change the parameters that are non-default.
The following call would run a high precision Shrake & Rupley calculation with 10000 test points
The type freesasa_classifier has function pointers to functions that take residue and atom names as argument (pairs such as "ALA","CA"), and returns a radius or a class (polar, apolar, etc). The classifier can be passed to freesasa_structure_from_pdb(), freesasa_structure_array() or freesasa_structure_add_atom_wopt() to customize the radii assigned to atoms, which can then be used to calculate the SASA of the structure. It can also be used in freesasa_result_classify() to get the SASA integrated over the different classes of atoms, i.e. the SASA of all polar atoms, etc.
Users of the API can provide their own classification by writing their own functions and providing them via a freesasa_classifier object. A classifier-configuration can also be read from a file using freesasa_classifier_from_file() (see Classifier configuration files).
The default classifier is available through the const variable freesasa_default_classifier. This uses the radii, defined in the paper by Tsai et al. (JMB 1999, 290: 253) for the standard amino acids (20 regular plus SEC, PYL, ASX and GLX), for some capping groups (ACE/NH2) and the nucleic acids. If the element can't be determined or is unknown, a negative radius is returned. It classes all carbons as apolar and all other known atoms as polar.
Early versions of FreeSASA used the atomic radii by Ooi et al. (PNAS 1987, 84: -3086, this classifier is still available through freesasa_classifier_oons().
The default behavior of freesasa_structure_from_pdb(), freesasa_structure_array(), freesasa_structure_add_atom() and freesasa_structure_add_atom_wopt() is to first try the default classifier and then guess the radius if necessary (emitting warnings if this is done, uses VdW radii defined by [Mantina et al. J Phys Chem 2009, 113:5806](http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3658832/)).
See the documentation for these functions for what parameters to use to change the default behavior.