summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tng_io.h47
-rw-r--r--src/lib/tng_io.c148
2 files changed, 194 insertions, 1 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index f13563b..8f6fcef 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -1288,6 +1288,23 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_w_id_add
tng_chain_t *chain);
/**
+ * @brief Add a bond between two atoms to a molecule.
+ * @param tng_data is the trajectory data container containing the molecule.
+ * @param molecule is the molecule containing the atoms to connect.
+ * @param from_atom_id is the id of one of the two atoms in the bond.
+ * @param to_atom_id is the id of the other atom in the bond.
+ * @param bond is a pointer to the newly created bond.
+ * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (!) if a minor error
+ * has occured or TNG_CRITICAL (2) if a major error has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_molecule_bond_add
+ (const tng_trajectory_t tng_data,
+ tng_molecule_t molecule,
+ const int64_t from_atom_id,
+ const int64_t to_atom_id,
+ tng_bond_t *bond);
+
+/**
* @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.
@@ -1443,6 +1460,19 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_name_of_particle_nr_get
int max_len);
/**
+ * @brief Get the molecule id 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 id is will be set to the id of the molecule.
+ * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
+ * has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_molecule_id_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ int64_t *id);
+
+/**
* @brief Get the bonds of the current molecular system.
* @param tng_data is the trajectory data container containing the molecular
* system.
@@ -1497,7 +1527,8 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_name_of_particle_nr_get
int max_len);
/**
- * @brief Get the residue id of real particle number (number in mol system).
+ * @brief Get the residue id (local to molecule) 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 id is a pointer to the variable, which will be set to the ID.
@@ -1510,6 +1541,20 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_id_of_particle_nr_get
int64_t *id);
/**
+ * @brief Get the residue id (based on other molecules and molecule counts)
+ * 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 id is a pointer to the variable, which will be set to the ID.
+ * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
+ * has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_global_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 d7bc988..26c8986 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -7329,6 +7329,63 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_chain_w_id_add
return(stat);
}
+tng_function_status DECLSPECDLLEXPORT tng_molecule_bond_add
+ (const tng_trajectory_t tng_data,
+ tng_molecule_t molecule,
+ const int64_t from_atom_id,
+ const int64_t to_atom_id,
+ tng_bond_t *bond)
+{
+ int64_t i;
+ tng_bond_t new_bonds;
+ 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);
+ }
+
+ for(i = 0; i < molecule->n_bonds; i++)
+ {
+ *bond = &molecule->bonds[i];
+ /* Check if the bond already exists */
+ if(((*bond)->from_atom_id == from_atom_id && (*bond)->to_atom_id == to_atom_id) ||
+ ((*bond)->to_atom_id == from_atom_id && (*bond)->from_atom_id == to_atom_id))
+ {
+ return(TNG_SUCCESS);
+ }
+ }
+
+ new_bonds = realloc(molecule->bonds,
+ sizeof(struct tng_bond) *
+ (molecule->n_bonds + 1));
+
+ if(!new_bonds)
+ {
+ printf("Cannot allocate memory (%"PRId64" bytes). %s: %d\n",
+ sizeof(struct tng_bond) * (molecule->n_bonds + 1),
+ __FILE__, __LINE__);
+ *bond = 0;
+ free(molecule->bonds);
+ molecule->bonds = 0;
+ return(TNG_CRITICAL);
+ }
+
+ molecule->bonds = new_bonds;
+
+ *bond = &new_bonds[molecule->n_bonds];
+
+ (*bond)->from_atom_id = from_atom_id;
+ (*bond)->to_atom_id = to_atom_id;
+
+ molecule->n_bonds++;
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_chain_name_set
(tng_trajectory_t tng_data,
tng_chain_t chain,
@@ -7768,6 +7825,47 @@ tng_function_status DECLSPECDLLEXPORT tng_molecule_name_of_particle_nr_get
return(TNG_SUCCESS);
}
+tng_function_status DECLSPECDLLEXPORT tng_molecule_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 = 0;
+ tng_molecule_t mol;
+ 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);
+ }
+
+ tng_molecule_cnt_list_get(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;
+ }
+ found = TNG_TRUE;
+ break;
+ }
+ if(!found)
+ {
+ return(TNG_FAILURE);
+ }
+
+ *id = mol->id;
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_molsystem_bonds_get
(const tng_trajectory_t tng_data,
int64_t *n_bonds,
@@ -7989,6 +8087,56 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_id_of_particle_nr_get
return(TNG_SUCCESS);
}
+tng_function_status DECLSPECDLLEXPORT tng_global_residue_id_of_particle_nr_get
+ (const tng_trajectory_t tng_data,
+ const int64_t nr,
+ int64_t *id)
+{
+ int64_t cnt = 0, i, offset = 0, *molecule_cnt_list = 0;
+ 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);
+ }
+
+ tng_molecule_cnt_list_get(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];
+ offset += mol->n_residues * 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);
+ }
+
+ offset += mol->n_residues * ((nr - cnt) / mol->n_atoms);
+
+ *id = atom->residue->id + offset;
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_atom_name_of_particle_nr_get
(const tng_trajectory_t tng_data,
const int64_t nr,
contact: Jan Huwald // Impressum