Skip to content

Commit

Permalink
Fix bug where chain groups did not use correct radii. Closes #41.
Browse files Browse the repository at this point in the history
  • Loading branch information
mittinatten committed Mar 2, 2019
1 parent 5235c58 commit 0618103
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 38 deletions.
6 changes: 5 additions & 1 deletion src/freesasa.h
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ freesasa_structure_add_atom_wopt(freesasa_structure *structure,
@param structure Input structure.
@param chains String of chain labels (e.g. `"AB"`)
@param classifier A classifier to use to build the new structure
@param options Structure options as in freesasa_structure_add_atom_wopt()
@return A new structure consisting only of the specified
chains. Returns `NULL` if one or more of the requested chains don't
Expand All @@ -874,7 +876,9 @@ freesasa_structure_add_atom_wopt(freesasa_structure *structure,
*/
freesasa_structure*
freesasa_structure_get_chains(const freesasa_structure *structure,
const char* chains);
const char* chains,
const freesasa_classifier* classifier,
int options);

/**
Get string listing all chains in structure.
Expand Down
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ get_structures(FILE *input,
n2 = *n;
for (i = 0; i < state->n_chain_groups; ++i) {
for (j = 0; j < *n; ++j) {
tmp = freesasa_structure_get_chains(structures[j], state->chain_groups[i]);
tmp = freesasa_structure_get_chains(structures[j], state->chain_groups[i],
state->classifier, state->structure_options);
if (tmp != NULL) {
++n2;
structures = realloc(structures, sizeof(freesasa_structure*)*n2);
Expand Down
10 changes: 6 additions & 4 deletions src/structure.c
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,9 @@ freesasa_structure_array(FILE *pdb,

freesasa_structure*
freesasa_structure_get_chains(const freesasa_structure *structure,
const char* chains)
const char* chains,
const freesasa_classifier* classifier,
int options)
{
freesasa_structure *new_s;
struct atom *ai;
Expand All @@ -881,9 +883,9 @@ freesasa_structure_get_chains(const freesasa_structure *structure,
c = ai->chain_label;
if (strchr(chains,c) != NULL) {
v = freesasa_coord_i(structure->xyz,i);
res = freesasa_structure_add_atom(new_s, ai->atom_name,
ai->res_name, ai->res_number,
c, v[0], v[1], v[2]);
res = freesasa_structure_add_atom_wopt(new_s, ai->atom_name,
ai->res_name, ai->res_number,
c, v[0], v[1], v[2], classifier, options);
if (res == FREESASA_FAIL) {
fail_msg("");
goto cleanup;
Expand Down
30 changes: 15 additions & 15 deletions tests/test_freesasa.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ double surface_two_spheres(const double *x, const double *r, double probe)
return surface_spheres_intersecting(r[0]+probe,r[1]+probe,sqrt(d2));
}

int test_sasa(double ref, const char *test, const double *xyz,
int test_sasa(double ref, const char *test, const double *xyz,
const double *r, int n)
{
double err;
Expand All @@ -66,7 +66,7 @@ void setup_lr_precision(void)
}
void teardown_lr_precision(void)
{

}
void setup_sr_precision(void)
{
Expand All @@ -77,7 +77,7 @@ void setup_sr_precision(void)
}
void teardown_sr_precision(void)
{

}

START_TEST (test_sasa_alg_basic)
Expand Down Expand Up @@ -132,7 +132,7 @@ START_TEST (test_sasa_alg_basic)
memcpy(coord2,coord5,12*sizeof(double));
ck_assert(test_sasa(ref,"Four spheres in plane, rotated 90 deg round x-axis.",
coord2,r2,n));

}
END_TEST

Expand All @@ -148,7 +148,7 @@ START_TEST (test_minimal_calc)
// access areas
ck_assert(fabs(result->sasa[0] - result->total) < 1e-10);
ck_assert(fabs(result->total - (4*M_PI*M_PI*2.4*2.4)));

freesasa_result_free(result);
}
END_TEST
Expand Down Expand Up @@ -202,7 +202,7 @@ START_TEST (test_sasa_1ubq)
ck_assert(float_eq(res->total, total_ref, 1e-5));
ck_assert(float_eq(res_class.polar, polar_ref, 1e-5));
ck_assert(float_eq(res_class.apolar, apolar_ref, 1e-5));

FILE *devnull = fopen("/dev/null","w");
ck_assert(freesasa_write_pdb(devnull, tree) == FREESASA_SUCCESS);
ck_assert(freesasa_tree_export(devnull, tree, FREESASA_PDB) == FREESASA_SUCCESS);
Expand Down Expand Up @@ -260,7 +260,7 @@ START_TEST (test_write_pdb) {
for (int i = 0; i < n; ++i) res.sasa[i] = 1.23;
res.parameters = freesasa_default_parameters;
res.n_atoms = n;

freesasa_structure_set_radius(s, res.sasa);
root = freesasa_tree_init(&res, s, "bla");
ck_assert(freesasa_write_pdb(tf, root) == FREESASA_SUCCESS);
Expand Down Expand Up @@ -301,7 +301,7 @@ START_TEST (test_write_pdb) {
END_TEST


START_TEST (test_trimmed_pdb)
START_TEST (test_trimmed_pdb)
{
// This test is due to suggestion from João Rodrigues (issue #6 on Github)
double total_ref = 16133.867124;
Expand Down Expand Up @@ -399,7 +399,7 @@ START_TEST (test_calc_errors)
ck_assert(empty != NULL);
ck_assert(freesasa_structure_from_pdb(empty, NULL, 0) == NULL);
fclose(empty);

freesasa_set_verbosity(FREESASA_V_NORMAL);

}
Expand All @@ -425,15 +425,15 @@ START_TEST (test_multi_calc)
p.lee_richards_n_slices = 20;
ck_assert((res = freesasa_calc_structure(st,&p)) != NULL);
ck_assert(fabs(res->total - 4804.055641) < 1e-5);

freesasa_structure_free(st);
freesasa_result_free(res);
#endif /* USE_THREADS */
}
END_TEST

