# Question regarding box deform angle limit

**URL:** https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331
**Category:** User discussions
**Tags:** mdrun
**Created:** [June 21, 2022, 9:43pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331 "2022-06-21T21:43:13Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Hugowan](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hugowan](https://gromacs.bioexcel.eu/u/Hugowan)
#### Post date: [June 21, 2022, 9:43pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/1 "2022-06-21T21:43:13Z")

</div>

GROMACS version: 2020.6  
GROMACS modification: No  
I have used the deform function in Gromacs-2020.6. However, when the deform was bigger than 30 degrees, the box was changed to another direction. I attached the images here. ( The image is the frame, where the deform angle is bigger than 30)

 ![2_frame](https://europe1.discourse-cdn.com/flex017/uploads/bioexcel1/original/2X/2/235801de5e71ba9e036f2884cfab3689c9ee3416.jpeg)

In this situation, if I want to continue the shear deformation in this direction, what should I do ??

Appreciating your precious suggestion in advance!

---

<div class="post-metadata">

### Author: ![MichelePellegrino](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/michelepellegrino/32/628_2.png) [@MichelePellegrino](https://gromacs.bioexcel.eu/u/MichelePellegrino)
#### Post date: [June 22, 2022, 1:14pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/2 "2022-06-22T13:14:19Z")

</div>

Hi,

My understanding is that Gromacs utilizes what’s called _modular invariance_ to reset the box and prevent it to deform too much. Basically, if the initial box were cubic with side length _L_ and were deformed in a off diagonal direction with speed _u_, at time _t_ such that _t=L/(2u)_ you would see the box ‘jumping’ as your image shows.

For liquid that’s preferable, since they react to deformation rates and you would keep like to keep shearing indefinitely. For solids (I don’t know what your systems is but it is too ordered to be a liquid)… I think there is no workaround: modular invariance is hardcoded in Gromacs, anyone correct me if I am wrong.

---

<div class="post-metadata">

### Author: ![MichelePellegrino](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/michelepellegrino/32/628_2.png) [@MichelePellegrino](https://gromacs.bioexcel.eu/u/MichelePellegrino)
#### Post date: [June 22, 2022, 1:52pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/3 "2022-06-22T13:52:22Z")

</div>

If you want, you can try and edit `BoxDeformation::apply` in `src/gromacs/mdlib/boxdeformation.cpp`, removing the for loop that does the reset:

```auto
/* We correct the off-diagonal elements,
     * which can grow indefinitely during shearing,
     * so the shifts do not get messed up.
     */
    for (int i = 1; i < DIM; i++)
    {
        for (int j = i - 1; j >= 0; j--)
        {
            while (updatedBox[i][j] - box[i][j] > 0.5 * updatedBox[j][j])
            {
                rvec_dec(updatedBox[i], updatedBox[j]);
            }
            while (updatedBox[i][j] - box[i][j] < -0.5 * updatedBox[j][j])
            {
                rvec_inc(updatedBox[i], updatedBox[j]);
            }
        }
    }

```

But I cannot predict the side effects :-|

---

<div class="post-metadata">

### Author: ![Hugowan](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hugowan](https://gromacs.bioexcel.eu/u/Hugowan)
#### Post date: [June 22, 2022, 6:39pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/4 "2022-06-22T18:39:17Z")

</div>

Thank your very much, I will do some tests.

Best

---

<div class="post-metadata">

### Author: ![Hugowan](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hugowan](https://gromacs.bioexcel.eu/u/Hugowan)
#### Post date: [June 23, 2022, 4:54am UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/5 "2022-06-23T04:54:17Z")

</div>

Hello Pellegrino

If I want to increase the deformation angle, for example, up to 60 degrees, what should I do to change this code?

Best

---

<div class="post-metadata">

### Author: ![MichelePellegrino](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/michelepellegrino/32/628_2.png) [@MichelePellegrino](https://gromacs.bioexcel.eu/u/MichelePellegrino)
#### Post date: [June 23, 2022, 8:01am UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/6 "2022-06-23T08:01:21Z")

</div>

Hi,

I don’t think the checked criterion is on the deformation angle itself, but rather on the deformation tensor (that is: you would probably reach a different max angle if your simulation box were taller or shorter).

Nevertheless, I tried to removed that for loop and my run crashed, so I don’t think there is a easy fix.

---

<div class="post-metadata">

### Author: ![Hugowan](https://avatars.discourse-cdn.com/v4/letter/h/6de8d8/32.png) [@Hugowan](https://gromacs.bioexcel.eu/u/Hugowan)
#### Post date: [June 23, 2022, 8:41am UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/7 "2022-06-23T08:41:40Z")

</div>

Thanks for your reply.  
Would you mind paraphrasing the details regarding the deformation tensor in the boxdefromation.cpp file? I am still confused.

Appreciating in advance

---

<div class="post-metadata">

### Author: ![Ema2022](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Ema2022](https://gromacs.bioexcel.eu/u/Ema2022)
#### Post date: [February 12, 2025, 11:08am UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/8 "2025-02-12T11:08:11Z")

</div>

Hi,  
My polymer material is viscoelastic. I did shear deformation in xz-plane and I observed box is more deformed than the polymer. Can we avoid this in deformation simulation? I used deformation rate as 10e-4 nm ps-1. My aim to calculate shear modulus and Young’s modulus of the material.

 ![Screenshot from 2025-02-12 11-08-00](https://europe1.discourse-cdn.com/flex017/uploads/bioexcel1/original/2X/c/c3d97880f470aa58c4b07fdb66a71dc88438c656.jpeg)

---

<div class="post-metadata">

### Author: ![MichelePellegrino](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/michelepellegrino/32/628_2.png) [@MichelePellegrino](https://gromacs.bioexcel.eu/u/MichelePellegrino)
#### Post date: [February 14, 2025, 3:52pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/9 "2025-02-14T15:52:22Z")

</div>

Hi,  
I am pretty sure that’s just a visualization “issue”, probably having to do on how the coordinates are mapped to the triclininc box. I was seeng the same thing when testing the deform code on water.  
The deformation rate itself doesn’t seem to large to me, you should do a convergence study by taking smaller and smaller rates.

---

<div class="post-metadata">

### Author: ![Ema2022](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Ema2022](https://gromacs.bioexcel.eu/u/Ema2022)
#### Post date: [February 14, 2025, 8:41pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/10 "2025-02-14T20:41:21Z")

</div>

Thank you for your response. I checked the coordinates of the .gro file. Unfortunately, while the box has deformed into a triclinic shape, the polymer remains confined within a rectangular form in 3D. Only the box seems deformed, but the polymer remains unchanged. Please advise to overcome this.

---

<div class="post-metadata">

### Author: ![MichelePellegrino](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/michelepellegrino/32/628_2.png) [@MichelePellegrino](https://gromacs.bioexcel.eu/u/MichelePellegrino)
#### Post date: [February 17, 2025, 3:45pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/11 "2025-02-17T15:45:14Z")

</div>

Again. I think it’s just the effect of mapping between triclining and orthogonal box when coordinates are dumped. For the calculation of viscosity the “absolute” position of particles are not important, velocities are.  
Have you looked at the relation between deformation velocity and shear stresses? Is it reasonable?

---

<div class="post-metadata">

### Author: ![hess](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/hess/32/416_2.png) [@hess](https://gromacs.bioexcel.eu/u/hess)
#### Post date: [February 18, 2025, 11:50am UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/12 "2025-02-18T11:50:35Z")

</div>

I only noticed the original post now. There is no issue at all here, apart from visualization. Change or no change in box direction is mathematically fully equivalent. The behavior of the system is identical in both cases.

---

<div class="post-metadata">

### Author: ![Ema2022](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@Ema2022](https://gromacs.bioexcel.eu/u/Ema2022)
#### Post date: [February 21, 2025, 1:23pm UTC](https://gromacs.bioexcel.eu/t/question-regarding-box-deform-angle-limit/4331/13 "2025-02-21T13:23:13Z")

</div>

Thanks a lot.
