# Writing the trajectory of a smaller volume of the simulation box

**URL:** <https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377>\
**Category:** User discussions\
**Created:** [June 25, 2020, 9:50pm UTC](https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377 "2020-06-25T21:50:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yasser.almeida](https://avatars.discourse-cdn.com/v4/letter/y/76d3ee/32.png) [@yasser.almeida](https://gromacs.bioexcel.eu/u/yasser.almeida)\
**Post date:** [June 25, 2020, 9:50pm UTC](https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377/1 "2020-06-25T21:50:49Z")

</div>

GROMACS version: \> = 2019.5  
GROMACS modification:  
Here post your question :

Hi all,  
How can I write the trajectory of a smaller volume (box and/or sphere) around the COM of a simulation box?

Thanks in advance.

Best.

---

<div class="post-metadata">

**Author:** ![cblau](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/cblau/32/5_2.png) [@cblau](https://gromacs.bioexcel.eu/u/cblau)\
**Post date:** [June 26, 2020, 12:31pm UTC](https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377/2 "2020-06-26T12:31:23Z")

</div>

Hi Yasser,

This is a bit more tricky than it seems, because the number of atoms will change dynamically for that and the most widely used trajectory format `.xtc` does not support this.

You can however patch together such a trajectory using `gmx select` to define a matching selection, see  
[http://manual.gromacs.org/documentation/current/onlinehelp/selections.html](http://manual.gromacs.org/documentation/current/onlinehelp/selections.html)

and use something like  
`within 1 of [1.2, 3.1, 2.4]`

together with `-on` that will give you an index file for a specific frame that you then can write out using `trjconv` or similar tools.

You can also use these dynamic selections in a bunch of analysis tools, so you might be able to skip writing the trajectory at all and just analyse the properties you want directly from the unfiltered trajectory.

---

<div class="post-metadata">

**Author:** ![yasser.almeida](https://avatars.discourse-cdn.com/v4/letter/y/76d3ee/32.png) [@yasser.almeida](https://gromacs.bioexcel.eu/u/yasser.almeida)\
**Post date:** [June 26, 2020, 8:19pm UTC](https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377/3 "2020-06-26T20:19:19Z")

</div>

Hi cblau,

Thank you very much for the tip. In my case, I do need the trajectory because I need to analyze some properties during the simulation in a certain region of the box.

I haven’t used `gmx select` before, but if I got it properly, in principle, with that command I could write the content of that region in a certain frame, and then concatenate all frames in a trajectory, right?

Best,  
Yasser

---

<div class="post-metadata">

**Author:** ![cblau](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/cblau/32/5_2.png) [@cblau](https://gromacs.bioexcel.eu/u/cblau)\
**Post date:** [June 30, 2020, 9:53am UTC](https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377/4 "2020-06-30T09:53:43Z")

</div>

Hi Yasser,

Only to some extent - you will be able to write out all the coordinates, but concatenating is more difficult. If you use `.pdb` or `.gro` for writing out the frames and then concatenate them to a trajectory that should work, but most other trajectory formats expect the same number of atoms for every frame.

---

<div class="post-metadata">

**Author:** ![yasser.almeida](https://avatars.discourse-cdn.com/v4/letter/y/76d3ee/32.png) [@yasser.almeida](https://gromacs.bioexcel.eu/u/yasser.almeida)\
**Post date:** [June 30, 2020, 12:13pm UTC](https://gromacs.bioexcel.eu/t/writing-the-trajectory-of-a-smaller-volume-of-the-simulation-box/377/5 "2020-06-30T12:13:24Z")

</div>

Hi cblau,

In that case, it should be fine in principle, because the tool I am using for the trajectory characterization only accepts `.gro` format.

Thanks again.  
Best
