m3g / packmol

Packmol - Initial configurations for molecular dynamics simulations
http://m3g.github.io/packmol
MIT License
214 stars 48 forks source link

packmol cannot handle paths with spaces #27

Closed rkingsbury closed 2 years ago

rkingsbury commented 2 years ago

Thank you for developing this very useful tool! I have noticed that packmol is not able to accommodate paths that contain spaces, even when standard Unix terminal conventions like escaping or quoting the path are followed. For example, if I place the input files from the "water and urea" example from the documentation in a subdirectory called 'folder with space' and then execute either

packmol < folder\ with\ space/mixture.inp

or

packmol < "folder with space/mixture.inp"

packmol fails with

  ERROR: Could not open file.
         Could not find file: water.pdb
         Please check if all the input and structure
         files are in the current directory or if the
         correct paths are provided.

The same error occurs if mixture.inp is in the current working directory, but references *.pdb files located in the subdirectory, e.g.:

#
# A mixture of water and urea
#

tolerance 2.0
filetype pdb
output mixture.pdb

structure folder\ with\ space/water.pdb
  number 1000
  inside box 0. 0. 0. 40. 40. 40.
end structure

structure folder\ with\ space/urea.pdb
  number 400
  inside box 0. 0. 0. 40. 40. 40.
end structure

Whereas a directory name without spaces works properly.

The above testing was done on Mac OS, though I have observed similar behavior on linux (Windows 10 WSL2, Ubuntu)

Being able to call packmol on files stored in subdirectories that may contain spaces is important because users may not always have the option of renaming directories. This capability would be especially helpful when carrying out large numbers of calculations, as we do in the Materials Project. Is there a way the path parsing routines used by packmol could be modified to accommodate standard Unix conventions for space-containing paths?

lmiq commented 2 years ago

Should be fixed in 20.3.0, you can use both quotes or \ to set spaces:

tolerance 2.0
filetype pdb
output ./path\ with\ space/mixture.pdb

structure "path with space/water.pdb"
  number 1000 
  inside box 0. 0. 0. 40. 40. 40. 
end structure

structure ./path\ with\ space/urea.pdb
  number 400
  inside box 0. 0. 0. 40. 40. 40. 
end structure
lmiq commented 2 years ago

Note: the paths cannot contain the "~" character. If that is a problem, please let me know. The character that is temporarily used to handle spaces is defined here:

https://github.com/m3g/packmol/blob/master/input.f90#L67

rkingsbury commented 2 years ago

Thank you very much for your speedy attention to this!