diff options
author | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-06-20 11:26:50 (GMT) |
---|---|---|
committer | Magnus Lundborg <lundborg.magnus@gmail.com> | 2013-06-20 11:26:50 (GMT) |
commit | ab29a946117a76d7af273c615ecd120ff4f2c8ed (patch) | |
tree | c8775eb6c00524a0bdfdb22cf3232c03aa756a8a | |
parent | f6a818c829d9c4118a2e4a43e50242db0eec3ac1 (diff) |
Added exponential of distance unit.
New data added to the general information block to specify
the unit of distances in the trajectory, e.g. -9 for nm or
-10 for Å.
-rw-r--r-- | Doxyfile.in | 2 | ||||
-rw-r--r-- | include/tng_io.h | 30 | ||||
-rw-r--r-- | src/lib/tng_io.c | 58 |
3 files changed, 85 insertions, 5 deletions
diff --git a/Doxyfile.in b/Doxyfile.in index 32fbaba..84b5770 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -32,7 +32,7 @@ PROJECT_NAME = "TNG API" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = "1.1" +PROJECT_NUMBER = "1.3" # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/include/tng_io.h b/include/tng_io.h index eb67dd8..2716ccf 100644 --- a/include/tng_io.h +++ b/include/tng_io.h @@ -1,6 +1,6 @@ /* This code is part of the tng binary trajectory format. * - * VERSION 1.1 + * VERSION 1.3 * * Written by Magnus Lundborg * Copyright (c) 2012, The GROMACS development team. @@ -25,7 +25,7 @@ * Each block can contain MD5 hashes to verify data integrity and the file * can be signed by the user to ensure that the origin is correct. * - * This is version 1.1 of the TNG API. The intention is that this version of + * This is version 1.3 of the TNG API. The intention is that this version of * the API and ABI should be stable, but it is still possible that future * changes might make that impossible, in which case that will be clarified. * @@ -343,7 +343,7 @@ typedef unsigned long long int uint64_t; /** The version of this TNG build */ -#define TNG_VERSION 3 +#define TNG_VERSION 3 /* TNG_VERSION 3 => Api version 1.3 */ /** Flag to indicate frame dependent data. */ #define TNG_FRAME_DEPENDENT 1 @@ -922,6 +922,30 @@ tng_function_status DECLSPECDLLEXPORT tng_num_molecules_get int64_t *n); /** + * @brief Get the exponential used for distances in the trajectory. + * @param tng_data is the trajectory from which to get the information. + * @param exp is pointing to a value set to the distance unit exponential. + * @details Example: If the distances are specified in nm (default) exp is -9. + * If the distances are specified in Å exp is -10. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_distance_unit_exponential_get + (const tng_trajectory_t tng_data, + int64_t *exp); + +/** + * @brief Set the exponential used for distances in the trajectory. + * @param tng_data is the trajectory of which to set the unit exponential. + * @param exp is the distance unit exponential to use. + * @details Example: If the distances are specified in nm (default) exp is -9. + * If the distances are specified in Å exp is -10. + * @return TNG_SUCCESS (0) if successful. + */ +tng_function_status DECLSPECDLLEXPORT tng_distance_unit_exponential_set + (const tng_trajectory_t tng_data, + const int64_t exp); + +/** * @brief Get the number of frames per frame set. * @param tng_data is the trajectory from which to get the number of frames * per frame set. diff --git a/src/lib/tng_io.c b/src/lib/tng_io.c index 0d5f1a8..997a488 100644 --- a/src/lib/tng_io.c +++ b/src/lib/tng_io.c @@ -296,6 +296,10 @@ struct tng_trajectory { char *last_pgp_signature; /** The time (n seconds since 1970) when the file was created */ int64_t time; + /** The exponential of the value of the distance unit used. The default + * distance unit is nm (1e-9), i.e. distance_unit_exponential = -9. If + * the measurements are in Å the distance_unit_exponential = -10. */ + int64_t distance_unit_exponential; /** A flag indicating if the number of atoms can vary throughout the * simulation, e.g. using a grand canonical ensemble */ @@ -1417,6 +1421,23 @@ static tng_function_status tng_general_info_block_read __FILE__, __LINE__); } } + offset += sizeof(tng_data->long_stride_length); + + if(block->block_version >= 3) + { + memcpy(&tng_data->distance_unit_exponential, block->block_contents+offset, + sizeof(tng_data->distance_unit_exponential)); + if(tng_data->input_endianness_swap_func_64) + { + if(tng_data->input_endianness_swap_func_64(tng_data, + &tng_data->distance_unit_exponential) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } + } return(TNG_SUCCESS); } @@ -1589,6 +1610,7 @@ static tng_function_status tng_general_info_block_write sizeof(tng_data->last_trajectory_frame_set_input_file_pos) + sizeof(tng_data->medium_stride_length) + sizeof(tng_data->long_stride_length) + + sizeof(tng_data->distance_unit_exponential) + first_program_name_len + last_program_name_len + first_user_name_len + @@ -1732,6 +1754,20 @@ static tng_function_status tng_general_info_block_write __FILE__, __LINE__); } } + offset += sizeof(tng_data->long_stride_length); + + memcpy(block->block_contents+offset, &tng_data->distance_unit_exponential, + sizeof(tng_data->distance_unit_exponential)); + if(tng_data->output_endianness_swap_func_64) + { + if(tng_data->output_endianness_swap_func_64(tng_data, + (int64_t *)block->header_contents+offset) + != TNG_SUCCESS) + { + printf("Cannot swap byte order. %s: %d\n", + __FILE__, __LINE__); + } + } if(tng_block_header_write(tng_data, block, hash_mode) != TNG_SUCCESS) { @@ -6146,7 +6182,7 @@ static tng_function_status tng_header_pointers_update contents_start_pos = ftell(tng_data->output_file); - fseek(tng_data->output_file, block->block_contents_size - 4 * + fseek(tng_data->output_file, block->block_contents_size - 5 * sizeof(int64_t), SEEK_CUR); tng_data->input_file = temp; @@ -7708,6 +7744,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init(tng_trajectory_t *tng_ tng_data->compress_algo_pos = 0; tng_data->compress_algo_vel = 0; + tng_data->distance_unit_exponential = -9; frame_set->first_frame = -1; frame_set->n_mapping_blocks = 0; @@ -8246,6 +8283,7 @@ tng_function_status DECLSPECDLLEXPORT tng_trajectory_init_from_src(tng_trajector dest->compress_algo_pos = 0; dest->compress_algo_vel = 0; + dest->distance_unit_exponential = -9; frame_set->n_mapping_blocks = 0; frame_set->mappings = 0; @@ -9053,6 +9091,24 @@ tng_function_status DECLSPECDLLEXPORT tng_num_molecules_get return(TNG_SUCCESS); } +tng_function_status DECLSPECDLLEXPORT tng_distance_unit_exponential_get + (const tng_trajectory_t tng_data, + int64_t *exp) +{ + *exp = tng_data->distance_unit_exponential; + + return(TNG_SUCCESS); +} + +tng_function_status DECLSPECDLLEXPORT tng_distance_unit_exponential_set + (const tng_trajectory_t tng_data, + const int64_t exp) +{ + tng_data->distance_unit_exponential = exp; + + return(TNG_SUCCESS); +} + tng_function_status DECLSPECDLLEXPORT tng_num_frames_per_frame_set_get (const tng_trajectory_t tng_data, int64_t *n) |