diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-29 10:50:55 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-10-29 10:50:55 (GMT) |
commit | bb465175362766009433696506dab621c854bc78 (patch) | |
tree | 6cf6cbd1d58dde512671e8da87743b2bce450959 | |
parent | 04b40aa7c3cf21bad6dada99b2f8911efbfd1695 (diff) |
Added function to get residue ID of an atom.
-rw-r--r-- | include/tng_io.h | 15 | ||||
-rw-r--r-- | src/lib/tng_io.c | 55 | ||||
-rw-r--r-- | src/lib/tng_io_fortran.c | 8 |
3 files changed, 78 insertions, 0 deletions
diff --git a/include/tng_io.h b/include/tng_io.h index e9f2ec5..1b29fbf 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -1464,6 +1464,21 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_of_particle_nr_get int max_len); /** + * @brief Get the residue name of real particle number (number in mol system). + * @param tng_data is the trajectory data container containing the atom. + * @param nr is the real number of the particle in the molecular system. + * @param name is a string, which is set to the name of the residue. Memory + * must be reserved beforehand. + * @param max_len is the maximum length of name. + * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error + * has occured. + */ +tng_function_status DECLSPECDLLEXPORT tng_residue_id_of_particle_nr_get + (const tng_trajectory_t tng_data, + const int64_t nr, + int64_t *id); + +/** * @brief Get the atom name of real particle number (number in mol system). * @param tng_data is the trajectory data container containing the atom. * @param nr is the real number of the particle in the molecular system. diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index b1ea313..69dbadd 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -7896,6 +7896,61 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_of_particle_nr_get return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_residue_id_of_particle_nr_get + (const tng_trajectory_t tng_data, + const int64_t nr, + int64_t *id) +{ + int64_t cnt = 0, i, *molecule_cnt_list; + tng_molecule_t mol; + tng_atom_t atom; + tng_bool found = TNG_FALSE; + tng_function_status stat; + + stat = tng_check_trajectory_container(tng_data); + if(stat != TNG_SUCCESS) + { + printf("Trajectory container not properly setup. %s: %d\n", + __FILE__, __LINE__); + return(stat); + } + + if(tng_data->var_num_atoms_flag) + { + molecule_cnt_list = tng_data->current_trajectory_frame_set. + molecule_cnt_list; + } + else + { + molecule_cnt_list = tng_data->molecule_cnt_list; + } + + for(i = 0; i < tng_data->n_molecules; i++) + { + mol = &tng_data->molecules[i]; + if(cnt + mol->n_atoms * molecule_cnt_list[i] - 1 < nr) + { + cnt += mol->n_atoms * molecule_cnt_list[i]; + continue; + } + atom = &mol->atoms[nr % mol->n_atoms]; + found = TNG_TRUE; + break; + } + if(!found) + { + return(TNG_FAILURE); + } + if(!atom->residue) + { + return(TNG_FAILURE); + } + + *id = atom->residue->id; + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_atom_name_of_particle_nr_get (const tng_trajectory_t tng_data, const int64_t nr, diff --git a/src/lib/tng_io_fortran.c b/src/lib/tng_io_fortran.c index 22a6d61..5c7bbb7 100644 --- a/src/lib/tng_io_fortran.c +++ b/src/lib/tng_io_fortran.c @@ -650,6 +650,14 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_of_particle_nr_get_ return(tng_residue_name_of_particle_nr_get(tng_data, nr, name, max_len)); } +tng_function_status DECLSPECDLLEXPORT tng_residue_id_of_particle_nr_get_ + (const tng_trajectory_t tng_data, + const int64_t nr, + int64_t *id) +{ + return(tng_residue_id_of_particle_nr_get(tng_data, nr, id)); +} + tng_function_status DECLSPECDLLEXPORT tng_atom_name_of_particle_nr_get_ (const tng_trajectory_t tng_data, const int64_t nr, |