From 269784a07eb61262e2ba04c23553d7070b763756 Mon Sep 17 00:00:00 2001 From: Magnus Lundborg Date: Fri, 10 Jan 2014 16:12:11 +0100 Subject: Fixed bug in name comparisons. Added function to get residue of atom. diff --git a/include/tng_io.h b/include/tng_io.h index 3b19a32..67ac563 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -2042,6 +2042,18 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_atom_w_id_add tng_atom_t *atom); /** + * @brief Get the residue of an atom. + * @param tng_data the trajectory containing the atom. + * @param atom the atom of which to get the name. + * @param residue is set to the residue of the atom. + * @pre \code atom != 0 \endcode The atom must not be NULL. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status tng_atom_residue_get(tng_trajectory_t tng_data, + const tng_atom_t atom, + tng_residue_t *residue); + +/** * @brief Get the name of an atom. * @param tng_data the trajectory containing the atom. * @param atom the atom of which to get the name. diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index e4774dd..fa98865 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -6976,6 +6976,19 @@ static tng_function_status tng_frame_set_finalize // } */ +tng_function_status tng_atom_residue_get(tng_trajectory_t tng_data, + const tng_atom_t atom, + tng_residue_t *residue) +{ + (void) tng_data; + + TNG_ASSERT(atom, "TNG library: atom must not be NULL"); + + *residue = atom->residue; + + return(TNG_SUCCESS); +} + tng_function_status tng_atom_name_get(tng_trajectory_t tng_data, const tng_atom_t atom, char *name, @@ -7442,7 +7455,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_find for(i = 0; i < n_molecules; i++) { *molecule = &tng_data->molecules[i]; - if(name[0] != 0 || strcmp(name, (*molecule)->name) == 0) + if(name[0] == 0 || strcmp(name, (*molecule)->name) == 0) { if(nr == -1 || nr == (*molecule)->id) { @@ -7720,7 +7733,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_find for(i = 0; i < n_chains; i++) { *chain = &molecule->chains[i]; - if(name[0] != 0 || strcmp(name, (*chain)->name) == 0) + if(name[0] == 0 || strcmp(name, (*chain)->name) == 0) { if(nr == -1 || nr == (*chain)->id) { @@ -7868,7 +7881,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_atom_find for(i = 0; i < n_atoms; i++) { *atom = &molecule->atoms[i]; - if(name[0] != 0 || strcmp(name, (*atom)->name) == 0) + if(name[0] == 0 || strcmp(name, (*atom)->name) == 0) { if(id == -1 || id == (*atom)->id) { @@ -7986,7 +7999,7 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_find for(i = 0; i < n_residues; i++) { *residue = &chain->residues[i]; - if(name[0] != 0 || strcmp(name, (*residue)->name) == 0) + if(name[0] == 0 || strcmp(name, (*residue)->name) == 0) { if(id == -1 || id == (*residue)->id) { -- cgit v0.10.1