summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tng_io.h22
-rw-r--r--src/lib/tng_io.c32
2 files changed, 54 insertions, 0 deletions
diff --git a/include/tng_io.h b/include/tng_io.h
index 7028bdc..4d456bb 100644
--- a/include/tng_io.h
+++ b/include/tng_io.h
@@ -1358,6 +1358,28 @@ tng_function_status DECLSPECDLLEXPORT tng_frame_set_frame_range_get
int64_t *last_frame);
/**
+ * @brief Allocate memory for and setup a molecule container.
+ * @param tng_data is a trajectory data container.
+ * @param molecule_p is a pointer to molecule to allocate and initialise.
+ * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
+ * error has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_molecule_alloc(const tng_trajectory_t tng_data,
+ tng_molecule_t *molecule_p);
+
+/**
+ * @brief Clean up a molecule container and free its allocated memory.
+ * @param tng_data is a trajectory data container.
+ * @param molecule_p is the molecule to destroy.
+ * @details All allocated memory in the data structure is freed and also the memory
+ * of the molecule itself.
+ * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
+ * error has occured.
+ */
+tng_function_status DECLSPECDLLEXPORT tng_molecule_free(const tng_trajectory_t tng_data,
+ tng_molecule_t *molecule_p);
+
+/**
* @brief Setup a molecule container.
* @param tng_data is a trajectory data container.
* @param molecule is the molecule to initialise. Memory must be preallocated.
diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c
index 5349f20..ce1732c 100644
--- a/src/lib/tng_io.c
+++ b/src/lib/tng_io.c
@@ -7720,6 +7720,38 @@ tng_function_status DECLSPECDLLEXPORT tng_residue_atom_w_id_add
return(stat);
}
+tng_function_status DECLSPECDLLEXPORT tng_molecule_alloc(const tng_trajectory_t tng_data,
+ tng_molecule_t *molecule_p)
+{
+ *molecule_p = malloc(sizeof(struct tng_molecule));
+ if(!*molecule_p)
+ {
+ printf("TNG library: Cannot allocate memory (%lu bytes). %s: %d\n",
+ sizeof(struct tng_molecule), __FILE__, __LINE__);
+ return(TNG_CRITICAL);
+ }
+
+ tng_molecule_init(tng_data, *molecule_p);
+
+ return(TNG_SUCCESS);
+}
+
+tng_function_status DECLSPECDLLEXPORT tng_molecule_free(const tng_trajectory_t tng_data,
+ tng_molecule_t *molecule_p)
+{
+ if(!*molecule_p)
+ {
+ return(TNG_SUCCESS);
+ }
+
+ tng_molecule_destroy(tng_data, *molecule_p);
+
+ free(*molecule_p);
+ *molecule_p = 0;
+
+ return(TNG_SUCCESS);
+}
+
tng_function_status DECLSPECDLLEXPORT tng_molecule_init(const tng_trajectory_t tng_data,
tng_molecule_t molecule)
{
contact: Jan Huwald // Impressum