summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tng_io.h20
-rw-r--r--src/lib/tng_io.c51
2 files changed, 67 insertions, 4 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index 4b91f7e..d1ce168 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -923,6 +923,26 @@ tng_function_status tng_molecule_cnt_set(tng_trajectory_t tng_data,
int64_t cnt);
/**
+ * @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.
+ * @param name is a string containing the name of the chain. If name is empty
+ * only id will be used for finding the chain.
+ * @param id is the id of the chain to look for. If id is -1 only the name of
+ * the chain will be used for finding the chain.
+ * @param chain is a pointer to the chain if it was found - otherwise 0.
+ * @return TNG_SUCCESS (0) if the chain is found or TNG_FAILURE (1) if the
+ * chain is not found.
+ * @details If name is an empty string and id is -1 the first chain will be
+ * found.
+ */
+tng_function_status tng_molecule_chain_find(tng_trajectory_t tng_data,
+ tng_molecule_t molecule,
+ const char *name,
+ int64_t id,
+ tng_chain_t *chain);
+
+/**
* @brief Add a chain to a molecule.
* @param tng_data is the trajectory data container containing the molecule..
* @param molecule is the molecule to add a chain to.
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 5f85d18..b4a65ae 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -24,7 +24,6 @@
#include "md5.h"
-
struct tng_bond {
/** One of the atoms of the bond */
int64_t from_atom_id;
@@ -5757,10 +5756,37 @@ tng_function_status tng_molecule_cnt_set(tng_trajectory_t tng_data,
return(TNG_SUCCESS);
}
+tng_function_status tng_molecule_chain_find(tng_trajectory_t tng_data,
+ tng_molecule_t molecule,
+ const char *name,
+ int64_t id,
+ tng_chain_t *chain)
+{
+ int i, n_chains;
+
+ n_chains = molecule->n_chains;
+
+ for(i = 0; i < n_chains; i++)
+ {
+ *chain = &molecule->chains[i];
+ if(name[0] != 0 || strcmp(name, (*chain)->name) == 0)
+ {
+ if(id == -1 || id == (*chain)->id)
+ {
+ return(TNG_SUCCESS);
+ }
+ }
+ }
+
+ *chain = 0;
+
+ return(TNG_FAILURE);
+}
+
tng_function_status tng_molecule_chain_add(tng_trajectory_t tng_data,
- tng_molecule_t molecule,
- const char *name,
- tng_chain_t *chain)
+ tng_molecule_t molecule,
+ const char *name,
+ tng_chain_t *chain)
{
tng_chain_t new_chains;
@@ -11568,6 +11594,23 @@ tng_function_status tng_molecule_cnt_set_(tng_trajectory_t tng_data,
return(tng_molecule_cnt_set(tng_data, molecule, *cnt));
}
+tng_function_status tng_molecule_chain_find_(tng_trajectory_t tng_data,
+ tng_molecule_t molecule,
+ const char *name,
+ int64_t id,
+ tng_chain_t *chain,
+ int name_len)
+{
+ char *n = malloc(name_len + 1);
+ tng_function_status stat;
+
+ strncpy(n, name, name_len);
+ n[name_len] = 0;
+ stat = tng_molecule_chain_find(tng_data, molecule, n, id, chain);
+ free(n);
+ return(stat);
+}
+
tng_function_status tng_molecule_chain_add_(tng_trajectory_t tng_data,
tng_molecule_t molecule,
const char *name,
contact: Jan Huwald // Impressum