cmelab / polybinder

Initialization of thermoplastic polymer systems to simulate thermal welding
GNU General Public License v3.0
2 stars 5 forks source link

Particle out of box errors when trying to create gsd #6

Closed chrisjonesBSU closed 3 years ago

chrisjonesBSU commented 3 years ago

I keep getting particle out of box errors (they are pretty much sitting on the boundaries of the box)

*Warning*: pos 650:-8.92007446289 -21.2003688812 17.5756092072
*Warning*: fractional pos :0.289598673582 -6.15004901192e-05 0.914562821388
*Warning*: lo: -21.1977615356 -21.1977615356 -21.1977615356
*Warning*: hi: 21.1977615356 21.1977615356 21.1977615356
*Warning*: Not all particles were found inside the given box

Hoomd errors out before a simulation is started, it looks like it happens when trying to read the snapshot. So, the issue might lie somewhere in mbuild's hoomd_snapshot.py when preparing the snapshot.

~/miniconda3/envs/uli/lib/python3.7/site-packages/mbuild/formats/hoomd_simulation.py in create_hoomd_simulation(structure, ref_distance, ref_mass, ref_energy, r_cut, auto_scale, snapshot_kwargs, pppm_kwargs)
    110             ref_mass=ref_mass, ref_energy=ref_energy, **snapshot_kwargs)
    111     hoomd_objects.append(snapshot)
--> 112     hoomd.init.read_snapshot(snapshot)
    113 
    114     nl = hoomd.md.nlist.cell()

~/bin/hoomd-blue/build/hoomd/init.py in read_snapshot(snapshot)
    243         hoomd.context.current.system_definition = _hoomd.SystemDefinition(snapshot, hoomd.context.exec_conf, my_domain_decomposition);
    244     else:
--> 245         hoomd.context.current.system_definition = _hoomd.SystemDefinition(snapshot, hoomd.context.exec_conf);
    246 
    247     # initialize the system

RuntimeError: Error initializing ParticleData
chrisjonesBSU commented 3 years ago

Here is what I think is happening:

  1. The parmed box goes from 0 to L
  2. When shift_coords = True in hoomd_snapshot.py it shifts everything by half of the box length, so that the coordinates of everything spans from -L/2 to L/2. I think that when a particle is near the center of the box, it is then being moved right on or near one of the box boundaries.
  3. When shift_coords is set to False then the particles aren't shifted, but the box generated by Hoomd is still -L/2 to L/2, so we still get particle out of box errors, but they aren't right on one of the box boundaries.

I'm not really sure how or where the box is being generated as -L/2 to L/2. that is one potential fix.

A couple other ideas:

  1. Try to update the box size after particles are shifted, make it just a little bit larger

  2. There might be an option to wrap the coordinates somewhere in mBuild and/or Hoomd

chrisjonesBSU commented 3 years ago

I think I've found a solution; temporary at least..

In hoomd_snapshot.py I just multiplied the shifted xyz postions by a number really close to, but less than 1. This should move any particle that is right on the cusp of the box to just slightly inside. So far, it is no longer resulting in particle out of box errors.

The relevant bit of code in hoomd_snapshot.py:

xyz = np.array([[atom.xx, atom.xy, atom.xz] for atom in structure.atoms])
if shift_coords:
    xyz = coord_shift(xyz, structure.box[:3])  --> This can result in particles on box edge or just slightly over
    xyz *= 0.98  --> The fix, moves everything back in a little bit.

I'll open up an issue in mBuild for this. Maybe this isn't the ultimate solution, but it will be worth bringing up.

chrisjonesBSU commented 3 years ago

I think for now, the fix for this is to install from my fork of mbuild. I'll create the fork, add the fix and update the install instructions and environment.yml file to install mbuild from that fork. I'll raise an issue in mBuild, but we'll see how long it takes before its implemented.

chrisjonesBSU commented 3 years ago

Solved by PR #12