Bumped TNG to latest version.
[gromacs.git] / src / external / tng_io / include / tng_io.hpp
blobf3bc32abea9803cf15657eb180ed09a8c8fa5bea
1 /* This code is part of the tng binary trajectory format.
3 * VERSION 1.5
5 * Written by Anders Gärdenäs
6 * Copyright (c) 2012-2013, The GROMACS development team.
7 * Check out http://www.gromacs.org for more information.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the Revised BSD License.
14 #ifndef TNG_IO_HPP
15 #define TNG_IO_HPP
17 #include "tng_io.h"
19 namespace Tng
21 class Trajectory;
22 class Atom;
23 class Residue;
24 class Chain;
25 class Molecule;
26 typedef class Molecule * Molecule_t;
29 class Trajectory {
30 private:
31 tng_trajectory_t traj;
32 tng_function_status status;
33 public:
34 /**
35 * @brief Add a molecule to the trajectory.
36 * @param name is a pointer to the string containing the name of the new molecule.
37 * @param molecule is a pointer to the newly created molecule.
38 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
39 * error has occured.
42 tng_function_status addMolecule(const char *, Molecule_t);
43 tng_function_status addMoleculeWithId(const char *, int64_t id, Molecule_t);
44 tng_function_status findMolecule(const char *name, int64_t id, Molecule_t molecule);
45 friend class Atom;
46 friend class Residue;
47 friend class Chain;
48 friend class Molecule;
50 //! Normal constructor
51 Trajectory()
52 { status = tng_trajectory_init(&traj); }
54 //! Copy constructor
55 Trajectory(Trajectory * src)
56 { status = tng_trajectory_init_from_src(traj,&src->traj); }
58 //! Detructor
59 ~Trajectory()
60 { status = tng_trajectory_destroy(&traj); }
62 //! Status
63 tng_function_status getStatus()
64 { return status; }
67 /**
68 * @brief Get the name of the input file.
69 * @param file_name the string to fill with the name of the input file,
70 * memory must be allocated before.
71 * @param max_len maximum char length of the string, i.e. how much memory has
72 * been reserved for file_name. This includes \0 terminating character.
73 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
74 * has occurred (source string longer than destination string).
76 tng_function_status getInputFile (char *file_name, const int max_len)
78 return status = tng_input_file_get(traj, file_name, max_len);
81 /**
82 * @brief Set the name of the input file.
83 * @param file_name the name of the input file.
84 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
85 * error has occured.
87 tng_function_status setInputFile(const char *file_name)
89 return status = tng_input_file_set(traj, file_name);
93 /**
94 * @brief Get the name of the output file.
95 * @param file_name the string to fill with the name of the output file,
96 * memory must be allocated before.
97 * @param max_len maximum char length of the string, i.e. how much memory has
98 * been reserved for file_name. This includes \0 terminating character.
99 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
100 * has occurred (source string longer than destination string).
102 tng_function_status getOutputFile(char *file_name, const int max_len)
104 return status = tng_output_file_get(traj, file_name, max_len);
109 * @brief Set the name of the output file.
110 * @param file_name the name of the output file.
111 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
112 * error has occured.
114 tng_function_status setOutputFile(const char *file_name)
116 return status = tng_output_file_set(traj, file_name);
120 * @brief Get the endianness of the output file.
121 * current output file.
122 * @param endianness will contain the enumeration of the endianness.
123 * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (1) if the endianness
124 * could not be retrieved.
126 tng_function_status getOutputFileEndianness
127 (tng_file_endianness *endianness)
129 return status = tng_output_file_endianness_get(traj, endianness);
133 * @brief Set the endianness of the output file.
134 * @param endianness the enumeration of the endianness, can be either
135 * TNG_BIG_ENDIAN (0) or TNG_LITTLE_ENDIAN (1).
136 * @details The endianness cannot be changed after file output has started.
137 * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (1) if the endianness
138 * could not be set.
140 tng_function_status setOutputFileEndianness
141 (const tng_file_endianness endianness)
143 return status = tng_output_file_endianness_set(traj, endianness);
147 * @brief Get the name of the program used when creating the trajectory.
148 * @param name the string to fill with the name of the program,
149 * memory must be allocated before.
150 * @param max_len maximum char length of the string, i.e. how much memory has
151 * been reserved for name. This includes \0 terminating character.
152 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
153 * has occurred (source string longer than destination string).
155 tng_function_status getFirstProgramName(char *name, const int max_len)
157 return status = tng_first_program_name_get(traj,name,max_len);
162 * @brief Set the name of the program used when creating the trajectory..
163 * @param new_name is a string containing the wanted name.
164 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
165 * error has occured.
167 tng_function_status setFirstProgramName(const char *new_name)
169 return status = tng_first_program_name_set(traj, new_name);
174 * @brief Get the name of the program used when last modifying the trajectory.
175 * @param name the string to fill with the name of the program,
176 * memory must be allocated before.
177 * @param max_len maximum char length of the string, i.e. how much memory has
178 * been reserved for name. This includes \0 terminating character.
179 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
180 * has occurred (source string longer than destination string).
182 tng_function_status getLastProgramName(char *name, const int max_len)
184 return status = tng_last_program_name_get(traj, name, max_len);
189 * @brief Set the name of the program used when last modifying the trajectory.
190 * @param new_name is a string containing the wanted name.
191 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
192 * error has occured.
194 tng_function_status setLastProgramName(const char *new_name)
196 return status = tng_last_program_name_set(traj, new_name);
201 * @brief Get the name of the user who created the trajectory.
202 * @param name the string to fill with the name of the user,
203 * memory must be allocated before.
204 * @param max_len maximum char length of the string, i.e. how much memory has
205 * been reserved for name. This includes \0 terminating character.
206 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
207 * has occurred (source string longer than destination string).
209 tng_function_status getFirstUserName(char *name, const int max_len)
211 return status = tng_first_user_name_get(traj,name, max_len);
216 * @brief Set the name of the user who created the trajectory.
217 * @param new_name is a string containing the wanted name.
218 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
219 * error has occured.
221 tng_function_status setFirstUserName(const char *new_name)
223 return status = tng_first_user_name_set(traj, new_name);
228 * @brief Get the name of the user who last modified the trajectory.
229 * @param name the string to fill with the name of the user,
230 * memory must be allocated before.
231 * @param max_len maximum char length of the string, i.e. how much memory has
232 * been reserved for name. This includes \0 terminating character.
233 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
234 * has occurred (source string longer than destination string).
236 tng_function_status getLastUserName(char *name, const int max_len)
238 return status = tng_last_user_name_get(traj,name,max_len);
243 * @brief Set the name of the user who last modified the trajectory.
244 * @param new_name is a string containing the wanted name.
245 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
246 * error has occured.
248 tng_function_status setLastUserName(const char *new_name)
250 return status = tng_last_user_name_set(traj,new_name);
256 * @brief Get the name of the computer used when creating the trajectory.
257 * @param name the string to fill with the name of the computer,
258 * memory must be allocated before.
259 * @param max_len maximum char length of the string, i.e. how much memory has
260 * been reserved for name. This includes \0 terminating character.
261 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
262 * has occurred (source string longer than destination string).
264 tng_function_status getFirstComputerName(char *name, const int max_len)
266 return status = tng_first_computer_name_get(traj, name, max_len);
271 * @brief Set the name of the computer used when creating the trajectory.
272 * @param new_name is a string containing the wanted name.
273 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
274 * error has occured.
276 tng_function_status setFirstComputerName(const char *new_name)
278 return status = tng_first_computer_name_set(traj, new_name);
283 * @brief Get the name of the computer used when last modifying the trajectory.
284 * @param name the string to fill with the name of the computer,
285 * memory must be allocated before.
286 * @param max_len maximum char length of the string, i.e. how much memory has
287 * been reserved for name. This includes \0 terminating character.
288 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
289 * has occurred (source string longer than destination string).
291 tng_function_status getLastComputerName(char *name, const int max_len)
293 return status = tng_last_computer_name_get(traj,name,max_len);
298 * @brief Set the name of the computer used when last modifying the trajectory.
299 * @param new_name is a string containing the wanted name.
300 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
301 * error has occured.
303 tng_function_status setLastComputerName(const char *new_name)
305 return status = tng_last_computer_name_set(traj,new_name);
310 * @brief Get the pgp_signature of the user creating the trajectory.
311 * @param signature the string to fill with the signature,
312 * memory must be allocated before.
313 * @param max_len maximum char length of the string, i.e. how much memory has
314 * been reserved for name. This includes \0 terminating character.
315 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
316 * has occurred (source string longer than destination string).
318 tng_function_status getFirstSignature(char *signature, const int max_len)
320 return status = tng_last_computer_name_get(traj, signature,max_len);
325 * @brief Set the pgp_signature of the user creating the trajectory.
326 * @param signature is a string containing the pgp_signature.
327 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
328 * error has occured.
330 tng_function_status setFirstSignature(const char *signature)
332 return status = tng_first_signature_set(traj, signature);
337 * @brief Get the pgp_signature of the user last modifying the trajectory.
338 * @param signature the string to fill with the signature,
339 * memory must be allocated before.
340 * @param max_len maximum char length of the string, i.e. how much memory has
341 * been reserved for name. This includes \0 terminating character.
342 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
343 * has occurred (source string longer than destination string).
345 tng_function_status getLastSignature(char *signature, const int max_len)
347 return status = tng_first_signature_get(traj, signature, max_len);
352 * @brief Set the pgp_signature of the user last modifying the trajectory.
353 * @param signature is a string containing the pgp_signature.
354 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
355 * error has occured.
357 tng_function_status setLastSignature(const char *signature)
359 return status = tng_last_signature_set(traj, signature);
364 * @brief Get the name of the forcefield used in the trajectory.
365 * @param name the string to fill with the name of the forcefield,
366 * memory must be allocated before.
367 * @param max_len maximum char length of the string, i.e. how much memory has
368 * been reserved for name. This includes \0 terminating character.
369 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
370 * has occurred (source string longer than destination string).
372 tng_function_status getForcefieldName(char *name, const int max_len)
374 return status = tng_last_signature_get(traj,name,max_len);
379 * @brief Set the name of the forcefield used in the trajectory.
380 * @param new_name is a string containing the wanted name.
381 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
382 * error has occured.
384 tng_function_status setForcefieldName(const char *new_name)
386 return status = tng_forcefield_name_set(traj, new_name);
391 * @brief Get the medium stride length of the trajectory.
392 * @param len is pointing to a value set to the stride length.
393 * @return TNG_SUCCESS (0) if successful.
395 tng_function_status getMediumStrideLength(int64_t *len)
397 return status = tng_medium_stride_length_get(traj,len);
402 * @brief Set the medium stride length of the trajectory.
403 * @param len is the wanted medium stride length.
404 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
405 * has occurred.
407 tng_function_status setMediumStrideLength(const int64_t len)
409 return status = tng_medium_stride_length_set(traj,len);
414 * @brief Get the long stride length of the trajectory.
415 * @param len is pointing to a value set to the stride length.
416 * @return TNG_SUCCESS (0) if successful.
418 tng_function_status getLongStrideLength(int64_t *len)
420 return status = tng_long_stride_length_get(traj, len);
425 * @brief Set the long stride length of the trajectory.
426 * @param len is the wanted long stride length.
427 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
428 * has occurred.
430 tng_function_status setLongStrideLength(const int64_t len)
432 return status = tng_long_stride_length_set(traj,len);
437 * @brief Get the current time per frame of the trajectory.
438 * @param len is pointing to a value set to the time per frame.
439 * @return TNG_SUCCESS (0) if successful.
441 tng_function_status getTimePerFrame(double *time)
443 return status = tng_time_per_frame_get(traj, time);
448 * @brief Set the time per frame of the trajectory.
449 * @param len is the new time per frame.
450 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
451 * has occurred.
453 tng_function_status setTimePerFrame(const double time)
455 return status = tng_time_per_frame_set(traj, time);
460 * @brief Get the length of the input file.
461 * @param len is pointing to a value set to the file length.
462 * @return TNG_SUCCESS (0) if successful.
464 tng_function_status getInputFileLen(int64_t *len)
466 return status = tng_input_file_len_get(traj, len);
471 * @brief Get the number of frames in the trajectory
472 * @param n is pointing to a value set to the number of frames.
473 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
474 * has occurred (could not find last frame set).
476 tng_function_status getNumFrames(int64_t *n)
478 return status = tng_num_frames_get(traj, n);
482 * @brief Get the current number of particles.
483 * @param n is pointing to a value set to the number of particles.
484 * @details If variable number of particles are used this function will return
485 * the number of particles in the current frame set.
486 * @return TNG_SUCCESS (0) if successful.
488 tng_function_status getNumParticles(int64_t *n)
490 return status = tng_num_particles_get(traj, n);
497 * @brief Get the current total number of molecules.
498 * @param n is pointing to a value set to the number of molecules.
499 * @details If variable number of particles are used this function will return
500 * the total number of molecules in the current frame set.
501 * @return TNG_SUCCESS (0) if successful.
503 tng_function_status getNumMolecules(int64_t *n)
505 return status = tng_num_molecules_get(traj,n);
509 * @brief Get the exponential used for distances in the trajectory.
510 * @param exp is pointing to a value set to the distance unit exponential.
511 * @details Example: If the distances are specified in nm (default) exp is -9.
512 * If the distances are specified in Å exp is -10.
513 * @return TNG_SUCCESS (0) if successful.
515 tng_function_status getDistanceUnitExponential
516 (int64_t *exp)
518 return status = tng_distance_unit_exponential_get(traj, exp);
522 * @brief Set the exponential used for distances in the trajectory.
523 * @param exp is the distance unit exponential to use.
524 * @details Example: If the distances are specified in nm (default) exp is -9.
525 * If the distances are specified in Å exp is -10.
526 * @return TNG_SUCCESS (0) if successful.
528 tng_function_status setDistanceUnitExponential
529 (int64_t exp)
531 return status = tng_distance_unit_exponential_set(traj, exp);
536 * @brief Get the number of frames per frame set.
537 * per frame set.
538 * @param n is pointing to a value set to the number of frames per frame set.
539 * @return TNG_SUCCESS (0) if successful.
541 tng_function_status getNumFramesPerFrameSet(int64_t *n)
543 return status = tng_num_frames_per_frame_set_get(traj,n);
547 * @brief Set the number of frames per frame set.
548 * @param n is the number of frames per frame set.
549 * @details This does not affect already existing frame sets. For
550 * consistency the number of frames per frame set should be set
551 * betfore creating any frame sets.
552 * @return TNG_SUCCESS (0) if successful.
554 tng_function_status setNumFramesPerFrameSet(const int64_t n)
556 return status = tng_num_frames_per_frame_set_set(traj,n);
560 * @brief Get the number of frame sets.
561 * @param n is pointing to a value set to the number of frame sets.
562 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
563 * has occurred or TNG_CRITICAL (2) if a major error has occured.
565 tng_function_status getNumFrameSets(int64_t *n)
567 return status = tng_num_frame_sets_get(traj, n);
572 * @brief Get the current trajectory frame set.
573 * @param frame_set_p will be set to point at the memory position of
574 * the found frame set.
575 * @return TNG_SUCCESS (0) if successful.
577 tng_function_status getCurrentFrameSet(tng_trajectory_frame_set_t *frame_set_p)
579 return status = tng_current_frame_set_get(traj, frame_set_p);
584 * @brief Find the requested frame set number.
585 * @param nr is the frame set number to search for.
586 * @details tng_data->current_trajectory_frame_set will contain the
587 * found trajectory if successful.
588 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
589 * has occurred or TNG_CRITICAL (2) if a major error has occured.
591 tng_function_status findFrameSetNr(const int64_t nr)
593 return status = tng_frame_set_nr_find(traj,nr);
598 * @brief Find the frame set containing a specific frame.
599 * @param frame is the frame number to search for.
600 * @details tng_data->current_trajectory_frame_set will contain the
601 * found trajectory if successful.
602 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
603 * has occurred or TNG_CRITICAL (2) if a major error has occured.
605 tng_function_status findFrameSetOfFrame(const int64_t frame)
607 return status = tng_frame_set_of_frame_find(traj, frame);
612 * @brief Get the file position of the next frame set in the input file.
613 * @param frame_set is the frame set of which to get the position of the
614 * following frame set.
615 * @param pos is pointing to a value set to the file position.
616 * @return TNG_SUCCESS (0) if successful.
618 tng_function_status getNextFrameSetFilePos
619 (const tng_trajectory_frame_set_t frame_set,int64_t *pos)
621 return status = tng_frame_set_next_frame_set_file_pos_get(traj,frame_set,pos );
625 * @brief Get the file position of the previous frame set in the input file.
626 * @param frame_set is the frame set of which to get the position of the
627 * previous frame set.
628 * @param pos is pointing to a value set to the file position.
629 * @return TNG_SUCCESS (0) if successful.
631 tng_function_status getPrevFrameSetFilePos
632 (const tng_trajectory_frame_set_t frame_set,int64_t *pos)
634 return status = tng_frame_set_prev_frame_set_file_pos_get(traj, frame_set, pos);
639 * @brief Get the first and last frames of the frame set.
640 * @param frame_set is the frame set of which to get the frame range.
641 * @param first_frame is set to the first frame of the frame set.
642 * @param last_frame is set to the last frame of the frame set.
643 * @return TNG_SUCCESS (0) if successful.
645 tng_function_status getFrameSetFrameRange
646 (const tng_trajectory_frame_set_t frame_set,
647 int64_t *first_frame,
648 int64_t *last_frame)
650 return status = tng_frame_set_frame_range_get(traj,frame_set, first_frame, last_frame);
655 * @brief Get the molecume name of real particle number (number in mol system).
656 * @param nr is the real number of the particle in the molecular system.
657 * @param name is a string, which is set to the name of the molecule. Memory
658 * must be reserved beforehand.
659 * @param max_len is the maximum length of name.
660 * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
661 * has occured.
663 tng_function_status getMoleculeNameOfParticleNr
664 (const int64_t nr,char *name,int max_len)
666 return status = tng_molecule_name_of_particle_nr_get(traj,nr,name,max_len);
671 * @brief Get the chain name of real particle number (number in mol system).
672 * @param nr is the real number of the particle in the molecular system.
673 * @param name is a string, which is set to the name of the chain. Memory
674 * must be reserved beforehand.
675 * @param max_len is the maximum length of name.
676 * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
677 * has occured.
679 tng_function_status getChainNameOfParticleNr
680 (const int64_t nr,char *name,int max_len)
682 return status = tng_chain_name_of_particle_nr_get(traj, nr, name, max_len);
687 * @brief Get the residue name of real particle number (number in mol system).
688 * @param nr is the real number of the particle in the molecular system.
689 * @param name is a string, which is set to the name of the residue. Memory
690 * must be reserved beforehand.
691 * @param max_len is the maximum length of name.
692 * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
693 * has occured.
695 tng_function_status getResidueNameOfParticleNr
696 (const int64_t nr,char *name,int max_len)
698 return status = tng_residue_name_of_particle_nr_get(traj,nr,name,max_len);
703 * @brief Get the atom name of real particle number (number in mol system).
704 * @param nr is the real number of the particle in the molecular system.
705 * @param name is a string, which is set to the name of the atom. Memory
706 * must be reserved beforehand.
707 * @param max_len is the maximum length of name.
708 * @return TNG_SUCCESS (0) if successful or TNG_FAILURE (!) if a minor error
709 * has occured.
711 tng_function_status getAtomNameOfParticleNr
712 (const int64_t nr,char *name,int max_len)
714 return status = tng_atom_name_of_particle_nr_get(traj, nr,name,max_len);
719 * @brief Add a particle mapping table.
720 * @details Each particle mapping table will be written as a separate block,
721 * followed by the data blocks for the corresponding particles. In most cases
722 * there is one particle mapping block for each thread writing the trajectory.
723 * @details The mapping information is added to the currently active frame set
724 * of tng_data
725 * @param first_particle_number is the first particle number of this mapping
726 * block.
727 * @param n_particles is the number of particles in this mapping block.
728 * @param mapping_table is a list of the real particle numbers (i.e. the numbers
729 * used in the molecular system). The list is n_particles long.
730 * @details mapping_table[0] is the real particle number of the first particle
731 * in the following data blocks.
732 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
733 * has occurred or TNG_CRITICAL (2) if a major error has occured.
735 tng_function_status addParticleMapping
736 (const int64_t first_particle_number,
737 const int64_t n_particles,
738 const int64_t *mapping_table)
740 return status = tng_particle_mapping_add(traj,first_particle_number,n_particles,mapping_table );
745 * @brief Read the header blocks from the input_file of tng_data.
746 * @details The trajectory blocks must be read separately and iteratively in chunks
747 * to fit in memory.
748 * @details tng_data->input_file_path specifies
749 * which file to read from. If the file (input_file) is not open it will be
750 * opened.
751 * @param hash_mode is an option to decide whether to use the md5 hash or not.
752 * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be
753 * compared to the md5 hash of the read contents to ensure valid data.
754 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
755 * error has occured.
757 tng_function_status readFileHeaders(const tng_hash_mode hash_mode)
759 return status = tng_file_headers_read(traj, hash_mode);
764 * @brief Write the header blocks to the output_file of tng_data.
765 * @details The trajectory blocks must be written separately and iteratively in chunks
766 * to fit in memory.
767 * @details tng_data->output_file_path
768 * specifies which file to write to. If the file (output_file) is not open it
769 * will be opened.
770 * @param hash_mode is an option to decide whether to use the md5 hash or not.
771 * If hash_mode == TNG_USE_HASH an md5 hash for each header block will be generated.
772 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
773 * error has occured.
775 tng_function_status writeFileHeaders(const tng_hash_mode hash_mode)
777 return status = tng_file_headers_write(traj, hash_mode);
783 * @brief Read one (the next) block (of any kind) from the input_file of tng_data.
784 * which file to read from. If the file (input_file) is not open it will be
785 * opened.
786 * @param block_data is a pointer to the struct which will be populated with the
787 * data.
788 * @details If block_data->input_file_pos > 0 it is the position from where the
789 * reading starts otherwise it starts from the current position.
790 * @param hash_mode is an option to decide whether to use the md5 hash or not.
791 * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be
792 * compared to the md5 hash of the read contents to ensure valid data.
793 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
794 * has occurred or TNG_CRITICAL (2) if a major error has occured.
796 tng_function_status readNextBlock(const tng_hash_mode hash_mode, tng_gen_block_t block_data)
798 return status = tng_block_read_next(traj,block_data, hash_mode);
804 * @brief Read one (the next) frame set, including mapping and related data blocks
805 * from the input_file of tng_data.
806 * which file to read from. If the file (input_file) is not open it will be
807 * opened.
808 * @param hash_mode is an option to decide whether to use the md5 hash or not.
809 * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be
810 * compared to the md5 hash of the read contents to ensure valid data.
811 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
812 * has occurred or TNG_CRITICAL (2) if a major error has occured.
814 tng_function_status readNextFrameSet(const tng_hash_mode hash_mode)
816 return status = tng_frame_set_read_next(traj, hash_mode);
821 * @brief Write one frame set, including mapping and related data blocks
822 * to the output_file of tng_data.
823 * @details tng_data->output_file_path specifies
824 * which file to write to. If the file (output_file) is not open it will be
825 * opened.
826 * @param hash_mode is an option to decide whether to use the md5 hash or not.
827 * If hash_mode == TNG_USE_HASH an md5 hash for each header block will be generated.
828 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
829 * has occurred or TNG_CRITICAL (2) if a major error has occured.
831 tng_function_status writeFrameSet(const tng_hash_mode hash_mode)
833 return status = tng_frame_set_write(traj, hash_mode);
838 * @brief Create and initialise a frame set.
839 * @param first_frame is the first frame of the frame set.
840 * @param n_frames is the number of frames in the frame set.
841 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
842 * has occurred or TNG_CRITICAL (2) if a major error has occured.
844 tng_function_status newFrameSet(const int64_t first_frame,
845 const int64_t n_frames)
847 return status = tng_frame_set_new(traj, first_frame, n_frames);
852 * @brief Create and initialise a frame set with the time of the first frame
853 * specified.
854 * @param first_frame is the first frame of the frame set.
855 * @param n_frames is the number of frames in the frame set.
856 * @param first_frame_time is the time stamp of the first frame (in seconds).
857 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
858 * has occurred or TNG_CRITICAL (2) if a major error has occured.
860 tng_function_status newFrameSetWithTime
861 (const int64_t first_frame,
862 const int64_t n_frames,
863 const double first_frame_time)
865 return status = tng_frame_set_with_time_new(traj,
866 first_frame, n_frames,
867 first_frame_time);
872 * @brief Set the time stamp of the first frame of the current frame set.
873 * @param first_frame_time is the time stamp of the first frame in the
874 * frame set.
875 * @return TNG_SUCCESS (0) if successful.
877 tng_function_status setTimeOfFirstFrameOfFrameSet
878 (const double first_frame_time)
880 return status = tng_frame_set_first_frame_time_set(traj,
881 first_frame_time);
885 * @brief Add a non-particle dependent data block.
886 * @param id is the block ID of the block to add.
887 * @param block_name is a descriptive name of the block to add
888 * @param datatype is the datatype of the data in the block (e.g. int/float)
889 * @param block_type_flag indicates if this is a non-trajectory block (added
890 * directly to tng_data) or if it is a trajectory block (added to the
891 * frame set)
892 * @param n_frames is the number of frames of the data block (automatically
893 * set to 1 if adding a non-trajectory data block)
894 * @param n_values_per_frame is how many values a stored each frame (e.g. 9
895 * for a box shape block)
896 * @param stride_length is how many frames are between each entry in the
897 * data block
898 * @param codec_id is the ID of the codec to compress the data.
899 * @param new_data is an array of data values to add.
900 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
901 * has occurred or TNG_CRITICAL (2) if a major error has occured.
903 tng_function_status addDataBlock(const int64_t id,
904 const char *block_name,
905 const tng_data_type datatype,
906 const tng_block_type block_type_flag,
907 int64_t n_frames,
908 const int64_t n_values_per_frame,
909 const int64_t stride_length,
910 const int64_t codec_id,
911 void *new_data)
913 return status = tng_data_block_add(traj, id,block_name,
914 datatype,block_type_flag, n_frames,
915 n_values_per_frame, stride_length,
916 codec_id, new_data);
921 * @brief Add a particle dependent data block.
922 * @param id is the block ID of the block to add.
923 * @param block_name is a descriptive name of the block to add
924 * @param datatype is the datatype of the data in the block (e.g. int/float)
925 * @param block_type_flag indicates if this is a non-trajectory block (added
926 * directly to tng_data) or if it is a trajectory block (added to the
927 * frame set)
928 * @param n_frames is the number of frames of the data block (automatically
929 * set to 1 if adding a non-trajectory data block)
930 * @param n_values_per_frame is how many values a stored each frame (e.g. 9
931 * for a box shape block)
932 * @param stride_length is how many frames are between each entry in the
933 * data block
934 * @param first_particle_number is the number of the first particle stored
935 * in this data block
936 * @param n_particles is the number of particles stored in this data block
937 * @param codec_id is the ID of the codec to compress the data.
938 * @param new_data is an array of data values to add.
939 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
940 * has occurred or TNG_CRITICAL (2) if a major error has occured.
942 tng_function_status addParticleDataBlock(const int64_t id,
943 const char *block_name,
944 const tng_data_type datatype,
945 const tng_block_type block_type_flag,
946 int64_t n_frames,
947 const int64_t n_values_per_frame,
948 const int64_t stride_length,
949 const int64_t first_particle_number,
950 const int64_t n_particles,
951 const int64_t codec_id,
952 void *new_data)
954 return status = tng_particle_data_block_add(traj,id, block_name,
955 datatype, block_type_flag, n_frames,n_values_per_frame,
956 stride_length,first_particle_number,n_particles,
957 codec_id, new_data);
962 * @brief Write data of one trajectory frame to the output_file of tng_data.
963 * @param frame_nr is the index number of the frame to write.
964 * @param block_id is the ID of the data block to write the data to.
965 * @param data is an array of data to write. The length of the array should
966 * equal n_values_per_frame.
967 * @param hash_mode is an option to decide whether to use the md5 hash or not.
968 * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be
969 * compared to the md5 hash of the read contents to ensure valid data.
970 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
971 * has occurred or TNG_CRITICAL (2) if a major error has occured.
973 tng_function_status writeFrameData(const int64_t frame_nr,
974 const int64_t block_id,
975 const void *data,
976 const tng_hash_mode hash_mode)
978 return status = tng_frame_data_write(traj,frame_nr,block_id,data,hash_mode);
983 * @brief Write particle data of one trajectory frame to the output_file of
984 * tng_data.
985 * @param frame_nr is the index number of the frame to write.
986 * @param block_id is the ID of the data block to write the data to.
987 * @param val_first_particle is the number of the first particle in the data
988 * array.
989 * @param val_n_particles is the number of particles in the data array.
990 * @param data is a 1D-array of data to write. The length of the array should
991 * equal n_particles * n_values_per_frame.
992 * @param hash_mode is an option to decide whether to use the md5 hash or not.
993 * If hash_mode == TNG_USE_HASH the written md5 hash in the file will be
994 * compared to the md5 hash of the read contents to ensure valid data.
995 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
996 * has occurred or TNG_CRITICAL (2) if a major error has occured.
998 tng_function_status writeFrameParticleData(const int64_t frame_nr,
999 const int64_t block_id,
1000 const int64_t val_first_particle,
1001 const int64_t val_n_particles,
1002 const void *data,
1003 const tng_hash_mode hash_mode)
1005 return status = tng_frame_particle_data_write(traj,frame_nr,block_id,val_first_particle,val_n_particles,data,hash_mode);
1010 * @brief Free data is an array of values (2D).
1011 * @param values is the 2D array to free and will be set to 0 afterwards.
1012 * @param n_frames is the number of frames in the data array.
1013 * @param n_values_per_frame is the number of values per frame in the data array.
1014 * @param type is the data type of the data in the array (e.g. int/float/char).
1015 * @return TNG_SUCCESS (0) if successful.
1017 tng_function_status freeDataValues(union data_values **values,
1018 const int64_t n_frames,
1019 const int64_t n_values_per_frame,
1020 const tng_data_type type)
1022 return status = tng_data_values_free(traj, values, n_frames,n_values_per_frame,type);
1027 * @brief Free data is an array of values (3D).
1028 * @param values is the array to free and will be set to 0 afterwards.
1029 * @param n_frames is the number of frames in the data array.
1030 * @param n_particles is the number of particles in the data array.
1031 * @param n_values_per_frame is the number of values per frame in the data array.
1032 * @param type is the data type of the data in the array (e.g. int/float/char).
1033 * @return TNG_SUCCESS (0) if successful.
1035 tng_function_status freeParticleDataValues(union data_values ***values,
1036 const int64_t n_frames,
1037 const int64_t n_particles,
1038 const int64_t n_values_per_frame,
1039 const tng_data_type type)
1041 return status = tng_particle_data_values_free(traj, values,n_frames,n_particles,n_values_per_frame,type);
1046 * @brief Retrieve non-particle data, from the last read frame set. Obsolete!
1047 * which file to read from. If the file (input_file) is not open it will be
1048 * opened.
1049 * @param block_id is the id number of the particle data block to read.
1050 * @param values is a pointer to a 2-dimensional array (memory unallocated), which
1051 * will be filled with data. The array will be sized
1052 * (n_frames * n_values_per_frame).
1053 * Since ***values is allocated in this function it is the callers
1054 * responsibility to free the memory.
1055 * @param n_frames is set to the number of particles in the returned data. This is
1056 * needed to properly reach and/or free the data afterwards.
1057 * @param n_values_per_frame is set to the number of values per frame in the data.
1058 * This is needed to properly reach and/or free the data afterwards.
1059 * @param type is set to the data type of the data in the array.
1060 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1061 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1063 tng_function_status getData(const int64_t block_id,
1064 union data_values ***values,
1065 int64_t *n_frames,
1066 int64_t *n_values_per_frame,
1067 char *type)
1069 return status = tng_data_get(traj, block_id, values, n_frames,
1070 n_values_per_frame, type);
1074 * @brief Retrieve a vector (1D array) of non-particle data, from the last read frame set.
1075 * @param block_id is the id number of the particle data block to read.
1076 * @param values is a pointer to a 1-dimensional array (memory unallocated), which
1077 * will be filled with data. The length of the array will be (n_frames * n_values_per_frame).
1078 * Since **values is allocated in this function it is the callers
1079 * responsibility to free the memory.
1080 * @param n_frames is set to the number of particles in the returned data. This is
1081 * needed to properly reach and/or free the data afterwards.
1082 * @param stride_length is set to the stride length of the returned data.
1083 * @param n_values_per_frame is set to the number of values per frame in the data.
1084 * This is needed to properly reach and/or free the data afterwards.
1085 * @param type is set to the data type of the data in the array.
1086 * @details This does only work for numerical (int, float, double) data.
1087 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1088 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1090 tng_function_status getDataVector
1091 (const int64_t block_id,
1092 void **values,
1093 int64_t *n_frames,
1094 int64_t *stride_length,
1095 int64_t *n_values_per_frame,
1096 char *type)
1098 return status = tng_data_vector_get(traj, block_id, values, n_frames,
1099 stride_length, n_values_per_frame,
1100 type);
1104 * @brief Read and retrieve non-particle data, in a specific interval. Obsolete!
1105 * which file to read from. If the file (input_file) is not open it will be
1106 * opened.
1107 * @param block_id is the id number of the particle data block to read.
1108 * @param start_frame_nr is the index number of the first frame to read.
1109 * @param end_frame_nr is the index number of the last frame to read.
1110 * @param hash_mode is an option to decide whether to use the md5 hash or not.
1111 * If hash_mode == TNG_USE_HASH the md5 hash in the file will be
1112 * compared to the md5 hash of the read contents to ensure valid data.
1113 * @param values is a pointer to a 2-dimensional array (memory unallocated), which
1114 * will be filled with data. The array will be sized
1115 * (n_frames * n_values_per_frame).
1116 * Since ***values is allocated in this function it is the callers
1117 * responsibility to free the memory.
1118 * @param n_values_per_frame is set to the number of values per frame in the data.
1119 * This is needed to properly reach and/or free the data afterwards.
1120 * @param type is set to the data type of the data in the array.
1121 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1122 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1124 tng_function_status getDataInterval(const int64_t block_id,
1125 const int64_t start_frame_nr,
1126 const int64_t end_frame_nr,
1127 const tng_hash_mode hash_mode,
1128 union data_values ***values,
1129 int64_t *n_values_per_frame,
1130 char *type)
1132 return status = tng_data_interval_get(traj, block_id, start_frame_nr,
1133 end_frame_nr, hash_mode, values,
1134 n_values_per_frame, type);
1139 * @brief Read and retrieve a vector (1D array) of non-particle data,
1140 * in a specific interval.
1141 * @param block_id is the id number of the particle data block to read.
1142 * @param start_frame_nr is the index number of the first frame to read.
1143 * @param end_frame_nr is the index number of the last frame to read.
1144 * @param hash_mode is an option to decide whether to use the md5 hash or not.
1145 * If hash_mode == TNG_USE_HASH the md5 hash in the file will be
1146 * compared to the md5 hash of the read contents to ensure valid data.
1147 * @param values is a pointer to a 1-dimensional array (memory unallocated), which
1148 * will be filled with data. The length of the array will be (n_frames * n_values_per_frame).
1149 * Since **values is allocated in this function it is the callers
1150 * responsibility to free the memory.
1151 * @param stride_length is set to the stride length (writing frequency) of
1152 * the data.
1153 * @param n_values_per_frame is set to the number of values per frame in the data.
1154 * This is needed to properly reach and/or free the data afterwards.
1155 * @param type is set to the data type of the data in the array.
1156 * @details This does only work for numerical (int, float, double) data.
1157 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1158 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1160 tng_function_status getDataVectorInterval
1161 (const int64_t block_id,
1162 const int64_t start_frame_nr,
1163 const int64_t end_frame_nr,
1164 const char hash_mode,
1165 void **values,
1166 int64_t *stride_length,
1167 int64_t *n_values_per_frame,
1168 char *type)
1170 return status = tng_data_vector_interval_get(traj, block_id,
1171 start_frame_nr,
1172 end_frame_nr,
1173 hash_mode, values,
1174 stride_length,
1175 n_values_per_frame,
1176 type);
1180 * @brief Retrieve particle data, from the last read frame set. Obsolete!
1181 * @details The particle dimension of the returned values array is translated
1182 * to real particle numbering, i.e. the numbering of the actual molecular
1183 * system.
1184 * specifies which file to read from. If the file (input_file) is not open it
1185 * will be opened.
1186 * @param block_id is the id number of the particle data block to read.
1187 * @param values is a pointer to a 3-dimensional array (memory unallocated), which
1188 * will be filled with data. The array will be sized
1189 * (n_frames * n_particles * n_values_per_frame).
1190 * Since ****values is allocated in this function it is the callers
1191 * responsibility to free the memory.
1192 * @param n_frames is set to the number of particles in the returned data. This is
1193 * needed to properly reach and/or free the data afterwards.
1194 * @param n_particles is set to the number of particles in the returned data. This is
1195 * needed to properly reach and/or free the data afterwards.
1196 * @param n_values_per_frame is set to the number of values per frame in the data.
1197 * This is needed to properly reach and/or free the data afterwards.
1198 * @param type is set to the data type of the data in the array.
1199 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1200 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1202 tng_function_status getParticleData(const int64_t block_id,
1203 union data_values ****values,
1204 int64_t *n_frames,
1205 int64_t *n_particles,
1206 int64_t *n_values_per_frame,
1207 char *type)
1209 return status = (tng_particle_data_get(traj, block_id, values, n_frames,
1210 n_particles, n_values_per_frame, type));
1215 * @brief Retrieve a vector (1D array) of particle data, from the last read frame set.
1216 * @details The particle dimension of the returned values array is translated
1217 * to real particle numbering, i.e. the numbering of the actual molecular
1218 * system.
1219 * @param block_id is the id number of the particle data block to read.
1220 * @param values is a pointer to a 1-dimensional array (memory unallocated), which
1221 * will be filled with data. The length of the array will be
1222 * (n_frames * n_particles * n_values_per_frame).
1223 * Since **values is allocated in this function it is the callers
1224 * responsibility to free the memory.
1225 * @param n_frames is set to the number of frames in the returned data. This is
1226 * needed to properly reach and/or free the data afterwards.
1227 * @param stride_length is set to the stride length of the returned data.
1228 * @param n_particles is set to the number of particles in the returned data. This is
1229 * needed to properly reach and/or free the data afterwards.
1230 * @param n_values_per_frame is set to the number of values per frame in the data.
1231 * This is needed to properly reach and/or free the data afterwards.
1232 * @param type is set to the data type of the data in the array.
1233 * @details This does only work for numerical (int, float, double) data.
1234 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1235 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1237 tng_function_status getParticleDataVector
1238 (const int64_t block_id,
1239 void **values,
1240 int64_t *n_frames,
1241 int64_t *stride_length,
1242 int64_t *n_particles,
1243 int64_t *n_values_per_frame,
1244 char *type)
1246 return status = tng_particle_data_vector_get(traj, block_id,
1247 values, n_frames,
1248 stride_length,
1249 n_particles,
1250 n_values_per_frame, type);
1255 * @brief Read and retrieve particle data, in a specific interval. Obsolete!
1256 * @details The particle dimension of the returned values array is translated
1257 * to real particle numbering, i.e. the numbering of the actual molecular
1258 * system.
1259 * @param block_id is the id number of the particle data block to read.
1260 * @param start_frame_nr is the index number of the first frame to read.
1261 * @param end_frame_nr is the index number of the last frame to read.
1262 * @param hash_mode is an option to decide whether to use the md5 hash or not.
1263 * If hash_mode == TNG_USE_HASH the md5 hash in the file will be
1264 * compared to the md5 hash of the read contents to ensure valid data.
1265 * @param values is a pointer to a 3-dimensional array (memory unallocated), which
1266 * will be filled with data. The array will be sized
1267 * (n_frames * n_particles * n_values_per_frame).
1268 * Since ****values is allocated in this function it is the callers
1269 * responsibility to free the memory.
1270 * @param n_particles is set to the number of particles in the returned data. This is
1271 * needed to properly reach and/or free the data afterwards.
1272 * @param n_values_per_frame is set to the number of values per frame in the data.
1273 * This is needed to properly reach and/or free the data afterwards.
1274 * @param type is set to the data type of the data in the array.
1275 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1276 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1278 tng_function_status getParticleDataInterval(const int64_t block_id,
1279 const int64_t start_frame_nr,
1280 const int64_t end_frame_nr,
1281 const tng_hash_mode hash_mode,
1282 union data_values ****values,
1283 int64_t *n_particles,
1284 int64_t *n_values_per_frame,
1285 char *type)
1287 return status = (tng_particle_data_interval_get(traj, block_id, start_frame_nr,
1288 end_frame_nr, hash_mode, values,
1289 n_particles, n_values_per_frame,
1290 type));
1295 * @brief Read and retrieve a vector (1D array) particle data, in a
1296 * specific interval.
1297 * @details The particle dimension of the returned values array is translated
1298 * to real particle numbering, i.e. the numbering of the actual molecular
1299 * system.
1300 * @param block_id is the id number of the particle data block to read.
1301 * @param start_frame_nr is the index number of the first frame to read.
1302 * @param end_frame_nr is the index number of the last frame to read.
1303 * @param hash_mode is an option to decide whether to use the md5 hash or not.
1304 * If hash_mode == TNG_USE_HASH the md5 hash in the file will be
1305 * compared to the md5 hash of the read contents to ensure valid data.
1306 * @param values is a pointer to a 1-dimensional array (memory unallocated), which
1307 * will be filled with data. The length of the array will be
1308 * (n_frames * n_particles * n_values_per_frame).
1309 * Since **values is allocated in this function it is the callers
1310 * responsibility to free the memory.
1311 * @param stride_length is set to the stride length (writing frequency) of
1312 * the data.
1313 * @param n_particles is set to the number of particles in the returned data. This is
1314 * needed to properly reach and/or free the data afterwards.
1315 * @param n_values_per_frame is set to the number of values per frame in the data.
1316 * This is needed to properly reach and/or free the data afterwards.
1317 * @param type is set to the data type of the data in the array.
1318 * @details This does only work for numerical (int, float, double) data.
1319 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1320 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1322 tng_function_status getParticleDataVectorInterval
1323 (const int64_t block_id,
1324 const int64_t start_frame_nr,
1325 const int64_t end_frame_nr,
1326 const tng_hash_mode hash_mode,
1327 void **values,
1328 int64_t *n_particles,
1329 int64_t *stride_length,
1330 int64_t *n_values_per_frame,
1331 char *type)
1333 return status = tng_particle_data_vector_interval_get(traj, block_id,
1334 start_frame_nr,
1335 end_frame_nr,
1336 hash_mode,
1337 values,
1338 n_particles,
1339 stride_length,
1340 n_values_per_frame,
1341 type);
1345 /** @brief Get the date and time of initial file creation in ISO format (string).
1346 * @param time is a pointer to the string in which the date will be stored. Memory
1347 must be reserved beforehand.
1348 * @return TNG_SUCCESS (0) if successful.
1350 tng_function_status getTimeStr(char *time)
1352 return status = tng_time_get_str(traj, time);
1362 class Molecule
1364 private:
1366 tng_molecule_t mol;
1367 Trajectory * traj;
1368 tng_function_status status;
1369 public:
1370 tng_function_status addChain(const char *name, Chain *chain);
1371 tng_function_status findChain(const char *name, int64_t id, Chain *chain);
1372 friend class Trajectory;
1373 //Constructor
1374 Molecule(Trajectory * trajectory)
1376 traj = trajectory;
1378 //status = tng_molecule_init(traj->traj,mol);
1381 *@Dose nothing, use ~TngMolecule()
1383 ~Molecule()
1385 status = tng_molecule_destroy(traj->traj,mol);
1387 //! Status
1388 tng_function_status getStatus()
1389 { return status; }
1393 * @brief Set the name of a molecule.
1394 * @param new_name is a string containing the wanted name.
1395 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1396 * error has occured.
1398 tng_function_status setName(const char *new_name)
1400 return status = tng_molecule_name_set(traj->traj,mol,new_name);
1404 * @brief Get the count of a molecule.
1405 * @param cnt is a pointer to the variable to be populated with the count.
1406 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1407 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1409 tng_function_status getCnt(int64_t *cnt)
1411 return status = tng_molecule_cnt_get(traj->traj,mol,cnt);
1415 * @brief Set the count of a molecule.
1416 * @param cnt is the number of instances of this molecule.
1417 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if a minor error
1418 * has occurred or TNG_CRITICAL (2) if a major error has occured.
1420 tng_function_status setCnt(int64_t cnt)
1422 return status = tng_molecule_cnt_set(traj->traj,mol,cnt);
1427 tng_function_status Trajectory::addMolecule(const char *name, Molecule_t molecule)
1429 return status = tng_molecule_add(traj,name, &molecule->mol);
1432 tng_function_status Trajectory::addMoleculeWithId
1433 (const char *name,
1434 const int64_t id,
1435 Molecule_t molecule)
1437 return status = tng_molecule_w_id_add(traj, name, id, &molecule->mol);
1441 * @brief Find a molecule.
1442 * @param tng_data is the trajectory data container containing the molecule.
1443 * @param name is a string containing the name of the molecule. If name is empty
1444 * only id will be used for finding the molecule.
1445 * @param id is the id of the molecule to look for. If id is -1 only the name of
1446 * the molecule will be used for finding the molecule.
1447 * @param molecule is a pointer to the molecule if it was found - otherwise 0.
1448 * @return TNG_SUCCESS (0) if the molecule is found or TNG_FAILURE (1) if the
1449 * molecule is not found.
1450 * @details If name is an empty string and id is -1 the first molecule will be
1451 * found.
1453 tng_function_status Trajectory::findMolecule
1454 (const char *name,
1455 int64_t id,
1456 Molecule_t molecule)
1458 return status = tng_molecule_find(traj, name, id,
1459 &molecule->mol);
1463 class Atom
1465 private:
1466 tng_atom_t atom;
1467 Trajectory * traj;
1468 tng_function_status status;
1469 public:
1470 friend class Residue;
1471 //constructor
1472 Atom(Trajectory * trajectory)
1474 traj = trajectory;
1476 //deonstructor
1478 *@Dose nothing, use ~TngMolecule()
1480 ~Atom()
1482 //delete atom;
1484 //! Status
1485 tng_function_status getStatus()
1486 { return status; }
1488 * @brief Set the name of an atom.
1489 * @param new_name is a string containing the wanted name.
1490 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1491 * error has occured.
1493 tng_function_status setName(const char *new_name)
1495 return status = tng_atom_name_set(traj->traj, atom , new_name);
1499 * @param new_type is a string containing the atom type.
1500 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1501 * error has occured.
1503 tng_function_status setType(const char *new_type)
1505 return status = tng_atom_type_set(traj->traj, atom, new_type);
1509 class Residue
1511 private:
1512 tng_residue_t residue;
1513 Trajectory * traj;
1514 tng_function_status status;
1515 public:
1516 friend class Chain;
1517 //constructor
1518 Residue(Trajectory * trajectory)
1520 traj = trajectory;
1522 //deonstructor
1524 *@Dose nothing, use ~TngMolecule()
1526 ~Residue()
1528 //delete residue;
1530 //! Status
1531 tng_function_status getStatus()
1532 { return status; }
1534 * @brief Set the name of a residue.
1535 * @param residue is the residue to rename.
1536 * @param new_name is a string containing the wanted name.
1537 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1538 * error has occured.
1540 tng_function_status setName(const char *new_name)
1542 return status = tng_residue_name_set(traj->traj, residue,new_name);
1546 * @brief Add an atom to a residue.
1547 * @param atom_name is a string containing the name of the atom.
1548 * @param atom_type is a string containing the atom type of the atom.
1549 * @param atom is a pointer to the newly created atom.
1550 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1551 * error has occured.
1553 tng_function_status addAtom(const char *atom_name,
1554 const char *atom_type,
1555 Atom * atom)
1557 return status = tng_residue_atom_add(traj->traj, residue, atom_name,
1558 atom_type, &atom->atom);
1563 * @brief Add an atom with a specific ID to a residue.
1564 * @param atom_name is a string containing the name of the atom.
1565 * @param atom_type is a string containing the atom type of the atom.
1566 * @param id is the ID of the created atom.
1567 * @param atom is a pointer to the newly created atom.
1568 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if the ID could
1569 * not be set properly or TNG_CRITICAL (2) if a major error has occured.
1571 tng_function_status addAtomWithId
1572 (const char *atom_name,
1573 const char *atom_type,
1574 const int64_t id,
1575 Atom * atom)
1577 return status = tng_residue_atom_w_id_add(traj->traj, residue,
1578 atom_name, atom_type,
1579 id, &atom->atom);
1584 class Chain
1586 private:
1587 tng_chain_t chain;
1588 Trajectory * traj;
1589 tng_function_status status;
1590 public:
1591 friend class Molecule;
1592 //constructor
1593 Chain(Trajectory * trajectory)
1595 traj = trajectory;
1597 //deonstructor
1599 *@Dose nothing, use ~TngMolecule()
1601 ~Chain()
1603 //delete chain;
1605 //! Status
1606 tng_function_status getStatus()
1607 { return status; }
1609 * @brief Set the name of a chain.
1610 * @param new_name is a string containing the wanted name.
1611 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1612 * error has occured.
1614 tng_function_status setName(const char *new_name)
1616 return status = tng_chain_name_set(traj->traj, chain, new_name);
1621 * @brief Find a residue in a chain.
1622 * @param name is a string containing the name of the residue.
1623 * @param id is the id of the residue to find. If id == -1 the first residue
1624 * that matches the specified name will be found.
1625 * @param residue is a pointer to the residue if it was found - otherwise 0.
1626 * @return TNG_SUCCESS (0) if the residue is found or TNG_FAILURE (1) if the
1627 * residue is not found.
1628 * @details If name is an empty string the first residue will be found.
1630 tng_function_status findResidue
1631 (const char *name,
1632 int64_t id,
1633 Residue *residue)
1635 return status = tng_chain_residue_find(traj->traj, chain, name,
1636 id, &residue->residue);
1640 * @brief Add a residue to a chain.
1641 * @param name is a string containing the name of the residue.
1642 * @param residue is a pointer to the newly created residue.
1643 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1644 * error has occured.
1646 tng_function_status addResidue(const char *name,
1647 Residue * residue)
1649 return status = tng_chain_residue_add(traj->traj, chain,
1650 name, &residue->residue);
1654 * @brief Add a residue with a specific ID to a chain.
1655 * @param name is a string containing the name of the residue.
1656 * @param id is the ID of the created residue.
1657 * @param residue is a pointer to the newly created residue.
1658 * @return TNG_SUCCESS (0) if successful, TNG_FAILURE (1) if the ID could
1659 * not be set properly or TNG_CRITICAL (2) if a major error has occured.
1661 tng_function_status addResidueWithId
1662 (const char *name,
1663 const int64_t id,
1664 Residue * residue)
1666 return status = tng_chain_residue_w_id_add(traj->traj, chain,
1667 name, id, &residue->residue);
1672 * @brief Add a chain to a molecule.
1673 * @param name is a string containing the name of the chain.
1674 * @param chain s a pointer to the newly created chain.
1675 * @return TNG_SUCCESS (0) if successful or TNG_CRITICAL (2) if a major
1676 * error has occured.
1678 tng_function_status Molecule::addChain(const char *name, Chain *chain)
1680 return status = tng_molecule_chain_add(traj->traj,mol,name,&chain->chain);
1684 * @brief Find a chain in a molecule.
1685 * @param name is a string containing the name of the chain. If name is empty
1686 * only id will be used for finding the chain.
1687 * @param id is the id of the chain to look for. If id is -1 only the name of
1688 * the chain will be used for finding the chain.
1689 * @param chain is a pointer to the chain if it was found - otherwise 0.
1690 * @return TNG_SUCCESS (0) if the chain is found or TNG_FAILURE (1) if the
1691 * chain is not found.
1692 * @details If name is an empty string and id is -1 the first chain will be
1693 * found.
1695 tng_function_status Molecule::findChain
1696 (const char *name,
1697 int64_t id,
1698 Chain *chain)
1700 return status = tng_molecule_chain_find(traj->traj, mol, name, id,
1701 &chain->chain);
1705 #endif