// test an NMR structure with hydrogens and several models
START_TEST (test_1d3z)
START_TEST (test_1d3z)
{
FILE *pdb = fopen(DATADIR "1d3z.pdb","r");
int n = 0;
Expand All @@ -447,7 +447,7 @@ START_TEST (test_1d3z)
memcpy(radii_ref,freesasa_structure_radius(st),sizeof(double)*602);
rewind(pdb);
freesasa_structure_free(st);

freesasa_set_verbosity(FREESASA_V_SILENT);
st = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HYDROGEN);
result = freesasa_calc_structure(st, &param);
Expand Down Expand Up @@ -507,7 +507,7 @@ START_TEST (test_memerr)
set_fail_after(0);
ck_assert_ptr_eq(ptr, NULL);
set_fail_after(i);
ptr = freesasa_structure_get_chains(s, "A");
ptr = freesasa_structure_get_chains(s, "A", NULL, 0);
set_fail_after(0);
ck_assert_ptr_eq(ptr, NULL);
}
Expand All @@ -529,13 +529,13 @@ Suite *sasa_suite()
tcase_add_test(tc_basic, test_user_classes);
tcase_add_test(tc_basic, test_write_pdb);
tcase_add_test(tc_basic, test_memerr);

TCase *tc_lr_basic = tcase_create("Basic L&R");
tcase_add_checked_fixture(tc_lr_basic,setup_lr_precision,teardown_lr_precision);
tcase_add_test(tc_lr_basic, test_sasa_alg_basic);

TCase *tc_lr_static = test_LR_static();

TCase *tc_sr_basic = tcase_create("Basic S&R");
tcase_add_checked_fixture(tc_sr_basic,setup_sr_precision,teardown_sr_precision);
tcase_add_test(tc_sr_basic, test_sasa_alg_basic);
Expand Down
33 changes: 16 additions & 17 deletions tests/test_structure.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ START_TEST (test_structure_api)
freesasa_set_verbosity(FREESASA_V_SILENT);
ck_assert_int_eq(freesasa_structure_chain_index(s, 'B'), FREESASA_FAIL);
freesasa_set_verbosity(FREESASA_V_NORMAL);

int first, last;
ck_assert(freesasa_structure_residue_atoms(s, 0, &first, &last) == FREESASA_SUCCESS);
ck_assert(first == 0 && last == N-2);
Expand Down Expand Up @@ -172,7 +172,7 @@ START_TEST (test_pdb)
}
END_TEST

START_TEST (test_hydrogen)
START_TEST (test_hydrogen)
{
FILE *pdb = fopen(DATADIR "1d3z.pdb","r");
ck_assert(pdb != NULL);
Expand Down Expand Up @@ -203,7 +203,7 @@ START_TEST (test_hydrogen)
}
END_TEST

START_TEST (test_hetatm)
START_TEST (test_hetatm)
{
FILE *pdb = fopen(DATADIR "1ubq.pdb","r");
ck_assert(pdb != NULL);
Expand All @@ -228,7 +228,7 @@ START_TEST (test_structure_array_err)
rewind(pdb);
ck_assert_ptr_eq(freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_CHAINS), NULL);
fclose(pdb);

