summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMagnus Lundborg <magnus.lundborg@scilifelab.se>2013-01-14 13:02:17 (GMT)
committerMagnus Lundborg <magnus.lundborg@scilifelab.se>2013-01-14 13:02:17 (GMT)
commitb94471a09f76b28bc77af1d3d8469fc72674e7f8 (patch)
tree9bce56c1b440762e8a88262ebbabfd2a48ad8eea
parent04d1b62313b529a521f2a961b61fc21210d0c406 (diff)
Added functions to get residue and chain names from atom number.
-rw-r--r--src/lib/tng_io.c152
-rw-r--r--src/lib/tng_io.h72
-rw-r--r--src/tests/tng_io_read_pos.c10
3 files changed, 231 insertions, 3 deletions
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 708fc3d..47f215b 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -5471,6 +5471,110 @@ tng_function_status tng_molecule_name_of_particle_nr_get
return(TNG_SUCCESS);
}
+tng_function_status tng_chain_name_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *name,
+ int max_len)
+{
+ int64_t cnt = 0, i, *molecule_cnt_list;
+ tng_molecule_t mol;
+ tng_atom_t atom;
+ tng_bool found = FALSE;
+
+ 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 = TRUE;
+ break;
+ }
+ if(!found)
+ {
+ return(TNG_FAILURE);
+ }
+ if(!atom->residue || atom->residue->chain)
+ {
+ return(TNG_FAILURE);
+ }
+
+ strncpy(name, atom->residue->chain->name, max_len - 1);
+ name[max_len - 1] = 0;
+
+ if(strlen(atom->residue->chain->name) > max_len - 1)
+ {
+ return(TNG_FAILURE);
+ }
+ return(TNG_SUCCESS);
+}
+
+tng_function_status tng_residue_name_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *name,
+ int max_len)
+{
+ int64_t cnt = 0, i, *molecule_cnt_list;
+ tng_molecule_t mol;
+ tng_atom_t atom;
+ tng_bool found = FALSE;
+
+ 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 = TRUE;
+ break;
+ }
+ if(!found)
+ {
+ return(TNG_FAILURE);
+ }
+ if(!atom->residue)
+ {
+ return(TNG_FAILURE);
+ }
+
+ strncpy(name, atom->residue->name, max_len - 1);
+ name[max_len - 1] = 0;
+
+ if(strlen(atom->residue->name) > max_len - 1)
+ {
+ return(TNG_FAILURE);
+ }
+ return(TNG_SUCCESS);
+}
+
tng_function_status tng_atom_name_of_particle_nr_get
(const tng_trajectory_t tng_data,
const int64_t nr,
@@ -5519,6 +5623,54 @@ tng_function_status tng_atom_name_of_particle_nr_get
return(TNG_SUCCESS);
}
+tng_function_status tng_atom_type_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *type,
+ int max_len)
+{
+ int64_t cnt = 0, i, *molecule_cnt_list;
+ tng_molecule_t mol;
+ tng_atom_t atom;
+ tng_bool found = FALSE;
+
+ 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 = TRUE;
+ break;
+ }
+ if(!found)
+ {
+ return(TNG_FAILURE);
+ }
+
+ strncpy(type, atom->atom_type, max_len - 1);
+ type[max_len - 1] = 0;
+
+ if(strlen(atom->atom_type) > max_len - 1)
+ {
+ return(TNG_FAILURE);
+ }
+ return(TNG_SUCCESS);
+}
+
tng_function_status tng_particle_mapping_add
(tng_trajectory_t tng_data,
const int64_t num_first_particle,
diff --git a/src/lib/tng_io.h b/src/lib/tng_io.h
index c00abc0..0530112 100644
--- a/src/lib/tng_io.h
+++ b/src/lib/tng_io.h
@@ -1341,6 +1341,54 @@ tng_function_status tng_molecule_name_of_particle_nr_get_
}
/**
+ * @brief Get the chain 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 chain. 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 tng_chain_name_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *name,
+ int max_len);
+tng_function_status tng_chain_name_of_particle_nr_get_
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *name,
+ int max_len)
+{
+ return(tng_chain_name_of_particle_nr_get(tng_data, nr, name, 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 tng_residue_name_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *name,
+ int max_len);
+tng_function_status tng_residue_name_of_particle_nr_get_
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *name,
+ int max_len)
+{
+ return(tng_residue_name_of_particle_nr_get(tng_data, nr, name, max_len));
+}
+
+/**
* @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.
@@ -1365,6 +1413,30 @@ tng_function_status tng_atom_name_of_particle_nr_get_
}
/**
+ * @brief Get the atom type 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 type is a string, which is set to the type of the atom. Memory
+ * must be reserved beforehand.
+ * @param max_len is the maximum length of type.
+ * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
+ * has occured.
+ */
+tng_function_status tng_atom_type_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *type,
+ int max_len);
+tng_function_status tng_atom_type_of_particle_nr_get_
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ char *type,
+ int max_len)
+{
+ return(tng_atom_type_of_particle_nr_get(tng_data, nr, type, max_len));
+}
+
+/**
* @brief Add a particle mapping table.
* @details Each particle mapping table will be written as a separate block,
* followed by the data blocks for the corresponding particles. In most cases
diff --git a/src/tests/tng_io_read_pos.c b/src/tests/tng_io_read_pos.c
index 5d3be64..54193eb 100644
--- a/src/tests/tng_io_read_pos.c
+++ b/src/tests/tng_io_read_pos.c
@@ -12,7 +12,7 @@ int main(int argc, char **argv)
int64_t particle = 0;
// Set a default frame range
int first_frame = 0, last_frame = 50;
- char name[64];
+ char atom_name[64], res_name[64];
if(argc <= 1)
{
@@ -50,10 +50,14 @@ int main(int argc, char **argv)
n_frames = last_frame - first_frame + 1;
- if(tng_atom_name_of_particle_nr_get(traj, particle, name, sizeof(name)) ==
+ if(tng_atom_name_of_particle_nr_get(traj, particle, atom_name,
+ sizeof(atom_name)) ==
+ TNG_SUCCESS &&
+ tng_residue_name_of_particle_nr_get(traj, particle, res_name,
+ sizeof(res_name)) ==
TNG_SUCCESS)
{
- printf("Particle: %s\n", name);
+ printf("Particle: %s (%s)\n", atom_name, res_name);
}
else
{
contact: Jan Huwald // Impressum