diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-11-26 10:27:19 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-11-26 10:27:19 (GMT) |
commit | 062242b7c5360baa426e396b2be4c3cc1d58cd21 (patch) | |
tree | f7a95a6193e12abd42b8a5207a593cee1ad84055 | |
parent | 5ea15b21f5d497df39c021b4af854bf73db2e4b9 (diff) |
Function tng_molecule_atom_find() added.
-rw-r--r-- | include/tng_io.h | 41 | ||||
-rw-r--r-- | src/lib/tng_io.c | 35 |
2 files changed, 63 insertions, 13 deletions
diff --git a/include/tng_io.h b/include/tng_io.h index 4d456bb..660ddfc 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -1515,8 +1515,8 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_cnt_set * must not be a NULL pointer. * @return TNG_SUCCESS (0) if the molecule is found or TNG_FAILURE (1) if the * molecule is not found. - * @details If name is an empty string and id is -1 the first molecule will be - * found. + * @details If name is an empty string and id == -1 the first residue will + * be found. */ tng_function_status DECLSPECDLLEXPORT tng_molecule_find (tng_trajectory_t tng_data, @@ -1555,8 +1555,8 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_of_index_get * must not be a NULL pointer. * @return TNG_SUCCESS (0) if the chain is found or TNG_FAILURE (1) if the * chain is not found. - * @details If name is an empty string and id is -1 the first chain will be - * found. + * @details If name is an empty string and id == -1 the first residue will + * be found. */ tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_find (tng_trajectory_t tng_data, @@ -1625,12 +1625,33 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_bond_add tng_bond_t *bond); /** + * @brief Find an atom in a molecule. + * @param tng_data is the trajectory data container containing the molecule. + * @param molecule is the molecule in which to search for the atom. + * @param name is a string containing the name of the atom. If name is an + * empty string only id will be used for searching. + * @param id is the id of the atom to find. If id == -1 the first atom + * that matches the specified name will be found. + * @param atom is a pointer to the atom if it was found - otherwise 0. + * @pre \code name != 0 \endcode The pointer to the name string + * must not be a NULL pointer. + * @return TNG_SUCCESS (0) if the atom is found or TNG_FAILURE (1) if the + * atom is not found. + * @details If name is an empty string and id == -1 the first residue will + * be found. + */ +tng_function_status DECLSPECDLLEXPORT tng_molecule_atom_find + (tng_trajectory_t tng_data, + tng_molecule_t molecule, + const char *name, + int64_t id, + tng_atom_t *atom); + +/** * @brief Set the name of a chain. * @param tng_data is the trajectory data container containing the atom.. * @param chain is the chain to rename. * @param new_name is a string containing the wanted name. - * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) - * must be initialised before using it. * @pre \code new_name != 0 \endcode The pointer to the name string * must not be a NULL pointer. * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major @@ -1645,17 +1666,17 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_name_set * @brief Find a residue in a chain. * @param tng_data is the trajectory data container containing the chain. * @param chain is the chain in which to search for the residue. - * @param name is a string containing the name of the residue. + * @param name is a string containing the name of the residue. If name is an + * empty string only id will be used for searching. * @param id is the id of the residue to find. If id == -1 the first residue * that matches the specified name will be found. * @param residue is a pointer to the residue if it was found - otherwise 0. - * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) - * must be initialised before using it. * @pre \code name != 0 \endcode The pointer to the name string * must not be a NULL pointer. * @return TNG_SUCCESS (0) if the residue is found or TNG_FAILURE (1) if the * residue is not found. - * @details If name is an empty string the first residue will be found. + * @details If name is an empty string and id == -1 the first residue will + * be found. */ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_find (tng_trajectory_t tng_data, diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index ce1732c..f00810c 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -7429,6 +7429,37 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_bond_add return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_molecule_atom_find + (tng_trajectory_t tng_data, + tng_molecule_t molecule, + const char *name, + int64_t id, + tng_atom_t *atom) +{ + int64_t i, n_atoms; + (void)tng_data; + + TNG_ASSERT(name, "TNG library: name must not be a NULL pointer."); + + n_atoms = molecule->n_atoms; + + for(i = 0; i < n_atoms; i++) + { + *atom = &molecule->atoms[i]; + if(name[0] != 0 || strcmp(name, (*atom)->name) == 0) + { + if(id == -1 || id == (*atom)->id) + { + return(TNG_SUCCESS); + } + } + } + + *atom = 0; + + return(TNG_FAILURE); +} + tng_function_status DECLSPECDLLEXPORT tng_chain_name_set (tng_trajectory_t tng_data, tng_chain_t chain, @@ -7437,7 +7468,6 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_name_set unsigned int len; (void)tng_data; - TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(new_name, "TNG library: new_name must not be a NULL pointer."); len = tng_min_i((int)strlen(new_name) + 1, TNG_MAX_STR_LEN); @@ -7475,7 +7505,6 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_find int64_t i, n_residues; (void)tng_data; - TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); TNG_ASSERT(name, "TNG library: name must not be a NULL pointer."); n_residues = chain->n_residues; @@ -7732,7 +7761,7 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_alloc(const tng_trajectory_t } tng_molecule_init(tng_data, *molecule_p); - + return(TNG_SUCCESS); } |