diff options
-rw-r--r-- | include/tng_io.h | 220 | ||||
-rw-r--r-- | src/lib/tng_io.c | 194 |
2 files changed, 413 insertions, 1 deletions
diff --git a/include/tng_io.h b/include/tng_io.h index a58d0ed..a3dc306 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -1166,6 +1166,22 @@ tng_function_status DECLSPECDLLEXPORT tng_num_particles_get int64_t *n); /** + * @brief Get if the number of particle can be varied during the simulation. + * @param tng_data is the trajectory from which to get the number of particles. + * @param variable is pointing to a value set to TNG_CONSTANT_N_ATOMS if the + * number of particles cannot change or TNG_VARIABLE_N_ATOMS if the number of + * particles can change. + * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) + * must be initialised before using it. + * @pre \code variable != 0 \endcode The pointer to variable must not be + * a NULL pointer. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_num_particles_variable_get + (const tng_trajectory_t tng_data, + tng_variable_n_atoms_flag *variable); + +/** * @brief Get the number of molecule types (length of tng_data->molecules). * @param tng_data is the trajectory from which to get the number of molecules. * @param n is pointing to a value set to the number of molecule types. @@ -1197,7 +1213,7 @@ tng_function_status DECLSPECDLLEXPORT tng_num_molecules_get * @param tng_data is the trajectory from which to get the molecule count list. * @param mol_cnt_list is a list of the count of each molecule in the * mol system. This is a pointer to the list in the TNG container, which - * means that it should be handled carefully. + * means that it should be handled carefully, e.g. not freed. * @pre \code tng_data != 0 \endcode The trajectory container (tng_data) * must be initialised before using it. * @return TNG_SUCCESS (0) if successful or TNG_FAILURE(1) if the list of @@ -1475,6 +1491,26 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_existing_add tng_molecule_t *molecule); /** + * @brief Get the name of a molecule. + * @param tng_data the trajectory containing the molecule. + * @param molecule the molecule of which to get the name. + * @param name the string to fill with the name of the molecule, + * memory must be allocated before. + * @param max_len maximum char length of the string, i.e. how much memory has + * been reserved for name. This includes \0 terminating character. + * @pre \code molecule != 0 \endcode The molecule must not be NULL. + * @pre \code name != 0 \endcode The pointer to the name string + * must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error + * has occurred (source string longer than destination string). + */ +tng_function_status DECLSPECDLLEXPORT tng_molecule_name_get + (const tng_trajectory_t tng_data, + const tng_molecule_t molecule, + char *name, + const int max_len); + +/** * @brief Set the name of a molecule. * @param tng_data is the trajectory data container containing the molecule.. * @param molecule is the molecule to rename. @@ -1580,6 +1616,66 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t tng_trajectory_t tng_data_dest); /** + * @brief Get the chains of a molecule. + * @param tng_data is the trajectory containing the molecule. + * @param molecule is the molecule of which to get the chains. + * @param chains is pointing to the list of chains. This is a pointer + * to the list of the molecule, which means that it should be handled + * carefully, e.g. not freed. + * @param n is pointing to a value set to the number of chains. + * @pre \code molecule != 0 \endcode The molecule must not be NULL. + * @pre \code chains != 0 \endcode The pointer to the list of chains must not + * be a NULL pointer. + * @pre \code n != 0 \endcode The pointer to n must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_molecule_chains_get + (tng_trajectory_t tng_data, + tng_molecule_t molecule, + tng_chain_t **chains, + int64_t *n); + +/** + * @brief Get the residues of a molecule. + * @param tng_data is the trajectory containing the molecule. + * @param molecule is the molecule of which to get the residues. + * @param residues is pointing to the list of residues. This is a pointer + * to the list of the molecule, which means that it should be handled + * carefully, e.g. not freed. + * @param n is pointing to a value set to the number of residues. + * @pre \code molecule != 0 \endcode The molecule must not be NULL. + * @pre \code residues != 0 \endcode The pointer to the list of residues must not + * be a NULL pointer. + * @pre \code n != 0 \endcode The pointer to n must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_molecule_residues_get + (tng_trajectory_t tng_data, + tng_molecule_t molecule, + tng_residue_t **residues, + int64_t *n); + +/** + * @brief Get the atoms of a molecule. + * @param tng_data is the trajectory containing the molecule. + * @param molecule is the molecule of which to get the atoms. + * @param atoms is pointing to the list of atoms. This is a pointer + * to the list of the molecule, which means that it should be handled + * carefully, e.g. not freed. + * @param n is pointing to a value set to the number of atoms. + * @pre \code molecule != 0 \endcode The molecule must not be NULL. + * @pre \code atoms != 0 \endcode The pointer to the list of atoms must not + * be a NULL pointer. + * @pre \code n != 0 \endcode The pointer to n must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_molecule_atoms_get + (tng_trajectory_t tng_data, + tng_molecule_t molecule, + tng_atom_t **atoms, + int64_t *n); + +/** * @brief Find a chain 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 chain. @@ -1687,6 +1783,26 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_atom_find tng_atom_t *atom); /** + * @brief Get the name of a chain. + * @param tng_data the trajectory containing the chain. + * @param chain the chain of which to get the name. + * @param name the string to fill with the name of the chain, + * memory must be allocated before. + * @param max_len maximum char length of the string, i.e. how much memory has + * been reserved for name. This includes \0 terminating character. + * @pre \code chain != 0 \endcode The chain must not be NULL. + * @pre \code name != 0 \endcode The pointer to the name string + * must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error + * has occurred (source string longer than destination string). + */ +tng_function_status DECLSPECDLLEXPORT tng_chain_name_get + (const tng_trajectory_t tng_data, + const tng_chain_t chain, + char *name, + const int max_len); + +/** * @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. @@ -1702,6 +1818,26 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_name_set const char *new_name); /** + * @brief Get the residues of a chain. + * @param tng_data is the trajectory containing the chain. + * @param chain is the chain of which to get the residues. + * @param residues is pointing to the list of residues. This is a pointer + * to the list of the molecule, which means that it should be handled + * carefully, e.g. not freed. + * @param n is pointing to a value set to the number of residues. + * @pre \code chain != 0 \endcode The chain must not be NULL. + * @pre \code residues != 0 \endcode The pointer to the list of residues must not + * be a NULL pointer. + * @pre \code n != 0 \endcode The pointer to n must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_chain_residues_get + (const tng_trajectory_t tng_data, + const tng_chain_t chain, + tng_residue_t **residues, + int64_t *n); + +/** * @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. @@ -1765,6 +1901,26 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_w_id_add tng_residue_t *residue); /** + * @brief Get the name of a residue. + * @param tng_data the trajectory containing the residue. + * @param residue the residue of which to get the name. + * @param name the string to fill with the name of the residue, + * memory must be allocated before. + * @param max_len maximum char length of the string, i.e. how much memory has + * been reserved for name. This includes \0 terminating character. + * @pre \code residue != 0 \endcode The residue must not be NULL. + * @pre \code name != 0 \endcode The pointer to the name string + * must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error + * has occurred (source string longer than destination string). + */ +tng_function_status DECLSPECDLLEXPORT tng_residue_name_get + (const tng_trajectory_t tng_data, + const tng_residue_t residue, + char *name, + const int max_len); + +/** * @brief Set the name of a residue. * @param tng_data is the trajectory data container containing the residue. * @param residue is the residue to rename. @@ -1782,6 +1938,28 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_set const char *new_name); /** + * @brief Get the atoms of a residue. + * @param tng_data is the trajectory containing the residue. + * @param molecule is the molecule containing the residue. + * @param residue is the residue of which to get the atoms. + * @param atoms is pointing to the list of atoms. This is a pointer + * to the list of the molecule, which means that it should be handled + * carefully, e.g. not freed. + * @param n is pointing to a value set to the number of atoms. + * @pre \code residue != 0 \endcode The residue must not be NULL. + * @pre \code atoms != 0 \endcode The pointer to the list of atoms must not + * be a NULL pointer. + * @pre \code n != 0 \endcode The pointer to n must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_residue_atoms_get + (const tng_trajectory_t tng_data, + const tng_molecule_t molecule, + const tng_residue_t residue, + tng_atom_t **atoms, + int64_t *n); + +/** * @brief Add an atom to a residue. * @param tng_data is the trajectory containing the residue. * @param residue is the residue to add an atom to. @@ -1830,6 +2008,26 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_atom_w_id_add tng_atom_t *atom); /** + * @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. + * @param name the string to fill with the name of the atom, + * memory must be allocated before. + * @param max_len maximum char length of the string, i.e. how much memory has + * been reserved for name. This includes \0 terminating character. + * @pre \code atom != 0 \endcode The atom must not be NULL. + * @pre \code name != 0 \endcode The pointer to the name string + * must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error + * has occurred (source string longer than destination string). + */ +tng_function_status DECLSPECDLLEXPORT tng_atom_name_get + (const tng_trajectory_t tng_data, + const tng_atom_t atom, + char *name, + const int max_len); + +/** * @brief Set the name of an atom. * @param tng_data is the trajectory data container containing the atom. * @param atom is the atom to rename. @@ -1847,6 +2045,26 @@ tng_function_status DECLSPECDLLEXPORT tng_atom_name_set const char *new_name); /** + * @brief Get the type of an atom. + * @param tng_data the trajectory containing the atom. + * @param atom the atom of which to get the type. + * @param type the string to fill with the type of the atom, + * memory must be allocated before. + * @param max_len maximum char length of the string, i.e. how much memory has + * been reserved for type. This includes \0 terminating character. + * @pre \code atom != 0 \endcode The atom must not be NULL. + * @pre \code type != 0 \endcode The pointer to the type string + * must not be a NULL pointer. + * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error + * has occurred (source string longer than destination string). + */ +tng_function_status DECLSPECDLLEXPORT tng_atom_type_get + (const tng_trajectory_t tng_data, + const tng_atom_t atom, + char *type, + const int max_len); + +/** * @brief Set the atom type of an atom. * @param tng_data is the trajectory data container containing the atom. * @param atom is the atom to change. diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 121688d..d17d60b 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -6973,6 +6973,26 @@ static tng_function_status tng_frame_set_finalize // return(TNG_SUCCESS); // } */ + +tng_function_status tng_atom_name_get(tng_trajectory_t tng_data, + const tng_atom_t atom, + char *name, + const int max_len) +{ + (void) tng_data; + TNG_ASSERT(atom, "TNG library: atom must not be NULL"); + TNG_ASSERT(name, "TNG library: name must not be a NULL pointer"); + + strncpy(name, atom->name, max_len - 1); + name[max_len - 1] = 0; + + if(strlen(atom->name) > (unsigned int)max_len - 1) + { + return(TNG_FAILURE); + } + return(TNG_SUCCESS); +} + tng_function_status tng_atom_name_set(tng_trajectory_t tng_data, tng_atom_t atom, const char *new_name) @@ -7008,6 +7028,25 @@ tng_function_status tng_atom_name_set(tng_trajectory_t tng_data, return(TNG_SUCCESS); } +tng_function_status tng_atom_type_get(tng_trajectory_t tng_data, + const tng_atom_t atom, + char *type, + const int max_len) +{ + (void) tng_data; + TNG_ASSERT(atom, "TNG library: atom must not be NULL"); + TNG_ASSERT(type, "TNG library: type must not be a NULL pointer"); + + strncpy(type, atom->atom_type, max_len - 1); + type[max_len - 1] = 0; + + if(strlen(atom->atom_type) > (unsigned int)max_len - 1) + { + return(TNG_FAILURE); + } + return(TNG_SUCCESS); +} + tng_function_status tng_atom_type_set(tng_trajectory_t tng_data, tng_atom_t atom, const char *new_type) @@ -7259,6 +7298,25 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_existing_add return(TNG_SUCCESS); } +tng_function_status tng_molecule_name_get(tng_trajectory_t tng_data, + const tng_molecule_t molecule, + char *name, + const int max_len) +{ + (void) tng_data; + TNG_ASSERT(molecule, "TNG library: molecule must not be NULL"); + TNG_ASSERT(name, "TNG library: name must not be a NULL pointer"); + + strncpy(name, molecule->name, max_len - 1); + name[max_len - 1] = 0; + + if(strlen(molecule->name) > (unsigned int)max_len - 1) + { + return(TNG_FAILURE); + } + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_molecule_name_set (tng_trajectory_t tng_data, tng_molecule_t molecule, @@ -7532,6 +7590,57 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_system_copy(tng_trajectory_t return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_molecule_chains_get + (const tng_trajectory_t tng_data, + const tng_molecule_t molecule, + tng_chain_t **chains, + int64_t *n) +{ + (void) tng_data; + TNG_ASSERT(molecule, "TNG library: molecule must not be NULL"); + TNG_ASSERT(chains, "TNG library: chains must not be a NULL pointer"); + TNG_ASSERT(n, "TNG library: n must not be a NULL pointer"); + + *chains = &molecule->chains; + *n = molecule->n_chains; + + return(TNG_SUCCESS); +} + +tng_function_status DECLSPECDLLEXPORT tng_molecule_residues_get + (const tng_trajectory_t tng_data, + const tng_molecule_t molecule, + tng_residue_t **residues, + int64_t *n) +{ + (void) tng_data; + TNG_ASSERT(molecule, "TNG library: molecule must not be NULL"); + TNG_ASSERT(residues, "TNG library: residues must not be a NULL pointer"); + TNG_ASSERT(n, "TNG library: n must not be a NULL pointer"); + + *residues = &molecule->residues; + *n = molecule->n_residues; + + return(TNG_SUCCESS); +} + +tng_function_status DECLSPECDLLEXPORT tng_molecule_atoms_get + (const tng_trajectory_t tng_data, + const tng_molecule_t molecule, + tng_atom_t **atoms, + int64_t *n) +{ + (void) tng_data; + TNG_ASSERT(molecule, "TNG library: molecule must not be NULL"); + TNG_ASSERT(atoms, "TNG library: atoms must not be a NULL pointer"); + TNG_ASSERT(n, "TNG library: n must not be a NULL pointer"); + + *atoms = &molecule->atoms; + *n = molecule->n_atoms; + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_find (tng_trajectory_t tng_data, tng_molecule_t molecule, @@ -7712,6 +7821,25 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_atom_find return(TNG_FAILURE); } +tng_function_status tng_chain_name_get(const tng_trajectory_t tng_data, + const tng_chain_t chain, + char *name, + const int max_len) +{ + (void) tng_data; + TNG_ASSERT(chain, "TNG library: chain must not be NULL"); + TNG_ASSERT(name, "TNG library: name must not be a NULL pointer"); + + strncpy(name, chain->name, max_len - 1); + name[max_len - 1] = 0; + + if(strlen(chain->name) > (unsigned int)max_len - 1) + { + return(TNG_FAILURE); + } + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_chain_name_set (tng_trajectory_t tng_data, tng_chain_t chain, @@ -7747,6 +7875,23 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_name_set return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_chain_residues_get + (const tng_trajectory_t tng_data, + const tng_chain_t chain, + tng_residue_t **residues, + int64_t *n) +{ + (void) tng_data; + TNG_ASSERT(chain, "TNG library: chain must not be NULL"); + TNG_ASSERT(residues, "TNG library: residues must not be a NULL pointer"); + TNG_ASSERT(n, "TNG library: n must not be a NULL pointer"); + + *residues = &chain->residues; + *n = chain->n_residues; + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_chain_residue_find (tng_trajectory_t tng_data, tng_chain_t chain, @@ -7886,6 +8031,25 @@ tng_function_status DECLSPECDLLEXPORT tng_chain_residue_w_id_add return(stat); } +tng_function_status tng_residue_name_get(tng_trajectory_t tng_data, + const tng_residue_t residue, + char *name, + const int max_len) +{ + (void) tng_data; + TNG_ASSERT(residue, "TNG library: residue must not be NULL"); + TNG_ASSERT(name, "TNG library: name must not be a NULL pointer"); + + strncpy(name, residue->name, max_len - 1); + name[max_len - 1] = 0; + + if(strlen(residue->name) > (unsigned int)max_len - 1) + { + return(TNG_FAILURE); + } + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_residue_name_set(tng_trajectory_t tng_data, tng_residue_t residue, const char *new_name) @@ -7921,6 +8085,24 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_set(tng_trajectory_t tng_ return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_residue_atoms_get + (const tng_trajectory_t tng_data, + const tng_molecule_t molecule, + const tng_residue_t residue, + tng_atom_t **atoms, + int64_t *n) +{ + (void) tng_data; + TNG_ASSERT(residue, "TNG library: residue must not be NULL"); + TNG_ASSERT(atoms, "TNG library: atoms must not be a NULL pointer"); + TNG_ASSERT(n, "TNG library: n must not be a NULL pointer"); + + **atoms = &molecule->atoms[residue->atoms_offset]; + *n = residue->n_atoms; + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_residue_atom_add (tng_trajectory_t tng_data, tng_residue_t residue, @@ -10273,6 +10455,18 @@ tng_function_status DECLSPECDLLEXPORT tng_num_particles_get return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_num_particles_variable_get + (const tng_trajectory_t tng_data, + tng_variable_n_atoms_flag *variable) +{ + TNG_ASSERT(tng_data, "TNG library: Trajectory container not properly setup."); + TNG_ASSERT(variable, "TNG library: variable must not be a NULL pointer"); + + *variable = tng_data->var_num_atoms_flag; + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_num_molecule_types_get (const tng_trajectory_t tng_data, int64_t *n) |