pdb = fopen(DATADIR "1ubq.pdb", "r");
ck_assert_ptr_eq(freesasa_structure_array(pdb, &n, NULL, 0), NULL);
fclose(pdb);
Expand All @@ -244,7 +244,7 @@ START_TEST (test_structure_array_one_chain) {

pdb = fopen(DATADIR "1ubq.pdb","r");
ss = freesasa_structure_array(pdb, &n, NULL, FREESASA_SEPARATE_CHAINS);

ck_assert(ss != NULL);
ck_assert(n == 1);
ck_assert(freesasa_structure_n(ss[0]) == 602);
Expand Down Expand Up @@ -340,7 +340,7 @@ START_TEST (test_structure_array_chains_models)

// many chains, many models, join models
rewind(pdb);
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HETATM |
freesasa_structure *s = freesasa_structure_from_pdb(pdb, NULL, FREESASA_INCLUDE_HETATM |
FREESASA_INCLUDE_HYDROGEN |
FREESASA_JOIN_MODELS);
ck_assert(s != NULL);
Expand Down Expand Up @@ -370,35 +370,35 @@ START_TEST (test_get_chains) {
ck_assert_int_eq(freesasa_structure_chain_atoms(s, 'D', &first, &last),FREESASA_SUCCESS);
ck_assert_int_eq(first, 129*3);
ck_assert_int_eq(last, 129*4-1);
freesasa_structure *s2 = freesasa_structure_get_chains(s,"");

freesasa_structure *s2 = freesasa_structure_get_chains(s, "", NULL, 0);
ck_assert(s2 == NULL);
s2 = freesasa_structure_get_chains(s,"X");
s2 = freesasa_structure_get_chains(s, "X", NULL, 0);
ck_assert(s2 == NULL);

s2 = freesasa_structure_get_chains(s,"A");
s2 = freesasa_structure_get_chains(s, "A", NULL, 0);
ck_assert(freesasa_structure_n(s2) == 129);
ck_assert(freesasa_structure_atom_chain(s2,0) == 'A');
ck_assert_str_eq(freesasa_structure_chain_labels(s2),"A");
freesasa_structure_free(s2);

s2 = freesasa_structure_get_chains(s,"D");
s2 = freesasa_structure_get_chains(s, "D", NULL, 0);
ck_assert(freesasa_structure_n(s2) == 129);
ck_assert(freesasa_structure_atom_chain(s2,0) == 'D');
ck_assert_str_eq(freesasa_structure_chain_labels(s2),"D");
freesasa_structure_free(s2);

s2 = freesasa_structure_get_chains(s,"AC");
s2 = freesasa_structure_get_chains(s, "AC", NULL, 0);
ck_assert(freesasa_structure_n(s2) == 2*129);
ck_assert(freesasa_structure_atom_chain(s2,0) == 'A');
ck_assert(freesasa_structure_atom_chain(s2,129) == 'C');
ck_assert_str_eq(freesasa_structure_chain_labels(s2),"AC");
freesasa_structure_free(s2);

s2 = freesasa_structure_get_chains(s,"E");
s2 = freesasa_structure_get_chains(s, "E", NULL, 0);
ck_assert_ptr_eq(s2, NULL);

s2 = freesasa_structure_get_chains(s,"AE");
s2 = freesasa_structure_get_chains(s, "AE", NULL, 0);
ck_assert_ptr_eq(s2, NULL);

freesasa_structure_free(s);
Expand All @@ -418,7 +418,7 @@ START_TEST (test_occupancy)
ck_assert(float_eq(r[1], 1.88, 1e-6));
ck_assert(float_eq(r[2], 1.61, 1e-6));
freesasa_structure_free(s);

}
END_TEST

Expand Down Expand Up @@ -481,7 +481,7 @@ Suite* structure_suite() {
tcase_add_test(tc_pdb,test_structure_array_one_chain);
tcase_add_test(tc_pdb,test_structure_array_nmr);
tcase_add_test(tc_pdb,test_structure_array_chains_models);

TCase *tc_1ubq = tcase_create("1UBQ");
tcase_add_checked_fixture(tc_1ubq,setup_1ubq,teardown_1ubq);
tcase_add_test(tc_1ubq,test_structure_1ubq);
Expand All @@ -493,4 +493,3 @@ Suite* structure_suite() {

return s;
}

0 comments on commit 0618103

Please sign in to comment.