Skip to content

Commit

Permalink
Add code to get long chain labels from structure.
Browse files Browse the repository at this point in the history
  • Loading branch information
mittinatten committed Dec 13, 2023
1 parent a8a15cc commit cf92868
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/freesasa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,28 @@ freesasa_structure_get_chains(const freesasa_structure *structure,
const char *
freesasa_structure_chain_labels(const freesasa_structure *structure);

/**
Get number of chains in structure
@param structure The structure.
@return number of chains
@ingroup structure
*/
int freesasa_structure_number_chains(const freesasa_structure *structure);

/**
Get label of given chain (auth_asym_id)
@param structure The structure.
@param index Index of chain
@return chain-label
@ingroup structure
*/
const char *
freesasa_structure_chain_label(const freesasa_structure *structure, int index);

/**
Get number of atoms.
Expand Down
16 changes: 16 additions & 0 deletions src/structure.c
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,22 @@ freesasa_structure_chain_labels(const freesasa_structure *structure)
return structure->chains.short_labels;
}

int freesasa_structure_number_chains(const freesasa_structure *structure)
{
assert(structure);

return structure->chains.n;
}

const char *
freesasa_structure_chain_label(const freesasa_structure *structure, int index)
{
assert(structure);
assert(index >= 0 && index < structure->chains.n);

return structure->chains.labels[index];
}

const coord_t *
freesasa_structure_xyz(const freesasa_structure *structure)
{
Expand Down
15 changes: 14 additions & 1 deletion tests/test_structure.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ END_TEST
START_TEST(test_cif)
{
int first, last;
const char *const *chain_labels;

s = freesasa_structure_new();
for (int i = 0; i < N; ++i) {
struct freesasa_cif_atom_lcl atom = {
Expand Down Expand Up @@ -162,7 +164,7 @@ START_TEST(test_cif)

struct freesasa_cif_atom_lcl atom = {
.group_PDB = "",
.auth_asym_id = lcl[0],
.auth_asym_id = "BBB",
.auth_seq_id = rnu[0],
.pdbx_PDB_ins_code = "A",
.auth_comp_id = rna[0],
Expand All @@ -177,6 +179,17 @@ START_TEST(test_cif)
ck_assert_int_eq(freesasa_structure_add_cif_atom_lcl(s, &atom, NULL, 0),
FREESASA_SUCCESS);
ck_assert_str_eq(freesasa_structure_atom_res_number(s, N), " 1A");

ck_assert_int_eq(freesasa_structure_chain_atoms_lcl(s, "BBB", &first, &last), FREESASA_SUCCESS);
ck_assert_int_eq(first, N);
ck_assert_int_eq(last, N);
ck_assert_int_eq(freesasa_structure_chain_residues_lcl(s, "BBB", &first, &last), FREESASA_SUCCESS);
ck_assert_int_eq(first, 2);
ck_assert_int_eq(last, 2);

ck_assert_int_eq(freesasa_structure_number_chains(s), 2);
ck_assert_str_eq(freesasa_structure_chain_label(s, 0), lcl[0]);
ck_assert_str_eq(freesasa_structure_chain_label(s, 1), "BBB");
}

double a2r(const char *rn, const char *am)
Expand Down

0 comments on commit cf92868

Please sign in to comment.