| 1 |
#include "tools.h" |
| 2 |
#include <check.h> |
| 3 |
#include <freesasa.h> |
| 4 |
#include <freesasa_internal.h> |
| 5 |
#include <math.h> |
| 6 |
#include <pdb.h> |
| 7 |
#include <stdio.h> |
| 8 |
#include <stdlib.h> |
| 9 |
|
| 10 |
#define N 6 |
| 11 |
const char an[N][PDB_ATOM_NAME_STRL + 1] = {" C ", " CA ", " O ", " CB ", " SD ", "SE "}; |
| 12 |
const char rna[N][PDB_ATOM_RES_NAME_STRL + 1] = { |
| 13 |
"MET", |
| 14 |
"MET", |
| 15 |
"MET", |
| 16 |
"MET", |
| 17 |
"MET", |
| 18 |
"SEC", |
| 19 |
}; |
| 20 |
const char rnu[N][PDB_ATOM_RES_NUMBER_STRL + 1] = {" 1", " 1", " 1", " 1", " 1", " 2"}; |
| 21 |
const char symbol[N][PDB_ATOM_SYMBOL_STRL + 1] = {" C", " C", " O", " C", " S", "SE"}; |
| 22 |
const char cl[N] = {'A', 'A', 'A', 'A', 'A', 'A'}; |
| 23 |
const double bfactors[N] = {1., 1., 1., 1., 1., 1.}; |
| 24 |
|
| 25 |
freesasa_structure *s; |
| 26 |
|
| 27 |
START_TEST(test_structure_api) |
| 28 |
{ |
| 29 |
s = freesasa_structure_new(); |
| 30 |
for (int i = 0; i < N; ++i) { |
| 31 |
ck_assert_int_eq(freesasa_structure_add_atom(s, an[i], rna[i], rnu[i], cl[i], i, i, i), |
| 32 |
FREESASA_SUCCESS); |
| 33 |
} |
| 34 |
for (int i = 0; i < N; ++i) { |
| 35 |
ck_assert_str_eq(freesasa_structure_atom_name(s, i), an[i]); |
| 36 |
ck_assert_str_eq(freesasa_structure_atom_res_name(s, i), rna[i]); |
| 37 |
ck_assert_str_eq(freesasa_structure_atom_res_number(s, i), rnu[i]); |
| 38 |
ck_assert_str_eq(freesasa_structure_atom_symbol(s, i), symbol[i]); |
| 39 |
ck_assert_int_eq(freesasa_structure_atom_chain(s, i), cl[i]); |
| 40 |
} |
| 41 |
freesasa_structure_atom_set_radius(s, 0, 10.0); |
| 42 |
ck_assert(float_eq(freesasa_structure_atom_radius(s, 0), 10.0, 1e-10)); |
| 43 |
|
| 44 |
const coord_t *c = freesasa_structure_xyz(s); |
| 45 |
ck_assert(freesasa_structure_coord_array(s) == freesasa_coord_all(c)); |
| 46 |
for (int i = 0; i < N; ++i) { |
| 47 |
const double *xyz = freesasa_coord_i(c, i); |
| 48 |
ck_assert(fabs(xyz[0] + xyz[1] + xyz[2] - 3 * i) < 1e-10); |
| 49 |
} |
| 50 |
ck_assert_int_eq(freesasa_structure_n(s), N); |
| 51 |
ck_assert_int_eq(freesasa_structure_n_residues(s), 2); |
| 52 |
ck_assert_int_eq(freesasa_structure_n_chains(s), 1); |
| 53 |
|
| 54 |
ck_assert_str_eq(freesasa_structure_residue_name(s, 0), rna[0]); |
| 55 |
ck_assert_str_eq(freesasa_structure_residue_number(s, 0), rnu[0]); |
| 56 |
ck_assert_int_eq(freesasa_structure_residue_chain(s, 0), cl[0]); |
| 57 |
|
| 58 |
ck_assert_int_eq(freesasa_structure_chain_index(s, 'A'), 0); |
| 59 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 60 |
ck_assert_int_eq(freesasa_structure_chain_index(s, 'B'), FREESASA_FAIL); |
| 61 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 62 |
|
| 63 |
int first, last; |
| 64 |
ck_assert(freesasa_structure_residue_atoms(s, 0, &first, &last) == FREESASA_SUCCESS); |
| 65 |
ck_assert(first == 0 && last == N - 2); |
| 66 |
ck_assert(freesasa_structure_chain_atoms(s, 'A', &first, &last) == FREESASA_SUCCESS); |
| 67 |
ck_assert(first == 0 && last == N - 1); |
| 68 |
ck_assert(freesasa_structure_chain_residues(s, 'A', &first, &last) == FREESASA_SUCCESS); |
| 69 |
ck_assert_int_eq(first, 0); |
| 70 |
ck_assert_int_eq(last, 1); |
| 71 |
freesasa_structure_free(s); |
| 72 |
s = NULL; |
| 73 |
} |
| 74 |
END_TEST |
| 75 |
|
| 76 |
START_TEST(test_add_atom) |
| 77 |
{ |
| 78 |
freesasa_structure *s = freesasa_structure_new(); |
| 79 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 80 |
ck_assert_int_eq(freesasa_structure_add_atom(s, "HABC", "ALA", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 81 |
ck_assert_int_eq(freesasa_structure_add_atom(s, "SE ", "SEC", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 82 |
ck_assert_int_eq(freesasa_structure_add_atom(s, "CL ", "ABC", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 83 |
ck_assert_int_eq(freesasa_structure_add_atom(s, "1H2' ", " G", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 84 |
ck_assert_int_eq(freesasa_structure_n(s), 4); |
| 85 |
ck_assert_str_eq(freesasa_structure_atom_symbol(s, 0), " H"); |
| 86 |
ck_assert_str_eq(freesasa_structure_atom_symbol(s, 1), "SE"); |
| 87 |
ck_assert_str_eq(freesasa_structure_atom_symbol(s, 2), "CL"); |
| 88 |
ck_assert_str_eq(freesasa_structure_atom_symbol(s, 3), " H"); |
| 89 |
|
| 90 |
ck_assert_int_eq(freesasa_structure_add_atom(s, "A", "ALA", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 91 |
ck_assert_int_eq(freesasa_structure_add_atom(s, " C ", "AL", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 92 |
ck_assert_int_eq(freesasa_structure_add_atom(s, " C ", "ALA", " 1", 'A', 0, 0, 0), FREESASA_SUCCESS); |
| 93 |
ck_assert_int_eq(freesasa_structure_n(s), 7); |
| 94 |
|
| 95 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "A", "ALA", " 1", 'A', 0, 0, 0, NULL, FREESASA_SKIP_UNKNOWN), FREESASA_WARN); |
| 96 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "HABC", "ALA", " 1", 'A', 0, 0, 0, NULL, FREESASA_SKIP_UNKNOWN), FREESASA_WARN); |
| 97 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "SE ", "SEC", " 1", 'A', 0, 0, 0, NULL, FREESASA_SKIP_UNKNOWN), FREESASA_SUCCESS); |
| 98 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "CL ", "ABC", " 1", 'A', 0, 0, 0, NULL, FREESASA_SKIP_UNKNOWN), FREESASA_WARN); |
| 99 |
ck_assert_int_eq(freesasa_structure_n(s), 8); |
| 100 |
|
| 101 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "HABC", "ALA", " 1", 'A', 0, 0, 0, NULL, FREESASA_HALT_AT_UNKNOWN), FREESASA_FAIL); |
| 102 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "SE ", "SEC", " 1", 'A', 0, 0, 0, NULL, FREESASA_HALT_AT_UNKNOWN), FREESASA_SUCCESS); |
| 103 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "CL ", "ABC", " 1", 'A', 0, 0, 0, NULL, FREESASA_HALT_AT_UNKNOWN), FREESASA_FAIL); |
| 104 |
ck_assert_int_eq(freesasa_structure_n(s), 9); |
| 105 |
|
| 106 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "HABC", "ALA", " 1", 'A', 0, 0, 0, NULL, FREESASA_HALT_AT_UNKNOWN | FREESASA_SKIP_UNKNOWN), FREESASA_FAIL); |
| 107 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "SE ", "SEC", " 1", 'A', 0, 0, 0, NULL, FREESASA_HALT_AT_UNKNOWN | FREESASA_SKIP_UNKNOWN), FREESASA_SUCCESS); |
| 108 |
ck_assert_int_eq(freesasa_structure_add_atom_wopt(s, "CL ", "ABC", " 1", 'A', 0, 0, 0, NULL, FREESASA_HALT_AT_UNKNOWN | FREESASA_SKIP_UNKNOWN), FREESASA_FAIL); |
| 109 |
ck_assert_int_eq(freesasa_structure_n(s), 10); |
| 110 |
|
| 111 |
for (int i = 0; i < freesasa_structure_n(s); ++i) { |
| 112 |
ck_assert_int_eq(freesasa_structure_atom_class(s, i), |
| 113 |
freesasa_classifier_class(&freesasa_default_classifier, freesasa_structure_atom_res_name(s, i), freesasa_structure_atom_name(s, i))); |
| 114 |
} |
| 115 |
|
| 116 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 117 |
|
| 118 |
freesasa_structure_free(s); |
| 119 |
} |
| 120 |
END_TEST |
| 121 |
|
| 122 |
double a2r(const char *rn, const char *am) |
| 123 |
{ |
| 124 |
return 1.0; |
| 125 |
} |
| 126 |
|
| 127 |
void setup_1ubq(void) |
| 128 |
{ |
| 129 |
FILE *pdb = fopen(DATADIR "1ubq.pdb", "r"); |
| 130 |
ck_assert(pdb != NULL); |
| 131 |
if (s) freesasa_structure_free(s); |
| 132 |
s = freesasa_structure_from_pdb(pdb, NULL, 0); |
| 133 |
fclose(pdb); |
| 134 |
} |
| 135 |
|
| 136 |
void teardown_1ubq(void) |
| 137 |
{ |
| 138 |
freesasa_structure_free(s); |
| 139 |
s = NULL; |
| 140 |
} |
| 141 |
|
| 142 |
START_TEST(test_structure_1ubq) |
| 143 |
{ |
| 144 |
ck_assert(freesasa_structure_n(s) == 602); |
| 145 |
ck_assert(freesasa_structure_n_residues(s) == 76); |
| 146 |
// check at random atom to see that parsing was correct |
| 147 |
ck_assert_str_eq(freesasa_structure_atom_res_name(s, 8), "GLN"); |
| 148 |
ck_assert_str_eq(freesasa_structure_atom_name(s, 8), " N "); |
| 149 |
ck_assert_str_eq(freesasa_structure_atom_res_number(s, 8), " 2 "); |
| 150 |
ck_assert_int_eq(freesasa_structure_atom_chain(s, 8), 'A'); |
| 151 |
ck_assert_str_eq(freesasa_structure_atom_symbol(s, 8), " N"); |
| 152 |
|
| 153 |
// check coordinates of that random atom |
| 154 |
const coord_t *c = freesasa_structure_xyz(s); |
| 155 |
ck_assert(c != NULL); |
| 156 |
const double *x = freesasa_coord_i(c, 8); |
| 157 |
ck_assert(x != NULL); |
| 158 |
ck_assert(fabs(x[0] - 26.335 + x[1] - 27.770 + x[2] - 3.258) < 1e-10); |
| 159 |
} |
| 160 |
END_TEST |
| 161 |
|
| 162 |
START_TEST(test_pdb) |
| 163 |
{ |
| 164 |
const char *file_names[] = {DATADIR "alt_model_twochain.pdb", |
| 165 |
DATADIR "empty.pdb", |
| 166 |
DATADIR "empty_model.pdb"}; |
| 167 |
const int result_null[] = {0, 1, 1}; |
| 168 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 169 |
for (int i = 0; i < 3; ++i) { |
| 170 |
FILE *pdb = fopen(file_names[i], "r"); |
| 171 |
ck_assert(pdb != NULL); |
| 172 |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, 0); |
| 173 |
if (result_null[i]) |
| 174 |
ck_assert(s == NULL); |
| 175 |
else |
| 176 |
ck_assert(s != NULL); |
| 177 |
fclose(pdb); |
| 178 |
freesasa_structure_free(s); |
| 179 |
} |
| 180 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 181 |
} |
| 182 |
END_TEST |
| 183 |
|
| 184 |
START_TEST(test_hydrogen) |
| 185 |
{ |
| 186 |
FILE *pdb = fopen(DATADIR "1d3z.pdb", "r"); |
| 187 |
ck_assert(pdb != NULL); |
| 188 |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, 0); |
| 189 |
ck_assert(s != NULL); |
| 190 |
ck_assert(freesasa_structure_n(s) == 602); |
| 191 |
freesasa_structure_free(s); |
| 192 |
rewind(pdb); |
| 193 |
|
| 194 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 195 |
|
| 196 |
s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HYDROGEN); |
| 197 |
ck_assert(s != NULL); |
| 198 |
ck_assert(freesasa_structure_n(s) == 1231); |
| 199 |
freesasa_structure_free(s); |
| 200 |
|
| 201 |
rewind(pdb); |
| 202 |
ck_assert_ptr_eq(freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HYDROGEN | FREESASA_HALT_AT_UNKNOWN), NULL); |
| 203 |
|
| 204 |
rewind(pdb); |
| 205 |
s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HYDROGEN | FREESASA_SKIP_UNKNOWN); |
| 206 |
ck_assert(s != NULL); |
| 207 |
ck_assert(freesasa_structure_n(s) == 602); |
| 208 |
freesasa_structure_free(s); |
| 209 |
|
| 210 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 211 |
fclose(pdb); |
| 212 |
} |
| 213 |
END_TEST |
| 214 |
|
| 215 |
START_TEST(test_hetatm) |
| 216 |
{ |
| 217 |
FILE *pdb = fopen(DATADIR "1ubq.pdb", "r"); |
| 218 |
ck_assert(pdb != NULL); |
| 219 |
freesasa_set_verbosity(FREESASA_V_SILENT); // unknown atoms warnings suppressed |
| 220 |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HETATM); |
| 221 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 222 |
ck_assert(s != NULL); |
| 223 |
ck_assert(freesasa_structure_n(s) == 660); |
| 224 |
freesasa_structure_free(s); |
| 225 |
fclose(pdb); |
| 226 |
} |
| 227 |
END_TEST |
| 228 |
|
| 229 |
START_TEST(test_structure_array_err) |
| 230 |
{ |
| 231 |
FILE *pdb; |
| 232 |
int n = 0; |
| 233 |
|
| 234 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 235 |
pdb = fopen(DATADIR "err.config", "r"); |
| 236 |
ck_assert_ptr_eq(freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_MODELS), NULL); |
| 237 |
rewind(pdb); |
| 238 |
ck_assert_ptr_eq(freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_CHAINS), NULL); |
| 239 |
fclose(pdb); |
| 240 |
|
| 241 |
pdb = fopen(DATADIR "1ubq.pdb", "r"); |
| 242 |
ck_assert_ptr_eq(freesasa_structure_array(pdb, &n, NULL, 0), NULL); |
| 243 |
fclose(pdb); |
| 244 |
|
| 245 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 246 |
} |
| 247 |
END_TEST |
| 248 |
|
| 249 |
START_TEST(test_structure_array_one_chain) |
| 250 |
{ |
| 251 |
FILE *pdb; |
| 252 |
int n = 0; |
| 253 |
freesasa_structure **ss; |
| 254 |
|
| 255 |
pdb = fopen(DATADIR "1ubq.pdb", "r"); |
| 256 |
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_CHAINS); |
| 257 |
|
| 258 |
ck_assert(ss != NULL); |
| 259 |
ck_assert(n == 1); |
| 260 |
ck_assert(freesasa_structure_n(ss[0]) == 602); |
| 261 |
freesasa_structure_free(ss[0]); |
| 262 |
free(ss); |
| 263 |
fclose(pdb); |
| 264 |
} |
| 265 |
END_TEST |
| 266 |
|
| 267 |
START_TEST(test_structure_array_nmr) |
| 268 |
{ |
| 269 |
FILE *pdb; |
| 270 |
int n = 0; |
| 271 |
freesasa_structure **ss; |
| 272 |
|
| 273 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 274 |
pdb = fopen(DATADIR "1d3z.pdb", "r"); |
| 275 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 276 |
|
| 277 |
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_MODELS); |
| 278 |
|
| 279 |
ck_assert(ss != NULL); |
| 280 |
ck_assert(n == 10); |
| 281 |
|
| 282 |
for (int i = 0; i < n; ++i) { |
| 283 |
ck_assert(ss[i] != NULL); |
| 284 |
ck_assert(freesasa_structure_n(ss[i]) == 602); |
| 285 |
freesasa_structure_free(ss[i]); |
| 286 |
} |
| 287 |
free(ss); |
| 288 |
rewind(pdb); |
| 289 |
|
| 290 |
freesasa_set_verbosity(FREESASA_V_SILENT); // Silence Hydrogen warnings |
| 291 |
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_CHAINS | FREESASA_SEPARATE_MODELS | FREESASA_INCLUDE_HYDROGEN); |
| 292 |
ck_assert(ss != NULL); |
| 293 |
ck_assert(n == 10); |
| 294 |
for (int i = 0; i < n; ++i) { |
| 295 |
ck_assert(ss[i] != NULL); |
| 296 |
ck_assert(freesasa_structure_n(ss[i]) == 1231); |
| 297 |
freesasa_structure_free(ss[i]); |
| 298 |
} |
| 299 |
free(ss); |
| 300 |
fclose(pdb); |
| 301 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 302 |
} |
| 303 |
END_TEST |
| 304 |
|
| 305 |
START_TEST(test_structure_array_chains_models) |
| 306 |
{ |
| 307 |
FILE *pdb; |
| 308 |
int n = 0; |
| 309 |
freesasa_structure **ss; |
| 310 |
|
| 311 |
pdb = fopen(DATADIR "1d3z.pdb", "r"); |
| 312 |
|
| 313 |
// one chain |
| 314 |
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_CHAINS); |
| 315 |
ck_assert(ss != NULL); |
| 316 |
ck_assert(n == 1); |
| 317 |
ck_assert(ss[0] != NULL); |
| 318 |
ck_assert(freesasa_structure_n(ss[0]) == 602); |
| 319 |
freesasa_structure_free(ss[0]); |
| 320 |
free(ss); |
| 321 |
fclose(pdb); |
| 322 |
|
| 323 |
// many chains |
| 324 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 325 |
pdb = fopen(DATADIR "2jo4.pdb", "r"); |
| 326 |
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_MODELS | FREESASA_INCLUDE_HETATM | FREESASA_INCLUDE_HYDROGEN); |
| 327 |
ck_assert(ss != NULL); |
| 328 |
ck_assert(n == 10); |
| 329 |
for (int i = 0; i < n; ++i) { |
| 330 |
ck_assert(ss[i] != NULL); |
| 331 |
ck_assert(freesasa_structure_n(ss[i]) == 286 * 4); |
| 332 |
freesasa_structure_free(ss[i]); |
| 333 |
} |
| 334 |
free(ss); |
| 335 |
rewind(pdb); |
| 336 |
|
| 337 |
// separate both chains and models |
| 338 |
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_MODELS | FREESASA_SEPARATE_CHAINS | FREESASA_INCLUDE_HETATM | FREESASA_INCLUDE_HYDROGEN); |
| 339 |
ck_assert(ss != NULL); |
| 340 |
ck_assert(n == 10 * 4); |
| 341 |
for (int i = 0; i < n; ++i) { |
| 342 |
ck_assert(ss[i] != NULL); |
| 343 |
ck_assert(freesasa_structure_n(ss[i]) == 286); |
| 344 |
freesasa_structure_free(ss[i]); |
| 345 |
} |
| 346 |
free(ss); |
| 347 |
|
| 348 |
// many chains, many models, join models |
| 349 |
rewind(pdb); |
| 350 |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HETATM | FREESASA_INCLUDE_HYDROGEN | FREESASA_JOIN_MODELS); |
| 351 |
ck_assert(s != NULL); |
| 352 |
ck_assert(freesasa_structure_n(s) == 286 * 4 * 10); |
| 353 |
freesasa_structure_free(s); |
| 354 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 355 |
fclose(pdb); |
| 356 |
} |
| 357 |
END_TEST |
| 358 |
|
| 359 |
START_TEST(test_get_chains) |
| 360 |
{ |
| 361 |
FILE *pdb = fopen(DATADIR "2jo4.pdb", "r"); |
| 362 |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, 0); |
| 363 |
int first, last; |
| 364 |
ck_assert_int_eq(freesasa_structure_n(s), 4 * 129); |
| 365 |
ck_assert_int_eq(freesasa_structure_n_chains(s), 4); |
| 366 |
ck_assert_str_eq(freesasa_structure_chain_labels(s), "ABCD"); |
| 367 |
ck_assert_int_eq(freesasa_structure_chain_atoms(s, 'A', &first, &last), FREESASA_SUCCESS); |
| 368 |
ck_assert_int_eq(first, 0); |
| 369 |
ck_assert_int_eq(last, 128); |
| 370 |
ck_assert_int_eq(freesasa_structure_chain_atoms(s, 'B', &first, &last), FREESASA_SUCCESS); |
| 371 |
ck_assert_int_eq(first, 129); |
| 372 |
ck_assert_int_eq(last, 129 * 2 - 1); |
| 373 |
ck_assert_int_eq(freesasa_structure_chain_atoms(s, 'C', &first, &last), FREESASA_SUCCESS); |
| 374 |
ck_assert_int_eq(first, 129 * 2); |
| 375 |
ck_assert_int_eq(last, 129 * 3 - 1); |
| 376 |
ck_assert_int_eq(freesasa_structure_chain_atoms(s, 'D', &first, &last), FREESASA_SUCCESS); |
| 377 |
ck_assert_int_eq(first, 129 * 3); |
| 378 |
ck_assert_int_eq(last, 129 * 4 - 1); |
| 379 |
|
| 380 |
freesasa_structure *s2 = freesasa_structure_get_chains(s, "", NULL, 0); |
| 381 |
ck_assert(s2 == NULL); |
| 382 |
s2 = freesasa_structure_get_chains(s, "X", NULL, 0); |
| 383 |
ck_assert(s2 == NULL); |
| 384 |
|
| 385 |
s2 = freesasa_structure_get_chains(s, "A", NULL, 0); |
| 386 |
ck_assert(freesasa_structure_n(s2) == 129); |
| 387 |
ck_assert(freesasa_structure_atom_chain(s2, 0) == 'A'); |
| 388 |
ck_assert_str_eq(freesasa_structure_chain_labels(s2), "A"); |
| 389 |
freesasa_structure_free(s2); |
| 390 |
|
| 391 |
s2 = freesasa_structure_get_chains(s, "D", NULL, 0); |
| 392 |
ck_assert(freesasa_structure_n(s2) == 129); |
| 393 |
ck_assert(freesasa_structure_atom_chain(s2, 0) == 'D'); |
| 394 |
ck_assert_str_eq(freesasa_structure_chain_labels(s2), "D"); |
| 395 |
freesasa_structure_free(s2); |
| 396 |
|
| 397 |
s2 = freesasa_structure_get_chains(s, "AC", NULL, 0); |
| 398 |
ck_assert(freesasa_structure_n(s2) == 2 * 129); |
| 399 |
ck_assert(freesasa_structure_atom_chain(s2, 0) == 'A'); |
| 400 |
ck_assert(freesasa_structure_atom_chain(s2, 129) == 'C'); |
| 401 |
ck_assert_str_eq(freesasa_structure_chain_labels(s2), "AC"); |
| 402 |
freesasa_structure_free(s2); |
| 403 |
|
| 404 |
s2 = freesasa_structure_get_chains(s, "E", NULL, 0); |
| 405 |
ck_assert_ptr_eq(s2, NULL); |
| 406 |
|
| 407 |
s2 = freesasa_structure_get_chains(s, "AE", NULL, 0); |
| 408 |
ck_assert_ptr_eq(s2, NULL); |
| 409 |
|
| 410 |
freesasa_structure_free(s); |
| 411 |
} |
| 412 |
END_TEST |
| 413 |
|
| 414 |
START_TEST(test_occupancy) |
| 415 |
{ |
| 416 |
FILE *pdb = fopen(DATADIR "1ubq.occ.pdb", "r"); |
| 417 |
ck_assert_ptr_ne(pdb, NULL); |
| 418 |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_RADIUS_FROM_OCCUPANCY); |
| 419 |
fclose(pdb); |
| 420 |
ck_assert_ptr_ne(s, NULL); |
| 421 |
const double *r = freesasa_structure_radius(s); |
| 422 |
ck_assert_ptr_ne(r, NULL); |
| 423 |
ck_assert(float_eq(r[0], 3.64, 1e-6)); |
| 424 |
ck_assert(float_eq(r[1], 1.88, 1e-6)); |
| 425 |
ck_assert(float_eq(r[2], 1.61, 1e-6)); |
| 426 |
freesasa_structure_free(s); |
| 427 |
} |
| 428 |
END_TEST |
| 429 |
|
| 430 |
START_TEST(test_memerr) |
| 431 |
{ |
| 432 |
FILE *file = fopen(DATADIR "1ubq.pdb", "r"); |
| 433 |
void *ptr; |
| 434 |
int n; |
| 435 |
freesasa_set_verbosity(FREESASA_V_SILENT); |
| 436 |
set_fail_after(1); |
| 437 |
ptr = freesasa_structure_new(); |
| 438 |
set_fail_after(0); |
| 439 |
ck_assert_ptr_eq(ptr, NULL); |
| 440 |
for (int i = 1; i < 100; ++i) { |
| 441 |
rewind(file); |
| 442 |
set_fail_after(i); |
| 443 |
ptr = freesasa_structure_from_pdb(file, NULL, 0); |
| 444 |
set_fail_after(0); |
| 445 |
ck_assert_ptr_eq(ptr, NULL); |
| 446 |
} |
| 447 |
|
| 448 |
file = fopen(DATADIR "2jo4.pdb", "r"); |
| 449 |
for (int i = 1; i < 100; ++i) { |
| 450 |
rewind(file); |
| 451 |
set_fail_after(i); |
| 452 |
ptr = freesasa_structure_array(file, &n, NULL, FREESASA_SEPARATE_MODELS); |
| 453 |
set_fail_after(0); |
| 454 |
ck_assert_ptr_eq(ptr, NULL); |
| 455 |
|
| 456 |
rewind(file); |
| 457 |
set_fail_after(i); |
| 458 |
ptr = freesasa_structure_array(file, &n, NULL, FREESASA_SEPARATE_MODELS | FREESASA_SEPARATE_CHAINS); |
| 459 |
set_fail_after(0); |
| 460 |
ck_assert_ptr_eq(ptr, NULL); |
| 461 |
} |
| 462 |
set_fail_after(0); |
| 463 |
fclose(file); |
| 464 |
freesasa_set_verbosity(FREESASA_V_NORMAL); |
| 465 |
} |
| 466 |
END_TEST |
| 467 |
|
| 468 |
Suite *structure_suite() |
| 469 |
{ |
| 470 |
// what goes in what Case is kind of arbitrary |
| 471 |
Suite *s = suite_create("Structure"); |
| 472 |
TCase *tc_core = tcase_create("Core"); |
| 473 |
tcase_add_test(tc_core, test_structure_api); |
| 474 |
tcase_add_test(tc_core, test_add_atom); |
| 475 |
tcase_add_test(tc_core, test_memerr); |
| 476 |
|
| 477 |
TCase *tc_pdb = tcase_create("PDB"); |
| 478 |
tcase_add_test(tc_pdb, test_pdb); |
| 479 |
tcase_add_test(tc_pdb, test_hydrogen); |
| 480 |
tcase_add_test(tc_pdb, test_hetatm); |
| 481 |
tcase_add_test(tc_pdb, test_get_chains); |
| 482 |
tcase_add_test(tc_pdb, test_occupancy); |
| 483 |
|
| 484 |
TCase *tc_array = tcase_create("Array"); |
| 485 |
tcase_add_test(tc_pdb, test_structure_array_err); |
| 486 |
tcase_add_test(tc_pdb, test_structure_array_one_chain); |
| 487 |
tcase_add_test(tc_pdb, test_structure_array_nmr); |
| 488 |
tcase_add_test(tc_pdb, test_structure_array_chains_models); |
| 489 |
|
| 490 |
TCase *tc_1ubq = tcase_create("1UBQ"); |
| 491 |
tcase_add_checked_fixture(tc_1ubq, setup_1ubq, teardown_1ubq); |
| 492 |
tcase_add_test(tc_1ubq, test_structure_1ubq); |
| 493 |
|
| 494 |
suite_add_tcase(s, tc_core); |
| 495 |
suite_add_tcase(s, tc_pdb); |
| 496 |
suite_add_tcase(s, tc_array); |
| 497 |
suite_add_tcase(s, tc_1ubq); |
| 498 |
|
| 499 |
return s; |
| 500 |
} |