summaryrefslogtreecommitdiff
path: root/src/lib/tng_io.c
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 /src/lib/tng_io.c
parent04d1b62313b529a521f2a961b61fc21210d0c406 (diff)
Added functions to get residue and chain names from atom number.
Diffstat (limited to 'src/lib/tng_io.c')
-rw-r--r--src/lib/tng_io.c152
1 files changed, 152 insertions, 0 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,
contact: Jan Huwald // Impressum